Util#
find_nearest_value(array, value)
#
Find nearest value to a user define value from array
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
array
|
Array of values |
required |
value |
int
|
value to find into the array |
required |
Returns:
Type | Description |
---|---|
int
|
a number with the nearest value found |
find_nearest_index(array, values)
#
Find nearest index to a user define value from array
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
array
|
Array of values |
required |
values |
int
|
value to find into the array |
required |
Returns:
Type | Description |
---|---|
int
|
a number with the nearest index found |
find_nearest(array, value)
#
Find nearest index and value to a user define value from array
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
array
|
Array of values |
required |
value |
int
|
value to find into the array |
required |
Returns:
Type | Description |
---|---|
int
|
a number with the nearest value found |
CCC(y_true, y_pred)
#
Lin's Concordance correlation coefficient
Computes Lin's (1989, 2000) concordance correlation coefficient for agreement on a continuous measure obtained by two methods. The concordance correlation coefficient combines measures of both precision and accuracy to determine how far the observed data deviate from the line of perfect concordance (that is, the line at 45 degrees on a square scatter plot).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true |
array
|
Array of observed values |
required |
y_pred |
array
|
Array of predicted values |
required |
Returns:
Type | Description |
---|---|
float
|
Concordance correlation coefficient |
Cb(x, y)
#
A bias correction factor that measures how far the best-fit line deviates from a line at 45 degrees (a measure of accuracy).
No deviation from the 45 degree line occurs when Cb = 1. See Lin (1989 page 258).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
array
|
Array of observed values |
required |
y |
array
|
Array of predicted values |
required |
Returns:
Type | Description |
---|---|
float
|
Bias correction factor |
getScores(df, fld1=None, fld2=None)
#
Get stats for model results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
array
|
A pandas dataframe with Observed and Simulated values |
required |
fld1 |
str
|
Name of the columns or field with observed values |
None
|
fld2 |
str
|
Name of the columns or field with predicted values |
None
|
Returns:
Name | Type | Description |
---|---|---|
r2score |
float
|
R squared metric |
mape |
float
|
Mean absolute percentage error |
rmse |
float
|
Root mean squared error |
n_rmse |
float
|
Normalized RMSE |
d_index |
float
|
d-index metric |
ef |
float
|
Nash-Sutcliffe metric |
ccc |
float
|
Concordance correlation coefficient |
cb |
float
|
A bias correction factor |
accuracy |
float
|
Accuracy in percentage |
filterTopCombinations(df_m, df_cmb, fnct='PRFT', VPDstress=False, top=3, Cb=1.0, ccc=0.86, rmsre=100)
#
Filter combinations for selecting Top 3 of the best simulations
Deprecated
Stop using this function, instead use filterSimulations
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_m |
array
|
A dataframe with metrics from each simulations |
required |
df_cmb |
array
|
A dataframe with combinations results |
required |
fnct |
str
|
Temperature response function. default 'PRFT' |
'PRFT'
|
VPDstress |
bool
|
Stressed VPD. default False |
False
|
top |
int
|
Number of selected records. default 3 |
3
|
Cb |
float
|
A threshold for Cb metric. default 1.0 |
1.0
|
ccc |
float
|
A threshold for CCC metric. default 0.86 |
0.86
|
rmsre |
float
|
A threshold for RMSRE metric. default 100 |
100
|
Returns:
Type | Description |
---|---|
object
|
A dataframe with all filtered combinations |
filterSimulations(functype='PRFT', VPDstress=False, cmb=None, met=None, cmb_filters=None, met_filters=None, pdFormat=False, dispFig=True, saveFig=False, figname='Fig_topComb_avgYield', figfmt='jpg', saveResults=True, outputPath='./', fmt='parquet')
#
Filter a table with several combinations results from the three temperature functions.
This function is similar to util.filterTopCombinations
function but
optimized to work only with Apache parquet files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
functype |
str
|
Name of the temperature response function. Default 'PRFT' |
'PRFT'
|
VPDstress |
bool
|
Stressed VPD. default False |
False
|
cmb |
str
|
Full path of the combinations result file |
None
|
met |
str
|
Full path of the metrics result file |
None
|
cmb_filters |
dict
|
Dictionary with the parameters to use as a constraints in combonation filters. it must match with the respective temperature function parameters. Default filters: dict( RUE = ('RUE', '=', 3.0 ), TminFactor = ('TminFactor', '=', 0.25 ) ) |
None
|
met_filters |
dict
|
Dictionary with the parameters to use as a constraints in metrics filters. Default values: metfilters = dict( Cb = ('>=', 0.9), CCC = ('>=', 0.8) ) |
None
|
pdFormat |
bool
|
Export filtered dataset in pandas format. Default |
False
|
dispFig |
bool
|
Display figure of grain yield correlation. Default is |
True
|
saveFig |
bool
|
Save figure. Default is |
False
|
figname |
str
|
Name of the figure file to be saved |
'Fig_topComb_avgYield'
|
figfmt |
str
|
Format of the figure file. |
'jpg'
|
saveResults |
bool
|
Save filtered data. Default |
True
|
outputPath |
str
|
Output folder to save the data |
'./'
|
fmt |
str
|
File format to save in csv or parquet. Default is |
'parquet'
|
Returns:
Type | Description |
---|---|
object
|
A dataframe or parquet file with the filtered dataset |
figures
#
chart_compareResults(df_result=None, fld1=None, fld2=None, alpha=0.75, s=15, xy_lim=2, hue=None, loc_leg=2, ncol=2, ha='left', va='top', title='Observed vs Simulated grain yield', xlabel='Observed Yield (tha$^{-1}$)', ylabel='Simulated Yield (tha$^{-1}$)', dirname='Figures_tFunt', fname='Fig_model_', dispScore=True, dispLegend=True, saveFig=False, showFig=True, fmt='pdf')
#
Display a scatter plot to compare two variables in the results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_result |
array
|
A pandas DataFrame with the results and variables to compare |
None
|
fld1 |
str
|
Variable or column name to compare |
None
|
fld2 |
str
|
Variable or column name to compare |
None
|
alpha |
float
|
Transparency of the points in chart |
0.75
|
s |
float
|
Size of the points in chart |
15
|
xy_lim |
int
|
Used to extend the x-axis limit. Default 2 units |
2
|
hue |
str
|
Variable to classify or discriminate the results in colors |
None
|
title |
str
|
Title of the figure |
'Observed vs Simulated grain yield'
|
xlabel |
str
|
Label of the x-axis |
'Observed Yield (tha$^{-1}$)'
|
ylabel |
str
|
Label of the y-axis |
'Simulated Yield (tha$^{-1}$)'
|
dirname |
str
|
Folder name to save results |
'Figures_tFunt'
|
fname |
str
|
File name to save the figure |
'Fig_model_'
|
dispScore |
bool
|
Display the accurracy and others stats of the model |
True
|
dispLegend |
bool
|
Display the legend of the chart |
True
|
saveFig |
bool
|
Save file in JPG or PDF format |
False
|
fmt |
str
|
Format of the output |
'pdf'
|
Returns:
Type | Description |
---|---|
object
|
A figure in JPG or PDF format with the filename specified into the folder name |