# **Location of the stress factor in potential evapo-transpiration models**
%% Cell type:markdown id:capable-israel tags:
%% Cell type:markdown id:based-knight tags:
# Part I - Methodology
## <u> Motivation </u>
### Theoretical background
In the literature, different approaches to scale potential evapo-transpiration to actual evapo-transpiration accouting for water stress conditions can be found. In this work we investigate only the approaches using a stress factor which lowers potential evapo-transpiration down to actual evapo-transpiration (Barton 1979, Fisher et al. 2008, Martens et al. 2017, Miralles et al. 2011). Different definitions of the stress factor can be encountered, with different mathematical shapes and taking different parameters into account. In this study, we only consider the soil water content, $\theta$, and we define the stress function as a simple piecewise linear function :
Different models are being developped out of different potential evapo-transpiration models to assess the potential of this method. Especially, we are here interested in assessing the position of this stress factor by combining it with the Penman-Monteith model :
Different experiments are carried out to infer the best possible model between the constant surface conductance and varying surface conductance models:
1. Both models are calibrated for a single year and their ability to reproduce an observed time serie is assessed
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.
3. The same procedure is repeated across different sites in Australia
%% Cell type:markdown id:nonprofit-ordering tags:
%% Cell type:markdown id:touched-oliver tags:
# Part II - Functions set up
%% Cell type:markdown id:played-python tags:
%% Cell type:markdown id:eligible-township tags:
## Importing relevant packages
%% Cell type:code id:wrapped-attachment tags:
%% Cell type:code id:religious-powder tags:
``` python
# data manipulation and plotting
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib._layoutgrid import plot_children
from collections import OrderedDict
from IPython.display import display
import os # to look into the other folders of the project
import importlib.util # to open the .py files written somewhere else
#sns.set_theme(style="whitegrid")
# Sympy and sympbolic mathematics
from sympy import (asin, cos, diff, Eq, exp, init_printing, log, pi, sin,
solve, sqrt, Symbol, symbols, tan, Abs)
from sympy.physics.units import convert_to
init_printing()
from sympy.printing import StrPrinter
from sympy import Piecewise
StrPrinter._print_Quantity = lambda self, expr: str(expr.abbrev) # displays short units (m instead of meter)
from sympy.printing.aesaracode import aesara_function
from sympy.physics.units import * # Import all units and dimensions from sympy
from sympy.physics.units.systems.si import dimsys_SI, SI
# for ESSM, environmental science for symbolic math, see https://github.com/environmentalscience/essm
from essm.variables._core import BaseVariable, Variable
from essm.equations import Equation
from essm.variables.units import derive_unit, SI, Quantity
from essm.variables.utils import (extract_variables, generate_metadata_table, markdown,
replace_defaults, replace_variables, subs_eq)
from essm.variables.units import (SI_BASE_DIMENSIONS, SI_EXTENDED_DIMENSIONS, SI_EXTENDED_UNITS,
names = getattr(mod, '__all__', [n for n in dir(mod) if not n.startswith('_')])
glob = globals()
for name in names:
print(name)
glob[name] = getattr(mod, name)
```
%%%% Output: stream
AIC
AME
BIC
CD
CP
IoA
KGE
MAE
MARE
ME
MRE
MSRE
MdAPE
NR4MS4E
NRMSE
NS
NSC
PDIFF
PEP
R4MS4E
RAE
RMSE
RVE
np
nt
%% Cell type:markdown id:later-server tags:
%% Cell type:markdown id:valuable-smart tags:
## Data import, preprocess and shape for the computations
%% Cell type:markdown id:foster-legislation tags:
%% Cell type:markdown id:piano-sharp tags:
### Get the different files where data are stored
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
### Define and test a function that process the fPAR data
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)
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 id:fitted-involvement tags:
%% Cell type:code id:known-sport tags:
``` python
def fPARSet(df_add, fPAR_pd):
# construct the time serie of the fPAR coefficients
# transform fPAR_val into dataframe to concatenate to df:
fPAR = pd.DataFrame(fPAR_val, index = df_add.index)
df_add = pd.concat([df_add,fPAR], axis = 1)
df_add = df_add.rename(columns = {0:"fPAR"})
return(df_add)
```
%% Cell type:markdown id:outstanding-object tags:
%% Cell type:markdown id:unnecessary-hunger tags:
### DataChose function
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
ErrorObs = pd.DataFrame(Error_obs, index = df.index)
df = pd.concat([df,ErrorObs], axis = 1)
df = df.rename(columns = {0:"error"})
return(df)
```
%% Cell type:markdown id:pregnant-success tags:
%% Cell type:markdown id:third-optimization tags:
## Compile the different functions defined in the symbolic domain
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:incident-original tags:
%% Cell type:markdown id:magnetic-slave tags:
### Water stress functions
%% Cell type:code id:macro-ceremony tags:
%% Cell type:code id:hundred-measurement tags:
``` python
def rising_slope_compiled():
"""Compile the slope of the function between theta 4 and theta 3"""