Newer
Older
{
"cells": [
{
"cell_type": "markdown",
"id": "extended-offering",
"metadata": {},
"source": [
"# **Location of the stress factor in potential evapo-transpiration models**"
]
},
{
"cell_type": "markdown",
"id": "supported-annotation",
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
55
56
57
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Part I - Methodology \n",
"\n",
"## <u> Motivation </u> \n",
"\n",
"### Theoretical background\n",
"\n",
"In the literature, this scaling of the potential evapo-transpiration is commonly found with simpler radiation-temperature models such as the Priestley and Taylor model instead of the Penman-Monteith one. Recall the expression of the Priestley and Taylor model: \n",
"\n",
"\\begin{equation}\\label{eq_PT}\n",
" \\lambda E_{p,PT} = \\alpha \\frac{\\Delta}{\\Delta + \\gamma}(Rn - G)\n",
"\\end{equation}\n",
"\n",
"The Priestley and Taylor is not physicaly based as can be the Penman-Monteith model. Then we aim at investigating the differences obtained when using such a model. \n",
"\n",
"This notebook compares different newly implemented models : \n",
"* Priestley and Taylor model with a stress factor : \n",
"\\begin{align}\n",
" E_{a, PT} = f_{PAR}.S(\\theta).E_{p,PT}(\\textbf{X})\n",
"\\end{align}\n",
"\n",
"* Modified varying surface conductance Penman-Monteith model :\n",
"\\begin{align}\n",
" E_{a, var, PM} = f_{PAR}.E_{p,PM mod}(\\textbf{X}, S(\\theta))\n",
"\\end{align}\n",
"\n",
"* Modified constant surface conductance Penman-Monteith model :\n",
"\\begin{align}\n",
" E_{a, cst, PM} = f_{PAR}.S(\\theta).E_{p,PM mod}(\\textbf{X})\n",
"\\end{align}\n",
"\n",
"The modified version of the Penman-Monteith equation takes into account the double sided exchange of sensible heat. This model was developped at the leaf scale but is tested here at the canopy scale in the framework of the big leaf model (*Schymanski and Or, 2017*). The analytical expression of the modified expression is henceforth: \n",
"\\begin{equation}\n",
"E = \\frac{1}{\\lambda}\\frac{\\Delta (R_n - G) + c_p \\rho_a g_a a_{sh} VPD }{\\Delta + \\gamma \\left( 1+ \\frac{g_a}{g_s} \\right) \\frac{a_{sh}}{a_s}}\n",
"\\end{equation}\n",
"\n",
"### Modelling experiements\n",
"\n",
"Different experiments are carried out to compare the different models and assess their behavior: \n",
"1. All models are calibrated for a single year and their ability to reproduce an observed time serie is assessed\n",
"2. Their prediction capability is evaluated by randomly taking one or several years of data from the Howard Springs dataset, calibrating the model for this specific year and predicting the evapo-transpiration time serie for the other years. \n",
"3. The same procedure is repeated across different sites in Australia"
]
},
{
"cell_type": "markdown",
"id": "infrared-heritage",
"metadata": {},
"source": [
"# Part II - Functions set up"
]
},
{
"cell_type": "markdown",
"id": "surprised-restoration",
"metadata": {},
"source": [
"## Importing relevant packages"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "reasonable-queue",
"source": [
"# data manipulation and plotting\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
Oscar Corvi
committed
"from matplotlib.patches import Polygon\n",
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"from matplotlib._layoutgrid import plot_children\n",
"from collections import OrderedDict\n",
"from IPython.display import display\n",
"import os # to look into the other folders of the project\n",
"import importlib.util # to open the .py files written somewhere else\n",
"#sns.set_theme(style=\"whitegrid\")\n",
"\n",
"# Sympy and sympbolic mathematics\n",
"from sympy import (asin, cos, diff, Eq, exp, init_printing, log, pi, sin, \n",
" solve, sqrt, Symbol, symbols, tan, Abs)\n",
"from sympy.physics.units import convert_to\n",
"init_printing() \n",
"from sympy.printing import StrPrinter\n",
"from sympy import Piecewise\n",
"StrPrinter._print_Quantity = lambda self, expr: str(expr.abbrev) # displays short units (m instead of meter)\n",
"from sympy.printing.aesaracode import aesara_function\n",
"from sympy.physics.units import * # Import all units and dimensions from sympy\n",
"from sympy.physics.units.systems.si import dimsys_SI, SI\n",
"\n",
"# for ESSM, environmental science for symbolic math, see https://github.com/environmentalscience/essm\n",
"from essm.variables._core import BaseVariable, Variable\n",
"from essm.equations import Equation\n",
"from essm.variables.units import derive_unit, SI, Quantity\n",
"from essm.variables.utils import (extract_variables, generate_metadata_table, markdown, \n",
" replace_defaults, replace_variables, subs_eq)\n",
"from essm.variables.units import (SI_BASE_DIMENSIONS, SI_EXTENDED_DIMENSIONS, SI_EXTENDED_UNITS,\n",
" derive_unit, derive_baseunit, derive_base_dimension)\n",
"\n",
"# For netCDF\n",
"import netCDF4\n",
"import numpy as np\n",
"import xarray as xr\n",
"import warnings\n",
"from netCDF4 import Dataset\n",
"\n",
"# For regressions\n",
"from sklearn.linear_model import LinearRegression\n",
"\n",
"# Deactivate unncessary warning messages related to a bug in Numpy\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
"\n",
"# for calibration\n",
"from scipy import optimize\n",
"\n",
"from random import random"
]
},
{
"cell_type": "markdown",
"id": "breathing-musician",
"metadata": {},
"source": [
"## Path of the different files (pre-defined python functions, sympy equations, sympy variables)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "numeric-firmware",
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"path_variable = '../../theory/pyFile_storage/theory_variable.py'\n",
"path_equation = '../../theory/pyFile_storage/theory_equation.py' \n",
"path_analysis_functions = '../../theory/pyFile_storage/analysis_functions.py'\n",
"path_data = '../../../data/eddycovdata/'\n",
"dates_fPAR = '../../../data/fpar_howard_spring/dates_v5'\n",
"\n",
Oscar Corvi
committed
"tex_file_whole = \"latex_files/whole_year.tex\"\n",
"tex_file_dry = \"latex_files/dry_season.tex\"\n",
"tex_file_wet = \"latex_files/wet_season.tex\"\n",
"\n",
"timeSerie_oneSite_oneYear = 'timeSerie_oneSite_oneYear.png'\n",
"inverseModelling = \"inverseModelling.png\"\n",
"Influence_atmo_E_dry = \"Influence_atmo_E_dry.png\"\n",
"Influence_atmo_E_wet = \"Influence_atmo_E_wet.png\"\n",
"Influence_atmo_rel_dry = \"Influence_atmo_rel_dry.png\"\n",
"Influence_atmo_rel_wet = \"Influence_atmo_rel_wet.png\"\n",
"sensitivity_parameters = \"sensitivity_parameters.png\"\n",
"statistical_assessment = \"statistical_assessment.png\"\n",
"different_sites = \"different_sites.png\""
]
},
{
"cell_type": "markdown",
"id": "experimental-avatar",
"metadata": {},
"source": [
"## Importing the sympy variables and equations defined in the theory.ipynb notebook"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "excited-place",
"metadata": {},
"outputs": [
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta_sat\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta_sat'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta_res\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta_res'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:alpha\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.alpha'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:n\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.n'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:m\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.m'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:S_mvg\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.S_mvg'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:h\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.h'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:S\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.S'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta_4\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta_4'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta_3\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta_3'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta_2\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta_2'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:theta_1\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.theta_1'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:L\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.L'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:Mw\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.Mw'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:Pv\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.Pv'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:Pvs\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.Pvs'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:R\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.R'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:T\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.T'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:c1\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.c1'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:T0\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.T0'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:Delta\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.Delta'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:E\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.E'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:G\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.G'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:H\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.H'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:Rn\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.Rn'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:LE\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.LE'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:gamma\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.gamma'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:alpha_PT\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.alpha_PT'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:c_p\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.c_p'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:w\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.w'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:kappa\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.kappa'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:z\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.z'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:u_star\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.u_star'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:VH\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.VH'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:d\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.d'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:z_om\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.z_om'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:z_oh\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.z_oh'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:r_a\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.r_a'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:g_a\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.g_a'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:r_s\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.r_s'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:g_s\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.g_s'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:c1_e\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.c1_e'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:c2_e\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.c2_e'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:e\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.e'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:T_min\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.T_min'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:T_max\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.T_max'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:RH_max\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.RH_max'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:RH_min\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.RH_min'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:e_a\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.e_a'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:e_s\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.e_s'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:iv_T\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.iv_T'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:T_kv\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.T_kv'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:P\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.P'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:rho_a\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.rho_a'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/variables/_core.py:89: UserWarning: \"e/theory_variable:VPD\" will be overridden by \"e/theory_variable:<class 'e/theory_variable.VPD'>\"\n",
" instance[expr] = instance\n"
]
},
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
{
"name": "stdout",
"output_type": "stream",
"text": [
"theta_sat\n",
"theta_res\n",
"alpha\n",
"n\n",
"m\n",
"S_mvg\n",
"theta\n",
"h\n",
"S\n",
"theta_4\n",
"theta_3\n",
"theta_2\n",
"theta_1\n",
"L\n",
"Mw\n",
"Pv\n",
"Pvs\n",
"R\n",
"T\n",
"c1\n",
"T0\n",
"Delta\n",
"E\n",
"G\n",
"H\n",
"Rn\n",
"LE\n",
"gamma\n",
"alpha_PT\n",
"c_p\n",
"w\n",
"kappa\n",
"z\n",
"u_star\n",
"VH\n",
"d\n",
"z_om\n",
"z_oh\n",
"r_a\n",
"g_a\n",
"r_s\n",
"g_s\n",
"c1_e\n",
"c2_e\n",
"e\n",
"T_min\n",
"T_max\n",
"RH_max\n",
"RH_min\n",
"e_a\n",
"e_s\n",
"iv_T\n",
"T_kv\n",
"P\n",
"rho_a\n",
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
"VPD\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_m_n\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_m_n'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_MVG_neg_case\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_MVG_neg_case'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_MVG\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_MVG'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_sat_degree\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_sat_degree'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_MVG_h\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_MVG_h'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_h_FC\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_h_FC'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_theta_4_3\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_theta_4_3'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_theta_2_1\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_theta_2_1'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_water_stress_simple\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_water_stress_simple'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_Pvs_T\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_Pvs_T'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_Delta\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_Delta'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_PT\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_PT'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_PM\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_PM'>\"\n",
" instance[expr] = instance\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"eq_m_n\n",
"eq_MVG_neg_case\n",
"eq_MVG\n",
"eq_sat_degree\n",
"eq_MVG_h\n",
"eq_h_FC\n",
"eq_theta_4_3\n",
"eq_theta_2_1\n",
"eq_water_stress_simple\n",
"eq_Pvs_T\n",
"eq_Delta\n",
"eq_PT\n",
"eq_PM\n",
"eq_PM_VPD\n",
"eq_PM_g\n",
"eq_PM_inv\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_PM_VPD\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_PM_VPD'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_PM_g\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_PM_g'>\"\n",
" instance[expr] = instance\n",
"/opt/conda/lib/python3.8/site-packages/essm/equations/_core.py:107: UserWarning: \"e/theory_equation:eq_PM_inv\" will be overridden by \"e/theory_equation:<class 'e/theory_equation.eq_PM_inv'>\"\n",
" instance[expr] = instance\n"
]
}
],
"source": [
"for code in [path_variable,path_equation]:\n",
" name_code = code[-20:-3]\n",
" spec = importlib.util.spec_from_file_location(name_code, code)\n",
" mod = importlib.util.module_from_spec(spec)\n",
" spec.loader.exec_module(mod)\n",
" names = getattr(mod, '__all__', [n for n in dir(mod) if not n.startswith('_')])\n",
" glob = globals()\n",
" for name in names:\n",
" print(name)\n",
" glob[name] = getattr(mod, name)"
]
},
{
"cell_type": "markdown",
"id": "fossil-perfume",
"metadata": {},
"source": [
"## Importing the performance assessment functions defined in the analysis_function.py file"
]
},
{
"cell_type": "code",
"execution_count": 88,
"id": "authorized-pound",
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AIC\n",
"AME\n",
"BIC\n",
"CD\n",
"CP\n",
"IoA\n",
"KGE\n",
"MAE\n",
"MARE\n",
"ME\n",
"MRE\n",
"MSRE\n",
"MdAPE\n",
"NR4MS4E\n",
"NRMSE\n",
"NS\n",
"NSC\n",
"PDIFF\n",
"PEP\n",
"R4MS4E\n",
"RAE\n",
"RMSE\n",
"np\n",
"nt\n"
]
}
],
"source": [
"for code in [path_analysis_functions]:\n",
" name_code = code[-20:-3]\n",
" spec = importlib.util.spec_from_file_location(name_code, code)\n",
" mod = importlib.util.module_from_spec(spec)\n",
" spec.loader.exec_module(mod)\n",
" names = getattr(mod, '__all__', [n for n in dir(mod) if not n.startswith('_')])\n",
" glob = globals()\n",
" for name in names:\n",
" print(name)\n",
" glob[name] = getattr(mod, name)"
]
},
{
"cell_type": "markdown",
"id": "empirical-blackjack",
"metadata": {},
"source": [
"## Data import, preprocess and shape for the computations"
]
},
{
"cell_type": "markdown",
"id": "hindu-ireland",
"metadata": {},
"source": [
"### Get the different files where data are stored\n",
"\n",
"Eddy-covariance data from the OzFlux network are stored in **.nc** files (NetCDF4 files) which is roughly a panda data frame with meta-data (see https://www.unidata.ucar.edu/software/netcdf/ for more details about NetCDF4 file format). fPAR data are stored in **.txt** files"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "measured-basis",
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['../../../data/eddycovdata/fpar_adelaide_v5.txt', '../../../data/eddycovdata/fpar_daly_v5.txt', '../../../data/eddycovdata/fpar_dry_v5.txt', '../../../data/eddycovdata/fpar_howard_v5.txt', '../../../data/eddycovdata/fpar_sturt_v5.txt']\n",
"['../../../data/eddycovdata/AdelaideRiver_L4.nc', '../../../data/eddycovdata/DalyUncleared_L4.nc', '../../../data/eddycovdata/DryRiver_L4.nc', '../../../data/eddycovdata/HowardSprings_L4.nc', '../../../data/eddycovdata/SturtPlains_L4.nc']\n"
]
}
],
"source": [
"fPAR_files = []\n",
"eddy_files = []\n",
"\n",
"for file in os.listdir(path_data):\n",
" if file.endswith(\".txt\"):\n",
" fPAR_files.append(os.path.join(path_data, file))\n",
" elif file.endswith(\".nc\"):\n",
" eddy_files.append(os.path.join(path_data, file))\n",
" \n",
"fPAR_files.sort()\n",
"print(fPAR_files)\n",
"eddy_files.sort()\n",
"print(eddy_files)"
]
},
{
"cell_type": "markdown",
"id": "sunset-dispatch",
"metadata": {},
"source": [
"### Define and test a function that process the fPAR data\n",
"In the **.txt** files, only one value per month is given for the fPAR. The following function takes one .txt file containing data about the fPAR coefficients, and the related dates, stored in the a seperate file. The fPAR data (date and coefficients) are cleaned (good string formatting), mapped together and averaged to output one value per month (the fPAR measurement period doesn't spans the measurement period of the eddy covariance data)"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "stopped-jacket",
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
"metadata": {},
"outputs": [],
"source": [
"def fPAR_data_process(fPAR_file,dates_fPAR):\n",
" \n",
" fparv5_dates = np.genfromtxt(dates_fPAR, dtype='str', delimiter=',')\n",
" fparv5_dates = pd.to_datetime(fparv5_dates[:,1], format=\"%Y%m\")\n",
" dates_pd = pd.date_range(fparv5_dates[0], fparv5_dates[-1], freq='MS')\n",
"\n",
" fparv5_howard = np.loadtxt(fPAR_file,delimiter=',', usecols=3 )\n",
" fparv5_howard[fparv5_howard == -999] = np.nan\n",
" fparv5_howard_pd = pd.Series(fparv5_howard, index = fparv5_dates)\n",
" fparv5_howard_pd = fparv5_howard_pd.resample('MS').max()\n",
"\n",
" # convert fparv5_howard_pd to dataframe\n",
" fPAR_pd = pd.DataFrame(fparv5_howard_pd)\n",
" fPAR_pd = fPAR_pd.rename(columns={0:\"fPAR\"})\n",
" fPAR_pd.index = fPAR_pd.index.rename(\"time\")\n",
"\n",
" # convert fPAR_pd to xarray to aggregate the data\n",
" fPAR_xr = fPAR_pd.to_xarray()\n",
" fPAR_agg = fPAR_xr.fPAR.groupby('time.month').max()\n",
"\n",
" # convert back to dataframe\n",
" fPAR_pd = fPAR_agg.to_dataframe()\n",
" Month = np.arange(1,13)\n",
" Month_df = pd.DataFrame(Month)\n",
" Month_df.index = fPAR_pd.index\n",
" Month_df = Month_df.rename(columns={0:\"Month\"})\n",
"\n",
" fPAR_mon = pd.concat([fPAR_pd,Month_df], axis = 1)\n",
" \n",
" return(fPAR_mon)"
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "corresponding-selection",
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>fPAR</th>\n",
" <th>Month</th>\n",
" </tr>\n",
" <tr>\n",
" <th>month</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.78</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.84</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.79</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.84</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.71</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.75</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>0.60</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>0.54</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>0.52</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>0.67</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>0.73</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>0.78</td>\n",
" <td>12</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" fPAR Month\n",
"month \n",
"1 0.78 1\n",
"2 0.84 2\n",
"3 0.79 3\n",
"4 0.84 4\n",
"5 0.71 5\n",
"6 0.75 6\n",
"7 0.60 7\n",
"8 0.54 8\n",
"9 0.52 9\n",
"10 0.67 10\n",
"11 0.73 11\n",
"12 0.78 12"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fPAR_data_process(fPAR_files[3],dates_fPAR)"
]
},
{
"cell_type": "markdown",
"id": "related-appraisal",
"metadata": {},
"source": [
"### fPARSet function\n",
"Map the fPAR time serie to the given eddy-covariance data. Takes two dataframes as input (one containing the fPAR data, the other containing the eddy-covariance data) and returns a data frame where the fPAR monthly values have been scaled to the time scale of the eddy covariance data"
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "macro-musician",
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
"metadata": {},
"outputs": [],
"source": [
"def fPARSet(df_add, fPAR_pd):\n",
" \n",
" # construct the time serie of the fPAR coefficients\n",
" dummy_len = df_add[\"Fe\"].size\n",
" fPAR_val = np.zeros((dummy_len,))\n",
" \n",
" dummy_pd = df_add\n",
" dummy_pd.reset_index(inplace=True)\n",
" dummy_pd.index=dummy_pd.time\n",
" \n",
" month_pd = dummy_pd['time'].dt.month\n",
" \n",
" for i in range(dummy_len):\n",
" current_month = month_pd.iloc[i]\n",
" line_fPAR = fPAR_pd[fPAR_pd['Month'] == current_month]\n",
" fPAR_val[i] = line_fPAR['fPAR']\n",
" \n",
" # transform fPAR_val into dataframe to concatenate to df:\n",
" fPAR = pd.DataFrame(fPAR_val, index = df_add.index)\n",
" df_add = pd.concat([df_add,fPAR], axis = 1)\n",
" df_add = df_add.rename(columns = {0:\"fPAR\"})\n",
" \n",
" return(df_add)"
]
},
{
"cell_type": "markdown",
"id": "hungarian-dominant",
"metadata": {},
"source": [
"### DataChose function\n",
"\n",
"Function taking the raw netcdf4 data file from the eddy covariance measurement and shape it such that it can be used for the computations. Only relevant variables are kept (latent heat flux, net radiation, ground heat flux, soil water content, wind speed, air temperature, VPD, bed shear stress). The desired data period is selected and is reshaped at the desired time scale (daily by default). Uses the fPARSet function defined above\n",
"\n",
"List of variable abbreviation : \n",
"* `Rn` : Net radiation flux\n",
"* `G` : Ground heat flux \n",
"* `Sws` : soil moisture\n",
"* `Ta` : Air temperature\n",
"* `RH` : Relative humidity\n",
"* `W` : Wind speed\n",
"* `E` : measured evaporation\n",
"* `VPD` : Vapour pressure deficit"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "advisory-reader",
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
"metadata": {},
"outputs": [],
"source": [
"def DataChose(ds_ref, period_sel, fPAR_given, Freq = \"D\", sel_period_flag = True):\n",
" \"\"\"Take subset of dataset if Flag == True, entire dataset else\n",
" \n",
" ds_ref: xarray object to be considered as the ref for selecting attributes\n",
" agg_flag: aggregate the data at daily time scale if true\n",
" Flag: select specific period if true (by default)\n",
" period: time period to be selected\n",
" ----------\n",
" Method : \n",
" - transform the xarray in panda dataframe for faster iteration\n",
" - keep only the necessary columns : Fe, Fn, Fg, Ws, Sws, Ta, ustar, RH\n",
" - transform / create new variables : Temperature in °C, T_min/T_max, RH_min/RH_max\n",
" - create the Data vector (numpy arrays)\n",
" - create back a xarray \n",
" - return an xarray\n",
" ----------\n",
" \n",
" Returns an xarray and a Data vector\n",
" \"\"\"\n",
" \n",
" if sel_period_flag:\n",
" df = ds_ref.sel(time = period_sel) \n",
" # nameXarray_output = period + \"_\" + nameXarray_output\n",
" else : \n",
" df = ds_ref\n",
" \n",
" # keep only the columns of interest\n",
" df = df[[\"Fe\",\"Fn\",\"Fg\",\"Ws\",\"Sws\",\"Ta\",\"ustar\",\"RH\", \"VPD\",\"ps\"]]\n",
" \n",
" # convert to dataframe\n",
" df = df.to_dataframe()\n",
" \n",
" # aggregate following the rule stated in freq\n",
" pd_Tmin = df.Ta.groupby([pd.Grouper(level = \"latitude\"), pd.Grouper(level = \"longitude\"), pd.Grouper(level = \"time\", freq = Freq)]).min()\n",
" \n",
" pd_Tmax = df.Ta.groupby([pd.Grouper(level = \"latitude\"), pd.Grouper(level = \"longitude\"), pd.Grouper(level = \"time\", freq = Freq)]).max()\n",
" \n",
" pd_RHmin = df.RH.groupby([pd.Grouper(level = \"latitude\"), pd.Grouper(level = \"longitude\"), pd.Grouper(level = \"time\", freq = Freq)]).min()\n",
" \n",
" pd_RHmax = df.RH.groupby([pd.Grouper(level = \"latitude\"), pd.Grouper(level = \"longitude\"), pd.Grouper(level = \"time\", freq = Freq)]).max()\n",
" \n",
" df = df.groupby([pd.Grouper(level = \"latitude\"), pd.Grouper(level = \"longitude\"), pd.Grouper(level = \"time\", freq = Freq)]).mean()\n",
" df = pd.DataFrame(df)\n",
" \n",
" pd_Tmin = pd.DataFrame(pd_Tmin, index = df.index)\n",
" pd_Tmin = pd_Tmin.rename(columns = {\"Ta\":\"Ta_min\"})\n",
" \n",
" pd_Tmax = pd.DataFrame(pd_Tmax, index = df.index)\n",
" pd_Tmax = pd_Tmax.rename(columns = {\"Ta\":\"Ta_max\"})\n",
" \n",
" pd_RHmin = pd.DataFrame(pd_RHmin, index = df.index)\n",
" pd_RHmin = pd_RHmin.rename(columns = {\"RH\":\"RH_min\"})\n",
" \n",
" pd_RHmax = pd.DataFrame(pd_RHmax, index = df.index)\n",
" pd_RHmax = pd_RHmax.rename(columns = {\"RH\":\"RH_max\"})\n",
" \n",
" df = pd.concat([df,pd_Tmin,pd_Tmax,pd_RHmin,pd_RHmax],axis = 1)\n",
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
" \n",
" # convert data to the good units : \n",
" df[\"Fe\"] = df[\"Fe\"]/2.45e6 # divide by latent heat of vaporization\n",
" df[\"Ta\"] = df[\"Ta\"]+273 # convert to kelvin\n",
" df[\"VPD\"] = df[\"VPD\"]*1000 # convert from kPa to Pa\n",
" \n",
" # construct the time serie of the fPAR coefficients\n",
" df = fPARSet(df,fPAR_given)\n",
" \n",
" # initialise array for the error\n",
" Error_obs = np.zeros((df.Fe.size,))\n",
" \n",
" for i in range(df.Fe.size):\n",
" size_window_left, size_window_right = min(i,7),min(df.Fe.size - i-1, 7)\n",
" #print(size_window_left, size_window_right)\n",
" sub_set = df.Fe[i-size_window_left : i+size_window_right].to_numpy()\n",
" mean_set = np.mean(sub_set)\n",
" sdt_set = np.std(sub_set)\n",
" error_obs = 2*sdt_set\n",
" Error_obs[i] = error_obs\n",
" \n",
" ErrorObs = pd.DataFrame(Error_obs, index = df.index)\n",
" \n",
" df = pd.concat([df,ErrorObs], axis = 1)\n",
" df = df.rename(columns = {0:\"error\"})\n",
"\n",
" \n",
" return(df)"
]
},
{
"cell_type": "markdown",
"id": "addressed-korean",
"metadata": {},
"source": [
"## Compile the different functions defined in the symbolic domain\n",
"All functions defined with sympy and ESSM are defined in the symbolic domain. In order to be efficiently evaluated, they need to be vectorized to allow computations with numpu arrays. We use the *aesara* printing compiler from the sympy package. Note that this printer replace the older one (*theano*) which is deprecated. A comparison of the performances between the two packages can be found in the aesara repository."
]
},
{
"cell_type": "markdown",
"id": "honest-berlin",
"metadata": {},
"source": [
"### Water stress functions"
]
},
{
"cell_type": "code",
"execution_count": 94,
"id": "favorite-corpus",
"metadata": {},
"outputs": [],
"source": [
"def rising_slope_compiled():\n",
" \"\"\"Compile the slope of the function between theta 4 and theta 3\"\"\"\n",
" \n",
" rising_slope = aesara_function([theta,theta_3, theta_4], [eq_theta_4_3.rhs], dims = {theta:1, theta_3:1, theta_4:1})\n",
" \n",
" return(rising_slope)\n",
"\n",
"def desc_slope_compiled():\n",
" \"\"\"Compile the slope of the function between theta 2 and theta 1\"\"\"\n",
" \n",
" desc_slope = aesara_function([theta,theta_1, theta_2], [eq_theta_2_1.rhs], dims = {theta:1, theta_1:1, theta_2:1})\n",
" \n",
" return(desc_slope)"
]
},
{
"cell_type": "markdown",
"id": "piano-isolation",
"metadata": {},
"source": [
"### Soil water potential"
]
},
{
"cell_type": "code",
"execution_count": 95,
"id": "simplified-wilson",
"metadata": {},
"outputs": [],
"source": [
"def relative_saturation_compiled(ThetaRes, ThetaSat):\n",
" \"\"\"Compile the relative saturation function of a soil\"\"\"\n",
" Dict_value = {theta_res : ThetaRes, theta_sat : ThetaSat}\n",
" \n",
" S_mvg_func = aesara_function([theta], [eq_sat_degree.rhs.subs(Dict_value)], dims = {theta:1})\n",
" \n",
" return(S_mvg_func)"
]
},
{
"cell_type": "code",
"execution_count": 96,
"id": "significant-addition",
"metadata": {},
"outputs": [],
"source": [
"def Psi_compiled(alphaVal, nVal):\n",
" \"\"\"Compile the soil water retention function as function of theta\"\"\"\n",
" mVal = 1-1/nVal\n",
" \n",
" Dict_value = {alpha : alphaVal, n : nVal, m : mVal}\n",
" \n",
" Psi_function = aesara_function([S_mvg], [eq_MVG_h.rhs.subs(Dict_value)], dims = {S_mvg:1})\n",
" \n",
" return(Psi_function)"
]
},
{
"cell_type": "markdown",
"id": "empirical-parks",
"metadata": {},
"source": [
"### Penman-Monteith"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "designing-mambo",
"metadata": {},
"outputs": [],
"source": [
"def Delta_compiled():\n",
" \"\"\"Compile the Delta function\"\"\"\n",
" \n",
" # creating the dictionnary with all default values from the above defined constants\n",
" var_dict = Variable.__defaults__.copy()\n",
" \n",
" # computing delta values out of temperature values (slope of the water pressure curve)\n",
" Delta_func = aesara_function([T],[eq_Delta.rhs.subs(var_dict)], dims = {T:1})\n",
" \n",
" return(Delta_func)"
]
},
{
"cell_type": "code",