# **Location of the stress factor in potential evapo-transpiration models**
%% Cell type:markdown id:ideal-flower tags:
%% Cell type:markdown id:convinced-cargo 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
## Data import, preprocess and shape for the computations
%% Cell type:markdown id:dense-animal tags:
%% Cell type:markdown id:canadian-response 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:infectious-transcript tags:
%% Cell type:code id:adjusted-forwarding 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:later-tampa tags:
%% Cell type:markdown id:eight-publisher 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:viral-colon tags:
%% Cell type:markdown id:opponent-circuit 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:silver-bracket tags:
%% Cell type:markdown id:southeast-yield tags:
### Water stress functions
%% Cell type:code id:deluxe-testimony tags:
%% Cell type:code id:billion-revolution tags:
``` python
def rising_slope_compiled():
"""Compile the slope of the function between theta 4 and theta 3"""