PM-JPL 1.2.0__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 PM-JPL might be problematic. Click here for more details.
- PMJPL/MCD12C1/MCD12C1.py +10 -0
- PMJPL/MCD12C1/__init__.py +1 -0
- PMJPL/PMJPL.py +406 -0
- PMJPL/SEBAL/SEBAL.py +45 -0
- PMJPL/SEBAL/__init__.py +1 -0
- PMJPL/VPD_factor.py +26 -0
- PMJPL/__init__.py +9 -0
- PMJPL/canopy_aerodynamic_resistance.py +31 -0
- PMJPL/canopy_conductance.py +36 -0
- PMJPL/constants.py +34 -0
- PMJPL/correctance_factor.py +17 -0
- PMJPL/downscaling/__init__.py +1 -0
- PMJPL/downscaling/downscaling.py +271 -0
- PMJPL/downscaling/linear_downscale.py +71 -0
- PMJPL/evapotranspiration_conversion/__init__.py +1 -0
- PMJPL/evapotranspiration_conversion/evapotranspiration_conversion.py +80 -0
- PMJPL/fwet.py +21 -0
- PMJPL/interception.py +41 -0
- PMJPL/meteorology_conversion/__init__.py +1 -0
- PMJPL/meteorology_conversion/meteorology_conversion.py +123 -0
- PMJPL/parameters.py +41 -0
- PMJPL/penman_monteith/__init__.py +1 -0
- PMJPL/penman_monteith/penman_monteith.py +20 -0
- PMJPL/potential_soil_evaporation.py +48 -0
- PMJPL/priestley_taylor/__init__.py +1 -0
- PMJPL/priestley_taylor/priestley_taylor.py +27 -0
- PMJPL/santanello/__init__.py +1 -0
- PMJPL/santanello/santanello.py +46 -0
- PMJPL/soil_heat_flux/__init__.py +1 -0
- PMJPL/soil_heat_flux/soil_heat_flux.py +62 -0
- PMJPL/soil_moisture_constraint.py +19 -0
- PMJPL/tmin_factor.py +45 -0
- PMJPL/transpiration.py +44 -0
- PMJPL/vegetation_conversion/__init__.py +1 -0
- PMJPL/vegetation_conversion/vegetation_conversion.py +47 -0
- PMJPL/verma_net_radiation/__init__.py +1 -0
- PMJPL/verma_net_radiation/verma_net_radiation.py +108 -0
- PMJPL/wet_canopy_resistance.py +21 -0
- PMJPL/wet_soil_evaporation.py +36 -0
- pm_jpl-1.2.0.dist-info/METADATA +84 -0
- pm_jpl-1.2.0.dist-info/RECORD +44 -0
- pm_jpl-1.2.0.dist-info/WHEEL +5 -0
- pm_jpl-1.2.0.dist-info/licenses/LICENSE +201 -0
- pm_jpl-1.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from dateutil import parser
|
|
3
|
+
import numpy as np
|
|
4
|
+
from rasters import Raster, RasterGeometry, RasterGrid
|
|
5
|
+
import rasters as rt
|
|
6
|
+
|
|
7
|
+
DEFAULT_UPSAMPLING = "average"
|
|
8
|
+
DEFAULT_DOWNSAMPLING = "linear"
|
|
9
|
+
|
|
10
|
+
def bias_correct(
|
|
11
|
+
coarse_image: Raster,
|
|
12
|
+
fine_image: Raster,
|
|
13
|
+
upsampling: str = "average",
|
|
14
|
+
downsampling: str = "linear",
|
|
15
|
+
return_bias: bool = False):
|
|
16
|
+
fine_geometry = fine_image.geometry
|
|
17
|
+
coarse_geometry = coarse_image.geometry
|
|
18
|
+
upsampled = fine_image.to_geometry(coarse_geometry, resampling=upsampling)
|
|
19
|
+
bias_coarse = upsampled - coarse_image
|
|
20
|
+
bias_fine = bias_coarse.to_geometry(fine_geometry, resampling=downsampling)
|
|
21
|
+
bias_corrected_fine = fine_image - bias_fine
|
|
22
|
+
|
|
23
|
+
if return_bias:
|
|
24
|
+
return bias_corrected_fine, bias_fine
|
|
25
|
+
else:
|
|
26
|
+
return bias_corrected_fine
|
|
27
|
+
|
|
28
|
+
def linear_downscale(
|
|
29
|
+
coarse_image: Raster,
|
|
30
|
+
fine_image: Raster,
|
|
31
|
+
upsampling: str = "average",
|
|
32
|
+
downsampling: str = "linear",
|
|
33
|
+
use_gap_filling: bool = False,
|
|
34
|
+
apply_scale: bool = True,
|
|
35
|
+
apply_bias: bool = True,
|
|
36
|
+
return_scale_and_bias: bool = False) -> Raster:
|
|
37
|
+
if upsampling is None:
|
|
38
|
+
upsampling = DEFAULT_UPSAMPLING
|
|
39
|
+
|
|
40
|
+
if downsampling is None:
|
|
41
|
+
downsampling = DEFAULT_DOWNSAMPLING
|
|
42
|
+
|
|
43
|
+
coarse_geometry = coarse_image.geometry
|
|
44
|
+
fine_geometry = fine_image.geometry
|
|
45
|
+
upsampled = fine_image.to_geometry(coarse_geometry, resampling=upsampling)
|
|
46
|
+
|
|
47
|
+
if apply_scale:
|
|
48
|
+
scale_coarse = coarse_image / upsampled
|
|
49
|
+
scale_coarse = rt.where(coarse_image == 0, 0, scale_coarse)
|
|
50
|
+
scale_coarse = rt.where(upsampled == 0, 0, scale_coarse)
|
|
51
|
+
scale_fine = scale_coarse.to_geometry(fine_geometry, resampling=downsampling)
|
|
52
|
+
scale_corrected_fine = fine_image * scale_fine
|
|
53
|
+
fine_image = scale_corrected_fine
|
|
54
|
+
else:
|
|
55
|
+
scale_fine = fine_image * 0 + 1
|
|
56
|
+
|
|
57
|
+
if apply_bias:
|
|
58
|
+
upsampled = fine_image.to_geometry(coarse_geometry, resampling=upsampling)
|
|
59
|
+
bias_coarse = upsampled - coarse_image
|
|
60
|
+
bias_fine = bias_coarse.to_geometry(fine_geometry, resampling=downsampling)
|
|
61
|
+
bias_corrected_fine = fine_image - bias_fine
|
|
62
|
+
fine_image = bias_corrected_fine
|
|
63
|
+
else:
|
|
64
|
+
bias_fine = fine_image * 0
|
|
65
|
+
|
|
66
|
+
if use_gap_filling:
|
|
67
|
+
gap_fill = coarse_image.to_geometry(fine_geometry, resampling=downsampling)
|
|
68
|
+
fine_image = fine_image.fill(gap_fill)
|
|
69
|
+
|
|
70
|
+
if return_scale_and_bias:
|
|
71
|
+
fine_image["scale"] = scale_fine
|
|
72
|
+
fine_image["bias"] = bias_fine
|
|
73
|
+
|
|
74
|
+
return fine_image
|
|
75
|
+
|
|
76
|
+
def NDVI_to_FVC(NDVI: Raster) -> Raster:
|
|
77
|
+
NDVIv = 0.52 # +- 0.03
|
|
78
|
+
NDVIs = 0.04 # +- 0.03
|
|
79
|
+
FVC = rt.clip((NDVI - NDVIs) / (NDVIv - NDVIs), 0, 1)
|
|
80
|
+
|
|
81
|
+
return FVC
|
|
82
|
+
|
|
83
|
+
def downscale_air_temperature(
|
|
84
|
+
time_UTC: datetime,
|
|
85
|
+
Ta_K_coarse: Raster,
|
|
86
|
+
ST_K: Raster,
|
|
87
|
+
water: Raster = None,
|
|
88
|
+
fine_geometry: RasterGeometry = None,
|
|
89
|
+
coarse_geometry: RasterGeometry = None,
|
|
90
|
+
resampling: str = None,
|
|
91
|
+
upsampling: str = None,
|
|
92
|
+
downsampling: str = None,
|
|
93
|
+
apply_scale: bool = True,
|
|
94
|
+
apply_bias: bool = True,
|
|
95
|
+
return_scale_and_bias: bool = False) -> Raster:
|
|
96
|
+
"""
|
|
97
|
+
near-surface air temperature (Ta) in Kelvin
|
|
98
|
+
:param time_UTC: date/time in UTC
|
|
99
|
+
:param geometry: optional target geometry
|
|
100
|
+
:param resampling: optional sampling method for resampling to target geometry
|
|
101
|
+
:return: raster of Ta
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
if isinstance(time_UTC, str):
|
|
105
|
+
time_UTC = parser.parse(time_UTC)
|
|
106
|
+
|
|
107
|
+
if fine_geometry is None:
|
|
108
|
+
fine_geometry = ST_K.geometry
|
|
109
|
+
|
|
110
|
+
if coarse_geometry is None:
|
|
111
|
+
coarse_geometry = Ta_K_coarse.geometry
|
|
112
|
+
|
|
113
|
+
ST_K_water = None
|
|
114
|
+
|
|
115
|
+
if water is not None:
|
|
116
|
+
ST_K_water = rt.where(water, ST_K, np.nan)
|
|
117
|
+
ST_K = rt.where(water, np.nan, ST_K)
|
|
118
|
+
|
|
119
|
+
scale = None
|
|
120
|
+
bias = None
|
|
121
|
+
|
|
122
|
+
Ta_K = linear_downscale(
|
|
123
|
+
coarse_image=Ta_K_coarse,
|
|
124
|
+
fine_image=ST_K,
|
|
125
|
+
upsampling=upsampling,
|
|
126
|
+
downsampling=downsampling,
|
|
127
|
+
apply_scale=apply_scale,
|
|
128
|
+
apply_bias=apply_bias,
|
|
129
|
+
return_scale_and_bias=return_scale_and_bias
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if water is not None:
|
|
133
|
+
Ta_K_water = linear_downscale(
|
|
134
|
+
coarse_image=Ta_K_coarse,
|
|
135
|
+
fine_image=ST_K_water,
|
|
136
|
+
upsampling=upsampling,
|
|
137
|
+
downsampling=downsampling,
|
|
138
|
+
apply_scale=apply_scale,
|
|
139
|
+
apply_bias=apply_bias,
|
|
140
|
+
return_scale_and_bias=False
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
Ta_K = rt.where(water, Ta_K_water, Ta_K)
|
|
144
|
+
|
|
145
|
+
Ta_K.filenames = Ta_K_coarse.filenames
|
|
146
|
+
|
|
147
|
+
return Ta_K
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def downscale_soil_moisture(
|
|
151
|
+
time_UTC: datetime,
|
|
152
|
+
fine_geometry: RasterGrid,
|
|
153
|
+
coarse_geometry: RasterGrid,
|
|
154
|
+
SM_coarse: Raster,
|
|
155
|
+
SM_resampled: Raster,
|
|
156
|
+
ST_fine: Raster,
|
|
157
|
+
NDVI_fine: Raster,
|
|
158
|
+
water: Raster,
|
|
159
|
+
fvlim=0.5,
|
|
160
|
+
a=0.5,
|
|
161
|
+
smoothing="linear") -> Raster:
|
|
162
|
+
fine = fine_geometry
|
|
163
|
+
ST_fine = ST_fine.mask(~water)
|
|
164
|
+
NDVI_fine = NDVI_fine.mask(~water)
|
|
165
|
+
FVC_fine = NDVI_to_FVC(NDVI_fine)
|
|
166
|
+
soil_fine = FVC_fine < fvlim
|
|
167
|
+
Tmin_coarse = ST_fine.to_geometry(coarse_geometry, resampling="min")
|
|
168
|
+
Tmax_coarse = ST_fine.to_geometry(coarse_geometry, resampling="max")
|
|
169
|
+
Ts_fine = ST_fine.mask(soil_fine)
|
|
170
|
+
Tsmin_coarse = Ts_fine.to_geometry(coarse_geometry, resampling="min").fill(Tmin_coarse)
|
|
171
|
+
Tsmax_coarse = Ts_fine.to_geometry(coarse_geometry, resampling="max").fill(Tmax_coarse)
|
|
172
|
+
ST_coarse = ST_fine.to_geometry(coarse_geometry, resampling="average")
|
|
173
|
+
SEE_coarse = (Tsmax_coarse - ST_coarse) / rt.clip(Tsmax_coarse - Tsmin_coarse, 1, None)
|
|
174
|
+
SM_SEE_proportion = (SM_coarse / SEE_coarse).to_geometry(fine, resampling=smoothing)
|
|
175
|
+
Tsmax_fine = Tsmax_coarse.to_geometry(fine_geometry, resampling=smoothing)
|
|
176
|
+
Tsrange_fine = (Tsmax_coarse - Tsmin_coarse).to_geometry(fine, resampling=smoothing)
|
|
177
|
+
SEE_fine = (Tsmax_fine - ST_fine) / rt.clip(Tsrange_fine, 1, None)
|
|
178
|
+
|
|
179
|
+
SEE_mean = SEE_coarse.to_geometry(fine, resampling=smoothing)
|
|
180
|
+
SM_fine = rt.clip(SM_resampled + a * SM_SEE_proportion * (SEE_fine - SEE_mean), 0, 1)
|
|
181
|
+
SM_fine = SM_fine.mask(~water)
|
|
182
|
+
|
|
183
|
+
return SM_fine
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def downscale_vapor_pressure_deficit(
|
|
187
|
+
time_UTC: datetime,
|
|
188
|
+
VPD_Pa_coarse: Raster,
|
|
189
|
+
ST_K: Raster,
|
|
190
|
+
fine_geometry: RasterGeometry = None,
|
|
191
|
+
coarse_geometry: RasterGeometry = None,
|
|
192
|
+
resampling: str = None,
|
|
193
|
+
upsampling: str = None,
|
|
194
|
+
downsampling: str = None,
|
|
195
|
+
return_scale_and_bias: bool = False) -> Raster:
|
|
196
|
+
if upsampling is None:
|
|
197
|
+
upsampling = "average"
|
|
198
|
+
|
|
199
|
+
if downsampling is None:
|
|
200
|
+
downsampling = "linear"
|
|
201
|
+
|
|
202
|
+
if fine_geometry is None:
|
|
203
|
+
fine_geometry = ST_K.geometry
|
|
204
|
+
|
|
205
|
+
if coarse_geometry is None:
|
|
206
|
+
coarse_geometry = VPD_Pa_coarse.geometry
|
|
207
|
+
|
|
208
|
+
return linear_downscale(
|
|
209
|
+
coarse_image=VPD_Pa_coarse,
|
|
210
|
+
fine_image=ST_K,
|
|
211
|
+
upsampling=upsampling,
|
|
212
|
+
downsampling=downsampling,
|
|
213
|
+
return_scale_and_bias=return_scale_and_bias
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def downscale_relative_humidity(
|
|
218
|
+
time_UTC: datetime,
|
|
219
|
+
RH_coarse: Raster,
|
|
220
|
+
SM,
|
|
221
|
+
ST_K,
|
|
222
|
+
VPD_kPa,
|
|
223
|
+
water: Raster = None,
|
|
224
|
+
fine_geometry: RasterGeometry = None,
|
|
225
|
+
coarse_geometry: RasterGeometry = None,
|
|
226
|
+
resampling: str = None,
|
|
227
|
+
upsampling: str = None,
|
|
228
|
+
downsampling: str = None) -> Raster:
|
|
229
|
+
if upsampling is None:
|
|
230
|
+
upsampling = "average"
|
|
231
|
+
|
|
232
|
+
if downsampling is None:
|
|
233
|
+
downsampling = "linear"
|
|
234
|
+
|
|
235
|
+
if fine_geometry is None:
|
|
236
|
+
fine_geometry = SM.geometry
|
|
237
|
+
|
|
238
|
+
if coarse_geometry is None:
|
|
239
|
+
coarse_geometry = RH_coarse.geometry
|
|
240
|
+
|
|
241
|
+
bias_fine = None
|
|
242
|
+
|
|
243
|
+
RH_estimate_fine = SM ** (1 / VPD_kPa)
|
|
244
|
+
|
|
245
|
+
RH = bias_correct(
|
|
246
|
+
coarse_image=RH_coarse,
|
|
247
|
+
fine_image=RH_estimate_fine,
|
|
248
|
+
upsampling=upsampling,
|
|
249
|
+
downsampling=downsampling,
|
|
250
|
+
return_bias=False
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
if water is not None:
|
|
254
|
+
ST_K_water = rt.where(water, ST_K, np.nan)
|
|
255
|
+
RH_coarse_complement = 1 - RH_coarse
|
|
256
|
+
RH_complement_water = linear_downscale(
|
|
257
|
+
coarse_image=RH_coarse_complement,
|
|
258
|
+
fine_image=ST_K_water,
|
|
259
|
+
upsampling=upsampling,
|
|
260
|
+
downsampling=downsampling,
|
|
261
|
+
apply_bias=True,
|
|
262
|
+
return_scale_and_bias=False
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
RH_water = 1 - RH_complement_water
|
|
266
|
+
RH = rt.where(water, RH_water, RH)
|
|
267
|
+
|
|
268
|
+
RH = rt.clip(RH, 0, 1)
|
|
269
|
+
|
|
270
|
+
return RH
|
|
271
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from rasters import Raster
|
|
2
|
+
import rasters as rt
|
|
3
|
+
|
|
4
|
+
DEFAULT_UPSAMPLING = "average"
|
|
5
|
+
DEFAULT_DOWNSAMPLING = "linear"
|
|
6
|
+
|
|
7
|
+
def bias_correct(
|
|
8
|
+
coarse_image: Raster,
|
|
9
|
+
fine_image: Raster,
|
|
10
|
+
upsampling: str = "average",
|
|
11
|
+
downsampling: str = "linear",
|
|
12
|
+
return_bias: bool = False):
|
|
13
|
+
fine_geometry = fine_image.geometry
|
|
14
|
+
coarse_geometry = coarse_image.geometry
|
|
15
|
+
upsampled = fine_image.to_geometry(coarse_geometry, resampling=upsampling)
|
|
16
|
+
bias_coarse = upsampled - coarse_image
|
|
17
|
+
bias_fine = bias_coarse.to_geometry(fine_geometry, resampling=downsampling)
|
|
18
|
+
bias_corrected_fine = fine_image - bias_fine
|
|
19
|
+
|
|
20
|
+
if return_bias:
|
|
21
|
+
return bias_corrected_fine, bias_fine
|
|
22
|
+
else:
|
|
23
|
+
return bias_corrected_fine
|
|
24
|
+
|
|
25
|
+
def linear_downscale(
|
|
26
|
+
coarse_image: Raster,
|
|
27
|
+
fine_image: Raster,
|
|
28
|
+
upsampling: str = "average",
|
|
29
|
+
downsampling: str = "cubic",
|
|
30
|
+
use_gap_filling: bool = False,
|
|
31
|
+
apply_scale: bool = True,
|
|
32
|
+
apply_bias: bool = True,
|
|
33
|
+
return_scale_and_bias: bool = False) -> Raster:
|
|
34
|
+
if upsampling is None:
|
|
35
|
+
upsampling = DEFAULT_UPSAMPLING
|
|
36
|
+
|
|
37
|
+
if downsampling is None:
|
|
38
|
+
downsampling = DEFAULT_DOWNSAMPLING
|
|
39
|
+
|
|
40
|
+
coarse_geometry = coarse_image.geometry
|
|
41
|
+
fine_geometry = fine_image.geometry
|
|
42
|
+
upsampled = fine_image.to_geometry(coarse_geometry, resampling=upsampling)
|
|
43
|
+
|
|
44
|
+
if apply_scale:
|
|
45
|
+
scale_coarse = coarse_image / upsampled
|
|
46
|
+
scale_coarse = rt.where(coarse_image == 0, 0, scale_coarse)
|
|
47
|
+
scale_coarse = rt.where(upsampled == 0, 0, scale_coarse)
|
|
48
|
+
scale_fine = scale_coarse.to_geometry(fine_geometry, resampling=downsampling)
|
|
49
|
+
scale_corrected_fine = fine_image * scale_fine
|
|
50
|
+
fine_image = scale_corrected_fine
|
|
51
|
+
else:
|
|
52
|
+
scale_fine = fine_image * 0 + 1
|
|
53
|
+
|
|
54
|
+
if apply_bias:
|
|
55
|
+
upsampled = fine_image.to_geometry(coarse_geometry, resampling=upsampling)
|
|
56
|
+
bias_coarse = upsampled - coarse_image
|
|
57
|
+
bias_fine = bias_coarse.to_geometry(fine_geometry, resampling=downsampling)
|
|
58
|
+
bias_corrected_fine = fine_image - bias_fine
|
|
59
|
+
fine_image = bias_corrected_fine
|
|
60
|
+
else:
|
|
61
|
+
bias_fine = fine_image * 0
|
|
62
|
+
|
|
63
|
+
if use_gap_filling:
|
|
64
|
+
gap_fill = coarse_image.to_geometry(fine_geometry, resampling=downsampling)
|
|
65
|
+
fine_image = fine_image.fill(gap_fill)
|
|
66
|
+
|
|
67
|
+
if return_scale_and_bias:
|
|
68
|
+
fine_image["scale"] = scale_fine
|
|
69
|
+
fine_image["bias"] = bias_fine
|
|
70
|
+
|
|
71
|
+
return fine_image
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .evapotranspiration_conversion import *
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
from sun_angles import SHA_deg_from_DOY_lat, daylight_from_SHA, sunrise_from_SHA
|
|
3
|
+
|
|
4
|
+
import rasters as rt
|
|
5
|
+
from rasters import Raster
|
|
6
|
+
import numpy as np
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
from ..meteorology_conversion.meteorology_conversion import celcius_to_kelvin
|
|
10
|
+
from ..verma_net_radiation.verma_net_radiation import daily_Rn_integration_verma
|
|
11
|
+
|
|
12
|
+
# latent heat of vaporization for water at 20 Celsius in Joules per kilogram
|
|
13
|
+
LAMBDA_JKG_WATER_20C = 2450000.0
|
|
14
|
+
|
|
15
|
+
def lambda_Jkg_from_Ta_K(Ta_K: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
16
|
+
# Calculate the latent heat of vaporization (J kg-1)
|
|
17
|
+
return (2.501 - 0.002361 * (Ta_K - 273.15)) * 1e6
|
|
18
|
+
|
|
19
|
+
def lambda_Jkg_from_Ta_C(Ta_C: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
20
|
+
Ta_K = celcius_to_kelvin(Ta_C)
|
|
21
|
+
lambda_Jkg = lambda_Jkg_from_Ta_K(Ta_K)
|
|
22
|
+
|
|
23
|
+
return lambda_Jkg
|
|
24
|
+
|
|
25
|
+
def daily_ET_from_daily_LE(
|
|
26
|
+
LE_daylight: Union[Raster, np.ndarray],
|
|
27
|
+
daylight_hours: Union[Raster, np.ndarray],
|
|
28
|
+
lambda_Jkg: float = LAMBDA_JKG_WATER_20C) -> Union[Raster, np.ndarray]:
|
|
29
|
+
"""
|
|
30
|
+
Calculate daily evapotranspiration (ET) from daily latent heat flux (LE).
|
|
31
|
+
|
|
32
|
+
Parameters:
|
|
33
|
+
LE_daily (Union[Raster, np.ndarray]): Daily latent heat flux.
|
|
34
|
+
daylight_hours (Union[Raster, np.ndarray]): Length of day in hours.
|
|
35
|
+
latent_vaporization (float, optional): Latent heat of vaporization. Defaults to LATENT_VAPORIZATION.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Union[Raster, np.ndarray]: Daily evapotranspiration in kilograms.
|
|
39
|
+
"""
|
|
40
|
+
# convert length of day in hours to seconds
|
|
41
|
+
daylight_seconds = daylight_hours * 3600.0
|
|
42
|
+
|
|
43
|
+
# factor seconds out of watts to get joules and divide by latent heat of vaporization to get kilograms
|
|
44
|
+
ET_daily_kg = rt.clip(LE_daylight * daylight_seconds / LAMBDA_JKG_WATER_20C, 0.0, None)
|
|
45
|
+
|
|
46
|
+
return ET_daily_kg
|
|
47
|
+
|
|
48
|
+
def process_daily_ET_table(input_df: pd.DataFrame) -> pd.DataFrame:
|
|
49
|
+
hour_of_day = input_df.hour_of_day
|
|
50
|
+
DOY = input_df.doy
|
|
51
|
+
lat = input_df.lat
|
|
52
|
+
LE = input_df.LE
|
|
53
|
+
Rn = input_df.Rn
|
|
54
|
+
EF = LE / Rn
|
|
55
|
+
|
|
56
|
+
SHA_deg = SHA_deg_from_DOY_lat(DOY=DOY, latitude=lat)
|
|
57
|
+
sunrise_hour = sunrise_from_SHA(SHA_deg)
|
|
58
|
+
daylight_hours = daylight_from_SHA(SHA_deg)
|
|
59
|
+
|
|
60
|
+
Rn_daylight = daily_Rn_integration_verma(
|
|
61
|
+
Rn=Rn,
|
|
62
|
+
hour_of_day=hour_of_day,
|
|
63
|
+
DOY=DOY,
|
|
64
|
+
lat=lat,
|
|
65
|
+
sunrise_hour=sunrise_hour,
|
|
66
|
+
daylight_hours=daylight_hours
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
LE_daylight = EF * Rn_daylight
|
|
70
|
+
ET = daily_ET_from_daily_LE(LE_daylight, daylight_hours)
|
|
71
|
+
|
|
72
|
+
output_df = input_df.copy()
|
|
73
|
+
output_df["EF"] = EF
|
|
74
|
+
output_df["sunrise_hour"] = sunrise_hour
|
|
75
|
+
output_df["daylight_hours"] = daylight_hours
|
|
76
|
+
output_df["Rn_daylight"] = Rn_daylight
|
|
77
|
+
output_df["ET"] = ET
|
|
78
|
+
|
|
79
|
+
return output_df
|
|
80
|
+
|
PMJPL/fwet.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from typing import Union
|
|
3
|
+
from rasters import Raster
|
|
4
|
+
|
|
5
|
+
from .constants import RH_THRESHOLD, MIN_FWET
|
|
6
|
+
|
|
7
|
+
def calculate_fwet(
|
|
8
|
+
RH: Union[Raster, np.ndarray],
|
|
9
|
+
RH_threshold: float = RH_THRESHOLD,
|
|
10
|
+
min_fwet: float = MIN_FWET) -> Union[Raster, np.ndarray]:
|
|
11
|
+
"""
|
|
12
|
+
calculates relative surface wetness
|
|
13
|
+
:param RH: relative humdity from 0.0 to 1.0
|
|
14
|
+
:return: relative surface wetness from 0.0 to 1.0
|
|
15
|
+
"""
|
|
16
|
+
fwet = np.float32(np.clip(RH ** 4.0, min_fwet, None))
|
|
17
|
+
|
|
18
|
+
if RH_threshold is not None:
|
|
19
|
+
fwet = np.where(RH < RH_threshold, min_fwet, fwet)
|
|
20
|
+
|
|
21
|
+
return fwet
|
PMJPL/interception.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
import numpy as np
|
|
3
|
+
import rasters as rt
|
|
4
|
+
from rasters import Raster
|
|
5
|
+
|
|
6
|
+
from .constants import GAMMA_PA
|
|
7
|
+
|
|
8
|
+
def calculate_interception(
|
|
9
|
+
delta_Pa: Union[Raster, np.ndarray],
|
|
10
|
+
Ac: Union[Raster, np.ndarray],
|
|
11
|
+
rho: Union[Raster, np.ndarray],
|
|
12
|
+
Cp: Union[Raster, np.ndarray],
|
|
13
|
+
VPD_Pa: Union[Raster, np.ndarray],
|
|
14
|
+
FVC: Union[Raster, np.ndarray],
|
|
15
|
+
rhrc: Union[Raster, np.ndarray],
|
|
16
|
+
fwet: Union[Raster, np.ndarray],
|
|
17
|
+
rvc: Union[Raster, np.ndarray],
|
|
18
|
+
water: Union[Raster, np.ndarray],
|
|
19
|
+
gamma_Pa: Union[Raster, np.ndarray, float] = GAMMA_PA) -> Union[Raster, np.ndarray]:
|
|
20
|
+
"""
|
|
21
|
+
Calculates the wet evaporation partition of the latent heat flux using the MOD16 method.
|
|
22
|
+
|
|
23
|
+
:param delta_Pa: slope of saturation to vapor pressure curve in Pascal per degree Celsius
|
|
24
|
+
:param Ac: available radiation to the canopy in watts per square meter
|
|
25
|
+
:param rho: air density in kilograms per cubic meter
|
|
26
|
+
:param Cp: specific heat capacity of the air in joules per kilogram per kelvin
|
|
27
|
+
:param VPD: vapor pressure deficit in Pascal
|
|
28
|
+
:param FVC: fraction of vegetation cover
|
|
29
|
+
:param rhrc: aerodynamic resistance in seconds per meter
|
|
30
|
+
:param fwet: relative surface wetness
|
|
31
|
+
:param rvc: wet canopy resistance
|
|
32
|
+
:param water: water content in the canopy
|
|
33
|
+
:param gamma_Pa: psychrometric constant for atmospheric pressure in Pascal (default: GAMMA_PA)
|
|
34
|
+
|
|
35
|
+
:return: wet evaporation in watts per square meter
|
|
36
|
+
"""
|
|
37
|
+
numerator = (delta_Pa * Ac + (rho * Cp * VPD_Pa * FVC / rhrc)) * fwet
|
|
38
|
+
denominator = delta_Pa + gamma_Pa * (rvc / rhrc)
|
|
39
|
+
LEi = numerator / denominator
|
|
40
|
+
|
|
41
|
+
return LEi
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .meteorology_conversion import *
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
import numpy as np
|
|
3
|
+
import rasters as rt
|
|
4
|
+
from rasters import Raster
|
|
5
|
+
|
|
6
|
+
# gas constant for dry air in joules per kilogram per kelvin
|
|
7
|
+
RD = 286.9
|
|
8
|
+
|
|
9
|
+
# gas constant for moist air in joules per kilogram per kelvin
|
|
10
|
+
RW = 461.5
|
|
11
|
+
|
|
12
|
+
# specific heat of water vapor in joules per kilogram per kelvin
|
|
13
|
+
CPW = 1846.0
|
|
14
|
+
|
|
15
|
+
# specific heat of dry air in joules per kilogram per kelvin
|
|
16
|
+
CPD = 1005.0
|
|
17
|
+
|
|
18
|
+
def kelvin_to_celsius(T_K: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
19
|
+
"""
|
|
20
|
+
convert temperature in kelvin to celsius.
|
|
21
|
+
:param T_K: temperature in kelvin
|
|
22
|
+
:return: temperature in celsius
|
|
23
|
+
"""
|
|
24
|
+
return T_K - 273.15
|
|
25
|
+
|
|
26
|
+
def celcius_to_kelvin(T_C: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
27
|
+
"""
|
|
28
|
+
convert temperature in celsius to kelvin.
|
|
29
|
+
:param T_C: temperature in celsius
|
|
30
|
+
:return: temperature in kelvin
|
|
31
|
+
"""
|
|
32
|
+
return T_C + 273.15
|
|
33
|
+
|
|
34
|
+
def calculate_specific_humidity(
|
|
35
|
+
Ea_Pa: Union[Raster, np.ndarray],
|
|
36
|
+
Ps_Pa: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
37
|
+
"""
|
|
38
|
+
Calculate the specific humidity of air as a ratio of kilograms of water to kilograms of air.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
Ea_Pa (Union[Raster, np.ndarray]): Actual water vapor pressure in Pascal.
|
|
42
|
+
surface_pressure_Pa (Union[Raster, np.ndarray]): Surface pressure in Pascal.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Union[Raster, np.ndarray]: Specific humidity in kilograms of water per kilograms of air.
|
|
46
|
+
"""
|
|
47
|
+
return ((0.622 * Ea_Pa) / (Ps_Pa - (0.387 * Ea_Pa)))
|
|
48
|
+
|
|
49
|
+
def calculate_specific_heat(specific_humidity: Union[Raster, np.ndarray]):
|
|
50
|
+
# calculate specific heat capacity of the air (Cp)
|
|
51
|
+
# in joules per kilogram per kelvin
|
|
52
|
+
# from specific heat of water vapor (CPW)
|
|
53
|
+
# and specific heat of dry air (CPD)
|
|
54
|
+
Cp_Jkg = specific_humidity * CPW + (1 - specific_humidity) * CPD
|
|
55
|
+
|
|
56
|
+
return Cp_Jkg
|
|
57
|
+
|
|
58
|
+
def calculate_air_density(
|
|
59
|
+
surface_pressure_Pa: Union[Raster, np.ndarray],
|
|
60
|
+
Ta_K: Union[Raster, np.ndarray],
|
|
61
|
+
specific_humidity: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
62
|
+
"""
|
|
63
|
+
Calculate air density.
|
|
64
|
+
|
|
65
|
+
Parameters:
|
|
66
|
+
surface_pressure_Pa (Union[Raster, np.ndarray]): Surface pressure in Pascal.
|
|
67
|
+
Ta_K (Union[Raster, np.ndarray]): Air temperature in Kelvin.
|
|
68
|
+
specific_humidity (Union[Raster, np.ndarray]): Specific humidity.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Union[Raster, np.ndarray]: Air density in kilograms per cubic meter.
|
|
72
|
+
"""
|
|
73
|
+
# numerator: Pa(N / m ^ 2 = kg * m / s ^ 2); denominator: J / kg / K * K)
|
|
74
|
+
rhoD = surface_pressure_Pa / (RD * Ta_K)
|
|
75
|
+
|
|
76
|
+
# calculate air density (rho) in kilograms per cubic meter
|
|
77
|
+
rho = rhoD * ((1.0 + specific_humidity) / (1.0 + specific_humidity * (RW / RD)))
|
|
78
|
+
|
|
79
|
+
return rho
|
|
80
|
+
|
|
81
|
+
def SVP_kPa_from_Ta_C(Ta_C: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
82
|
+
"""
|
|
83
|
+
Calculate the saturation vapor pressure in kiloPascal (kPa) from air temperature in Celsius.
|
|
84
|
+
|
|
85
|
+
Parameters:
|
|
86
|
+
Ta_C (Union[Raster, np.ndarray]): Air temperature in Celsius.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Union[Raster, np.ndarray]: Saturation vapor pressure in kPa.
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
SVP_kPa = np.clip(0.611 * np.exp((Ta_C * 17.27) / (Ta_C + 237.7)), 1, None)
|
|
93
|
+
|
|
94
|
+
return SVP_kPa
|
|
95
|
+
|
|
96
|
+
def SVP_Pa_from_Ta_C(Ta_C: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
97
|
+
"""
|
|
98
|
+
Calculate the saturation vapor pressure in Pascal (Pa) from the air temperature in Celsius (Ta_C).
|
|
99
|
+
|
|
100
|
+
Parameters:
|
|
101
|
+
Ta_C (Union[Raster, np.ndarray]): Air temperature in Celsius.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Union[Raster, np.ndarray]: Saturation vapor pressure in Pascal (Pa).
|
|
105
|
+
"""
|
|
106
|
+
return SVP_kPa_from_Ta_C(Ta_C) * 1000
|
|
107
|
+
|
|
108
|
+
def calculate_surface_pressure(elevation_m: Union[Raster, np.ndarray], Ta_C: Union[Raster, np.ndarray]) -> Union[Raster, np.ndarray]:
|
|
109
|
+
"""
|
|
110
|
+
Calculate surface pressure using elevation and air temperature.
|
|
111
|
+
|
|
112
|
+
Parameters:
|
|
113
|
+
elevation_m (Union[Raster, np.ndarray]): Elevation in meters.
|
|
114
|
+
Ta_K (Union[Raster, np.ndarray]): Air temperature in Kelvin.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Union[Raster, np.ndarray]: Surface pressure in Pascal (Pa).
|
|
118
|
+
"""
|
|
119
|
+
Ta_K = kelvin_to_celsius(Ta_C)
|
|
120
|
+
Ps_Pa = 101325.0 * (1.0 - 0.0065 * elevation_m / Ta_K) ** (9.807 / (0.0065 * 287.0)) # [Pa]
|
|
121
|
+
|
|
122
|
+
return Ps_Pa
|
|
123
|
+
|
PMJPL/parameters.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
from os.path import join, abspath, dirname
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
from rasters import Raster, RasterGeometry
|
|
7
|
+
|
|
8
|
+
from .MCD12C1.MCD12C1 import load_MCD12C1_IGBP
|
|
9
|
+
|
|
10
|
+
LUT = pd.read_csv(join(abspath(dirname(__file__)), 'mod16.csv'))
|
|
11
|
+
|
|
12
|
+
def MOD16_parameter_from_IGBP(variable: str, IGBP: Union[Raster, np.ndarray] = None, geometry: RasterGeometry = None) -> Union[Raster, np.ndarray]:
|
|
13
|
+
"""
|
|
14
|
+
Translates the IGBP (International Geosphere-Biosphere Programme) values to the corresponding values in the Look-Up Table (LUT) for a given variable.
|
|
15
|
+
|
|
16
|
+
Parameters:
|
|
17
|
+
variable (str): The variable for which the translation is performed.
|
|
18
|
+
gl_sh (m s-1 LAI-1) Leaf conductance to sensible heat per unit LAI
|
|
19
|
+
gl_e_wv (m s-1 LAI-1) Leaf conductance to evaporated water per unit LAI
|
|
20
|
+
rbl_min (s m-1) Minimum atmospheric boundary layer resistance
|
|
21
|
+
rbl_max (s m-1) Maximum atmospheric boundary layer resistance
|
|
22
|
+
cl (m s-1) Mean potential stomatal conductance per unit leaf area
|
|
23
|
+
tmin_open (deg C) Temperature at which stomata are completely open, i.e., there is no effect of temperature on transpiration
|
|
24
|
+
tmin_close (deg C) Temperature at which stomata are almost completely closed due to (minimum) temperature stress
|
|
25
|
+
vpd_close (Pa) The VPD at which stomata are almost completely closed due to water stress
|
|
26
|
+
vpd_open (Pa) The VPD at which stomata are completely open, i.e., there is no effect of water stress on transpiration
|
|
27
|
+
IGBP (Union[np.ndarray, Raster]): The IGBP values to be translated.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Union[np.ndarray, Raster]: The translated values.
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
if IGBP is None:
|
|
34
|
+
IGBP = load_MCD12C1_IGBP(geometry=geometry)
|
|
35
|
+
|
|
36
|
+
result = np.float32(np.array(LUT[variable])[np.array(IGBP).astype(int)])
|
|
37
|
+
|
|
38
|
+
if isinstance(IGBP, Raster):
|
|
39
|
+
result = Raster(result, geometry=IGBP.geometry)
|
|
40
|
+
|
|
41
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .penman_monteith import *
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
import numpy as np
|
|
3
|
+
from ..evapotranspiration_conversion.evapotranspiration_conversion import lambda_Jkg_from_Ta_C
|
|
4
|
+
from ..meteorology_conversion.meteorology_conversion import celcius_to_kelvin
|
|
5
|
+
|
|
6
|
+
from rasters import Raster
|
|
7
|
+
|
|
8
|
+
SPECIFIC_HEAT_CAPACITY_AIR = 1013 # J kg-1 K-1, Monteith & Unsworth (2001)
|
|
9
|
+
MOL_WEIGHT_WET_DRY_RATIO_AIR = 0.622
|
|
10
|
+
|
|
11
|
+
def calculate_gamma(
|
|
12
|
+
Ta_C: Union[Raster, np.ndarray],
|
|
13
|
+
Ps_Pa: Union[Raster, np.ndarray],
|
|
14
|
+
Cp_Jkg: Union[Raster, np.ndarray, float] = SPECIFIC_HEAT_CAPACITY_AIR,
|
|
15
|
+
RMW: Union[Raster, np.ndarray, float] = MOL_WEIGHT_WET_DRY_RATIO_AIR) -> Union[Raster, np.ndarray]:
|
|
16
|
+
# calculate latent heat of vaporization (J kg-1)
|
|
17
|
+
lambda_Jkg = lambda_Jkg_from_Ta_C(Ta_C)
|
|
18
|
+
gamma = (Cp_Jkg * Ps_Pa) / (lambda_Jkg * RMW)
|
|
19
|
+
|
|
20
|
+
return gamma
|