| Title: | Tools to Analyse and Visualise Data from the OptirrigHIVE Platform |
|---|---|
| Description: | Provides tools to prepare, analyse, and visualise data from the OptirrigHIVE platform. The package includes utilities for scenario building, data transformation, statistical analysis, and irrigation- oriented visualisation workflows for OptirrigCORE studies. |
| Authors: | Florian Ricquier [aut, cre] (ORCID: <https://orcid.org/0000-0002-6595-7984>), Kevin Bosirany Orlando [aut] (ORCID: <https://orcid.org/0009-0009-2784-3108>), Bruno Cheviron [aut], UMR G-Eau Aqua Department INRAE Montpellier Team Optimiste [aut] |
| Maintainer: | Florian Ricquier <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-05-23 09:09:23 UTC |
| Source: | https://forge.inrae.fr/OptirrigHIVE/OptirrigTOOLS |
Copies specified input files into the "inputs" directory of a given project.
add_input_files_to_add(x, project_name, input_files_to_add, ...)add_input_files_to_add(x, project_name, input_files_to_add, ...)
x |
character. Path to the base directory where the project is located. |
project_name |
character. Name of the project folder. |
input_files_to_add |
character. Paths to the input files to be copied. If |
... |
Additional arguments. |
This function copies the files specified in input_files_to_add into the "inputs" subdirectory of the project directory (file.path(x, project_name, "inputs")). If input_files_to_add is NULL, the function does nothing.
Invisibly returns x.
Build MC global uncertainty panels (no OAT)
build_uncertainty_mc_global_panels( x, show_quantile_lines = TRUE, show_median_line = TRUE, x_axis = c("Date", "TT_sowing"), tt_step = 20 )build_uncertainty_mc_global_panels( x, show_quantile_lines = TRUE, show_median_line = TRUE, x_axis = c("Date", "TT_sowing"), tt_step = 20 )
x |
Output of |
show_quantile_lines |
Logical; if |
show_median_line |
Logical; if |
x_axis |
Axis used for daily uncertainty ribbons: |
tt_step |
Thermal-time grid step used when |
Named list of ggplot objects (climate, water, plant, seasonal).
This function computes various performance metrics to evaluate the predictive accuracy of a model. By comparing observed (obs) and simulated (sim) data, it provides insights into how well the simulated data matches the observed values.
The function supports widely used metrics like Nash-Sutcliffe Efficiency (NSE), Root Mean Square Error (RMSE), Mean Absolute Error (MAE), and others. Normalized versions of error metrics (nRMSE, nMAE) are also available, enabling comparisons across datasets with different scales.
calc_criteria(obs, sim, error = NULL, weights = NULL, method, norm = "mean")calc_criteria(obs, sim, error = NULL, weights = NULL, method, norm = "mean")
obs |
A numeric vector representing the observed (actual) data. This should contain the true values that the model attempts to predict. |
sim |
A numeric vector representing the simulated (predicted) data. These are the values produced by the model being evaluated. |
error |
(Optional) A numeric vector representing uncertainty in the observed values. If provided, the function adjusts calculations to account for error bounds. |
weights |
(Optional) Numeric vector of point weights (same length as
|
method |
A string specifying the performance metric to calculate. Supported options include:
|
norm |
A string indicating the normalization method for normalized metrics (
|
Nash-Sutcliffe Efficiency (NSE): Measures how well the simulated data matches observed data. A value of 1 indicates perfect agreement, while values <0 suggest poor performance.
Root Mean Square Error (RMSE): Indicates the standard deviation of prediction errors. Smaller values suggest better performance.
Mean Absolute Error (MAE): Calculates the mean of absolute differences between observed and simulated values.
Normalized RMSE (nRMSE): A normalized version of RMSE based on the chosen normalization method.
Normalized MAE (nMAE): Similar to nRMSE but applies normalization to MAE.
Coefficient of Determination (R2):
Measures the proportion of variance in obs explained by sim.
Index of Agreement (d): Indicates the level of predictive accuracy, with values ranging from 0 (no agreement) to 1 (perfect agreement).
A numeric value representing the calculated performance metric based on the specified method. Higher efficiency metrics (e.g., NSE, R2, d) and lower error metrics (e.g., RMSE, MAE) indicate better model performance.
If obs or sim contain only NA values, the function returns NA. Similarly, if obs has only a single non-NA value, relative error metrics are computed.
Willmott, C.J., "On the Validation of Models", Physical Geography, 1981. DOI:10.1080/02723646.1981.10642213
Willmott, C.J., "Some Comments on the Evaluation of Model Performance", Bulletin of the American Meteorological Society, 1982. DOI:10.1175/1520-0477(1982)063<1309:SCOTEO>2.0.CO;2
# Example of observed and simulated data obs <- c(1, 2, 3, 4, 5) sim <- c(1.1, 1.9, 3.1, 4.2, 4.8) # Calculate Index of Agreement (d) calc_criteria(obs, sim, method = "dWillmot") # Calculate Nash-Sutcliffe Efficiency (NSE) calc_criteria(obs, sim, method = "NSE") # Calculate normalized RMSE (nRMSE) calc_criteria(obs, sim, method = "nRMSE", norm = "mean")# Example of observed and simulated data obs <- c(1, 2, 3, 4, 5) sim <- c(1.1, 1.9, 3.1, 4.2, 4.8) # Calculate Index of Agreement (d) calc_criteria(obs, sim, method = "dWillmot") # Calculate Nash-Sutcliffe Efficiency (NSE) calc_criteria(obs, sim, method = "NSE") # Calculate normalized RMSE (nRMSE) calc_criteria(obs, sim, method = "nRMSE", norm = "mean")
Creates one Optirrig scenario per trial by taking fixed inputs directly from
datasets and injecting values from best_par on top.
calib_build_inputs_all(datasets, trials = NULL, best_par)calib_build_inputs_all(datasets, trials = NULL, best_par)
datasets |
Named list of trial datasets. |
trials |
Optional character vector of trial names. If |
best_par |
Named parameter vector. |
A flat list of model inputs suitable for run_model().
Wrapper around create_spec() to create one spec per trial.
calib_build_specs( datasets, trials = NULL, params = NULL, ranges, project_dir, yield_var = "Y_sugar", date_start = "01/01", date_end = "31/12" )calib_build_specs( datasets, trials = NULL, params = NULL, ranges, project_dir, yield_var = "Y_sugar", date_start = "01/01", date_end = "31/12" )
datasets |
Named list of trial datasets. |
trials |
Character vector of trial names. If |
params |
params used in base overrides. |
ranges |
Parameter ranges for calibration. |
project_dir |
Project directory used by calibration pipeline. |
yield_var |
Yield variable passed to |
date_start |
Calibration window start (MM/DD). |
date_end |
Calibration window end (MM/DD). |
Named list of specs.
Utility functions used to parse calibration outputs, reshape observed and simulated values, compute relative-deviation summaries, and assemble the diagnostic plots used in calibration workflows.
calib_display_parse_num(x) calib_display_parse_date(x) calib_display_get_run_id(i, inputs, outputs) calib_display_get_trial_type(run_id) calib_display_get_site_label(run_id) calib_display_build_sim_long(outputs, inputs, vars, x_var = "TT_sowing") calib_display_build_obs_long(inputs, outputs, vars, x_var = "TT_sowing") calib_display_make_palette() calib_display_plot_obs_vs_sim(obs_sim, title = NULL) calib_display_plot_obs_sim_curves( sim_df, obs_df, title = NULL, x_var = "TT_sowing" ) calib_display_plot_trials_grid( sim_df, obs_df, var, var_pot, trial_levels, title = NULL, which_site_ids = NULL, x_var = "TT_sowing", uncertainty_df = NULL ) calib_display_calc_ed(a, b, method = "classic") calib_display_summarize_ed(ed, stat = "mean") calib_display_compute_ed_summary( obs_sim, var = "Y_sugar", method = "classic", stat = "mean", trial_order_ed = c("Ndc", "Irri", "ArrT", "ArrP", "IrriMn", "DclT", "Tem") ) calib_display_plot_ed_recap(df_ed, title = NULL, which_id = NULL, ncol = 3L) calib_display_get_top_screen(screen_res, param_cols, n = 10L) calib_display_run_once( datasets, best_par, display_dir, pdf_name, title_prefix = "Optimized params", trials_display = NULL, vars_main = c("B", "LAI", "Y_sugar"), trial_levels = c("Ndc", "Irri", "ArrT", "ArrP", "IrriMn", "DclT", "Tem"), trial_order_ed = trial_levels, x_var = "TT_sowing", run_options = list(log = FALSE, save = FALSE, force = TRUE, return_outputs = TRUE, plan = "multicore", workers = 10), uncertainty_daily = NULL, png_width = 12, png_height = 9.86, png_dpi = 160 )calib_display_parse_num(x) calib_display_parse_date(x) calib_display_get_run_id(i, inputs, outputs) calib_display_get_trial_type(run_id) calib_display_get_site_label(run_id) calib_display_build_sim_long(outputs, inputs, vars, x_var = "TT_sowing") calib_display_build_obs_long(inputs, outputs, vars, x_var = "TT_sowing") calib_display_make_palette() calib_display_plot_obs_vs_sim(obs_sim, title = NULL) calib_display_plot_obs_sim_curves( sim_df, obs_df, title = NULL, x_var = "TT_sowing" ) calib_display_plot_trials_grid( sim_df, obs_df, var, var_pot, trial_levels, title = NULL, which_site_ids = NULL, x_var = "TT_sowing", uncertainty_df = NULL ) calib_display_calc_ed(a, b, method = "classic") calib_display_summarize_ed(ed, stat = "mean") calib_display_compute_ed_summary( obs_sim, var = "Y_sugar", method = "classic", stat = "mean", trial_order_ed = c("Ndc", "Irri", "ArrT", "ArrP", "IrriMn", "DclT", "Tem") ) calib_display_plot_ed_recap(df_ed, title = NULL, which_id = NULL, ncol = 3L) calib_display_get_top_screen(screen_res, param_cols, n = 10L) calib_display_run_once( datasets, best_par, display_dir, pdf_name, title_prefix = "Optimized params", trials_display = NULL, vars_main = c("B", "LAI", "Y_sugar"), trial_levels = c("Ndc", "Irri", "ArrT", "ArrP", "IrriMn", "DclT", "Tem"), trial_order_ed = trial_levels, x_var = "TT_sowing", run_options = list(log = FALSE, save = FALSE, force = TRUE, return_outputs = TRUE, plan = "multicore", workers = 10), uncertainty_daily = NULL, png_width = 12, png_height = 9.86, png_dpi = 160 )
x |
Object to parse as numeric values. |
i |
Index of the run to inspect. |
inputs |
List of model input objects. |
outputs |
List of model output tables. |
run_id |
Run identifier. |
vars |
Character vector of variable names to extract. |
x_var |
X-axis variable to use, usually |
obs_sim |
Data frame joining observed and simulated values. |
title |
Optional plot title. |
sim_df |
Long simulated data frame built by the calibration display helpers. |
obs_df |
Long observed data frame built by the calibration display helpers. |
var |
Variable to analyse or plot. |
var_pot |
Potential counterpart to |
trial_levels |
Character vector giving the display order of trial types. |
which_site_ids |
Optional subset of site identifiers to display. |
uncertainty_df |
Optional uncertainty summary used to add |
a |
Numeric vector for the first treatment or series in relative deviation calculations. |
b |
Numeric vector for the second treatment or series in relative deviation calculations. |
method |
Relative-deviation method. |
ed |
Numeric vector of relative deviations. |
stat |
Summary statistic to apply to relative deviations. |
trial_order_ed |
Trial order used to normalize pair ordering for relative-deviation summaries. |
df_ed |
Relative-deviation summary table produced by the calibration display helpers. |
which_id |
Optional subset of IDs to display in recap plots. |
ncol |
Number of columns in recap facets. |
screen_res |
Screening result object containing |
param_cols |
Character vector of parameter column names. |
n |
Number of rows to keep from screening results. |
datasets |
Calibration datasets used to rebuild model inputs. |
best_par |
Named vector or list of best parameter values. |
display_dir |
Output directory used to save plots. |
pdf_name |
Base file name associated with exported plots. |
title_prefix |
Title prefix shared across generated plots. |
trials_display |
Optional subset of trial identifiers to display. |
vars_main |
Main observed variables to display. |
run_options |
Options passed to |
uncertainty_daily |
Optional daily uncertainty summary used as ribbons in trial-grid plots. |
png_width |
Plot export width in inches. |
png_height |
Plot export height in inches. |
png_dpi |
Plot export resolution in dpi. |
Depending on the helper, a parsed vector, a long-format data frame, a
ggplot object, a numeric summary, or a list bundling generated
diagnostics.
Keeps only trials that contain at least min_obs observed points for one
variable in trial$obs.
calib_get_trials_from_datasets(datasets, min_obs = 3L)calib_get_trials_from_datasets(datasets, min_obs = 3L)
datasets |
Named list of trial datasets. |
min_obs |
Minimum number of observed points required per variable. |
Character vector of trial names to calibrate.
Plot main calibration diagnostics for all trials
calib_plot_main_trials( outputs_all, inputs_all, eval_all, title_prefix = "All trials", x_var = c("TT_sowing", "Date") )calib_plot_main_trials( outputs_all, inputs_all, eval_all, title_prefix = "All trials", x_var = c("TT_sowing", "Date") )
outputs_all |
Model outputs list. |
inputs_all |
Model inputs list. |
eval_all |
Evaluation list containing |
title_prefix |
Prefix used in plot titles. |
x_var |
X axis for curves/grids ( |
Invisibly returns NULL.
Print calibration score summary
calib_print_eval_summary(eval_all, scores_all_trials)calib_print_eval_summary(eval_all, scores_all_trials)
eval_all |
Output from |
scores_all_trials |
Trial-level score table from
|
Invisibly returns scores_all_trials.
Runs all inputs, evaluates Obs/Sim with run_model_eval(), then computes one
score per run and variable, plus a mean score per run.
calib_run_and_eval_trials( inputs_all, trials, run_options = list(log = FALSE, plan = "multicore", workers = 1, force = TRUE, save = FALSE, return_outputs = TRUE), method = "nrmse" )calib_run_and_eval_trials( inputs_all, trials, run_options = list(log = FALSE, plan = "multicore", workers = 1, force = TRUE, save = FALSE, return_outputs = TRUE), method = "nrmse" )
inputs_all |
List of model inputs. |
trials |
Character vector of trial names. |
run_options |
Options list passed to |
method |
Criterion used for evaluation and score computation. |
List with outputs_all, eval_all, scores_all_trials.
This function initializes a new project by creating the main directory and adding optional crop and soil information. It also generates parameter CSV and user configuration files, and can add additional input files if specified.
create_project( project_name, crop = NULL, soil = NULL, path = system.file("extdata", package = pkg), pkg = utils::packageName(), overwrite = FALSE, input_files_to_add = NULL, log = TRUE, ... )create_project( project_name, crop = NULL, soil = NULL, path = system.file("extdata", package = pkg), pkg = utils::packageName(), overwrite = FALSE, input_files_to_add = NULL, log = TRUE, ... )
project_name |
character. Name of the project to create. |
crop |
character. Crop information to include in the project. |
soil |
character. Soil information to include in the project. |
path |
character. Path where the project will be created. Defaults to the "extdata" directory of the package. |
pkg |
character. Name of the package. Defaults to the current package name. |
overwrite |
logical. Whether to overwrite an existing project directory. Defaults to FALSE. |
input_files_to_add |
character. Additional input files to add to the project. |
log |
logical. Whether to log the creation of the project. Defaults to TRUE. |
... |
Additional arguments passed to lower-level directory creation functions. |
The function creates a project directory structure, adds parameter and configuration files, and optionally copies additional input files. Logging is performed if enabled.
Invisibly returns the path to the created project directory.
This function generates a user-specific configuration file (config.user.ini) for a given project.
It creates a directory structure for the project if it does not exist and writes a configuration file
containing project metadata, data paths, and directory paths.
create_project.config_user( x, project_name, pkg = utils::packageName(), version = NULL, ... )create_project.config_user( x, project_name, pkg = utils::packageName(), version = NULL, ... )
x |
character The base directory path where the project will be created. |
project_name |
character The name of the project. |
pkg |
character The package name to retrieve the version from. Defaults to the current package. |
version |
character The version of the project or package. If |
... |
Additional arguments. |
The function creates a configuration list with project name and version, data path, and standard
subdirectories for configuration, inputs, and outputs. It writes this configuration to an INI file
using the ini package.
Invisibly returns the input x.
This function creates a standardized directory structure for a new project, including
subdirectories for configuration, input, and output files. It also copies relevant .ini
configuration files from a specified package's resource directory into the project's
configuration folder. Optionally, crop- and soil-specific .ini files can be included.
create_project.dir(x, project_name, crop, soil, pkg, overwrite = TRUE, ...)create_project.dir(x, project_name, crop, soil, pkg, overwrite = TRUE, ...)
x |
character. Path to the parent directory where the project will be created. |
project_name |
character. Name of the new project directory. |
crop |
character. Crop identifier to include crop-specific |
soil |
character. Soil identifier to include soil-specific |
pkg |
character. Name of the package containing the resource |
overwrite |
logical. Whether to overwrite existing files. Default is TRUE. |
... |
Additional arguments. |
The function creates the following subdirectories within the project directory:
config
inputs
outputs
It copies all .ini files from the package resource directory, excluding those with
.user., .plant., or .soil. in their names, unless they match the specified crop or soil.
Invisibly returns the path to the parent directory (x).
This function generates a CSV file containing project parameters for a given project.
It reads the default parameters from a .run.ini file within the specified package,
processes them, and writes them to a CSV file in the project directory. If the CSV
file already exists, the function does nothing.
create_project.params_csv(x, project_name, pkg = utils::packageName(), ...)create_project.params_csv(x, project_name, pkg = utils::packageName(), ...)
x |
character. Path to the base directory where the project folder is located. |
project_name |
character. Name of the project; used to create the project folder and CSV file. |
pkg |
character. Name of the package containing the |
... |
Additional arguments. |
The function searches for a .run.ini file in the specified package, reads its contents,
and processes the parameters into a data frame. It removes columns matching the pattern
"^types\\.", adds columns for run_id, crop, soil, date_sowing, and date_harvest,
and relocates some columns for convenience. The resulting data frame is written to a CSV file
named "<project_name>_params.csv" inside the project directory.
Invisibly returns the input path x.
create_scenarios() assembles model parameters provided by category blocks
(inputs, crop, soil, irrigation, run) into one or more structured
scenarios (class "model_scenarios").
create_scenarios( inputs = list(), crop = list(), soil = list(), irrigation = list(), run = list(), options = list(grid = FALSE, fill_missing = FALSE) )create_scenarios( inputs = list(), crop = list(), soil = list(), irrigation = list(), run = list(), options = list(grid = FALSE, fill_missing = FALSE) )
inputs |
Named list of observed inputs (e.g. climate, irrigation calendar). |
crop |
Named list of crop parameters. |
soil |
Named list of soil parameters. |
irrigation |
Named list of irrigation parameters (multi-period values as |
run |
Named list of run parameters ( |
options |
List of options:
|
The function supports two scenario generation modes:
options$grid = TRUE)Produces the cartesian product of varying parameters (all combinations), using
expand_grid() on the flattened configuration. This is appropriate for
factorial sensitivity analyses (e.g., exploring all combinations of zmax
and ratio_R_init).
options$grid = FALSE, default)Produces N scenarios by aligned indexing: first values together, second values together, etc. This mode is designed to safely create multi-run batches without exploding to a full grid.
When grid = FALSE, scenario count (N) is driven only by atomic vectors
(numeric/character/logical) with length > 1 found in the safe blocks:
run, crop, and soil. The inputs and irrigation blocks are not
zip triggers, to avoid accidentally creating scenarios from naturally vector
inputs (time series, calendars, constraints vectors, etc.).
Even though irrigation values do not trigger zipping, when multiple scenarios
are created (N > 1), irrigation parameters can be supplied per-run and will
be sliced by index if:
they are atomic vectors of length N, or
they are lists (non-data.frame) of length N.
irrig_not_allowed is explicitly excluded from run-wise slicing (it is assumed
to be an intra-run vector of dates, not a per-run vector).
If grid = FALSE and N > 1, all inputs parameters that are atomic vectors
or lists must have length 1 or N. For irrigation, lists of scalar values
(e.g. constraint windows) are treated as single values and do not need to
match N. Data frames and matrices are ignored by this check (they are treated
as single objects).
If multiple scenarios are produced and run_id is missing, a fallback ID is
assigned ("Run_1", "Run_2", ...). After scenario construction, if any run IDs
are missing or duplicated, IDs are replaced deterministically with
"Run_1" .. "Run_n", and scenario list names are aligned accordingly.
If options$fill_missing = TRUE, the returned scenarios are fully materialized
using OptirrigCORE::create_model_inputs() and OptirrigCORE::load_config() (defaults + parsing + loaders),
making them directly runnable with OptirrigCORE::run_model().
An object of class "model_scenarios" (a named list of scenarios).
## Not run: devtools::load_all() library(OptirrigCORE) library(patchwork) # --------------------------------------------------------------------------- # Test run_model with an input CSV file (single project) # --------------------------------------------------------------------------- path <- system.file("extdata", package = "OptirrigCORE") project_name <- "2021_mais_Lav" input <- read(file.path(path, project_name, "2021_mais_Lav_params_no_irrig.csv")) input_path <- file.path(path, project_name, "inputs") outputs <- run_model( input, options = list(log = FALSE), cfg = load_config(path_directory = input_path) ) plot_outputs(outputs) # --------------------------------------------------------------------------- # Load example climate + irrigation objects used in the dev workflow # --------------------------------------------------------------------------- data("2021clim") data("2021irrig") # --------------------------------------------------------------------------- # Case 1 - 1 simulation (zip mode, but no multi-length parameters in run/crop/soil) # --------------------------------------------------------------------------- scen_1 <- create_scenarios( run = list( run_id = "Run_1", date_start = "01/04/2021", date_end = "06/09/2021" ), inputs = list( climate = climate, irrigation = NA ), crop = list( crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021" ), soil = list( soil = "CL", zmax = 1.2, ratio_R_init = 70 ), irrigation = list( irrig_mod = 1, tbis_mod = 1, TT_d = 750, dose_fix = 10, irrig_strategy_start = "25/04/2021", irrig_strategy_end = "01/08/2021", irrig_constraints_start = "01/06/2021", irrig_constraints_end = "01/08/2021", irrig_not_allowed = c("11/06/2021", "17/06/2021", "03/07/2021", "19/07/2021"), WTurn_mod = 1, WTurn_ndays = 1, RU_thrld = list(30, 70), RU_target = list(30, 90), RU_units = 2, dose_max = 20, quota_max = 400, quota_wind = 20 ), options = list(grid = FALSE, fill_missing = TRUE) ) outputs_1 <- run_model( x = scen_1, options = list(plan = "sequential", log = FALSE) ) plot_outputs(outputs_1) # --------------------------------------------------------------------------- # Case 2 - 5 simulations without grid (automatic zip) # zmax and ratio_R_init are vectors in the soil block => N = 5 runs (aligned) # --------------------------------------------------------------------------- scen_5 <- create_scenarios( run = list( run_id = "Run_1", date_start = "01/04/2021", date_end = "06/09/2021" ), inputs = list(climate = climate, irrigation = NA), crop = list(crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021"), soil = list( soil = "CL", zmax = seq(1.2, 2, 0.2), ratio_R_init = seq(50, 90, 10) ), irrigation = list( irrig_mod = 1, tbis_mod = 1, TT_d = 750, irrig_strategy_start = "25/04/2021", irrig_strategy_end = "01/08/2021", irrig_constraints_start = list("25/04/2021", "25/06/2021"), irrig_constraints_end = list("25/06/2021", "01/08/2021"), irrig_not_allowed = c("11/06/2021", "17/06/2021", "03/07/2021", "19/07/2021"), WTurn_mod = 1, WTurn_ndays = 5, RU_thrld = list(30, 70), RU_target = list(30, 90), RU_units = 2, dose_fix = list(15, 30), quota_max = 400 ), options = list(grid = FALSE, fill_missing = TRUE) ) outputs_5 <- run_model( x = scen_5, options = list(plan = "multicore", log = FALSE), cfg = load_config() ) plot_outputs(outputs_5) # --------------------------------------------------------------------------- # Case 3 - 25 simulations with grid (full factorial) # zmax (5 values) x ratio_R_init (5 values) => 25 combinations # --------------------------------------------------------------------------- scen_25 <- create_scenarios( run = list(run_id = "Run_1", date_start = "01/04/2021", date_end = "06/09/2021"), inputs = list(climate = climate, irrigation = NA), crop = list(crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021"), soil = list(soil = "CL", zmax = seq(1.2, 2, 0.2), ratio_R_init = seq(50, 90, 10)), irrigation = list( irrig_mod = 1, tbis_mod = 1, TT_d = 750, irrig_strategy_start = "25/04/2021", irrig_strategy_end = "01/08/2021", irrig_constraints_start = list("25/04/2021", "25/06/2021"), irrig_constraints_end = list("25/06/2021", "01/08/2021"), irrig_not_allowed = c("11/06/2021", "17/06/2021", "03/07/2021", "19/07/2021"), WTurn_mod = 1, WTurn_ndays = 5, RU_thrld = list(30, 70), RU_target = list(30, 90), RU_units = 2, dose_fix = list(15, 30), quota_max = 400 ), options = list(grid = TRUE, fill_missing = TRUE) ) outputs_25 <- run_model( x = scen_25, options = list(plan = "multicore", log = FALSE), cfg = load_config() ) plot_outputs(outputs_25) # --------------------------------------------------------------------------- # Case 4 - 10 simulations with explicit irrigation strategies # run_id is a vector => zip creates 10 runs, and irrigation fields are sliced # when length == 10 (atomic) or list length == 10 # --------------------------------------------------------------------------- scen_strat <- create_scenarios( run = list( run_id = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"), date_start = "01/04/2021", date_end = "06/09/2021" ), inputs = list( climate = climate, irrigation = list(NA, irrig, NA, NA, NA, NA, NA, NA, NA, NA) ), crop = list( crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021" ), soil = list( soil = "CL", zmax = 1.2, ratio_R_init = 80, theta_fc = 0.30, theta_wp = 0.17, theta_sat = 0.42, theta_raw = 0.21, theta_r = 0.04 ), irrigation = list( irrig_mod = c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1), irrig_strategy_start = c( rep(list("05/05/2021"), 8), list(c("05/05/2021", "01/07/2021")), list(c("05/05/2021", "01/07/2021")) ), irrig_strategy_end = c( rep(list("08/08/2021"), 8), list(c("01/07/2021", "08/08/2021")), list(c("01/07/2021", "08/08/2021")) ), irrig_constraints_start = c(NA, NA, NA, NA, NA, NA, NA, NA, "01/07/2021", "10/07/2021"), irrig_constraints_end = c(NA, NA, NA, NA, NA, NA, NA, NA, "20/07/2021", "20/07/2021"), RU_thrld = list(NA, NA, 25, 50, 35, NA, 75, 75, list(30, 70), list(35, 50)), RU_target = list(NA, NA, 75, 80, 60, NA, 100, 100, list(30, 70), list(75, 65)), PI_thrld = c(NA, NA, NA, NA, NA, 30, NA, NA, NA, NA), PI_ndays = c(NA, NA, NA, NA, NA, 15, NA, NA, NA, NA), WTurn_ndays = c(NA, NA, NA, 7, NA, 7, NA, 7, 5, NA), WTurn_mod = c(NA, NA, 0, 1, 0, 1, 0, 1, 2, 0), dose_min = c(NA, NA, NA, NA, NA, NA, NA, 15, NA, 15), dose_max = c(NA, NA, NA, NA, NA, NA, NA, 20, NA, 20), dose_fix = c(NA, NA, 30, 30, 30, 20, 30, 30, 20, 30), quota_max = c(NA, NA, NA, NA, 400, NA, 300, 200, NA, 300), quota_wind = c(NA, NA, NA, NA, NA, NA, NA, NA, 100, 60) ), options = list(grid = FALSE, fill_missing = FALSE) ) outputs_strat <- run_model( x = scen_strat, options = list(plan = "multicore", log = FALSE), cfg = load_config() ) plot_outputs( outputs = outputs_strat, options = list( run_prefix = "S", pos = list("RU | Y", "IRR | B"), title = "Optirrig - Irrigations Strategies" ) ) ## End(Not run)## Not run: devtools::load_all() library(OptirrigCORE) library(patchwork) # --------------------------------------------------------------------------- # Test run_model with an input CSV file (single project) # --------------------------------------------------------------------------- path <- system.file("extdata", package = "OptirrigCORE") project_name <- "2021_mais_Lav" input <- read(file.path(path, project_name, "2021_mais_Lav_params_no_irrig.csv")) input_path <- file.path(path, project_name, "inputs") outputs <- run_model( input, options = list(log = FALSE), cfg = load_config(path_directory = input_path) ) plot_outputs(outputs) # --------------------------------------------------------------------------- # Load example climate + irrigation objects used in the dev workflow # --------------------------------------------------------------------------- data("2021clim") data("2021irrig") # --------------------------------------------------------------------------- # Case 1 - 1 simulation (zip mode, but no multi-length parameters in run/crop/soil) # --------------------------------------------------------------------------- scen_1 <- create_scenarios( run = list( run_id = "Run_1", date_start = "01/04/2021", date_end = "06/09/2021" ), inputs = list( climate = climate, irrigation = NA ), crop = list( crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021" ), soil = list( soil = "CL", zmax = 1.2, ratio_R_init = 70 ), irrigation = list( irrig_mod = 1, tbis_mod = 1, TT_d = 750, dose_fix = 10, irrig_strategy_start = "25/04/2021", irrig_strategy_end = "01/08/2021", irrig_constraints_start = "01/06/2021", irrig_constraints_end = "01/08/2021", irrig_not_allowed = c("11/06/2021", "17/06/2021", "03/07/2021", "19/07/2021"), WTurn_mod = 1, WTurn_ndays = 1, RU_thrld = list(30, 70), RU_target = list(30, 90), RU_units = 2, dose_max = 20, quota_max = 400, quota_wind = 20 ), options = list(grid = FALSE, fill_missing = TRUE) ) outputs_1 <- run_model( x = scen_1, options = list(plan = "sequential", log = FALSE) ) plot_outputs(outputs_1) # --------------------------------------------------------------------------- # Case 2 - 5 simulations without grid (automatic zip) # zmax and ratio_R_init are vectors in the soil block => N = 5 runs (aligned) # --------------------------------------------------------------------------- scen_5 <- create_scenarios( run = list( run_id = "Run_1", date_start = "01/04/2021", date_end = "06/09/2021" ), inputs = list(climate = climate, irrigation = NA), crop = list(crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021"), soil = list( soil = "CL", zmax = seq(1.2, 2, 0.2), ratio_R_init = seq(50, 90, 10) ), irrigation = list( irrig_mod = 1, tbis_mod = 1, TT_d = 750, irrig_strategy_start = "25/04/2021", irrig_strategy_end = "01/08/2021", irrig_constraints_start = list("25/04/2021", "25/06/2021"), irrig_constraints_end = list("25/06/2021", "01/08/2021"), irrig_not_allowed = c("11/06/2021", "17/06/2021", "03/07/2021", "19/07/2021"), WTurn_mod = 1, WTurn_ndays = 5, RU_thrld = list(30, 70), RU_target = list(30, 90), RU_units = 2, dose_fix = list(15, 30), quota_max = 400 ), options = list(grid = FALSE, fill_missing = TRUE) ) outputs_5 <- run_model( x = scen_5, options = list(plan = "multicore", log = FALSE), cfg = load_config() ) plot_outputs(outputs_5) # --------------------------------------------------------------------------- # Case 3 - 25 simulations with grid (full factorial) # zmax (5 values) x ratio_R_init (5 values) => 25 combinations # --------------------------------------------------------------------------- scen_25 <- create_scenarios( run = list(run_id = "Run_1", date_start = "01/04/2021", date_end = "06/09/2021"), inputs = list(climate = climate, irrigation = NA), crop = list(crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021"), soil = list(soil = "CL", zmax = seq(1.2, 2, 0.2), ratio_R_init = seq(50, 90, 10)), irrigation = list( irrig_mod = 1, tbis_mod = 1, TT_d = 750, irrig_strategy_start = "25/04/2021", irrig_strategy_end = "01/08/2021", irrig_constraints_start = list("25/04/2021", "25/06/2021"), irrig_constraints_end = list("25/06/2021", "01/08/2021"), irrig_not_allowed = c("11/06/2021", "17/06/2021", "03/07/2021", "19/07/2021"), WTurn_mod = 1, WTurn_ndays = 5, RU_thrld = list(30, 70), RU_target = list(30, 90), RU_units = 2, dose_fix = list(15, 30), quota_max = 400 ), options = list(grid = TRUE, fill_missing = TRUE) ) outputs_25 <- run_model( x = scen_25, options = list(plan = "multicore", log = FALSE), cfg = load_config() ) plot_outputs(outputs_25) # --------------------------------------------------------------------------- # Case 4 - 10 simulations with explicit irrigation strategies # run_id is a vector => zip creates 10 runs, and irrigation fields are sliced # when length == 10 (atomic) or list length == 10 # --------------------------------------------------------------------------- scen_strat <- create_scenarios( run = list( run_id = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"), date_start = "01/04/2021", date_end = "06/09/2021" ), inputs = list( climate = climate, irrigation = list(NA, irrig, NA, NA, NA, NA, NA, NA, NA, NA) ), crop = list( crop = "maize", date_sowing = "20/04/2021", date_harvest = "06/09/2021" ), soil = list( soil = "CL", zmax = 1.2, ratio_R_init = 80, theta_fc = 0.30, theta_wp = 0.17, theta_sat = 0.42, theta_raw = 0.21, theta_r = 0.04 ), irrigation = list( irrig_mod = c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1), irrig_strategy_start = c( rep(list("05/05/2021"), 8), list(c("05/05/2021", "01/07/2021")), list(c("05/05/2021", "01/07/2021")) ), irrig_strategy_end = c( rep(list("08/08/2021"), 8), list(c("01/07/2021", "08/08/2021")), list(c("01/07/2021", "08/08/2021")) ), irrig_constraints_start = c(NA, NA, NA, NA, NA, NA, NA, NA, "01/07/2021", "10/07/2021"), irrig_constraints_end = c(NA, NA, NA, NA, NA, NA, NA, NA, "20/07/2021", "20/07/2021"), RU_thrld = list(NA, NA, 25, 50, 35, NA, 75, 75, list(30, 70), list(35, 50)), RU_target = list(NA, NA, 75, 80, 60, NA, 100, 100, list(30, 70), list(75, 65)), PI_thrld = c(NA, NA, NA, NA, NA, 30, NA, NA, NA, NA), PI_ndays = c(NA, NA, NA, NA, NA, 15, NA, NA, NA, NA), WTurn_ndays = c(NA, NA, NA, 7, NA, 7, NA, 7, 5, NA), WTurn_mod = c(NA, NA, 0, 1, 0, 1, 0, 1, 2, 0), dose_min = c(NA, NA, NA, NA, NA, NA, NA, 15, NA, 15), dose_max = c(NA, NA, NA, NA, NA, NA, NA, 20, NA, 20), dose_fix = c(NA, NA, 30, 30, 30, 20, 30, 30, 20, 30), quota_max = c(NA, NA, NA, NA, 400, NA, 300, 200, NA, 300), quota_wind = c(NA, NA, NA, NA, NA, NA, NA, NA, 100, 60) ), options = list(grid = FALSE, fill_missing = FALSE) ) outputs_strat <- run_model( x = scen_strat, options = list(plan = "multicore", log = FALSE), cfg = load_config() ) plot_outputs( outputs = outputs_strat, options = list( run_prefix = "S", pos = list("RU | Y", "IRR | B"), title = "Optirrig - Irrigations Strategies" ) ) ## End(Not run)
Build a spec object consumable by calibration and uncertainty helpers.
create_spec( project_name, ranges, climate = NULL, irrigation = NULL, obs = NULL, crop = NULL, soil = NULL, date_sowing = NULL, date_harvest = NULL, date_start = date_sowing, date_end = date_harvest, irrig_mod = 0, yield_var = "Y", base_overrides = list(), optirrig_data = NULL, optirrig_crop_map = c(sugarbeet = "beetroot") )create_spec( project_name, ranges, climate = NULL, irrigation = NULL, obs = NULL, crop = NULL, soil = NULL, date_sowing = NULL, date_harvest = NULL, date_start = date_sowing, date_end = date_harvest, irrig_mod = 0, yield_var = "Y", base_overrides = list(), optirrig_data = NULL, optirrig_crop_map = c(sugarbeet = "beetroot") )
project_name |
Character scalar. Project folder name. |
ranges |
Named list of parameter ranges ( |
climate |
Climate table used by the model. |
irrigation |
Irrigation table used by the model. |
obs |
Optional named list of observed series specs. |
crop |
Character scalar. Crop name used by the model. |
soil |
Character scalar. Soil identifier used by the model. |
date_sowing |
Character/Date sowing date. |
date_harvest |
Character/Date harvest date. |
date_start |
Character/Date simulation start date. |
date_end |
Character/Date simulation end date. |
irrig_mod |
Numeric scalar irrigation mode modifier. |
yield_var |
Character scalar ( |
base_overrides |
Named list to override/add base fields. |
optirrig_data |
Optional simplified payload from
|
optirrig_crop_map |
Named mapping from dataset crop ids to model crop ids. |
A list with project_name, normalized ranges, and base.
Given at least two of sand, silt, and clay percentages, this function infers the missing fraction and returns the corresponding USDA soil texture class (coarse classes).
get_soil_texture_class(sand = NA, silt = NA, clay = NA)get_soil_texture_class(sand = NA, silt = NA, clay = NA)
sand |
Numeric (0-100), percentage of sand. |
silt |
Numeric (0-100), percentage of silt. |
clay |
Numeric (0-100), percentage of clay. |
Character string giving the soil texture class (e.g. "CL", "L", "Sa", "SiL").
Default grouping extracts parcel-year code patterns such as
2022_22526AL from trial ids. If no such pattern is found, the last trial
token without irrigation suffix is used.
group_uncertainty_mc_trials(x, group_fun = NULL)group_uncertainty_mc_trials(x, group_fun = NULL)
x |
Result from |
group_fun |
Optional function taking a trial id and returning a group id. |
A data.frame with columns trial_id and group_id.
Inject inferred soil codes into OptirrigDatasets payloads
inject_datasets_soil(x, overwrite = FALSE, strict = TRUE)inject_datasets_soil(x, overwrite = FALSE, strict = TRUE)
x |
A trial payload or a named list of trial payloads. |
overwrite |
Logical. If |
strict |
Logical. If |
Same structure as x with filled soil$soil where possible.
Formats and displays messages with custom styling using the cli package. The messages can include clickable file paths and are styled based on the type provided.
msg(text = "", ..., path = NULL, type = "T", verbose = TRUE)msg(text = "", ..., path = NULL, type = "T", verbose = TRUE)
text |
A character string containing the main message. |
... |
Additional text elements to append to the main message. |
path |
An optional character string specifying a file path that will be displayed as an italicized, clickable link. |
type |
A character specifying the message type. Examples: "S" (success), "W" (warning), "D" (danger), "I" (info), "T" (plain text). |
verbose |
A logical value indicating whether the message should be displayed. Defaults to TRUE. |
This function uses a custom cli theme to differentiate various message types, ensuring that success, warning, error, and informational messages are visually distinct.
Returns a unless it is NULL or NA, otherwise returns b.
a %||% ba %||% b
a |
First value to check |
b |
Default value to return if |
Either a or b.
Plot MC global uncertainty (no OAT)
plot_uncertainty_mc( x, group_by = c("none", "trial_group"), grouping = NULL, group_map = NULL, group_fun = NULL, show_quantile_lines = TRUE, show_median_line = TRUE, x_axis = c("Date", "TT_sowing"), tt_step = 20, show = TRUE, save = FALSE, path = NULL, width = 16, height = 14, dpi = 300 )plot_uncertainty_mc( x, group_by = c("none", "trial_group"), grouping = NULL, group_map = NULL, group_fun = NULL, show_quantile_lines = TRUE, show_median_line = TRUE, x_axis = c("Date", "TT_sowing"), tt_step = 20, show = TRUE, save = FALSE, path = NULL, width = 16, height = 14, dpi = 300 )
x |
Result from |
group_by |
Either |
grouping |
Optional common aggregation object. Supported forms:
|
group_map |
Optional data.frame with |
group_fun |
Optional function used to derive group ids when
|
show_quantile_lines |
Logical; if |
show_median_line |
Logical; if |
x_axis |
Axis used for daily uncertainty ribbons: |
tt_step |
Thermal-time grid step used when |
show |
Logical. If |
save |
Logical. If |
path |
Optional output path. If |
width, height, dpi
|
Export options passed to |
If group_by = "none", invisibly returns a list with plot,
panels, and path. If group_by = "trial_group", returns a named list
of per-group plot results.
Plot MC uncertainty by parcel-year group (one recap per group)
plot_uncertainty_mc_by_group( x, grouping = NULL, group_map = NULL, group_fun = NULL, show_quantile_lines = TRUE, show_median_line = TRUE, x_axis = c("Date", "TT_sowing"), tt_step = 20, show = TRUE, save = FALSE, path_dir = NULL, file_prefix = "uncertainty_mc", width = 16, height = 14, dpi = 300 )plot_uncertainty_mc_by_group( x, grouping = NULL, group_map = NULL, group_fun = NULL, show_quantile_lines = TRUE, show_median_line = TRUE, x_axis = c("Date", "TT_sowing"), tt_step = 20, show = TRUE, save = FALSE, path_dir = NULL, file_prefix = "uncertainty_mc", width = 16, height = 14, dpi = 300 )
x |
Result from |
grouping |
Optional common aggregation object. Supported forms:
|
group_map |
Optional data.frame with |
group_fun |
Optional function used when |
show_quantile_lines |
Logical; if |
show_median_line |
Logical; if |
x_axis |
Axis used for daily uncertainty ribbons: |
tt_step |
Thermal-time grid step used when |
show |
Logical. If |
save |
Logical. If |
path_dir |
Directory for exported plots when |
file_prefix |
Prefix for exported file names. |
width, height, dpi
|
Export options passed to |
Named list of results returned by plot_uncertainty_mc(), one per group.
Prepare MC uncertainty data for plotting (global MC only)
prepare_uncertainty_mc_plot_data( x, daily_vars = c("I", "Res", "Sw", "LAI", "B", "Y_sugar"), plant_vars = c("LAI", "B", "Y_sugar"), seasonal_vars = c("sumIRR", "Y_ratio", "Wprod", "Iprod"), x_axis = c("Date", "TT_sowing"), tt_step = 20 )prepare_uncertainty_mc_plot_data( x, daily_vars = c("I", "Res", "Sw", "LAI", "B", "Y_sugar"), plant_vars = c("LAI", "B", "Y_sugar"), seasonal_vars = c("sumIRR", "Y_ratio", "Wprod", "Iprod"), x_axis = c("Date", "TT_sowing"), tt_step = 20 )
x |
Object returned by |
daily_vars |
Character vector of daily variables to plot. |
plant_vars |
Character vector of plant variables to plot. |
seasonal_vars |
Character vector of seasonal indicators to plot. |
x_axis |
Axis used for daily uncertainty ribbons: |
tt_step |
Thermal-time grid step used when |
A list with standardized plotting tables and labels.
Dry out a precipitation series randomly and display a comparative barplot.
randomize_rainfall( precip, prob_remove = 0.2, min_factor = 0.3, max_factor = 0.9, col_modified = "red", seed = NULL, date_sowing = NULL, date_harvest = NULL, dates = NULL )randomize_rainfall( precip, prob_remove = 0.2, min_factor = 0.3, max_factor = 0.9, col_modified = "red", seed = NULL, date_sowing = NULL, date_harvest = NULL, dates = NULL )
precip |
Numeric. Precipitation series (>=0). |
prob_remove |
Probability of completely removing a rainy day. |
min_factor |
Minimum multiplicative factor (reduced days). |
max_factor |
Maximum multiplicative factor (reduced days). |
col_modified |
Color of the modified series (examples: "red", "blue"). |
seed |
Optional. For reproducibility. |
date_sowing |
Date (or index) marking the beginning of the crop window used to report cumulative rainfall. |
date_harvest |
Date (or index) marking the end of the crop window used to report cumulative rainfall. |
dates |
Optional vector of dates aligned with |
A modified precipitation vector (same length as original).
Reads an image from a specified file path, resizes it to multiple specified widths while preserving the aspect ratio, and saves the resized images with filenames that include the respective width.
resize_logo(filePath, widths)resize_logo(filePath, widths)
filePath |
A character string specifying the path to the source image file. Supported formats include PNG, JPG, etc. |
widths |
A numeric vector specifying the target widths (in pixels) for the resized images. |
The function reads the original image, computes the corresponding height for each specified width to maintain the original aspect ratio, and then resizes the image accordingly. The resized images are saved with filenames that include the width as a suffix (e.g., image_300px.png).
The magick package is used to handle image manipulation, ensuring that the resizing operation preserves the quality of the image. The resized images are saved in the PNG format by default.
A character vector containing the file paths of the resized images.
A character vector containing the file paths to the resized images.
DEoptim
Run Calibration with DEoptim
run_calibration_deoptim(fn, inputs, lower, upper, control, options)run_calibration_deoptim(fn, inputs, lower, upper, control, options)
fn |
Objective function. |
inputs |
Inputs passed to |
lower |
Lower bounds. |
upper |
Upper bounds. |
control |
Optimizer controls. |
options |
Options passed to |
A calibration object.
neldermead
Run Calibration with neldermead
run_calibration_neldermead(fn, inputs, lower, upper, control, options)run_calibration_neldermead(fn, inputs, lower, upper, control, options)
fn |
Objective function. |
inputs |
Inputs passed to |
lower |
Lower bounds. |
upper |
Upper bounds. |
control |
Optimizer controls. |
options |
Options passed to |
A calibration object.
optim
Run Calibration with optim
run_calibration_optim(fn, inputs, lower, upper, control, options)run_calibration_optim(fn, inputs, lower, upper, control, options)
fn |
Objective function. |
inputs |
Inputs passed to |
lower |
Lower bounds. |
upper |
Upper bounds. |
control |
Optimizer controls. |
options |
Options passed to |
A calibration object.
Run Calibration with parameter screening
run_calibration_screen(fn, inputs, lower, upper, control, options)run_calibration_screen(fn, inputs, lower, upper, control, options)
fn |
Objective function. |
inputs |
Inputs passed to |
lower |
Lower bounds. |
upper |
Upper bounds. |
control |
Screening controls. |
options |
Options passed to |
A calibration object.
Simple objective wrapper for calibration workflows.
It takes calibration inputs (typically specs), selected params,
and options, then:
builds model inputs,
runs run_model_eval().
run_model_calibration(inputs, params, options = list())run_model_calibration(inputs, params, options = list())
inputs |
Calibration inputs. Can be:
|
params |
Named numeric vector of selected parameters. |
options |
Named list of options. |
A list with:
method: criterion label returned by run_model_eval(),
score: scalar objective score,
timings: run/eval/total elapsed seconds.
The function extracts observations from inputs[[i]]$obs, extracts matching
simulated variables from outputs[[i]], joins Obs/Sim by
run_id + Date + var, computes one criterion per variable on pooled values
across runs, then aggregates variable scores to a final score.
run_model_eval( inputs, outputs, method = c("nrmse", "rmse", "prmse", "mse", "mae", "mre", "d"), FUN = NULL, var_weights = NULL, min_obs_n = 3L, single_obs_weight = 1 )run_model_eval( inputs, outputs, method = c("nrmse", "rmse", "prmse", "mse", "mae", "mre", "d"), FUN = NULL, var_weights = NULL, min_obs_n = 3L, single_obs_weight = 1 )
inputs |
List of run inputs. Each run must contain at least
|
outputs |
List of model outputs. |
method |
Criterion method used when |
FUN |
Optional custom criterion function |
var_weights |
Optional named weights by variable, e.g.
|
min_obs_n |
Minimum number of observed values required to keep one
|
single_obs_weight |
Relative point weight applied to one |
A list with:
method
score
score_by_var
score_tbl
obs_sim
This objective compares distances between trial trajectories instead of raw Obs/Sim points. For each variable, it computes one Euclidean-distance summary per site and trial pair on simulated values and on observed values, then measures the gap between both summaries.
run_model_eval_ed( inputs, outputs, vars = "Y_sugar", ed_method = c("classic", "symmetric", "symetric"), ed_stat = c("mean", "median", "sd", "max", "min"), loss = c("rmse", "mae", "bias_abs"), trial_levels = c("Ndc", "Irri", "ArrT", "ArrP", "IrriMn", "DclT", "Tem"), var_weights = NULL, min_obs_n = 3L )run_model_eval_ed( inputs, outputs, vars = "Y_sugar", ed_method = c("classic", "symmetric", "symetric"), ed_stat = c("mean", "median", "sd", "max", "min"), loss = c("rmse", "mae", "bias_abs"), trial_levels = c("Ndc", "Irri", "ArrT", "ArrP", "IrriMn", "DclT", "Tem"), var_weights = NULL, min_obs_n = 3L )
inputs |
List of run inputs. |
outputs |
List of model outputs. |
vars |
Variables used to build the ED objective. |
ed_method |
ED method: |
ed_stat |
Statistic used to aggregate ED within each trial pair. |
loss |
Loss used to compare simulated vs observed ED:
|
trial_levels |
Scenario suffix levels used to parse |
var_weights |
Optional named weights by variable. |
min_obs_n |
Minimum number of observed values required to keep one
|
A list with method, score, score_by_var, obs_sim,
ed_summary, and ed_gap.
Run Monte-Carlo uncertainty from calibration specs
run_uncertainty_mc( x, funs = NULL, n_draws = 50L, sampling = c("normal", "lhs", "uniform"), quantile_probs = c(0.05, 0.5, 0.95), forced_draws = NULL, seed = NULL, plan = "multicore", workers = NULL, output_vars = c("Date", "P", "I1", "RU", "RUmax", "stress_ETR", "B", "Bp", "Y", "Yp", "Y_sugar", "Yp_sugar", "LAI", "W_eff"), inputs_path = NULL, log = FALSE, verbose = TRUE, return_outputs = FALSE, output_path = NULL, rds_name = "uncertainty_mc.rds", force = FALSE, grouping = NULL )run_uncertainty_mc( x, funs = NULL, n_draws = 50L, sampling = c("normal", "lhs", "uniform"), quantile_probs = c(0.05, 0.5, 0.95), forced_draws = NULL, seed = NULL, plan = "multicore", workers = NULL, output_vars = c("Date", "P", "I1", "RU", "RUmax", "stress_ETR", "B", "Bp", "Y", "Yp", "Y_sugar", "Yp_sugar", "LAI", "W_eff"), inputs_path = NULL, log = FALSE, verbose = TRUE, return_outputs = FALSE, output_path = NULL, rds_name = "uncertainty_mc.rds", force = FALSE, grouping = NULL )
x |
A |
funs |
Optional named list of objective functions. |
n_draws |
Number of Monte-Carlo draws. |
sampling |
Sampling method: |
quantile_probs |
Optional vector of probabilities in |
forced_draws |
Optional forced parameter draws to append to the Monte-Carlo sample. Can be a named numeric vector, a data frame, or a list of such objects. Required columns/names must match the calibrated parameter names. |
seed |
Optional random seed. |
plan |
Execution plan forwarded to |
workers |
Optional number of workers forwarded to |
output_vars |
Character vector of model variables requested from
|
inputs_path |
Optional path to project |
log |
Logical. Forwarded to |
verbose |
Logical. Print workflow progress. |
return_outputs |
Logical. If |
output_path |
Optional directory for RDS cache. |
rds_name |
File name used in |
force |
Logical. If |
grouping |
Optional grouping object stored in the result. |
A list with draws, run map, daily summaries, seasonal metrics, optional quantiles, and optional raw outputs.
Cluster the best screening candidates below a score threshold and keep one low-score representative per cluster.
select_screen_representatives( screen_res, param_cols, score_gate = 0.2, n_representants = 5L )select_screen_representatives( screen_res, param_cols, score_gate = 0.2, n_representants = 5L )
screen_res |
Screening result object containing |
param_cols |
Character vector of parameter column names used to compute distances between candidates. |
score_gate |
Maximum score retained in the candidate pool. |
n_representants |
Number of representative clusters to retain. |
A list containing the filtered candidate pool, selected representatives, a representative parameter table, a cluster summary, and the number of clusters used.
This function applies stylistic formatting to R and Rmd files in specified directories using the styler package. It also detects non-ASCII (encoding) issues inside function definitions and forces UTF-8 encoding on each file.
stylifier(directory = c("R", "vignettes", "reports", "inst"), recursive = TRUE)stylifier(directory = c("R", "vignettes", "reports", "inst"), recursive = TRUE)
directory |
A character vector of directory names to search for files ending with
|
recursive |
A logical value indicating whether to search directories recursively. Defaults to TRUE. |
Files are scanned for non-ASCII characters only within function bodies. Upon finding any issues, the function logs detailed information before applying style formatting using styler::style_file.