Title: | PEcAn Functions Used for Benchmarking |
---|---|
Description: | The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific workflow management tool that is designed to simplify the management of model parameterization, execution, and analysis. The goal of PEcAn is to streamline the interaction between data and models, and to improve the efficacy of scientific investigation. |
Authors: | Michael Dietze, David LeBauer, Rob Kooper, Toni Viskari |
Maintainer: | Mike Dietze <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.7.3.9000 |
Built: | 2024-12-17 17:39:35 UTC |
Source: | https://github.com/PecanProject/pecan |
Add workflow specific info to settings list for benchmarking
add_workflow_info(settings, bety)
add_workflow_info(settings, bety)
settings |
settings or multisettings object |
bety |
connection to the database |
Betsy Cowdery
align_first_observation
align_by_first_observation(observation_one, observation_two, custom_table)
align_by_first_observation(observation_one, observation_two, custom_table)
observation_one |
a vector of plant functional types, or species. Provides species/pft names. |
observation_two |
another vector of plant functional types, or species. Provides the order. |
custom_table |
a table that either maps two pft's to one another or maps custom species codes to bety id codes. In the second case, must be passable to match_species_id. |
vector
Returns a vector of PFT's/species from observation_one that matches the order of observation_two
Tempest McCabe
observation_one<-c("AMCA3","AMCA3","AMCA3","AMCA3") observation_two<-c("a", "b", "a", "a") table<-list() table$plant_functional_type_one<- c("AMCA3","AMCA3","ARHY", "ARHY") table$plant_functional_type_two<- c('a','a','b', 'b') # PFT groupings table<-as.data.frame(table) aligned <- align_by_first_observation( observation_one = observation_one, observation_two = observation_two, custom_table = table) # aligned should be a vector '[1] "AMCA3" "ARHY" "AMCA3" "AMCA3"'
observation_one<-c("AMCA3","AMCA3","AMCA3","AMCA3") observation_two<-c("a", "b", "a", "a") table<-list() table$plant_functional_type_one<- c("AMCA3","AMCA3","ARHY", "ARHY") table$plant_functional_type_two<- c('a','a','b', 'b') # PFT groupings table<-as.data.frame(table) aligned <- align_by_first_observation( observation_one = observation_one, observation_two = observation_two, custom_table = table) # aligned should be a vector '[1] "AMCA3" "ARHY" "AMCA3" "AMCA3"'
Align timeseries data
align_data(model.calc, obvs.calc, var, align_method = "match_timestep")
align_data(model.calc, obvs.calc, var, align_method = "match_timestep")
model.calc |
data.frame |
obvs.calc |
data.frame |
var |
data.frame |
align_method |
name of function to use for alignment |
dat
Betsy Cowdery
align_data_to_data_pft
align_data_to_data_pft( con, observation_one, observation_two, custom_table = NULL, format_one, format_two, subset_is_ok = FALSE )
align_data_to_data_pft( con, observation_one, observation_two, custom_table = NULL, format_one, format_two, subset_is_ok = FALSE )
con |
database connection |
observation_one |
a vector of plant functional types, or species |
observation_two |
another vector of plant functional types, or species |
custom_table |
a table that either maps two pft's to one another or maps custom species codes to bety id codes. In the second case, must be passable to match_species_id. |
format_one |
The output of query.format.vars() of observation one of the form output$vars$bety_names |
format_two |
The output of query.format.vars() of observation two of the form output$vars$bety_names |
subset_is_ok |
When aligning two species lists, this allows for alignment when species lists aren't identical. set to FALSE by default. |
Aligns vectors of Plant Fucntional Typed and species. Can align: - two vectors of plant functional types (pft's) if a custom map is provided - a list of species (usda, fia, or latin_name format) to a plant functional type - a list of species in a custom format, with a table mapping it to bety_species_id's
Will return a list of what was originally provided, bety_species_codes if possible, and an aligned output. Because some alignement is order-sensitive, alignment based on observation_one and observation_two are both provided.
list
containing the following columns:
$original
Will spit back out original vectors pre-alignment
$aligned$aligned_by_observation_one
Where possible, will return a vector of observation_one pft's/species in the order of observation_two
species
Where possible, will return a vector of observation_two's pft's/species in the order of observation_one
$bety_species_id
Where possible, will return the bety_species_id's for one or both observations
$bety_species_intersection
Where possible, will return the intersection of two aligned lists of species. subset_is_ok must be set to TRUE.
Tempest McCabe
## Not run: observation_one<-c("AMCA3","AMCA3","AMCA3","AMCA3") observation_two<-c("a", "b", "a", "a") table<-list() table$plant_functional_type_one<- c("AMCA3","AMCA3","ARHY", "ARHY") table$plant_functional_type_two<- c('a','a','b', 'b') # PFT groupings table<-as.data.frame(table) format_one<-"species_USDA_symbol" format_two<-"plant_functional_type" aligned <- align_data_to_data_pft( con = con, observation_one = observation_one, observation_two = observation_two, format_one = format_one, format_two = format_two, custom_table = table) ## End(Not run)
## Not run: observation_one<-c("AMCA3","AMCA3","AMCA3","AMCA3") observation_two<-c("a", "b", "a", "a") table<-list() table$plant_functional_type_one<- c("AMCA3","AMCA3","ARHY", "ARHY") table$plant_functional_type_two<- c('a','a','b', 'b') # PFT groupings table<-as.data.frame(table) format_one<-"species_USDA_symbol" format_two<-"plant_functional_type" aligned <- align_data_to_data_pft( con = con, observation_one = observation_one, observation_two = observation_two, format_one = format_one, format_two = format_two, custom_table = table) ## End(Not run)
Align vectors of Plant Functional Type and species.
align_pft( con, observation_one, observation_two, custom_table = NULL, format_one, format_two, subset_is_ok = FALSE, comparison_type = "data_to_data", ... )
align_pft( con, observation_one, observation_two, custom_table = NULL, format_one, format_two, subset_is_ok = FALSE, comparison_type = "data_to_data", ... )
con |
database connection |
observation_one |
a vector of plant fucntional types, or species |
observation_two |
anouther vector of plant fucntional types, or species |
custom_table |
a table that either maps two pft's to one anouther or maps custom species codes to bety id codes. In the second case, must be passable to match_species_id. |
format_one |
The output of query.format.vars() of observation one of the form output$vars$bety_names |
format_two |
The output of query.format.vars() of observation two of the form output$vars$bety_names |
subset_is_ok |
When aligning two species lists, this allows for alignement when species lists aren't identical. set to FALSE by default. |
comparison_type |
one of "data_to_model", "data_to_data", or "model_to_model" |
... |
other arguments, currently ignored |
Can align: - two vectors of plant fucntional types (pft's) if a custom map is provided - a list of species (usda, fia, or latin_name format) to a plant fucntional type - a list of species in a custom format, with a table mapping it to bety_species_id's
Will return a list of what was originally provided, bety_speceis_codes if possible, and an aligned output. Becuase some alignement is order-sensitive, alignment based on observation_one and observation_two are both provided.
comparison_type
can be one of the following:
data_to_data
Will align lists of pfts and species. Must be assosiated with inputs.
data_to_model
Not yet implemented
model_to_model
Not yet implemented
list
containing the following columns:
$original
Will spit back out original vectors pre-alignment
$aligned$aligned_by_observation_one
Where possible, will return a vector of observation_one pft's/species in the order of observation_two
species
Where possible, will return a vector of observation_two's pft's/species in the order of observation_one
$bety_species_id
Where possible, will return the bety_species_id's for one or both observations
Tempest McCabe
## Not run: #------------ A species to PFT alignment ----------- observation_one<-c("AMCA3","AMCA3","AMCA3","AMCA3") observation_two<-c("a", "b", "a", "a") # format_one<-"species_USDA_symbol" format_two<-"plant_funtional_type" table<-list() table$plant_functional_type_one<- c("AMCA3","AMCA3","ARHY", "ARHY") table$plant_functional_type_two<- c('a','a','b', 'b') # PFT groupings table<-as.data.frame(table) aligned<-align_pft(con = con, observation_one = observation_one, observation_two = observation_two, format_one = format_one, format_two = format_two, custom_table = table) ## End(Not run)
## Not run: #------------ A species to PFT alignment ----------- observation_one<-c("AMCA3","AMCA3","AMCA3","AMCA3") observation_two<-c("a", "b", "a", "a") # format_one<-"species_USDA_symbol" format_two<-"plant_funtional_type" table<-list() table$plant_functional_type_one<- c("AMCA3","AMCA3","ARHY", "ARHY") table$plant_functional_type_two<- c('a','a','b', 'b') # PFT groupings table<-as.data.frame(table) aligned<-align_pft(con = con, observation_one = observation_one, observation_two = observation_two, format_one = format_one, format_two = format_two, custom_table = table) ## End(Not run)
Move benchmarking settings back in to original pecan settings object
bm_settings2pecan_settings(bm.settings)
bm_settings2pecan_settings(bm.settings)
bm.settings |
settings or multisettings object |
Betsy Cowdery
For each benchmark id, calculate metrics and update benchmarks_ensemble_scores
calc_benchmark(settings, bety, start_year = NA, end_year = NA)
calc_benchmark(settings, bety, start_year = NA, end_year = NA)
settings |
settings object describing the run to calculate |
bety |
database connection |
start_year , end_year
|
time range to read. If NA, these are taken from 'settings' |
Betsy Cowdery
calc_metrics
calc_metrics(model.calc, obvs.calc, var, metrics, ensemble.id, bm_dir)
calc_metrics(model.calc, obvs.calc, var, metrics, ensemble.id, bm_dir)
model.calc |
model data |
obvs.calc |
observational data |
var |
variables to be used |
metrics |
metrics to be used |
ensemble.id |
id of ensemble run |
bm_dir |
directory where benchmarking outputs will be saved |
Betsy Cowdery
Check whether a run has been registered as a reference run in BETY
check_BRR(settings_xml, con)
check_BRR(settings_xml, con)
settings_xml |
cleaned settings to be compared with BRR in the database |
con |
database connection |
Betsy Cowdery
check_if_legal_table
check_if_legal_table(table, observation_one, observation_two)
check_if_legal_table(table, observation_one, observation_two)
table |
a table that either maps two pft's to one anouther or maps custom species codes to bety id codes. In the second case, must be passable to match_species_id. |
observation_one |
a vector of plant functional types, or species |
observation_two |
anouther vector of plant functional types, or species |
Checks if custom_table: 1. is formated correctly 2. is complete (has all of the species/pft's in both observations) 3. is condense-able (Could be represented as a hierachry)
boolean
Tempest McCabe
Checks if format contains a variable named "plant_functional_type"
check_if_list_of_pfts(vars)
check_if_list_of_pfts(vars)
vars |
names to check |
boolean
Tempest McCabe
check_if_species_list
check_if_species_list(vars, custom_table = NULL)
check_if_species_list(vars, custom_table = NULL)
vars |
format |
custom_table |
a table that either maps two pft's to one anouther or maps custom species codes to bety id codes. In the second case, must be passable to match_species_id. |
Checks if format contains a species list in a known format, or a declared custom format.
boolean
Tempest McCabe
Cleans PEcAn settings file and prepares the settings to be saved in a reference run record in BETY
clean_settings_BRR(inputfile)
clean_settings_BRR(inputfile)
inputfile |
the PEcAn settings file to be used. |
Betsy Cowdery
For each benchmark id, calculate metrics and update benchmarks_ensemble_scores
create_BRR(ens_wf, con, user_id = "")
create_BRR(ens_wf, con, user_id = "")
ens_wf |
table made from joining ensemble and workflow tables |
con |
database connection |
user_id |
Optional user id to use for this record in reference_runs table |
Betsy Cowdery
Creates records for benchmarks, benchmarks_benchmarks_reference_runs, benchmarks_metrics
define_benchmark(settings, bety)
define_benchmark(settings, bety)
settings |
settings list |
bety |
database connection |
updated settings list
Betsy Cowdery
Function to convert wide format to long format
format_wide2long(out, format, vars_used, time.row)
format_wide2long(out, format, vars_used, time.row)
out |
wide format data |
format |
as returned by query.format.vars |
vars_used |
data frame mapping 'input_name' to 'bety_name' |
time.row |
ignored; value in output is set from 'format$vars$storage_type' |
list of updated values
Istem Fer
Returns the format type for convience of use with match_species_id
get_species_list_standard(vars)
get_species_list_standard(vars)
vars |
format to be matched |
character
Returns "usda", "latin_name", "fia" or "custom"
Tempest McCabe
load_csv
load_csv(data.path, format, site, vars = NULL)
load_csv(data.path, format, site, vars = NULL)
data.path |
character |
format |
list |
site |
list |
vars |
column names to return. If NULL, returns all columns |
Betsy Cowdery
Generic function to convert input files containing observational data to a common PEcAn format.
load_data( data.path, format, start_year = NA, end_year = NA, site = NA, vars.used.index = NULL, ... )
load_data( data.path, format, start_year = NA, end_year = NA, site = NA, vars.used.index = NULL, ... )
data.path |
character |
format |
list |
start_year |
numeric |
end_year |
numeric |
site |
list |
vars.used.index |
which variables to use? If NULL, these are taken from 'format' |
... |
further arguments, currently ignored |
Betsy Cowdery, Istem Fer, Joshua Mantooth
load_rds
load_rds(data.path, format, site, vars = NULL)
load_rds(data.path, format, site, vars = NULL)
data.path |
character |
format |
list, not used, for compatibility |
site |
not used, for compatibility |
vars |
optional variable names to load. if NULL, returns all variables in file |
Istem Fer
Load files with mime-type 'text/tab-separated-values'
load_tab_separated_values(data.path, format, site = NULL, vars = NULL)
load_tab_separated_values(data.path, format, site = NULL, vars = NULL)
data.path |
character |
format |
list |
site |
list |
vars |
variable names to load. If NULL, loads all columns |
Betsy Cowdery, Mike Dietze
Load from netCDF
load_x_netcdf(data.path, format, site, vars = NULL)
load_x_netcdf(data.path, format, site, vars = NULL)
data.path |
character vector or list |
format |
list |
site |
list |
vars |
character |
Istem Fer
Match time step
match_timestep(date.coarse, date.fine, data.fine)
match_timestep(date.coarse, date.fine, data.fine)
date.coarse |
numeric |
date.fine |
numeric |
data.fine |
matrix |
Istem Fer
Calculate benchmarking statistics
mean_over_larger_timestep(date.coarse, date.fine, data.fine)
mean_over_larger_timestep(date.coarse, date.fine, data.fine)
date.coarse |
numeric |
date.fine |
numeric |
data.fine |
data.frame |
Betsy Cowdery, Michael Dietze
Absolute Maximum Error
metric_AME(dat, ...)
metric_AME(dat, ...)
dat |
dataframe |
... |
ignored |
Betsy Cowdery
Correlation Coefficient
metric_cor(dat, ...)
metric_cor(dat, ...)
dat |
dataframe |
... |
ignored |
Mike Dietze
Frechet Distance
metric_Frechet(metric_dat, ...)
metric_Frechet(metric_dat, ...)
metric_dat |
dataframe |
... |
ignored |
Betsy Cowdery
Linear Regression Diagnostic Plot
metric_lmDiag_plot(metric_dat, var, filename = NA, draw.plot = FALSE)
metric_lmDiag_plot(metric_dat, var, filename = NA, draw.plot = FALSE)
metric_dat |
data.frame |
var |
ignored |
filename |
path to save plot, or NA to not save |
draw.plot |
logical: return plot object? |
Betsy Cowdery
Mean Absolute Error
metric_MAE(dat, ...)
metric_MAE(dat, ...)
dat |
dataframe |
... |
ignored |
Betsy Cowdery
Mean Square Error
metric_MSE(dat, ...)
metric_MSE(dat, ...)
dat |
dataframe |
... |
ignored |
Betsy Cowdery
Pearson Product Moment Correlation
metric_PPMC(metric_dat, ...)
metric_PPMC(metric_dat, ...)
metric_dat |
dataframe |
... |
ignored |
Betsy Cowdery
Coefficient of Determination (R2)
metric_R2(metric_dat, ...)
metric_R2(metric_dat, ...)
metric_dat |
dataframe |
... |
ignored |
Betsy Cowdery
Relative Absolute Error
metric_RAE(metric_dat, ...)
metric_RAE(metric_dat, ...)
metric_dat |
dataframe |
... |
ignored |
Betsy Cowdery
Residual Plot
metric_residual_plot( metric_dat, var, filename = NA, draw.plot = is.na(filename) )
metric_residual_plot( metric_dat, var, filename = NA, draw.plot = is.na(filename) )
metric_dat |
dataframe to plot, with at least columns 'time', 'model', 'obvs' |
var |
variable name, used as plot title |
filename |
path to save plot, or NA to not save |
draw.plot |
logical: Return the plot object? |
Betsy Cowdery
Root Mean Square Error
metric_RMSE(dat, ...)
metric_RMSE(dat, ...)
dat |
dataframe |
... |
ignored |
Betsy Cowdery
Model Run Check
metric_run(settings)
metric_run(settings)
settings |
list |
Betsy Cowdery
Scatter Plot
metric_scatter_plot( metric_dat, var, filename = NA, draw.plot = is.na(filename) )
metric_scatter_plot( metric_dat, var, filename = NA, draw.plot = is.na(filename) )
metric_dat |
dataframe to plot, with at least columns 'model' and 'obvs' |
var |
ignored |
filename |
path to save plot, or NA to not save |
draw.plot |
logical: Return the plot object? |
Betsy Cowdery
Timeseries Plot
metric_timeseries_plot( metric_dat, var, filename = NA, draw.plot = is.na(filename) )
metric_timeseries_plot( metric_dat, var, filename = NA, draw.plot = is.na(filename) )
metric_dat |
dataframe to plot, with at least columns 'time', 'model', 'obvs' |
var |
variable name, used as plot title |
filename |
path to save plot, or NA to not save |
draw.plot |
logical: Return the plot object? |
Betsy Cowdery
For each benchmark entry in a (multi)settings object, get run settings using reference run id and add to the settings object
read_settings_BRR(settings)
read_settings_BRR(settings)
settings |
settings or multisettings object |
Betsy Cowdery