-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature_forecast.py
54 lines (48 loc) · 2.23 KB
/
temperature_forecast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from numpy import empty
from numpy import log, exp
from read_metadata import read_satellite_step
from read_netcdf import read_temperature_forecast
from utils import get_nb_slots_per_day
def prepare_temperature_mask(lats, lons, beginning, ending, slot_step=1):
"""
Create a temperature mask which has the same temporal sampling than spectral channels
:param lats: latitudes array
:param lons: longitudes array
:param beginning: dfb beginning sampling
:param ending: dfb ending sampling
:param slot_step: slot sampling chosen by the user (probably 1)
:return:
"""
satellite_step = read_satellite_step()
nb_slots = get_nb_slots_per_day(satellite_step, slot_step) * (
ending - beginning + 1
)
temperatures = read_temperature_forecast(lats, lons, beginning, ending)
to_return = empty((nb_slots, len(lats), len(lons)))
for slot in range(nb_slots):
try:
nearest_temp_meas = int(0.5 + satellite_step * slot_step * slot / 60)
to_return[slot] = temperatures[nearest_temp_meas] + 273.15
except IndexError:
nearest_temp_meas = int(satellite_step * slot_step * slot / 60)
to_return[slot] = temperatures[nearest_temp_meas] + 273.15
return to_return
def expected_brightness_temperature_only_emissivity(forecast_temperature, lw_nm, eps):
"""
Compute the brightness temperature we can reasonably expect from the temperature forecast, the wavelength lw and
the emissivity parameter ems
NB: if there is also infrared reflectance, the observed brightness temperature will be superior to this "expected" brightness
NB: this function is designed for clouds recognition (their characteristics are low emissivity & very low reflectance in long infrared)
:param forecast_temperature:
:param lw_nm: the wavelength (in nanometers) of the brightness temperature we want compute
:param eps: the emissivity parameter (in [0, 1]). EG typical emissivity of snow is up to 0.95
:return: the expected brightness
"""
c = 3.0 * 10**8
h = 6.626 * 10 ** (-34)
k = 1.38 * 10 ** (-23)
K = h / k
nu = c / lw_nm
return 1.0 / (
1 / (K * nu) * log(1 + (exp(K * nu / forecast_temperature) - 1) / eps)
)