Model#
This class allows to manipulate the datasets in an efficient manner. it contains the necessary functions to load nad pre-process the raw data, calculate GPP, iPAR, Stress Factor, Day Temperature and estimate grain yield.
Model(config, params=None)
#
Bases: object
load_raw_datasets()
#
Load raw phenology and AgERA5 datasets
Return
A existing dataset including WeatherFile, PhenoFile, NDVIFile. The raw data can be seen in config object. eg. config['PhenoFile']
preprocess_raw_datasets(data)
#
Preprocess raw datasets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
dictionary
|
The phenology, ndvi and weather data for each location in example dataset. |
required |
Return
A dataset in a specific format for the tfunct package
getTDay(m=None, w=None, tminFactor=None)
#
Calculate day time temperature
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m |
object
|
A tfunct model with sites and the necessary information |
None
|
w |
array
|
Table of weather data with minimum and maximum temperature records |
None
|
tminFactor |
float
|
Minimum Temperature factor. Default is usually 0.25.
It can be reviewed in configuration parameters such as |
None
|
Returns:
Type | Description |
---|---|
array
|
A number or array of Day Temperature |
getIPAR(m=None, ndvi=None)
#
Total light interception - iPAR
Reference
iPAR = NDVI * 1.25 - 0.19 # between heading and maturity (Campos et al. 2018)
iPAR = NDVI * 1.25 - 0.21 Daughtry et al. (1992)
-
Asrar, G., Fuchs, M., Kanemasu, E.T., Hatfield, J.L., 1984. Estimating absorbed photosynthetic radiation and leaf area index from spectral reflectance in wheat. Agron. J. 76, 30-306.
-
Campos 2018 Remote sensing-based crop biomass with water or light-driven crop growth models in wheat commercial fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m |
object
|
A tfunct model |
None
|
ndvi |
array
|
Array of float values |
None
|
Returns:
Type | Description |
---|---|
array
|
An array of Total light interception values |
getYield(tfun='PRFT', sites=None, is_VPDStress=False, expCSV=True)
#
Get yield using a defined temperature function and default parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tfun |
str
|
Name of the temperature function |
'PRFT'
|
sites |
dictionary
|
List of sites with the basic information to estimate yield. |
None
|
is_VPDStress |
bool
|
Vapor Pressure Deficit stress. Default is False. |
False
|
expCSV |
bool
|
Export grain yield results in an individual file. Default is True. |
True
|
Returns:
Type | Description |
---|---|
array
|
A dataframe with simulated grain yield values |
runCombinations_PRFT(data=None, sites=None, comb=None, is_VPDStress=False, expCSV=True, individualCSV=False, target=None)
#
Run several combinations using different parameters for PRFT model
Deprecated
Stop using this function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
object
|
Array of base data. |
None
|
sites |
object
|
Array of sites |
None
|
comb |
object
|
Array of combinations |
None
|
is_VPDStress |
bool
|
Vapor Pressure Deficit stress. Default is False |
False
|
expCSV |
bool
|
Save results in CSV format. Default is True |
True
|
individualCSV |
bool
|
Default is False |
False
|
target |
str
|
Name of the target device. Available values are |
None
|
Returns:
Type | Description |
---|---|
object
|
A dataframe with estimated grain yield of all combinations. |
fit(data=None, sites=None, comb=None, ft='PRFT', is_VPDStress=False, expCSV=True, individualCSV=False, n_jobs=4, verbose=False)
#
Run a model to fit yield
Deprecated on Dec, 2022.
Stop using this function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
object
|
Array of base data. |
None
|
sites |
object
|
Array of sites |
None
|
comb |
object
|
Array of combinations |
None
|
ft |
str
|
Name of the temperature response function. Default is 'PRFT'. |
'PRFT'
|
is_VPDStress |
bool
|
Vapor Pressure Deficit stress. Default is False |
False
|
expCSV |
bool
|
Save results in CSV format. Default is True |
True
|
individualCSV |
bool
|
Default is False |
False
|
n_jobs |
int
|
Number of CPU cores to use in paralell processing. Default is 4. |
4
|
verbose |
bool
|
Display comments during processing. Default is False |
False
|
Returns:
Type | Description |
---|---|
array
|
An array of sites with intermediate results |
setup_dataInput_forCombinations(sites)
#
Set up data for each sites to estimate grain yield from different combinations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sites |
dictionary
|
|
required |
Return
Array of arrays with weather, iPAR and GPP data
getCombinations(functype='PRFT', cols=None, RUE=None, Tmin=None, Toptmin=None, Topt=None, Toptmax=None, Tmax=None, TminFactor=None, Lvpd=None, Uvpd=None, SFvpd_Lthres=None, SFvpd_Uthres=None, isVPDStress=False)
#
Generate combinations to establish the optimum temperature response for grain-filling period and estimate grain yield.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
functype |
str
|
Type of temperature response function (eg. PRFT, WETF, TPF) |
'PRFT'
|
cols |
int
|
Number of daily records in growing period |
None
|
RUE |
array
|
Array of RUE values |
None
|
Tmin |
array
|
Array of minimum temperature values |
None
|
Toptmin |
array
|
Array of Optimun minimum temperature values |
None
|
Topt |
array
|
Array of Optimun temperature values |
None
|
Toptmax |
array
|
Array of Optimun maximum temperature values |
None
|
Tmax |
array
|
Array of maximum temperature values |
None
|
TminFactor |
array
|
Array of minimum temperature factor |
None
|
Lvpd |
array
|
Array of lower VPD values |
None
|
Uvpd |
array
|
Array of lower VPD values |
None
|
SFvpd_Lthres |
array
|
Array of lower VPD stress factor values |
None
|
SFvpd_Uthres |
array
|
Array of lower VPD stress factor values |
None
|
isVPDStress |
bool
|
True/False value for using VPD stress condition |
False
|
Return
Array of combinations and an array to save results
getGYield_forCombinations(functype, df_GYield, data_input, array_params_to_run, isVPDStress, array_results, saveFile=True, returnDF=True, fmt='parquet')
#
Estimate grain yield using parameters for each combinations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_GYield |
array
|
Dataframe with observed grain yield |
required |
data_input |
array
|
Array of inputs containing weather, iPAR, PRFT and GPP data for each site. |
required |
array_params_to_run |
array
|
Array of combinations (RUE, TOpt and TminFactor) to simulate |
required |
isVPDStress |
bool
|
True/False value for using VPD stress condition |
required |
array_results |
array
|
Array used to save results |
required |
saveFile |
bool
|
True if save file in results folder |
True
|
returnDF |
bool
|
True if return a pandas dataframe. Use False when the combinations are too large. |
True
|
fmt |
str
|
Format to save file. Comma separate value (csv) or Apache parquet (parquet).
Default is |
'parquet'
|
Return
A dataframe or table with results
getCombinations_Metrics(functype, isVPDStress, df_GYield, array_params_to_run, array_results, saveFile=True, fmt='parquet')
#
Get evaluation metrics for each simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
functype |
str
|
Type of temperature response function (eg. PRFT, WETF, TPF) |
required |
isVPDStress |
bool
|
True/False value for using VPD stress condition |
required |
df_GYield |
array
|
Dataframe with observed grain yield |
required |
array_params_to_run |
array
|
Array of combinations (RUE, TOpt and TminFactor) to simulate |
required |
array_results |
array
|
Array used to save results |
required |
saveFile |
bool
|
True if save file in results folder |
True
|
fmt |
str
|
Format to save file. Comma separate value (csv) or Apache parquet (parquet).
Default is |
'parquet'
|
Return
A dataframe with several metrics
Returns:
Name | Type | Description |
---|---|---|
MAE |
float
|
Mean Absolute Error |
MSE |
float
|
Mean Squared Error |
RMSE |
float
|
Root Mean Squared Error |
RMSRE |
float
|
Root Mean Squared Relative Error |
MAPE |
float
|
Mean Absolute Percentage Error |
pvalue |
float
|
p-value |
R2 |
float
|
R Squared metric |
EF |
float
|
Nash-Sutcliffe metric |
intercept |
float
|
Intercept of the regression model |
slope |
float
|
Slope of the regression model |
Cb |
float
|
A bias correction factor |
CCC |
float
|
Concordance correlation coefficient |
Accuracy |
float
|
Accuracy in percentage |
gpp
#
calcGPP(SolRad, TF, iPAR, RUE=3.0, stressFactor=1.0)
#
Estimate the Gross primary production
Parameters:
Name | Type | Description | Default |
---|---|---|---|
SolRad |
float
|
Solar Radiation |
required |
TF |
float
|
Temperature function result (PRFT, WETF, TPF) |
required |
iPAR |
float
|
the photosynthetically active radiation (PAR) intercepted by a plant or crop estimated from NDVI |
required |
RUE |
float
|
Radiation-use efficiency. Default value is 3.0 gMJ^−1 |
3.0
|
stressFactor |
float
|
Stress Factor (eg. VPD stress factor) |
1.0
|
Deprecated.
This function only use one value for each paramters. it is not optimized for run models in parallel.
Returns:
Type | Description |
---|---|
float
|
the gross primary production (GPP) |
apply_GPP_v0(SolRad, PRFT, iPAR, RUE=3.0, stressFactor=1.0)
#
calculateGPP(SolRad, PRFT, iPAR, RUE=3.0, stressFactor=1.0)
#
Estimate the Gross primary production. The accumulated dry matter from heading to maturity
# GPP = Solar Radiation × TemFun × VPD_StressFactor × iPAR_fromNDVI × RUE
GPP = SolRad * 0.5 * RUE * PRFT * iPAR * stressFactor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
SolRad |
float
|
Solar Radiation |
required |
PRFT |
float
|
Photosynthesis reduction factor |
required |
iPAR |
float
|
the photosynthetically active radiation (PAR) intercepted by a plant or crop |
required |
RUE |
float
|
Radiation-use efficiency. Default value is 3.0 gMJ^-1 |
3.0
|
stressFactor |
float
|
Stress Factor |
1.0
|
Returns:
Type | Description |
---|---|
float
|
a number or array of values with the gross primary production (GPP) |
applyGPP_VPDStress(SolRad, PRFT, iPAR, SFvpd, RUE=3.0)
#
calculateGPP_VPDStress(SolRad, PRFT, iPAR, SFvpd, RUE=3.0)
#
Estimate the Gross primary production with stressed VPD
Parameters:
Name | Type | Description | Default |
---|---|---|---|
SolRad |
float
|
Solar Radiation |
required |
PRFT |
float
|
Photosynthesis reduction factor |
required |
iPAR |
float
|
the photosynthetically active radiation (PAR) intercepted by a plant or crop |
required |
RUE |
float
|
Radiation-use efficiency. Default value is 3.0 |
3.0
|
SFvpd |
float
|
Vapor Pressure Deficit (VPD) stress factor |
required |
Returns:
Type | Description |
---|---|
float
|
a number or array of values with the gross primary production (GPP) |
estimate(data, params, is_VPDStress, tf, results)
#
An optimized function for estimating GPP for all observations using one of the three Temperature Function (TF) such as PRFT, WETF and TPF.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
object
|
Array of arrays containing tn, tx, ndvi, solrad, VPDx, ipar, GPP datasets |
required |
params |
object
|
An array with RUE, tminFactor, Topt, Lvpd, Uvpd, SFvpd_Lthres, SFvpd_Uthres values |
required |
is_VPDStress |
array
|
Array of one value with T/F if Vapor Pressure Deficit stress affecting grain yield. Default is [False]. |
required |
tf |
array
|
Array of one value representing the type of function. [1]: PRFT; [2]: WETF; [3]: TPF. |
required |
results |
array
|
Empty array for outputs. |
required |
Returns:
Name | Type | Description |
---|---|---|
results |
array
|
An array with estimated yield for each site. |
gyield
#
estimate(data, params, is_VPDStress, tf, results)
#
An optimized function for estimating grain yield in one step for all observations using one of the three Temperature Function (TF) such as PRFT, WETF and TPF.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
object
|
Array of arrays containing tn, tx, ndvi, solrad, VPDx, ipar, GPP datasets |
required |
params |
object
|
An array with RUE, tminFactor, Topt, Lvpd, Uvpd, SFvpd_Lthres, SFvpd_Uthres values |
required |
is_VPDStress |
array
|
Array of one value with T/F if Vapor Pressure Deficit stress affecting grain yield. Default is [False]. |
required |
tf |
array
|
Array of one value representing the type of function. [1]: PRFT; [2]: WETF; [3]: TPF. |
required |
results |
array
|
Empty array for outputs. |
required |
Returns:
Name | Type | Description |
---|---|---|
results |
array
|
An array with estimated yield for each site. |
ipar
#
calcIPAR(ndvi)
#
Total light interception - iPAR
Reference
iPAR = NDVI * 1.25 - 0.19 # between heading and maturity (Campos et al. 2018)
iPAR = NDVI * 1.25 - 0.21 Daughtry et al. (1992)
-
Asrar, G., Fuchs, M., Kanemasu, E.T., Hatfield, J.L., 1984. Estimating absorbed photosynthetic radiation and leaf area index from spectral reflectance in wheat. Agron. J. 76, 30-306.
-
Campos 2018 Remote sensing-based crop biomass with water or light-driven crop growth models in wheat commercial fields.
Deprecated.
Stop using this function. This function estimate iPAR using only one value for each parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ndvi |
array
|
Array of float values |
required |
Returns:
Type | Description |
---|---|
array
|
An array of Total light interception values |
estimate_IPAR(ndvi=None)
#
Total light interception - iPAR.
It is assumed that NDVI at maturity is 0.25.
Reference
iPAR = NDVI * 1.25 - 0.19 # between heading and maturity (Campos et al. 2018)
iPAR = NDVI * 1.25 - 0.21 Daughtry et al. (1992)
-
Asrar, G., Fuchs, M., Kanemasu, E.T., Hatfield, J.L., 1984. Estimating absorbed photosynthetic radiation and leaf area index from spectral reflectance in wheat. Agron. J. 76, 30-306.
-
Campos 2018 Remote sensing-based crop biomass with water or light-driven crop growth models in wheat commercial fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ndvi |
array
|
Array of float values |
None
|
Returns:
Type | Description |
---|---|
array
|
An array of Total light interception values |
prft
#
calcPRFT(TDay, TOpt=18)
#
Estimate Photosynthesis reduction factor (PRFT)
Deprecated.
Stop using this function. This function estimate PRFT using only one value for each parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
TDay |
float
|
Number or array of Day Temperatures |
required |
TOpt |
float
|
Optimum Temperature. Default value 18 |
18
|
Returns:
Type | Description |
---|---|
float
|
A number or array of PRFT |
calculatePRFT(Tday, Topt=18)
#
Estimate Photosynthesis reduction factor (PRFT) in parallel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Tday |
float
|
Number or array of Day Temperatures |
required |
Topt |
float
|
Optimum Temperature. Default value 18 |
18
|
Returns:
Type | Description |
---|---|
float
|
A number or array of PRFT |
sfvpd
#
calcSFvpd(VPDx, Lvpd, Uvpd, SFvpd_Lthres, SFvpd_Uthres)
#
getSFvpd(VPDx, Lvpd, Uvpd, SFvpd_Lthres, SFvpd_Uthres)
#
apply_SFvpd(VPDMAX, Lvpd=1, Uvpd=4, SFvpd_Lthres=0.2, SFvpd_Uthres=1)
#
calculateSFvpd(VPDMAX, Lvpd=1, Uvpd=4, SFvpd_Lthres=0.2, SFvpd_Uthres=1)
#
Calculation of Vapor pressure deficit (VPD) stress factor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
VPDMAX |
array
|
Array of daily temperature values |
required |
Lvpd |
float
|
A number for threshold of lower VPD. Default is 1 |
1
|
Uvpd |
array
|
A number for threshold of upper VPD. Default is 4 |
4
|
SFvpd_Lthres |
array
|
A number for threshold of stress factor of lower VPD. Default is 0.2 |
0.2
|
SFvpd_Uthres |
array
|
A number for threshold of stress factor of upper VPD. Default is 1 |
1
|
Returns:
Type | Description |
---|---|
array
|
A number or array of stressed factors of VPD |
tday
#
calcTDay(Tmin, Tmax, tminFactor=0.25)
#
Calculate day time temperature. TDay is a function of weighted Tmin and weighted Tmax.
Deprecated.
Stop using this function. This function estimate day time temperature (TDay) using only one value for each parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Tmin |
float
|
Number or array of Minimum Temperatures |
required |
Tmax |
float
|
Number or array of Maximum Temperatures |
required |
tminFactor |
float
|
Minimum Temperature factor |
0.25
|
Returns:
Type | Description |
---|---|
float
|
A number of Day Temperatures |
getTDay(Tmin, Tmax, tminFactor=0.25)
#
apply_TDay(Tmin, Tmax, tminFactor)
#
estimate_TDay(Tmin=None, Tmax=None, tminFactor=0.25)
#
An optimized function to calculate day time temperature in parallel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Tmin |
float
|
Number or array of Minimum Temperatures |
None
|
Tmax |
float
|
Number or array of Maximum Temperatures |
None
|
tminFactor |
float
|
Minimum Temperature factor |
0.25
|
Returns:
Type | Description |
---|---|
float
|
A number of Day Temperatures |