STIC-JPL 1.1.0__py3-none-any.whl → 1.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of STIC-JPL might be problematic. Click here for more details.

STIC_JPL/model.py ADDED
@@ -0,0 +1,372 @@
1
+ from typing import Union, Callable
2
+ import logging
3
+ from datetime import datetime, timedelta
4
+ from os.path import join, abspath, expanduser
5
+ from typing import Dict, List
6
+ import numpy as np
7
+ import warnings
8
+
9
+ from pytictoc import TicToc
10
+
11
+ import colored_logging as cl
12
+ from check_distribution import check_distribution
13
+ import rasters as rt
14
+ from GEOS5FP import GEOS5FP
15
+ from solar_apparent_time import solar_day_of_year_for_area, solar_hour_of_day_for_area
16
+ from SEBAL_soil_heat_flux import calculate_SEBAL_soil_heat_flux
17
+
18
+ from rasters import Raster, RasterGeometry
19
+
20
+ from .constants import *
21
+ from .closure import STIC_closure
22
+ from .soil_moisture_initialization import initialize_soil_moisture
23
+ from .soil_moisture_iteration import iterate_soil_moisture
24
+ from .net_radiation import calculate_net_longwave_radiation
25
+ from .initialize_with_solar import initialize_with_solar
26
+ from .canopy_air_stream import calculate_canopy_air_stream_vapor_pressure
27
+ from .initialize_without_solar import initialize_without_solar
28
+ from .iterate_with_solar import iterate_with_solar
29
+ from .iterate_without_solar import iterate_without_solar
30
+ from .root_zone_initialization import calculate_root_zone_moisture
31
+ from .FVC_from_NDVI import FVC_from_NDVI
32
+ from .LAI_from_NDVI import LAI_from_NDVI
33
+ from .celcius_to_kelvin import celcius_to_kelvin
34
+
35
+ __author__ = 'Kaniska Mallick, Madeleine Pascolini-Campbell, Gregory Halverson'
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+ def STIC_JPL(
40
+ ST_C: Union[Raster, np.ndarray],
41
+ emissivity: Union[Raster, np.ndarray],
42
+ NDVI: Union[Raster, np.ndarray],
43
+ albedo: Union[Raster, np.ndarray],
44
+ Rn_Wm2: Union[Raster, np.ndarray],
45
+ geometry: RasterGeometry = None,
46
+ time_UTC: datetime = None,
47
+ hour_of_day: np.ndarray = None,
48
+ day_of_year: np.ndarray = None,
49
+ GEOS5FP_connection: GEOS5FP = None,
50
+ Ta_C: Union[Raster, np.ndarray] = None,
51
+ RH: Union[Raster, np.ndarray] = None,
52
+ G: Union[Raster, np.ndarray] = None,
53
+ G_method: str = DEFAULT_G_METHOD,
54
+ SM: Union[Raster, np.ndarray] = None,
55
+ Rg_Wm2: Union[Raster, np.ndarray] = None,
56
+ FVC: Union[Raster, np.ndarray] = None,
57
+ LAI: Union[Raster, np.ndarray] = None,
58
+ elevation_m: Union[Raster, np.ndarray] = None,
59
+ delta_hPa: Union[Raster, np.ndarray] = None,
60
+ gamma_hPa: Union[Raster, np.ndarray, float] = GAMMA_HPA,
61
+ rho_kgm3: Union[Raster, np.ndarray] = RHO_KGM3,
62
+ Cp_Jkg: Union[Raster, np.ndarray] = CP_JKG,
63
+ alpha: float = PT_ALPHA,
64
+ LE_convergence_target: float = LE_CONVERGENCE_TARGET_WM2,
65
+ max_iterations: int = MAX_ITERATIONS,
66
+ diagnostic_directory: str = None,
67
+ show_distributions: bool = SHOW_DISTRIBUTIONS,
68
+ use_variable_alpha: bool = USE_VARIABLE_ALPHA) -> Dict[str, Union[Raster, np.ndarray]]:
69
+ results = {}
70
+
71
+ if geometry is None and isinstance(ST_C, Raster):
72
+ geometry = ST_C.geometry
73
+
74
+ if GEOS5FP_connection is None:
75
+ GEOS5FP_connection = GEOS5FP()
76
+
77
+ if (day_of_year is None or hour_of_day is None) and time_UTC is not None and geometry is not None:
78
+ day_of_year = solar_day_of_year_for_area(time_UTC=time_UTC, geometry=geometry)
79
+ hour_of_day = solar_hour_of_day_for_area(time_UTC=time_UTC, geometry=geometry)
80
+
81
+ if time_UTC is None and day_of_year is None and hour_of_day is None:
82
+ raise ValueError("no time given between time_UTC, day_of_year, and hour_of_day")
83
+
84
+ diag_kwargs = {
85
+ "show_distributions": show_distributions,
86
+ "output_directory": diagnostic_directory
87
+ }
88
+
89
+ seconds_of_day = hour_of_day * 3600.0
90
+
91
+ # load air temperature in Celsius if not provided
92
+ if Ta_C is None:
93
+ Ta_C = GEOS5FP_connection.Ta_C(time_UTC=time_UTC, geometry=geometry, resampling=resampling)
94
+
95
+ # load relative humidity if not provided
96
+ if RH is None:
97
+ RH = GEOS5FP_connection.RH(time_UTC=time_UTC, geometry=geometry, resampling=resampling)
98
+
99
+ # calculate fraction of vegetation cover if it's not given
100
+ if FVC is None:
101
+ FVC = FVC_from_NDVI(NDVI)
102
+
103
+ # calculate leaf area index if it's not given
104
+ if LAI is None:
105
+ LAI = LAI_from_NDVI(NDVI)
106
+
107
+ # saturation air pressure in hPa
108
+ SVP_hPa = 6.13753 * (np.exp((17.27 * Ta_C) / (Ta_C + 237.3)))
109
+
110
+ # calculate delta term if it's not given
111
+ if delta_hPa is None:
112
+ # slope of saturation vapor pressure to air temperature (hpa/K)
113
+ delta_hPa = 4098 * SVP_hPa / (Ta_C + 237.3) ** 2
114
+
115
+ Ta_K = celcius_to_kelvin(Ta_C)
116
+
117
+ # actual vapor pressure at TA (hpa/K)
118
+ Ea_hPa = SVP_hPa * (RH)
119
+ Ea_Pa = Ea_hPa * 100.0
120
+
121
+ # vapor pressure deficit (hPa)
122
+ VPD_hPa = SVP_hPa - Ea_hPa
123
+
124
+ # swapping in the dew-point calculation from PT-JPL
125
+ Td_C = Ta_C - ((100 - RH * 100) / 5.0)
126
+
127
+ # difference between surface and air temperature (Celsius)
128
+ dTS_C = ST_C - Ta_C
129
+
130
+ # saturation vapor pressure at surface temperature (hPa/K)
131
+ Estar_hPa = 6.13753 * np.exp((17.27 * ST_C) / (ST_C + 237.3))
132
+
133
+ if Rg_Wm2 is None:
134
+ # if G is None and SM is None:
135
+ # raise ValueError("soil heat flux or soil moisture prior required if solar radiation is not given")
136
+
137
+ if G is None:
138
+ G = calculate_SEBAL_soil_heat_flux(
139
+ ST_C=ST_C,
140
+ NDVI=NDVI,
141
+ albedo=albedo,
142
+ Rn=Rn_Wm2,
143
+ )
144
+
145
+ phi_Wm2 = Rn_Wm2 - G
146
+
147
+ # initialize without solar radiation
148
+ SM, SMrz, s1, s3, s33, s44, Ms, Tsd_C, Es_hPa, Ds = initialize_without_solar(
149
+ ST_C = ST_C, # Surface temperature in Celsius
150
+ Ta_C = Ta_C, # Air temperature in Celsius
151
+ dTS = dTS_C, # Temperature difference between surface and air in Celsius
152
+ Td_C = Td_C, # Dewpoint temperature in Celsius
153
+ Ea_hPa = Ea_hPa, # Actual vapor pressure in hPa
154
+ Estar_hPa = Estar_hPa, # Saturation vapor pressure at surface temperature (hPa/K)
155
+ SVP_hPa = SVP_hPa, # Saturation vapor pressure at the surface in hPa
156
+ delta_hPa = delta_hPa, # Slope of the saturation vapor pressure-temperature curve in hPa/K
157
+ phi_Wm2 = phi_Wm2, # Available energy in W/m2
158
+ gamma_hPa = gamma_hPa, # Psychrometric constant in hPa/°C
159
+ alpha = alpha # Priestley-Taylor alpha
160
+ )
161
+ else:
162
+ SM, SMrz, Ms, s1, s3, Ep_PT, Rnsoil, LWnet_Wm2, G, Tsd_C, Ds, Es_hPa, phi_Wm2 = initialize_with_solar(
163
+ seconds_of_day = seconds_of_day, # time of day in seconds since midnight
164
+ Rg_Wm2 = Rg_Wm2, # solar radiation (W/m^2)
165
+ Rn_Wm2 = Rn_Wm2, # net radiation (W/m^2)
166
+ ST_C = ST_C, # surface temperature (Celsius)
167
+ emissivity = emissivity, # emissivity of the surface
168
+ Ta_C = Ta_C, # air temperature (Celsius)
169
+ dTS_C = dTS_C, # surface air temperature difference (Celsius)
170
+ Td_C = Td_C, # dew point temperature (Celsius)
171
+ VPD_hPa = VPD_hPa, # vapor pressure deficit (hPa)
172
+ SVP_hPa = SVP_hPa, # saturation vapor pressure at given air temperature (hPa)
173
+ Ea_hPa = Ea_hPa, # actual vapor pressure at air temperature (hPa)
174
+ Estar_hPa = Estar_hPa, # saturation vapor pressure at surface temperature (hPa)
175
+ delta_hPa = delta_hPa, # slope of saturation vapor pressure to air temperature (hpa/K)
176
+ NDVI=NDVI, # normalized difference vegetation index
177
+ FVC = FVC, # fractional vegetation cover
178
+ LAI = LAI, # leaf area index
179
+ albedo = albedo, # albedo of the surface
180
+ gamma_hPa=gamma_hPa, # psychrometric constant (hPa/°C)
181
+ G_method = DEFAULT_G_METHOD, # method for calculating soil heat flux
182
+ )
183
+
184
+ check_distribution(Ms, "Ms")
185
+
186
+ # STIC analytical equations (convergence on LE)
187
+ gB_ms, gS_ms, dT_C, EF = STIC_closure(
188
+ delta_hPa=delta_hPa,
189
+ phi_Wm2=phi_Wm2,
190
+ Es_hPa=Es_hPa,
191
+ Ea_hPa=Ea_hPa,
192
+ Estar_hPa=Estar_hPa,
193
+ SM=SM,
194
+ gamma_hPa=gamma_hPa,
195
+ rho_kgm3=rho_kgm3,
196
+ Cp_Jkg=Cp_Jkg,
197
+ alpha=alpha
198
+ )
199
+
200
+ gBB = gB_ms
201
+ gSS = gS_ms
202
+ gBB_by_gSS = rt.where(gSS == 0, 0, gBB / gSS)
203
+ gB_by_gS = rt.where(gS_ms == 0, 0, gB_ms / gS_ms)
204
+ dT_C = dT_C
205
+ T0_C = dT_C + Ta_C
206
+
207
+ PET_Wm2 = ((delta_hPa * phi_Wm2 + rho_kgm3 * Cp_Jkg * gB_ms * VPD_hPa) / (delta_hPa + gamma_hPa)) # Penman potential evaporation
208
+
209
+ gR = (4 * SB_SIGMA * (Ta_C + 273) ** 3 * emissivity) / (rho_kgm3 * Cp_Jkg)
210
+ omega = ((delta_hPa / gamma_hPa) + 1) / ((delta_hPa / gamma_hPa) + 1 + gB_by_gS)
211
+ LE_eq = (phi_Wm2 * (delta_hPa / gamma_hPa)) / ((delta_hPa / gamma_hPa) + 1)
212
+ LE_imp = (Cp_Jkg * 0.0289644 / gamma_hPa) * gS_ms * 40 * VPD_hPa
213
+ LE_init = omega * LE_eq + (1 - omega) * LE_imp
214
+ dry = (Ds > VPD_hPa) & (PET_Wm2 > phi_Wm2) & (dTS_C > 0) & (Td_C <= 0)
215
+ omega = rt.where(dry,
216
+ ((delta_hPa / gamma_hPa) + 1 + gR / gB_ms) / ((delta_hPa / gamma_hPa) + 1 + gB_ms / gS_ms + gR / gS_ms + gR / gB_ms),
217
+ omega)
218
+ LE_eq = rt.where(dry, (phi_Wm2 * (delta_hPa / gamma_hPa)) / ((delta_hPa / gamma_hPa) + 1 + gR / gB_ms), LE_eq)
219
+ LE_init = rt.where(dry, omega * LE_eq + (1 - omega * LE_imp), LE_init)
220
+
221
+ # sensible heat flux
222
+ H_Wm2 = ((gamma_hPa * phi_Wm2 * (1 + gB_by_gS) - rho_kgm3 * Cp_Jkg * gB_ms * VPD_hPa) / (delta_hPa + gamma_hPa * (1 + (gB_by_gS))))
223
+
224
+ LE_Wm2_new = LE_init
225
+ LE_Wm2_change = LE_convergence_target
226
+ LE_Wm2_old = LE_Wm2_new
227
+ LE_transpiration_Wm2 = None
228
+ PT_Wm2 = None
229
+ iteration = 1
230
+ LE_Wm2_max_change = 0
231
+
232
+ t = TicToc()
233
+ t.tic()
234
+
235
+ while (np.nanmax(LE_Wm2_change) >= LE_convergence_target and iteration <= max_iterations):
236
+ logger.info(f"running STIC iteration {cl.val(iteration)} / {cl.val(max_iterations)}")
237
+
238
+ if Rg_Wm2 is None:
239
+ SM, SMrz, Ms, s1, e0, e0star, Tsd_C, D0, alphaN = iterate_without_solar(
240
+ LE = LE_Wm2_new, # Latent heat flux (W/m^2)
241
+ PET = PET_Wm2, # Potential evapotranspiration (W/m^2)
242
+ SM = SM,
243
+ ST_C = ST_C, # Surface temperature (°C)
244
+ Ta_C = Ta_C, # Air temperature (°C)
245
+ dTS = dTS_C, # Surface-air temperature difference (°C)
246
+ T0 = T0_C, # Reference temperature (°C)
247
+ gB = gB_ms, # Boundary layer conductance (m/s)
248
+ gS = gS_ms, # Stomatal conductance (m/s)
249
+ Ea_hPa = Ea_hPa, # Actual vapor pressure (hPa)
250
+ Td_C = Td_C, # Dew point temperature (°C)
251
+ VPD_hPa = VPD_hPa, # Vapor pressure deficit (hPa)
252
+ Estar = Estar_hPa, # Saturation vapor pressure at surface temperature (hPa)
253
+ delta = delta_hPa, # Slope of the saturation vapor pressure-temperature curve (hPa/°C)
254
+ phi = phi_Wm2, # available energy (W/m^2)
255
+ Ds = Ds, # Vapor pressure deficit at source (hPa)
256
+ Es = Es_hPa, # Saturation vapor pressure (hPa)
257
+ s3 = s3, # Slope of the saturation vapor pressure and temperature
258
+ s4 = s44, # Slope of the saturation vapor pressure and temperature
259
+ gB_by_gS = gB_by_gS, # Ratio of boundary layer conductance to stomatal conductance
260
+ gamma_hPa = gamma_hPa, # Psychrometric constant (hPa/°C)
261
+ rho_kgm3 = rho_kgm3, # Air density (kg/m^3)
262
+ Cp_Jkg = Cp_Jkg # Specific heat at constant pressure (J/kg/K)
263
+ )
264
+ else:
265
+ SM, G, e0, e0star, D0, alphaN = iterate_with_solar(
266
+ seconds_of_day = seconds_of_day, # Seconds of the day
267
+ ST_C = ST_C, # Soil temperature (°C)
268
+ NDVI = NDVI, # Normalized Difference Vegetation Index
269
+ albedo = albedo, # Albedo
270
+ gB_ms = gB_ms, # boundary layer conductance (m/s)
271
+ gS_ms = gS_ms, # stomatal conductance (m/s)
272
+ LE_Wm2 = LE_Wm2_new, # latent heat flux (W/m^2)
273
+ Rg_Wm2 = Rg_Wm2, # Incoming solar radiation (W/m^2)
274
+ Rn_Wm2 = Rn_Wm2, # Net radiation (W/m^2)
275
+ LWnet_Wm2 = LWnet_Wm2, # Net longwave radiation (W/m^2)
276
+ Ta_C = Ta_C, # Air temperature (°C)
277
+ dTS_C = dTS_C, # Change in soil temperature (°C)
278
+ Td_C = Td_C, # Dew point temperature (°C)
279
+ Tsd_C = Tsd_C, # Soil dew point temperature (°C)
280
+ Ea_hPa = Ea_hPa, # actual vapor pressure (hPa)
281
+ Estar_hPa = Estar_hPa, # saturation vapor pressure at surface temperature (hPa)
282
+ VPD_hPa = VPD_hPa, # Vapor pressure deficit (hPa)
283
+ SVP_hPa = SVP_hPa, # Saturation vapor pressure (hPa)
284
+ delta_hPa = delta_hPa, # Slope of the saturation vapor pressure-temperature curve (hPa/°C)
285
+ phi_Wm2 = phi_Wm2, # Net radiation minus soil heat flux (W/m^2)
286
+ Es_hPa = Es_hPa, # Saturation vapor pressure (hPa)
287
+ s1 = s1, # Soil moisture parameter
288
+ s3 = s3, # Soil moisture parameter
289
+ FVC = FVC, # Fractional canopy cover
290
+ T0_C = T0_C, # Reference temperature (°C)
291
+ gB_by_gS = gB_by_gS, # Ratio of boundary layer conductance to stomatal conductance
292
+ gamma_hPa = gamma_hPa, # Psychrometric constant (hPa/°C)
293
+ rho_kgm3 = rho_kgm3, # Air density (kg/m^3)
294
+ Cp_Jkg = Cp_Jkg, # Specific heat at constant pressure (J/kg/K)
295
+ G_method = "santanello" # Method for calculating soil heat flux
296
+ )
297
+
298
+ if use_variable_alpha:
299
+ alpha = alphaN
300
+ logger.info(f"using variable Priestley-Taylor alpha with mean: {cl.val(np.round(np.nanmean(alpha), 3))}")
301
+
302
+ # re-estimated conductances and states
303
+ gB_ms, gS_ms, dT_C, EF = STIC_closure(
304
+ delta_hPa=delta_hPa, # Slope of the saturation vapor pressure-temperature curve (hPa/°C)
305
+ phi_Wm2=phi_Wm2, # available energy (W/m^2)
306
+ Es_hPa=Es_hPa, # Vapor pressure at the reference height (hPa)
307
+ Ea_hPa=Ea_hPa, # Actual vapor pressure (hPa)
308
+ Estar_hPa=Estar_hPa, # Saturation vapor pressure at the reference height (hPa)
309
+ SM=SM, # Soil moisture (m³/m³)
310
+ gamma_hPa=gamma_hPa, # Psychrometric constant (hPa/°C)
311
+ rho_kgm3=rho_kgm3, # Air density (kg/m³)
312
+ Cp_Jkg=Cp_Jkg, # Specific heat capacity of air (J/kg/°C)
313
+ alpha=alpha # Stability correction factor for conductance
314
+ )
315
+
316
+ gB_by_gS = rt.where(gS_ms == 0, 0, gB_ms / gS_ms)
317
+ T0_C = dT_C + Ta_C
318
+ # latent heat flux
319
+ LE_Wm2_new = ((delta_hPa * phi_Wm2 + rho_kgm3 * Cp_Jkg * gB_ms * VPD_hPa) / (delta_hPa + gamma_hPa * (1 + gB_by_gS)))
320
+ LE_Wm2_new = rt.where(LE_Wm2_new > phi_Wm2, phi_Wm2, LE_Wm2_new)
321
+ # Sensible Heat Flux
322
+ H_Wm2 = ((gamma_hPa * phi_Wm2 * (1 + gB_by_gS) - rho_kgm3 * Cp_Jkg * gB_ms * VPD_hPa) / (delta_hPa + gamma_hPa * (1 + (gB_by_gS))))
323
+ # potential evaporation (Penman)
324
+ PET_Wm2 = ((delta_hPa * phi_Wm2 + rho_kgm3 * Cp_Jkg * gB_ms * VPD_hPa) / (delta_hPa + gamma_hPa))
325
+ # Potential Transpiration
326
+ PT_Wm2 = (delta_hPa * phi_Wm2 + rho_kgm3 * Cp_Jkg * gB_ms * VPD_hPa) / (delta_hPa + gamma_hPa * (1 + SM * gB_by_gS)) # potential transpiration
327
+ # ET PARTITIONING
328
+ LE_soil_Wm2 = rt.clip(SM * PET_Wm2, 0, None)
329
+ LE_transpiration_Wm2 = rt.clip(LE_Wm2_new - LE_soil_Wm2, 0, None)
330
+ # change in latent heat flux estimate
331
+ LE_Wm2_change = np.abs(LE_Wm2_old - LE_Wm2_new)
332
+ LE_Wm2_new = rt.where(np.isnan(LE_Wm2_new), LE_Wm2_old, LE_Wm2_new)
333
+ LE_Wm2_old = LE_Wm2_new
334
+ LE_Wm2_max_change = np.nanmax(LE_Wm2_change)
335
+ logger.info(
336
+ f"completed STIC iteration {cl.val(iteration)} / {cl.val(max_iterations)} with max LE change: {cl.val(np.round(LE_Wm2_max_change, 3))} ({t.tocvalue()} seconds)")
337
+
338
+ check_distribution(SM, f"SM_{iteration}")
339
+ check_distribution(G, f"G_{iteration}")
340
+ check_distribution(LE_Wm2_new, f"LE_{iteration}")
341
+
342
+ if LE_Wm2_max_change <= LE_convergence_target:
343
+ logger.info(f"max LE change {cl.val(np.round(LE_Wm2_max_change, 3))} within convergence target {cl.val(np.round(LE_convergence_target, 3))} with {cl.val(iteration)} iteration{'s' if iteration > 1 else ''}")
344
+
345
+ iteration += 1
346
+
347
+ iteration -= 1
348
+ results["LE_max_change"] = LE_Wm2_max_change
349
+ results["iteration"] = iteration
350
+
351
+ LE = LE_Wm2_new
352
+
353
+ results["LE"] = LE
354
+ results["LE_change"] = LE_Wm2_change
355
+ results["LEt"] = LE_transpiration_Wm2
356
+ results["PT"] = PT_Wm2
357
+ results["PET"] = PET_Wm2
358
+ results["G"] = G
359
+
360
+ if isinstance(geometry, RasterGeometry):
361
+ for name, array in results.items():
362
+ try:
363
+ results[name] = Raster(array.reshape(geometry.shape), geometry=geometry)
364
+ except Exception as e:
365
+ pass
366
+
367
+ results["LE"].cmap = ET_COLORMAP
368
+ results["PET"].cmap = ET_COLORMAP
369
+
370
+ warnings.resetwarnings()
371
+
372
+ return results
@@ -0,0 +1,61 @@
1
+ import logging
2
+
3
+ import numpy as np
4
+ from dateutil import parser
5
+ from pandas import DataFrame
6
+ from rasters import Point
7
+ from sentinel_tiles import sentinel_tiles
8
+ from solar_apparent_time import UTC_to_solar
9
+ from SEBAL_soil_heat_flux import calculate_SEBAL_soil_heat_flux
10
+
11
+ from .model import STIC_JPL, MAX_ITERATIONS, USE_VARIABLE_ALPHA
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def process_STIC_table(
16
+ input_df: DataFrame,
17
+ max_iterations = MAX_ITERATIONS,
18
+ use_variable_alpha = USE_VARIABLE_ALPHA) -> DataFrame:
19
+ hour_of_day = np.float64(np.array(input_df.hour_of_day))
20
+ lon = np.float64(np.array(input_df.lon))
21
+ ST_C = np.float64(np.array(input_df.ST_C))
22
+ emissivity = np.float64(np.array(input_df.EmisWB))
23
+ NDVI = np.float64(np.array(input_df.NDVI))
24
+ albedo = np.float64(np.array(input_df.albedo))
25
+ Ta_C = np.float64(np.array(input_df.Ta_C))
26
+ RH = np.float64(np.array(input_df.RH))
27
+ Rn = np.float64(np.array(input_df.Rn))
28
+ Rg = np.float64(np.array(input_df.Rg))
29
+
30
+ if "G" in input_df:
31
+ G = np.array(input_df.G)
32
+ else:
33
+ G = calculate_SEBAL_soil_heat_flux(
34
+ Rn=Rn,
35
+ ST_C=ST_C,
36
+ NDVI=NDVI,
37
+ albedo=albedo
38
+ )
39
+
40
+ results = STIC_JPL(
41
+ hour_of_day=hour_of_day,
42
+ # longitude=lon,
43
+ ST_C = ST_C,
44
+ emissivity=emissivity,
45
+ NDVI=NDVI,
46
+ albedo=albedo,
47
+ Ta_C=Ta_C,
48
+ RH=RH,
49
+ Rn_Wm2=Rn,
50
+ G=G,
51
+ # Rg_Wm2=Rg,
52
+ max_iterations=max_iterations,
53
+ use_variable_alpha=use_variable_alpha
54
+ )
55
+
56
+ output_df = input_df.copy()
57
+
58
+ for key, value in results.items():
59
+ output_df[key] = value
60
+
61
+ return output_df
@@ -4,7 +4,8 @@ import numpy as np
4
4
  import rasters as rt
5
5
  from rasters import Raster
6
6
 
7
- from .vegetation_conversion.vegetation_conversion import FVC_from_NDVI
7
+ from .FVC_from_NDVI import FVC_from_NDVI
8
+ from .LAI_from_NDVI import LAI_from_NDVI
8
9
 
9
10
  from .constants import GAMMA_HPA
10
11
  from .root_zone_initialization import calculate_root_zone_moisture
STIC_JPL/version.txt CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.2.2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: STIC-JPL
3
- Version: 1.1.0
3
+ Version: 1.2.2
4
4
  Summary: Surface Temperature Initiated Closure (STIC) Evapotranspiration Model Python Implementation
5
5
  Author-email: Gregory Halverson <gregory.h.halverson@jpl.nasa.gov>, Kaniska Mallick <kaniska.mallick@list.lu>, Madeleine Pascolini-Campbell <madeleine.a.pascolini-campbell@jpl.nasa.gov>, "Claire S. Villanueva-Weeks" <claire.s.villanueva-weeks@jpl.gov>
6
6
  Project-URL: Homepage, https://github.com/JPL-Evapotranspiration-Algorithms/STIC-JPL
@@ -8,14 +8,21 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Operating System :: OS Independent
9
9
  Requires-Python: >=3.10
10
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: check-distribution
11
12
  Requires-Dist: colored-logging
12
- Requires-Dist: ECOv002-CMR
13
- Requires-Dist: ECOv002-granules
13
+ Requires-Dist: ECOv002-CMR>=1.0.5
14
+ Requires-Dist: ECOv002-granules>=1.0.3
15
+ Requires-Dist: ECOv003-granules
14
16
  Requires-Dist: GEOS5FP>=1.1.1
17
+ Requires-Dist: monte-carlo-sensitivity
15
18
  Requires-Dist: numpy
16
19
  Requires-Dist: pandas
17
- Requires-Dist: rasters
20
+ Requires-Dist: pytictoc
21
+ Requires-Dist: rasters>=1.4.6
22
+ Requires-Dist: seaborn
23
+ Requires-Dist: SEBAL-soil-heat-flux
18
24
  Requires-Dist: solar-apparent-time
25
+ Requires-Dist: verma-net-radiation>=1.1.0
19
26
  Provides-Extra: dev
20
27
  Requires-Dist: build; extra == "dev"
21
28
  Requires-Dist: pytest>=6.0; extra == "dev"
@@ -24,7 +31,8 @@ Requires-Dist: jupyter; extra == "dev"
24
31
  Requires-Dist: pytest; extra == "dev"
25
32
  Requires-Dist: twine; extra == "dev"
26
33
 
27
- # Surface Temperature Initiated Closure (STIC) Evapotranspiration Model Python Implementation
34
+ # `STIC-JPL`
35
+ ## Surface Temperature Initiated Closure (STIC) Evapotranspiration Model Python Implementation
28
36
 
29
37
  [![CI](https://github.com/JPL-Evapotranspiration-Algorithms/STIC/actions/workflows/ci.yml/badge.svg)](https://github.com/JPL-Evapotranspiration-Algorithms/STIC/actions/workflows/ci.yml)
30
38
 
@@ -63,21 +71,23 @@ NASA Jet Propulsion Laboratory 329G
63
71
 
64
72
  ## Installation
65
73
 
66
- Use the pip package manager to install the `STIC` PyPi package.
74
+ Use the pip package manager to install the `STIC-JPL` PyPi package with dashes in the name.
67
75
 
68
76
  ```
69
- pip install STIC
77
+ pip install STIC-JPL
70
78
  ```
71
79
 
72
80
  ## Usage
73
81
 
74
- Import the `STIC` function from the `STIC` package.
82
+ Import the `STIC_JPL` function from the `STIC_JPL` package with underscores in the name.
75
83
 
76
84
  ```
77
- from STIC import STIC
85
+ from STIC_JPL import STIC_JPL
78
86
  ```
79
87
 
80
- See the [ECOSTRESS example](ECOSTRESS%20Example.ipynb) for usage.
88
+ See the [ECOSTRESS example](ECOSTRESS%20Example.ipynb) notebook for usage.
89
+
90
+ See the [STIC sensitivity](STIC%20Sensitivity.ipynb) notebook for sensitivity analysis.
81
91
 
82
92
  ## References
83
93
 
@@ -0,0 +1,25 @@
1
+ STIC_JPL/FVC_from_NDVI.py,sha256=QiALDwRVoOmG9XLfQHZQhAfi8B7QuKc2cae6RIi9yYI,1852
2
+ STIC_JPL/LAI_from_NDVI.py,sha256=XgBIEtFG_sSAzNpb-v2E3rQ1HFoxw4gHhviQoiTVAPU,2529
3
+ STIC_JPL/STIC_JPL.py,sha256=qqxz7JOEHgmP_hoz1ZT_66v0WNs9R0SITRt-60rYb3I,127
4
+ STIC_JPL/__init__.py,sha256=FmTp-Ir0Wbae0SbZgxlNIxq48TDrWCev17Gv1hWskxU,216
5
+ STIC_JPL/canopy_air_stream.py,sha256=UYp3l7mt0XH4SqvCGZhRzCIL-v7-Rvxxfm-C81lheSU,1637
6
+ STIC_JPL/celcius_to_kelvin.py,sha256=QZ1gA8BHBHbdlgn1v8tEMG17yY2r-SCBnaHrGXySItg,316
7
+ STIC_JPL/closure.py,sha256=AzWoLnpoZ1MlQAKq0CgpmCMfDGVsp8-hYZ50ry33cic,4031
8
+ STIC_JPL/constants.py,sha256=xIVTsdc3_Rf3EPSgSk1QPjWiojFGn4lf1Swffov3oTM,595
9
+ STIC_JPL/generate_STIC_inputs.py,sha256=Vwuqq-PLiH2IBd1v0Vt2TVbdIRK8D1zU_uMgReCefmQ,2382
10
+ STIC_JPL/initialize_with_solar.py,sha256=P-22Wn8-sdvh2o4LGb9XfbCdXGWcOxdWwMzEYfx2Nfo,3759
11
+ STIC_JPL/initialize_without_solar.py,sha256=M_7QfP2pr2w5sQO7UOW1GPqxpmQkjmsQ526BgYVVALk,4675
12
+ STIC_JPL/iterate_with_solar.py,sha256=T9DezL59xaV63o6f7_ouCGcQwPi1dIvhlJB26TMGuDo,6373
13
+ STIC_JPL/iterate_without_solar.py,sha256=09RERpN6tdZr6ORDhMwEFXwx8941vyn1HMJQ-Q_bY6s,6140
14
+ STIC_JPL/model.py,sha256=W-4MPm4SHcQNGJGRV6xf823pbauFoDooY-YA-yg_I_w,17339
15
+ STIC_JPL/net_radiation.py,sha256=Uwudsazul8V-x5t8KQLi3wpYi-wjMwT__eqZCRV2bIw,1187
16
+ STIC_JPL/process_STIC_table.py,sha256=5s-fxbchyVnPCzUG5KZX-RrHZDpN4JVcwu42s821Kdw,1712
17
+ STIC_JPL/root_zone_initialization.py,sha256=3JVKNDt3ebIiGVfuhBawjKs-BicNwkbfMprkzSxd4Cg,1581
18
+ STIC_JPL/root_zone_iteration.py,sha256=1XOMFE3-TdJZzUU5vouflUO4NKaZwAW6s1KJrNez3Es,3787
19
+ STIC_JPL/soil_moisture_initialization.py,sha256=wWhAmvNT8tAIm_Sul8mEj6VdNuj7K14TBGUjKfqJrso,5610
20
+ STIC_JPL/soil_moisture_iteration.py,sha256=QJXOPMxxwIIskpx9zLkXUPfuhWgFPUBcRnGhZo2UjAw,6493
21
+ STIC_JPL/version.txt,sha256=xipcxhrEUlk1dT9ewoTAoFKksdpLOjWA3OK313ohVK4,6
22
+ stic_jpl-1.2.2.dist-info/METADATA,sha256=bTOMDANHZrwipZlIVEgzKx-trZnQhi0T-px1i6rjgf0,5789
23
+ stic_jpl-1.2.2.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
24
+ stic_jpl-1.2.2.dist-info/top_level.txt,sha256=9NkchxttzACJcGcAaWzMaZarzX40OXQ216hERNA9LIo,9
25
+ stic_jpl-1.2.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
STIC_JPL/diagnostic.py DELETED
@@ -1,70 +0,0 @@
1
- from typing import Union
2
- from os.path import join
3
- from datetime import date
4
- import numpy as np
5
- import logging
6
-
7
- import colored_logging as cl
8
- from rasters import Raster
9
-
10
- logger = logging.getLogger(__name__)
11
-
12
- def diagnostic(values: Union[Raster, np.ndarray], variable: str, show_distributions: bool = True, output_directory: str = None):
13
- if isinstance(values, Raster) and output_directory is not None:
14
- filename = join(output_directory, f"{variable}.tif")
15
- logger.info(filename)
16
- values.to_geotiff(filename)
17
-
18
- if show_distributions:
19
- unique = np.unique(values)
20
- nan_proportion = np.count_nonzero(np.isnan(values)) / np.size(values)
21
-
22
- if len(unique) < 10:
23
- logger.info(f"variable {cl.name(variable)} ({values.dtype}) has {cl.val(unique)} unique values")
24
-
25
- for value in unique:
26
- if np.isnan(value):
27
- count = np.count_nonzero(np.isnan(values))
28
- else:
29
- count = np.count_nonzero(values == value)
30
-
31
- if value == 0 or np.isnan(value):
32
- logger.info(f"* {cl.colored(value, 'red')}: {cl.colored(count, 'red')}")
33
- else:
34
- logger.info(f"* {cl.val(value)}: {cl.val(count)}")
35
- else:
36
- minimum = np.nanmin(values)
37
-
38
- if minimum < 0:
39
- minimum_string = cl.colored(f"{minimum:0.3f}", "red")
40
- else:
41
- minimum_string = cl.val(f"{minimum:0.3f}")
42
-
43
- maximum = np.nanmax(values)
44
-
45
- if maximum <= 0:
46
- maximum_string = cl.colored(f"{maximum:0.3f}", "red")
47
- else:
48
- maximum_string = cl.val(f"{maximum:0.3f}")
49
-
50
- if nan_proportion > 0.5:
51
- nan_proportion_string = cl.colored(f"{(nan_proportion * 100):0.2f}%", "yellow")
52
- elif nan_proportion == 1:
53
- nan_proportion_string = cl.colored(f"{(nan_proportion * 100):0.2f}%", "red")
54
- else:
55
- nan_proportion_string = cl.val(f"{(nan_proportion * 100):0.2f}%")
56
-
57
- message = "variable " + cl.name(variable) + \
58
- " min: " + minimum_string + \
59
- " mean: " + cl.val(f"{np.nanmean(values):0.3f}") + \
60
- " max: " + maximum_string + \
61
- " nan: " + nan_proportion_string
62
-
63
- if np.all(values == 0):
64
- message += " all zeros"
65
- logger.warning(message)
66
- else:
67
- logger.info(message)
68
-
69
- if nan_proportion == 1:
70
- raise ValueError(f"variable {variable} is blank")
@@ -1 +0,0 @@
1
- from .meteorology_conversion import *