SticsREval is an R package for evaluating and comparing versions of the STICS crop model. The core idea is to assess whether a new version of STICS performs better, equally, or worse than a reference version, both against field observations and against the reference simulation outputs.
The workflow:
SticsOnR
CroPlotR
You can install the development version of SticsREval from GitHub:
# install.packages("devtools")
devtools::install_github("SticsRPacks/SticsREval")Or using the pak package:
# install.packages("pak")
pak::pak("SticsRPacks/SticsREval")renv
SticsREval uses renv to ensure reproducible package dependencies. The renv.lock file records the exact versions of all dependencies.
To restore the project environment locally:
# install.packages("renv")
renv::restore()This will install all required packages at the versions specified in renv.lock. It is recommended to run this after cloning the repository and before running any code.
SticsREval relies on the following SticsRPacks packages:
| Package | Role |
|---|---|
SticsRFiles |
Reading simulated and observed data |
SticsOnR |
Running STICS simulations (optional) |
CroPlotR |
Computing statistical criteria and generating plots |
SticsREval evaluates a candidate version of STICS by running it and comparing its outputs against two sources:
STICS candidate version Reference version stats
(stics_exe + workspace) (reference_workspace)
│ │
▼ │
make_config() ◄──────────────────────┘
│
▼
evaluate() ← runs simulations + compares vs obs & reference → saves .parquet files
│
├──► export_stats_to_csv() ← export statistics + deteriorated USMs to CSV
└──► gen_plots() ← comparison plots + scatter plots of regressions
make_config()
Creates and validates the configuration object that is passed to all other functions. All parameters for simulation, evaluation, and export are defined here.
library(SticsREval)
config <- make_config(
stics_exe = "/path/to/stics",
workspace = "workspace/",
metadata_file = "metadata.csv",
run_simulations = TRUE, # set to FALSE to skip simulations
verbose = 1,
parallel = FALSE,
cores = NA,
reference_workspace = NULL, # path to reference version stats for regression detection
percentage = 5, # threshold (%) to flag deteriorated variables
eval_workspace = "eval_workspace/",
init_workspace = TRUE,
output_dir = "outputs/",
force = TRUE,
species = NULL
usms = NULL,
var2exclude = NULL
)| Argument | Description |
|---|---|
stics_exe |
Path to the STICS executable |
workspace |
Path to the simulation input directory |
metadata_file |
Path to the metadata CSV file describing simulations |
run_simulations |
Whether to run STICS simulations (default: TRUE) |
verbose |
Logging verbosity level (default: 1) |
parallel |
Enable parallel execution (default: FALSE) |
cores |
Number of cores for parallel execution (NA = auto) |
reference_workspace |
Path to the reference version simulation statistics, used to detect regressions |
percentage |
Threshold (%) above which a variable is flagged as deteriorated vs. the reference (default: 5) |
eval_workspace |
Path to the evaluation workspace |
init_workspace |
Whether to initialize the workspace (default: TRUE) |
output_dir |
Output directory for exports |
force |
Whether to overwrite an existing non-empty evaluation workspace without prompting. (default: FALSE) |
species |
Optional list of species to evaluate. If NULL, all available species are evaluated. (default: NULL) |
usms |
Optional list of USMs to evaluate. If NULL, all available USMs are evaluated. (default: NULL) |
var2exclude |
Optional list of variables to exclude from evaluation. If NULL, all available variables are evaluated. (default: NULL) |
evaluate()
The core function of the package. It orchestrates the full evaluation workflow:
SticsOnR)reference_workspace is provided)percentage thresholdeval_workspace directoryErrors during evaluation are caught and logged gracefully without stopping the full process.
evaluate(config)After running, the eval_workspace directory will contain Parquet files with simulated data, observed data, and evaluation statistics per species.
export_stats_to_csv()
Exports the evaluation statistics per species to CSV files. For each species, three files are produced when available:
| File | Content |
|---|---|
Criteres_stats.csv |
Global statistical criteria (RMSE, nRMSE, bias, R², etc.) |
RMSE_per_usm.csv |
RMSE broken down per USM (simulation unit) |
Deteriorated_USM.csv |
List of USMs with deteriorated performance |
export_stats_to_csv(config)gen_plots()
Generates diagnostic plots for each species:
percentage threshold (only generated when reference_workspace is set in make_config() and regressions are detected)
gen_plots(config)
library(SticsREval)
# 1. Configure the evaluation
# - stics_exe points to the candidate version of STICS to evaluate
# - reference_workspace points to the statistics of the reference version
config <- make_config(
stics_exe = "/path/to/stics_candidate",
workspace = "workspace/",
metadata_file = "metadata.csv",
run_simulations = TRUE,
reference_workspace = "reference_version_stats/", # stats from the reference version
percentage = 5, # flag variables with >5% deterioration
eval_workspace = "eval_workspace/",
output_dir = "outputs/"
)
# 2. Run simulations + evaluate vs observations and reference version stats
evaluate(config)
# 3. Export statistics and deteriorated USMs to CSV
export_stats_to_csv(config)
# 4. Generate comparison and regression scatter plots
gen_plots(config)A pre-built Docker image is available on the GitHub Container Registry, so you can run SticsREval without installing R or any dependencies locally.
docker run --rm -it \
-v /path/to/your/workspace:/workspace \
ghcr.io/sticsrpacks/stics-r-eval:latest \
RThen inside R:
library(SticsREval)
config <- make_config(
stics_exe = "/path/to/stics",
workspace = "/workspace/",
metadata_file = "/workspace/metadata.csv",
output_dir = "/workspace/outputs/"
)
evaluate(config)# Without a GitHub token
docker build -t stics-r-eval .
# With a GitHub token (needed to install private SticsRPacks dependencies)
docker build \
--secret id=GITHUB_TOKEN,src=<(echo $GITHUB_PAT) \
-t stics-r-eval .Note: The image is based on
rocker/r-ver:4and usesrenvto ensure reproducible package versions. Dependencies are restored fromrenv.lockat build time.
Please note that this project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.