| Title: | Optirrig Core: Simulate and Optimize Irrigation Scenarios |
|---|---|
| Description: | The OptirrigCORE package in R is based on the Optirrig model. It facilitates the extraction and formatting of observation data used by the model, as well as the integration of plant, soil and yield descriptions. It supports various analytical methods, such as Ex-Post and Ex-Ante analyses, with a view to drawing up an optimised irrigation schedule based on the criteria. The package includes all the calculation tools needed to describe biophysical processes with a generalist approach. It can be used as a dependency or complement to modify and reinterpret biophysical descriptions. What's more, it automates the modeling process, the description of biophysical processes and the analysis of results and performance, guaranteeing a reproducible approach. It also makes it easy to compile results in automated reports. |
| 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.8.0 |
| Built: | 2026-05-27 06:23:29 UTC |
| Source: | https://forge.inrae.fr/OptirrigHIVE/OptirrigCORE |
This function adds missing parameters to a given list or data frame x by referencing parameter definitions
from INI files associated with a specified type (e.g., crop, soil, irrigation, run). The function
loads the appropriate INI file(s) based on the types argument and fills in any missing parameters in x
with default values and types as specified in the INI files.
add_missing_params(x, types, ..., cfg = load_config())add_missing_params(x, types, ..., cfg = load_config())
x |
A list or data frame containing parameters. Missing parameters will be added based on the reference. |
types |
A character string specifying the type of parameters to reference. Must be one of: "crop", "soil", "irrigation", "run". |
... |
Additional arguments (currently unused). |
cfg |
A configuration object, typically loaded via |
The function searches for INI files using the per-type sources declared in cfg$ini_sources. Each source can
be a package name or a directory path, and sources are searched in order. It selects the relevant INI file(s)
based on the types argument and the contents of x (e.g., x$crop or x$soil). Parameter types are inferred
from the INI file and used to cast values appropriately (e.g., integer, numeric, logical, date).
A list with the same contents as x, but with any missing parameters added and cast to the appropriate types.
Generic and method-specific functions to assign the temperature
response parameter alpha based on thermal time (TT)
and a threshold TTmax. For each TT value, alpha1
is used when TT <= TTmax and alpha2 otherwise.
Methods are provided for numeric vectors, data.frames and matrices.
calc_alpha(x, ...) ## S3 method for class 'numeric' calc_alpha(x, TTmax, alpha1, alpha2, TT = x, ...) ## S3 method for class 'data.frame' calc_alpha( x, TT = x[iday, TT_name, drop = TRUE], TTmax, alpha1, alpha2, iday = seq.int(nrow(x)), TT_name = "TT_sowing", alpha_name = "alpha", ... ) ## S3 method for class 'matrix' calc_alpha( x, TT = x[iday, TT_name], TTmax, alpha1, alpha2, iday = seq.int(nrow(x)), alpha_name = "alpha", TT_name = "TT_sowing", ... )calc_alpha(x, ...) ## S3 method for class 'numeric' calc_alpha(x, TTmax, alpha1, alpha2, TT = x, ...) ## S3 method for class 'data.frame' calc_alpha( x, TT = x[iday, TT_name, drop = TRUE], TTmax, alpha1, alpha2, iday = seq.int(nrow(x)), TT_name = "TT_sowing", alpha_name = "alpha", ... ) ## S3 method for class 'matrix' calc_alpha( x, TT = x[iday, TT_name], TTmax, alpha1, alpha2, iday = seq.int(nrow(x)), alpha_name = "alpha", TT_name = "TT_sowing", ... )
x |
Input object. Can be numeric, matrix or data.frame. |
... |
Additional arguments passed to methods. |
TTmax |
numeric Thermal-time threshold used to switch
between |
alpha1 |
numeric Alpha value used when |
alpha2 |
numeric Alpha value used when |
TT |
numeric Thermal time (e.g. degree-days, °C.days).
For the numeric method, defaults to |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
TT_name |
character Layer or column name containing
|
alpha_name |
character Layer or column name used to store
calculated |
The numeric method applies a simple piecewise-constant mapping:
alpha1 is used when TT <= TTmax and alpha2
otherwise. Methods for matrix and data.frame inputs extract
TT values from the specified column or layer, compute
alpha for the selected time indices (iday), and
store the result in alpha_name. If the target column or
layer does not exist, it is created and initialised with
NA_real_.
For numeric input: a numeric vector of alpha values.
For matrix/data.frame input: an object of the same class as
x with a column alpha_name created or
updated for the specified indices (iday).
Generic function and methods to calculate biomass accumulation (B) based on photosynthetically active radiation (PAR), intercepted radiation (IR), radiation use efficiency (RUE), and stress factors. Supports various input types: numeric, matrix and data.frame.
calc_B(x = NULL, ...) ## S3 method for class ''NULL'' calc_B(x = NULL, B0, ...) ## S3 method for class 'numeric' calc_B( x, PAR, IR, RUE, stress_B, stress_noci_B, iday_crop_dev = rep(1, ifelse(length(x) == 1, length(PAR), length(x))), B0 = x, ... ) ## S3 method for class 'matrix' calc_B( x, B0, PAR = x[iday, PAR_name], IR = x[iday, IR_name], RUE, stress_B = x[iday, stress_B_name], stress_noci_B = x[iday, stress_noci_B_name], iday = seq.int(nrow(x)), stress_B_name = "stress_B", stress_noci_B_name = "stress_noci_B", PAR_name = "PAR", IR_name = "IR", B_name = "B", ... ) ## S3 method for class 'data.frame' calc_B( x, PAR = x$PAR, B0, IR = x$IR, RUE = x$RUE, stress_B = x$stress_B, stress_noci_B = x$stress_noci_B, iday = seq.int(nrow(x)), B_name = "B", ... )calc_B(x = NULL, ...) ## S3 method for class ''NULL'' calc_B(x = NULL, B0, ...) ## S3 method for class 'numeric' calc_B( x, PAR, IR, RUE, stress_B, stress_noci_B, iday_crop_dev = rep(1, ifelse(length(x) == 1, length(PAR), length(x))), B0 = x, ... ) ## S3 method for class 'matrix' calc_B( x, B0, PAR = x[iday, PAR_name], IR = x[iday, IR_name], RUE, stress_B = x[iday, stress_B_name], stress_noci_B = x[iday, stress_noci_B_name], iday = seq.int(nrow(x)), stress_B_name = "stress_B", stress_noci_B_name = "stress_noci_B", PAR_name = "PAR", IR_name = "IR", B_name = "B", ... ) ## S3 method for class 'data.frame' calc_B( x, PAR = x$PAR, B0, IR = x$IR, RUE = x$RUE, stress_B = x$stress_B, stress_noci_B = x$stress_noci_B, iday = seq.int(nrow(x)), B_name = "B", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
B0 |
numeric Initial biomass value. If |
PAR |
numeric vector or matrix of photosynthetically active radiation
values ( |
IR |
numeric vector or matrix of intercepted radiation fractions
(dimensionless, |
RUE |
numeric Radiation use efficiency
( |
stress_B |
numeric vector or matrix of stress coefficients affecting biomass accumulation. |
stress_noci_B |
numeric vector or matrix of exponents for stress coefficients. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
stress_B_name |
character Name of the column or array for stress_B (default: "stress_B"). |
stress_noci_B_name |
character Name of the column or array for stress_noci_B (default: "stress_noci_B"). |
PAR_name |
character Name of the column or array for PAR (default: "PAR"). |
IR_name |
character Name of the column or array for IR (default: "IR"). |
B_name |
character Name of the column or array for output biomass (default: "B"). |
The function computes biomass incrementally for each time step, using the formula:
Here PAR is expected in and IR is a
dimensionless intercepted fraction. The factor 0.0001 converts
to and then to
, so B remains expressed in .
If i == 0, the output is set to NA.
For matrix, data.frame methods, the function
iterates over time steps,
updating the biomass column or array.
Returns a numeric vector, matrix or data.frame with the calculated biomass values.
calc_B_root(),
calc_TT_sowing()
Generic and method-specific functions to compute root biomass using thermal-time thresholds. The numeric method updates root biomass for a single time step. Matrix and data.frame methods apply the same rule sequentially over a time series.
calc_B_root(x = NULL, ...) ## S3 method for class 'numeric' calc_B_root(x, B0, B_root0, TT_sowing, TT_B_root5, TT_B_root70, ...) ## S3 method for class 'matrix' calc_B_root( x, B0, B_root0, TT_sowing = x[iday, TT_sowing_name], TT_B_root5, TT_B_root70, iday = seq.int(nrow(x)), B_name = "B", B_root_name = "B_root", TT_sowing_name = "TT_sowing", ... ) ## S3 method for class 'data.frame' calc_B_root( x, B0, B_root0, TT_sowing = x[iday, TT_sowing_name], TT_B_root5, TT_B_root70, iday = seq.int(nrow(x)), B_name = "B", B_root_name = "B_root", TT_sowing_name = "TT_sowing", ... )calc_B_root(x = NULL, ...) ## S3 method for class 'numeric' calc_B_root(x, B0, B_root0, TT_sowing, TT_B_root5, TT_B_root70, ...) ## S3 method for class 'matrix' calc_B_root( x, B0, B_root0, TT_sowing = x[iday, TT_sowing_name], TT_B_root5, TT_B_root70, iday = seq.int(nrow(x)), B_name = "B", B_root_name = "B_root", TT_sowing_name = "TT_sowing", ... ) ## S3 method for class 'data.frame' calc_B_root( x, B0, B_root0, TT_sowing = x[iday, TT_sowing_name], TT_B_root5, TT_B_root70, iday = seq.int(nrow(x)), B_name = "B", B_root_name = "B_root", TT_sowing_name = "TT_sowing", ... )
x |
Input object (numeric value, matrix or data.frame). |
... |
Additional arguments passed to methods. |
B0 |
numeric Previous total biomass used for sequential
updates ( |
B_root0 |
numeric Previous root biomass used for sequential
updates ( |
TT_sowing |
numeric Thermal time since sowing (scalar or per-time values) (°C.days). |
TT_B_root5 |
numeric Thermal-time threshold for 5% root fraction (°C.days). |
TT_B_root70 |
numeric Thermal-time threshold for 70% root fraction (°C.days). |
iday |
integer Indices of time steps to process (for time-series methods). |
B_name |
character Name of the total biomass column or
layer (default |
B_root_name |
character Name of the root biomass column or
layer (default |
TT_sowing_name |
character Name of the thermal-time column
or layer (default |
Root biomass (B_root) is updated from total biomass (B)
and thermal time since sowing (TT_sowing) using two thresholds
TT_B_root5 and TT_B_root70. A piecewise linear rule
controls the fraction of the biomass increment allocated to roots:
if :
increases by 5\
if :
increases linearly from 5\
increment in ;
if :
increases by 70\
The update rule can be written as:
where is the allocation fraction defined above.
For matrix and data.frame methods, B0 and B_root0
are taken from the previous time step in the series, so that root
biomass is updated sequentially along the time dimension.
For numeric input: a numeric scalar (B_root).
For matrix/data.frame input: the object x with a column
or layer named B_root_name created or updated for the selected
indices (iday).
calc_B()
calc_TT_sowing()
Generic and method-specific functions to calculate potential biomass production (Bp).
calc_Bp(x, ...) ## S3 method for class 'model_init' calc_Bp(x, ...) ## S3 method for class 'matrix' calc_Bp(x, ...)calc_Bp(x, ...) ## S3 method for class 'model_init' calc_Bp(x, ...) ## S3 method for class 'matrix' calc_Bp(x, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
Updated model_init object with potential biomass production (Bp)
values.
calc_IR()
calc_PAR()
calc_B()
Generic function and methods to compute the root component of the biomass associated with the "Bp" pool.
calc_Bp_root(x = NULL, ...) ## S3 method for class 'matrix' calc_Bp_root(x, TT_B_root5, TT_B_root70, ...)calc_Bp_root(x = NULL, ...) ## S3 method for class 'matrix' calc_Bp_root(x, TT_B_root5, TT_B_root70, ...)
x |
Input data. For the matrix method, a numeric matrix (rows/columns as required by calc_B_root). |
... |
Additional arguments passed to calc_B_root (for example other control parameters or names). These are forwarded by the methods. |
TT_B_root5 |
integer Temperature threshold (or other threshold) used to determine the 5% reference for root allocation; passed to calc_B_root (°C days). |
TT_B_root70 |
integer Temperature threshold (or other threshold) used to determine the 70% reference for root allocation; passed to calc_B_root (°C days). |
The generic calc_Bp_root dispatches on the class of x. Methods call calc_B_root(...) with B_name = "Bp" and B_root_name = "Bp_root" so that the computed root variable is named "Bp_root" in the returned object.
An object of the same class as x with the computed root variable ("Bp_root") added or returned according to the underlying calc_B_root behavior.
calc_B_root()
Generic and method-specific functions to calculate model water balance cases.
calc_case(x, ...) ## S3 method for class 'numeric' calc_case(x, zES, zroot = x, ...) ## S3 method for class 'matrix' calc_case( x, zroot = x[iday, zroot_name], zES, iday = seq.int(nrow(x)), zroot_name = "zroot", case_name = "case", ... )calc_case(x, ...) ## S3 method for class 'numeric' calc_case(x, zES, zroot = x, ...) ## S3 method for class 'matrix' calc_case( x, zroot = x[iday, zroot_name], zES, iday = seq.int(nrow(x)), zroot_name = "zroot", case_name = "case", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
zES |
numeric Evaporation reservoir depth. |
zroot |
numeric Crop root depth (default: |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
zroot_name |
character Layer or column name containing root depth values (default: "zroot"). |
case_name |
character Layer or column name to store calculated case. |
Generic function to calculate the Cp value, which is used in crop
coefficient calculations. This function dispatches methods based on the
class of the input x.
calc_Cp(x, ...) ## S3 method for class 'numeric' calc_Cp( x, c1, c2, Kc, Ksol = NULL, iday_crop_dev = rep(1, length(x)), LAI = x, ... )calc_Cp(x, ...) ## S3 method for class 'numeric' calc_Cp( x, c1, c2, Kc, Ksol = NULL, iday_crop_dev = rep(1, length(x)), LAI = x, ... )
x |
Input object. |
... |
Additional arguments passed to methods. |
c1 |
numeric Coefficient related to the crop. |
c2 |
numeric Coefficient related to the crop. |
Kc |
numeric Crop coefficient. |
Ksol |
numeric Soil coefficient, optional. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
LAI |
numeric Leaf Area Index, defaults to |
The Cp value is calculated based on the provided parameters. For numeric inputs, the calculation uses the formula :
If Ksol is provided and Cp > 0 and Kc < Ksol, then Cp
is adjusted as:
Numeric value representing the Cp calculation.
calc_Kc()
calc_Ksol()
calc_LAI()
calc_Cp(3, c1 = 1.2, c2 = 0.5, Kc = 0.8, Ksol = 1.0)calc_Cp(3, c1 = 1.2, c2 = 0.5, Kc = 0.8, Ksol = 1.0)
Generic and method-specific functions to calculate root growth crac parameters.
calc_crac(x, ...) ## S3 method for class 'numeric' calc_crac(x, ks_root, seuil, iday_crop_dev = rep(1, length(x)), taum = x, ...) ## S3 method for class 'matrix' calc_crac( x, taum = x[iday, taum_name], ks_root = x[iday - 1, "ks_root"], seuil, iday = seq.int(nrow(x)), taum_name = "taum", crac_name = "crac", ... ) ## S3 method for class 'model_output' calc_crac(x, crop, iday, ...)calc_crac(x, ...) ## S3 method for class 'numeric' calc_crac(x, ks_root, seuil, iday_crop_dev = rep(1, length(x)), taum = x, ...) ## S3 method for class 'matrix' calc_crac( x, taum = x[iday, taum_name], ks_root = x[iday - 1, "ks_root"], seuil, iday = seq.int(nrow(x)), taum_name = "taum", crac_name = "crac", ... ) ## S3 method for class 'model_output' calc_crac(x, crop, iday, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
ks_root |
numeric Root growth parameter. |
seuil |
numeric Root growth parameter. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
taum |
numeric Root growth parameter. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
taum_name |
character Layer or column name containing taum values. |
crac_name |
character Layer or column name to store calculated crac values. |
crop |
list Crop parameters |
The calc_crac function calculates the root growth "crac" parameter.
Different methods handle numeric vectors, matrices, and model outputs.
For numeric inputs, crac is computed as:
where crac is set to 0 if there is no crop development on the given
day/layer (i.e., when iday_crop_dev is 0).
An object of the same class as x, with the calculated "crac"
values added.
calc_ks_root()
Generic and method-specific functions to calculate drainage from multiple possible inputs (gravity water reserve, water content, etc.)
calc_d(x, from = "Rgravity", ...) calc_d_from_Rgravity(x, ...) ## S3 method for class 'numeric' calc_d_from_Rgravity(x, Kd, Rgravity = x, ...) ## S3 method for class 'matrix' calc_d_from_Rgravity( x, Rgravity = x[iday, Rgravity_name], Kd, iday = seq.int(nrow(x)), Rgravity_name = "Rgravity", d_name = "d", ... )calc_d(x, from = "Rgravity", ...) calc_d_from_Rgravity(x, ...) ## S3 method for class 'numeric' calc_d_from_Rgravity(x, Kd, Rgravity = x, ...) ## S3 method for class 'matrix' calc_d_from_Rgravity( x, Rgravity = x[iday, Rgravity_name], Kd, iday = seq.int(nrow(x)), Rgravity_name = "Rgravity", d_name = "d", ... )
x |
Input object. Can be |
from |
character Input type. Currently only |
... |
Additional arguments passed to methods. |
Kd |
numeric Hydraulic conductivity. |
Rgravity |
numeric Gravity water reserve. Required if |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
Rgravity_name |
character Column or layer name for gravity water
reserve in |
d_name |
character Column or layer name to store calculated drainage. |
Currently, only drainage calculation from gravity water reserve is implemented. Drainage is computed as the minimum between available gravity water reserve and the maximum possible outflow (hydraulic conductivity Kd in mm/h multiplied by 24 h).
Drainage values are compute by the next formula:
An object of the same class as x with an additional column or layer
for calculated drainage.
calc_Rgravity()
Generic and method-specific functions to calculate "degred" root growth calculation input.
calc_degred(x, ...) ## S3 method for class 'Date' calc_degred(x, degred, vroot, dates = x, ...) ## S3 method for class 'matrix' calc_degred( x, dates = x[iday, dates_name], degred, vroot, iday = seq.int(nrow(x)), dates_name = "dates", degred_name = "degred", ... ) ## S3 method for class 'model_init' calc_degred(x, crop, dates, iday_sowing, iday_harvest, ...)calc_degred(x, ...) ## S3 method for class 'Date' calc_degred(x, degred, vroot, dates = x, ...) ## S3 method for class 'matrix' calc_degred( x, dates = x[iday, dates_name], degred, vroot, iday = seq.int(nrow(x)), dates_name = "dates", degred_name = "degred", ... ) ## S3 method for class 'model_init' calc_degred(x, crop, dates, iday_sowing, iday_harvest, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
degred |
numeric Base degred value |
vroot |
numeric Root growth parameter |
dates |
lubridate::Date Simulation dates |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
dates_name |
character Column or layer name containing dates |
degred_name |
character Column or layer name to store calculated degred |
crop |
list Crop parameters |
iday_sowing |
integer Day of year corresponding to sowing date |
iday_harvest |
integer Day of year corresponding to harvest date |
An object of the same class as x, with the calculated "degred"
values added.
Generic dispatcher to calculate an irrigation dose based on soil water content, soil properties (field capacity and wilting point) and a target soil moisture level. The default numeric method assumes a two-layer soil profile and uses water stored in each layer (R1, R2) and their depths (z1, z2).
calc_dose(x = NULL, ...) ## S3 method for class ''NULL'' calc_dose(x, R1, ...) ## S3 method for class 'numeric' calc_dose( x, R1 = x, R2, z1, z2, theta_fc, theta_wp, RU_target = NA, RU_units = 2, THETA_target = NA, ... )calc_dose(x = NULL, ...) ## S3 method for class ''NULL'' calc_dose(x, R1, ...) ## S3 method for class 'numeric' calc_dose( x, R1 = x, R2, z1, z2, theta_fc, theta_wp, RU_target = NA, RU_units = 2, THETA_target = NA, ... )
x |
An object for which the irrigation dose should be calculated. The method
dispatched depends on the class of |
... |
Additional arguments passed to specific methods. |
R1 |
numeric Soil water content in the first layer or initial value (mm). |
R2 |
numeric Soil water content in the second layer (mm). |
z1 |
numeric Depth of the first soil layer (m). |
z2 |
numeric Depth of the second soil layer (m). |
theta_fc |
numeric Soil water content at field capacity ( |
theta_wp |
numeric Soil water content at wilting point ( |
RU_target |
numeric Target readily available water (RU), either in
mm or as a fraction/percent of the maximum RU, depending on
|
RU_units |
integer Units for |
THETA_target |
numeric Target volumetric soil moisture ( |
The numeric method converts water stored in the two soil layers (R1, R2, in mm) and their depths (z1, z2, in m) into an average volumetric soil water content over the total depth (Hz = z1 + z2). Readily available water (RU) and its maximum (RUmax) are computed relative to the wilting point and field capacity.
The target can be specified either as a volumetric soil moisture
(THETA_target) or as a target readily available water
(RU_target), but not both at the same time. If both are provided,
the function throws an error. If neither is provided, a dose of 0 is
returned.
When RU_target is given in mm (RU_units = 1), it is clamped
to the range [0, RUmax]. When RU_units = 2, RU_target is
interpreted as a fraction or percent of RUmax (values in [0,1] or [0,100]
are accepted and normalized to [0,1]).
The computed dose is the water depth (mm) required to raise the current
soil moisture to the target, limited by optional minimum and maximum dose
constraints (dose_min, dose_max) and never negative.
A numeric value representing the irrigation dose (mm), as
determined by the method for the class of x.
calc_theta_fc()
calc_theta_wp()
calc_RU()
Generic and method-specific functions to calculate a relative soil
moisture term (dtheta_RU) based on volumetric water content
(theta), field capacity (theta_fc) and wilting point
(theta_wp). In the numeric method, dtheta_RU is the
amount by which theta exceeds field capacity, capped by the
total range between field capacity and wilting point.
calc_dtheta_RU(x, ...) ## S3 method for class 'numeric' calc_dtheta_RU(x, theta_fc, theta_wp, theta = x, ...) ## S3 method for class 'matrix' calc_dtheta_RU( x, theta = x[iday, theta_name], theta_fc, theta_wp, iday = seq.int(nrow(x)), theta_name = "theta", dtheta_RU_name = "dtheta_RU", ... )calc_dtheta_RU(x, ...) ## S3 method for class 'numeric' calc_dtheta_RU(x, theta_fc, theta_wp, theta = x, ...) ## S3 method for class 'matrix' calc_dtheta_RU( x, theta = x[iday, theta_name], theta_fc, theta_wp, iday = seq.int(nrow(x)), theta_name = "theta", dtheta_RU_name = "dtheta_RU", ... )
x |
Input object. Can be a |
... |
Additional arguments passed to specific methods. |
theta_fc |
numeric Volumetric soil water content at field
capacity ( |
theta_wp |
numeric Volumetric soil water content at wilting
point ( |
theta |
numeric Volumetric soil water content
( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character Column or layer name containing
|
dtheta_RU_name |
character Column or layer name used to store the calculated relative soil moisture values. |
The numeric implementation computes:
i.e. the excess water content above field capacity, limited to the maximum available water between field capacity and wilting point and not allowed to be negative.
If you instead want the classical available water between wilting point and field capacity, you can replace the core formula with:
For numeric input: a numeric vector of dtheta_RU values.
For matrix input: a matrix with a column dtheta_RU_name
created or updated for the specified indices (iday).
calc_RU()
calc_dtheta_RU_WP()
calc_theta()
Generic and method-specific functions to calculate the increment in
root depth (dzroot) for a given time step, based on crop state
and empirical parameters. Typically used in crop growth models to
simulate root development over time.
calc_dzroot(x, ...) ## S3 method for class 'numeric' calc_dzroot( x, dcrac, dzrootp, iday_crop_dev = rep(1, length(x)), taum = x, ... ) ## S3 method for class 'matrix' calc_dzroot( x, taum = x[iday, "taum"], dcrac = x[iday, "dcrac"], dzrootp = x[iday, "dzrootp"], iday = seq.int(nrow(x)), dzroot_name = "dzroot", ... ) ## S3 method for class 'model_output' calc_dzroot(x, crop, iday, ...)calc_dzroot(x, ...) ## S3 method for class 'numeric' calc_dzroot( x, dcrac, dzrootp, iday_crop_dev = rep(1, length(x)), taum = x, ... ) ## S3 method for class 'matrix' calc_dzroot( x, taum = x[iday, "taum"], dcrac = x[iday, "dcrac"], dzrootp = x[iday, "dzrootp"], iday = seq.int(nrow(x)), dzroot_name = "dzroot", ... ) ## S3 method for class 'model_output' calc_dzroot(x, crop, iday, ...)
x |
Input object. Can be numeric, a matrix or a
|
... |
Additional arguments passed to methods. |
dcrac |
numeric Base increment of root depth (same units as
|
dzrootp |
numeric Potential increment of root depth (same units
as |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
taum |
numeric Dimensionless development variable (e.g. relative
thermal time or phenological index). For the numeric method, defaults
to |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
dzroot_name |
character Column or layer name used to store
calculated |
crop |
list Crop parameter list, used by the
|
The numeric method applies a simple rule to each time step:
if iday_crop_dev[i] == 0, no root growth is computed
and NA_real_ is returned for that step;
if taum[i] <= 0.25, the root depth increment is taken
as dcrac[i];
otherwise, the increment is limited by the potential value
dzrootp[i] and never exceeds dcrac[i].
In practice, this is implemented as a piecewise expression using
taum, dcrac and dzrootp, with the result
returned as a numeric vector. Matrix and model_output methods wrap
this numeric logic and write dzroot into the appropriate
column or layer.
For numeric input: a numeric vector of dzroot values.
For matrix and model_output input: an object of the same class as
x with a column or layer named dzroot_name (default
"dzroot") created or updated for the specified indices.
calc_taum()
calc_crac()
calc_dzrootp()
Generic and method-specific functions to compute the change in root
depth (dzrootp) for different input types. The generic
dispatcher selects a method based on the class of x.
calc_dzrootp(x, ...) ## S3 method for class 'numeric' calc_dzrootp(x, zrootp_init, zrootp = x, ...) ## S3 method for class 'matrix' calc_dzrootp( x, zrootp = x[iday, "zrootp"], zrootp_init, iday = seq.int(nrow(x)), dzrootp_name = "dzrootp", ... )calc_dzrootp(x, ...) ## S3 method for class 'numeric' calc_dzrootp(x, zrootp_init, zrootp = x, ...) ## S3 method for class 'matrix' calc_dzrootp( x, zrootp = x[iday, "zrootp"], zrootp_init, iday = seq.int(nrow(x)), dzrootp_name = "dzrootp", ... )
x |
Input object. Can be a numeric value or matrix. |
... |
Additional arguments passed to methods. |
zrootp_init |
numeric Initial or previous root depth (same
units as |
zrootp |
numeric Current root depth (same units as
|
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
dzrootp_name |
character Name of the column used to store
|
Methods:
numeric: computes dzrootp as the simple
difference zrootp - zrootp_init.
matrix: computes dzrootp row-wise for the
indices iday, ensuring that a column named
dzrootp_name exists (it is created if missing). When
zrootp_init is a single value, it is treated as the root
depth at the previous time step and expanded to a lagged vector
using c(zrootp_init, zrootp[-length(zrootp)]).
This helper is typically used in root growth routines to express root extension as a per-step increment rather than an absolute depth.
For numeric input: a numeric value (or vector) of dzrootp.
For matrix input: the matrix x with a column
dzrootp_name created or updated for the selected indices
iday.
calc_taum()
calc_crac()
calc_dzroot()
calc_dzrootp(5, zrootp_init = 2) mat <- matrix(c(1, 2, 3, 4), ncol = 2) colnames(mat) <- c("zrootp", "other") calc_dzrootp(mat, zrootp_init = 1)calc_dzrootp(5, zrootp_init = 2) mat <- matrix(c(1, 2, 3, 4), ncol = 2) colnames(mat) <- c("zrootp", "other") calc_dzrootp(mat, zrootp_init = 1)
Generic S3 interface to compute soil evaporation (ES). This
function dispatches to class-specific implementations (for example
calc_ES.numeric) that perform the actual calculation.
calc_ES(x, ...) ## S3 method for class 'numeric' calc_ES(x, ES0, KES, Rmin = NULL, R = x, ...) ## S3 method for class 'matrix' calc_ES( x, R = x[iday, R_name], ES0 = x[iday, ES0_name], KES = x[iday, KES_name], Rmin = x[iday, Rmin_name], iday = seq.int(nrow(x)), R_name = "R", ES0_name = "ES0", KES_name = "KES", Rmin_name = "Rmin", ES_name = "ES", ... )calc_ES(x, ...) ## S3 method for class 'numeric' calc_ES(x, ES0, KES, Rmin = NULL, R = x, ...) ## S3 method for class 'matrix' calc_ES( x, R = x[iday, R_name], ES0 = x[iday, ES0_name], KES = x[iday, KES_name], Rmin = x[iday, Rmin_name], iday = seq.int(nrow(x)), R_name = "R", ES0_name = "ES0", KES_name = "KES", Rmin_name = "Rmin", ES_name = "ES", ... )
x |
Object for method dispatch. Currently only numeric vectors and matrices are supported. |
... |
Additional arguments passed to specific methods. |
ES0 |
numeric Potential soil evaporation rate ( |
KES |
numeric Soil evaporation coefficient. |
Rmin |
numeric Minimum residual soil water (mm) that must
remain after evaporation. Can be scalar or vector; if |
R |
numeric Available water for evaporation (mm). For the
numeric method, defaults to |
iday |
integer Indices of days (rows) to process. For matrix input, defaults to all rows. |
R_name |
character Name of the column used for |
ES0_name |
character Name of the column used for |
KES_name |
character Name of the column used for |
Rmin_name |
character Name of the column used for
|
ES_name |
character Name of the output column for
evaporation ( |
For numeric input, soil evaporation is computed as:
i.e. evaporation cannot exceed either the potential rate
(ES0 * KES) or the available water R. When a residual
Rmin is provided, the result is adjusted so that:
for each element, i.e. evaporation is reduced where necessary so as
not to deplete soil water below Rmin. Matrix input methods
extract the required columns by name for the selected rows
(iday) and write the result to a column named
ES_name, which is created if missing.
For numeric input: a numeric vector of soil evaporation values
(ES, ).
For matrix input: the matrix x with a column ES_name
created or updated for the selected rows.
Generic and method-specific functions to calculate potential soil
evaporation (ES0), representing the atmospheric demand for
evaporation from the soil surface given reference evapotranspiration
and partitioning coefficients.
calc_ES0(x, ...) ## S3 method for class 'numeric' calc_ES0(x, Kc, Cp, Ksol, ET0 = x, ...) ## S3 method for class 'matrix' calc_ES0( x, ET0 = x[iday, ET0_name], Kc = x[iday, Kc_name], Cp = x[iday, Cp_name], Ksol, iday = seq.int(nrow(x)), ET0_name = "ET0", Kc_name = "Kc", Cp_name = "Cp", ES0_name = "ES0", ... )calc_ES0(x, ...) ## S3 method for class 'numeric' calc_ES0(x, Kc, Cp, Ksol, ET0 = x, ...) ## S3 method for class 'matrix' calc_ES0( x, ET0 = x[iday, ET0_name], Kc = x[iday, Kc_name], Cp = x[iday, Cp_name], Ksol, iday = seq.int(nrow(x)), ET0_name = "ET0", Kc_name = "Kc", Cp_name = "Cp", ES0_name = "ES0", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
Kc |
numeric Crop coefficient. |
Cp |
numeric Canopy partition coefficient, representing the fraction of ET0 attributed to the canopy. Values are internally truncated to be at least zero. |
Ksol |
numeric Soil evaporation scaling or limiting factor,
used together with |
ET0 |
numeric Reference evapotranspiration ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
ET0_name |
character Column or layer name containing ET0
values (default |
Kc_name |
character Column or layer name containing Kc
values (default |
Cp_name |
character Column or layer name containing Cp
values (default |
ES0_name |
character Column or layer name used to store
calculated ES0 values (default |
The numeric implementation computes potential soil evaporation as:
i.e. the reference evapotranspiration is scaled by the larger of
the crop and soil coefficients, and then reduced by the fraction
attributed to the canopy (Cp, truncated at 0). The result is
a potential soil evaporation rate expressed in .
For matrix inputs, ET0, Kc and Cp are read from the specified
columns for rows indexed by iday, and ES0 is written to the
column named ES0_name, which is created if it does not
exist.
For numeric input: a numeric vector of potential soil evaporation
(ES0, ).
For matrix input: an object of the same class as x
with a column ES0_name created or updated where
applicable.
calc_ES()
Generic and method-specific functions to calculate reference
evapotranspiration (ET0) from potential evapotranspiration
(ETP) using a specified ratio. Methods are provided for
numeric vectors and matrices.
calc_ET0(x, ...) ## S3 method for class 'numeric' calc_ET0(x, ratio_ET0_ETP, ETP = x, ...) ## S3 method for class 'matrix' calc_ET0( x, ETP = x[iday, "ETP"], ratio_ET0_ETP = 1, iday = seq.int(nrow(x)), ET0_name = "ET0", ... )calc_ET0(x, ...) ## S3 method for class 'numeric' calc_ET0(x, ratio_ET0_ETP, ETP = x, ...) ## S3 method for class 'matrix' calc_ET0( x, ETP = x[iday, "ETP"], ratio_ET0_ETP = 1, iday = seq.int(nrow(x)), ET0_name = "ET0", ... )
x |
Input data. Can be a numeric vector or matrix. |
... |
Further arguments passed to or from other methods. |
ratio_ET0_ETP |
numeric Scalar ratio applied to |
ETP |
numeric Potential evapotranspiration ( |
iday |
integer Indices of days or time steps to process. Defaults to all rows (for matrix). |
ET0_name |
character Name of the ET0 column or variable to
create or overwrite (default |
For numeric and matrix inputs, the function applies a simple scaling:
For matrices, ETP is taken from the column named "ETP"
by default, and the result is written to a column named
ET0_name, which is created if missing.
For model_init objects, the ratio ratio_ET0_ETP is
first computed via calc_ET0_mulch_effect using soil
and irrigation parameters (e.g. mulch and irrigation method), then
the appropriate next method is called to perform the actual ET0
computation.
For numeric input: a numeric vector of ET0 values ().
For matrix input: a matrix with an added or updated ET0 column.
For model_init input: a model_init object with ET0
calculated.
# Numeric method etp <- c(2.1, 2.5, 2.3) calc_ET0(etp, ratio_ET0_ETP = 0.95) # Matrix method m <- matrix(c(1:6, rep(NA, 3)), ncol = 3) colnames(m) <- c("ETP", "foo", "bar") calc_ET0(m, ratio_ET0_ETP = 1.0, ET0_name = "ET0")# Numeric method etp <- c(2.1, 2.5, 2.3) calc_ET0(etp, ratio_ET0_ETP = 0.95) # Matrix method m <- matrix(c(1:6, rep(NA, 3)), ncol = 3) colnames(m) <- c("ETP", "foo", "bar") calc_ET0(m, ratio_ET0_ETP = 1.0, ET0_name = "ET0")
Generic S3 function to compute a multiplicative factor representing
the effect of mulch on reference evapotranspiration (ET0).
The returned value is intended to multiply ET0 to account for
mulch presence or specific simulation conditions.
calc_ET0_mulch_effect(x = NULL, ...) ## S3 method for class ''NULL'' calc_ET0_mulch_effect(x = NULL, mulch, ...) ## S3 method for class 'numeric' calc_ET0_mulch_effect(x, gge, mulch = x, ...)calc_ET0_mulch_effect(x = NULL, ...) ## S3 method for class ''NULL'' calc_ET0_mulch_effect(x = NULL, mulch, ...) ## S3 method for class 'numeric' calc_ET0_mulch_effect(x, gge, mulch = x, ...)
x |
Input object. Used for method dispatch. Currently only
|
... |
Additional arguments passed to or from other methods. |
mulch |
numeric Mulch level or mulching factor (dimensionless
or in arbitrary model units). For the numeric method, defaults to
|
gge |
numeric Indicator of the irrigation / simulation method. Commonly:
|
The numeric method returns a scalar multiplicative factor for ET0
based on gge and mulch:
if gge == 999 and mulch == 1000, a fixed
factor 0.1 is returned (special GGS simulation case);
if gge == 1, a proportional reduction is used:
if gge == 0, mulch has no effect and the factor is
1.
Any other value of gge triggers an error. This function is
intended to be applied at the time-step level; both gge and
mulch are treated as scalar values.
A numeric scalar representing the multiplicative factor to apply to
ET0 to account for mulch effects.
seealso:
calc_ET0()
# Using mulch as an explicit argument calc_ET0_mulch_effect(5, gge = 1, mulch = 50) # Using x as mulch when mulch is omitted calc_ET0_mulch_effect(50, gge = 1)# Using mulch as an explicit argument calc_ET0_mulch_effect(5, gge = 1, mulch = 50) # Using x as mulch when mulch is omitted calc_ET0_mulch_effect(50, gge = 1)
Generic and method-specific functions to calculate maximum
evapotranspiration (ETM), representing the crop water demand
as the sum of soil evaporation (ES0) and potential
transpiration (TP0).
calc_ETM(x = NULL, ...) ## S3 method for class ''NULL'' calc_ETM(x, ES0, ...) ## S3 method for class 'numeric' calc_ETM(x = NULL, TP0, ES0 = x, ...) ## S3 method for class 'matrix' calc_ETM( x, ES0 = x[iday, ES0_name], TP0 = x[iday, TP0_name], iday = seq.int(nrow(x)), ES0_name = "ES0", TP0_name = "TP0", ETM_name = "ETM", ... )calc_ETM(x = NULL, ...) ## S3 method for class ''NULL'' calc_ETM(x, ES0, ...) ## S3 method for class 'numeric' calc_ETM(x = NULL, TP0, ES0 = x, ...) ## S3 method for class 'matrix' calc_ETM( x, ES0 = x[iday, ES0_name], TP0 = x[iday, TP0_name], iday = seq.int(nrow(x)), ES0_name = "ES0", TP0_name = "TP0", ETM_name = "ETM", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
ES0 |
numeric Reference or potential soil evaporation
( |
TP0 |
numeric Potential transpiration ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
ES0_name |
character Name of the column in the matrix
containing |
TP0_name |
character Name of the column in the matrix
containing |
ETM_name |
character Name of the column in the matrix used
to store |
The calc_ETM function is a generic S3 interface with
methods for different input types:
NULL: delegates to the next method using the
ES0 argument as input;
numeric: computes ETM as the sum
;
matrix: ensures an ETM column exists, then
fills it for the selected rows as .
In all cases, ETM_{i} is expressed in , consistent with
ES0_{i} and TP0_{i}.
For numeric input: a numeric vector of ETM values
().
For matrix input: the matrix x with a column
ETM_name created or updated.
For NULL input: dispatches to the numeric method using ES0.
calc_ET0()
calc_TP0()
# Numeric example calc_ETM(ES0 = 2, TP0 = 1) # Matrix example mat <- matrix(c(2, 1, 3, 2), ncol = 2) colnames(mat) <- c("ES0", "TP0") calc_ETM(mat)# Numeric example calc_ETM(ES0 = 2, TP0 = 1) # Matrix example mat <- matrix(c(2, 1, 3, 2), ncol = 2) colnames(mat) <- c("ES0", "TP0") calc_ETM(mat)
Generic and method-specific functions to calculate actual
evapotranspiration (ETR) as the sum of soil evaporation
(ES) and crop transpiration (TP).
calc_ETR(x, ...) ## S3 method for class 'numeric' calc_ETR(x, TP, ES = x, ...) ## S3 method for class 'matrix' calc_ETR( x, ES = x[iday, ES_name], TP = x[iday, TP_name], iday = seq.int(nrow(x)), ES_name = "ES", TP_name = "TP", ETR_name = "ETR", ... )calc_ETR(x, ...) ## S3 method for class 'numeric' calc_ETR(x, TP, ES = x, ...) ## S3 method for class 'matrix' calc_ETR( x, ES = x[iday, ES_name], TP = x[iday, TP_name], iday = seq.int(nrow(x)), ES_name = "ES", TP_name = "TP", ETR_name = "ETR", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
TP |
numeric Crop transpiration ( |
ES |
numeric Soil evaporation ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
ES_name |
character Layer or column name containing ES
values (default |
TP_name |
character Layer or column name containing TP
values (default |
ETR_name |
character Layer or column name used to store ETR
values (default |
The numeric implementation combines soil evaporation and crop transpiration as:
i.e. negative transpiration values, if present, are treated as zero.
For matrix inputs, ES and TP are read from the specified columns for
rows indexed by iday, and ETR is written to a column named
ETR_name, which is created if missing.
All fluxes are assumed to be expressed in and consistent
across ES, TP and ETR.
For numeric input: a numeric vector of actual evapotranspiration
(ETR, ).
For matrix input: the matrix x with a column
ETR_name created or updated.
calc_ES()
calc_TP()
Generic and method-specific functions to calculate harvest index
(HI), defined as the ratio between harvested (economic) yield
and total above-ground biomass.
calc_HI(x, ...) ## S3 method for class 'numeric' calc_HI(x, Bp, HIp, iday_crop_dev = rep(1, length(x)), B = x, ...) ## S3 method for class 'matrix' calc_HI( x, B = x[iday, B_name], Bp = x[iday, Bp_name], HIp = x[iday, HIp_name], iday = seq.int(nrow(x)), B_name = "B", Bp_name = "Bp", HIp_name = "HIp", HI_name = "HI", ... )calc_HI(x, ...) ## S3 method for class 'numeric' calc_HI(x, Bp, HIp, iday_crop_dev = rep(1, length(x)), B = x, ...) ## S3 method for class 'matrix' calc_HI( x, B = x[iday, B_name], Bp = x[iday, Bp_name], HIp = x[iday, HIp_name], iday = seq.int(nrow(x)), B_name = "B", Bp_name = "Bp", HIp_name = "HIp", HI_name = "HI", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
Bp |
numeric Potential or reference biomass ( |
HIp |
numeric Potential harvest index. Can be scalar or time-varying. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
B |
numeric Total above-ground biomass ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
B_name |
character Column or layer name containing biomass
values (default |
Bp_name |
character Column or layer name containing potential
biomass values (default |
HIp_name |
character Column or layer name containing potential
harvest index values (default |
HI_name |
character Column or layer name used to store
calculated harvest index values (default |
The numeric method computes harvest index for each time step or element where the crop is in development:
where is either a scalar potential harvest index or a
time-varying value. For elements where iday_crop_dev[i] == 0,
NA_real_ is returned.
Matrix methods extract biomass and potential biomass (and HIp) from
the specified columns for rows indexed by iday, compute the
corresponding harvest index values using the numeric method, and
store them in a column named HI_name, which is created if it
does not exist.
For numeric input: a numeric vector of harvest index values.
For matrix input: the matrix x with a column HI_name
created or updated.
calc_Bp()
# Numeric example calc_HI(1:100, Bp = seq(1, 200, 2), HIp = 1) # Matrix example calc_HI(cbind(B = 1:100, Bp = seq(1, 200, 2), HIp = 1))# Numeric example calc_HI(1:100, Bp = seq(1, 200, 2), HIp = 1) # Matrix example calc_HI(cbind(B = 1:100, Bp = seq(1, 200, 2), HIp = 1))
Generic and method-specific functions to calculate the fraction of
intercepted radiation (IR) based on leaf area index (LAI) and
the Beer-Lambert extinction coefficient (k_BL).
calc_IR(x = NULL, ...) ## S3 method for class ''NULL'' calc_IR(x, LAI, ...) ## S3 method for class 'numeric' calc_IR(x, k_BL, iday_crop_dev = rep(1, length(x)), LAI = x, ...) ## S3 method for class 'matrix' calc_IR( x, LAI = x[iday, LAI_name], iday = seq.int(nrow(x)), k_BL, LAI_name = "LAI", IR_name = "IR", ... )calc_IR(x = NULL, ...) ## S3 method for class ''NULL'' calc_IR(x, LAI, ...) ## S3 method for class 'numeric' calc_IR(x, k_BL, iday_crop_dev = rep(1, length(x)), LAI = x, ...) ## S3 method for class 'matrix' calc_IR( x, LAI = x[iday, LAI_name], iday = seq.int(nrow(x)), k_BL, LAI_name = "LAI", IR_name = "IR", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
LAI |
numeric Leaf area index ( |
k_BL |
numeric Beer-Lambert extinction coefficient. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
LAI_name |
character Name of the LAI column or variable in
matrix objects (default |
IR_name |
character Name of the IR column or variable to
create or update (default |
The intercepted fraction is computed from the Beer-Lambert law as:
For the numeric method, this expression is applied element-wise.
For indices where iday_crop_dev[i] == 0, the result is set to
NA_real_ to indicate no crop development.
Matrix methods extract LAI values for the rows or time
indices specified by iday, compute intercepted radiation
using the numeric method, and store the results in a column or
layer named IR_name, which is created if it does not exist.
For numeric input: a numeric vector of intercepted radiation
values (dimensionless, between 0 and 1).
For matrix input: the object x with a column
variable named IR_name created or updated.
calc_LAI()
# Numeric usage LAI <- c(0.5, 1.5, 3.0) k <- 0.5 calc_IR(LAI, k_BL = k) # Matrix usage mat <- matrix(c(0.5, 1.5, 3.0), ncol = 1) colnames(mat) <- "LAI" calc_IR(mat, k_BL = k)# Numeric usage LAI <- c(0.5, 1.5, 3.0) k <- 0.5 calc_IR(LAI, k_BL = k) # Matrix usage mat <- matrix(c(0.5, 1.5, 3.0), ncol = 1) colnames(mat) <- "LAI" calc_IR(mat, k_BL = k)
Generic and method-specific functions to calculate the crop
coefficient (Kc) using leaf area index (LAI), a
maximum crop coefficient (Kc_max) and an extinction
coefficient (k). Methods are provided for numeric vectors and
matrices.
calc_Kc(x, ...) ## S3 method for class 'numeric' calc_Kc(x, Kc_max, k, iday_crop_dev = rep(1, length(x)), LAI = x, ...) ## S3 method for class 'matrix' calc_Kc(x, LAI = x[iday, "LAI"], Kc_max, k, iday = seq.int(nrow(x)), ...)calc_Kc(x, ...) ## S3 method for class 'numeric' calc_Kc(x, Kc_max, k, iday_crop_dev = rep(1, length(x)), LAI = x, ...) ## S3 method for class 'matrix' calc_Kc(x, LAI = x[iday, "LAI"], Kc_max, k, iday = seq.int(nrow(x)), ...)
x |
Input object. Can be a numeric vector or a matrix. |
... |
Further arguments passed to methods. |
Kc_max |
numeric Maximum crop coefficient. |
k |
numeric Extinction coefficient in the Kc-LAI relationship. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
LAI |
numeric Leaf area index ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
For the numeric method, the crop coefficient is computed for each element as:
for time steps where iday_crop_dev[i] == 1. For indices where
iday_crop_dev[i] == 0, the crop is considered not developed
and K_{c,i} is set to 0.
For the matrix method, LAI values are extracted from the rows
specified by iday, converted to a numeric vector, and passed
to the numeric method. The result is returned as a numeric vector of
K_{c} values aligned with the rows of the input matrix (with
NA_real_ for rows not in iday).
For numeric input: a numeric vector of crop coefficient values
.
For matrix input: a numeric vector of Kc values aligned with the
rows of x.
# Numeric vector example calc_Kc(c(1, 2, 3), Kc_max = 1.2, k = 0.5) # Matrix example (returns a vector of Kc values) mat <- cbind(LAI = c(1, 2, 3)) calc_Kc(mat, Kc_max = 1.2, k = 0.5)# Numeric vector example calc_Kc(c(1, 2, 3), Kc_max = 1.2, k = 0.5) # Matrix example (returns a vector of Kc values) mat <- cbind(LAI = c(1, 2, 3)) calc_Kc(mat, Kc_max = 1.2, k = 0.5)
Generic interface to compute hydraulic conductivity (Kd) for
a given soil water content (theta) using different empirical
methods. The default method "saxton" implements the
Saxton-Rawls formulation.
calc_Kd(x, from = "saxton", ...) calc_Kd_from_saxton(x, ...) ## S3 method for class 'numeric' calc_Kd_from_saxton(x, Ks, theta_fc, theta_wp, theta_sat, ...) ## S3 method for class 'matrix' calc_Kd_from_saxton(x, Ks, theta_fc, theta_wp, theta_sat, ...)calc_Kd(x, from = "saxton", ...) calc_Kd_from_saxton(x, ...) ## S3 method for class 'numeric' calc_Kd_from_saxton(x, Ks, theta_fc, theta_wp, theta_sat, ...) ## S3 method for class 'matrix' calc_Kd_from_saxton(x, Ks, theta_fc, theta_wp, theta_sat, ...)
x |
Numeric value, numeric vector or matrix representing
volumetric soil water content ( |
from |
character Name of the method used for the calculation.
Default is |
... |
Additional arguments passed to method-specific functions. |
Ks |
numeric Saturated hydraulic conductivity ( |
theta_fc |
numeric Volumetric water content at field capacity
( |
theta_wp |
numeric Volumetric water content at permanent
wilting point ( |
theta_sat |
numeric Volumetric water content at saturation
( |
The Saxton-Rawls method (from = "saxton") estimates hydraulic
conductivity as a function of soil water content and soil hydraulic
properties. It uses a Campbell-type relationship:
where:
: current volumetric water content (x);
: saturated hydraulic conductivity;
: water content at field capacity;
: water content at permanent wilting point;
: water content at saturation.
For matrix input, the Saxton method is applied element-wise and the
result has the same dimensions as x. Parameters
Ks, theta_fc, theta_wp and theta_sat may
be scalars or arrays conformable with x.
Reference: Saxton, K.E., and Rawls, W.J. (2006). Soil water characteristic estimates by texture and organic matter. Soil Science Society of America Journal, 70, 1569-1578.
For numeric input: a numeric vector of hydraulic conductivity values
(Kd, same units as Ks).
For matrix input: a numeric matrix of Kd values with the same
dimensions as x.
calc_theta_fc()
calc_theta_wp()
calc_theta_sat()
# Example for numeric input calc_Kd( 0.25, Ks = 0.1, theta_fc = 0.3, theta_wp = 0.1, theta_sat = 0.4 )# Example for numeric input calc_Kd( 0.25, Ks = 0.1, theta_fc = 0.3, theta_wp = 0.1, theta_sat = 0.4 )
Generic and method-specific functions to calculate the soil
evaporation coefficient (KES) from soil water content. KES is
a simple switch-like coefficient that indicates whether soil
moisture is above a residual threshold.
calc_KES(x, ...) ## S3 method for class 'numeric' calc_KES(x, theta_r, theta = x, ...) ## S3 method for class 'matrix' calc_KES( x, theta = x[iday, theta_name], theta_r, iday = seq.int(nrow(x)), theta_name = "theta", KES_name = "KES", ... )calc_KES(x, ...) ## S3 method for class 'numeric' calc_KES(x, theta_r, theta = x, ...) ## S3 method for class 'matrix' calc_KES( x, theta = x[iday, theta_name], theta_r, iday = seq.int(nrow(x)), theta_name = "theta", KES_name = "KES", ... )
x |
Input object. Can be a numeric vector or a matrix. |
... |
Additional arguments passed to methods. |
theta_r |
numeric Residual soil water content
( |
theta |
numeric Volumetric soil water content
( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character For matrix input, name of the column
containing soil water content (default |
KES_name |
character For matrix input, name of the column
used to store calculated KES values (default |
For numeric input, KES is computed element-wise as:
where is either a scalar residual water content or
a value specific to each element when theta_r has the same
length as theta.
For matrix input, soil water content is taken from the column named
theta_name for the rows specified by iday. The computed
KES values are stored in a column named KES_name, which is
created if it does not exist.
For numeric input: a numeric vector of KES values (0 or 1).
For matrix input: the matrix x with a column
KES_name created or updated for the selected rows.
calc_theta_r()
calc_Kd()
Generic interface and method-specific functions to estimate saturated
hydraulic conductivity () from soil texture
(percent sand and percent clay) using different empirical models.
calc_Ks(x, from = "saxton", ...) calc_Ks_from_saxton(x, ...) ## S3 method for class 'numeric' calc_Ks_from_saxton( x, psand, pclay = x, ref = data.frame(names = c("C", "CL", "L", "LSa", "Sa", "SaC", "SaCL", "SaL", "SiL", "SiC", "SiCL"), psand = c(25, 30, 40, 80, 88, 50, 60, 65, 20, 10, 10), pclay = c(50, 35, 20, 5, 5, 40, 25, 10, 15, 45, 35), Ks_Saxton_mm_h = c(1.1, 4.3, 15.5, 96.7, 108.1, 1.4, 11.3, 50.3, 16.1, 3.7, 5.7), stringsAsFactors = FALSE), ... ) calc_Ks_from_cosby(x, ...) ## S3 method for class 'numeric' calc_Ks_from_cosby(x, psand, pclay = x, ...) calc_Ks_from_ottoni(x, ...) ## S3 method for class 'numeric' calc_Ks_from_ottoni(x, psand, pclay = x, ...)calc_Ks(x, from = "saxton", ...) calc_Ks_from_saxton(x, ...) ## S3 method for class 'numeric' calc_Ks_from_saxton( x, psand, pclay = x, ref = data.frame(names = c("C", "CL", "L", "LSa", "Sa", "SaC", "SaCL", "SaL", "SiL", "SiC", "SiCL"), psand = c(25, 30, 40, 80, 88, 50, 60, 65, 20, 10, 10), pclay = c(50, 35, 20, 5, 5, 40, 25, 10, 15, 45, 35), Ks_Saxton_mm_h = c(1.1, 4.3, 15.5, 96.7, 108.1, 1.4, 11.3, 50.3, 16.1, 3.7, 5.7), stringsAsFactors = FALSE), ... ) calc_Ks_from_cosby(x, ...) ## S3 method for class 'numeric' calc_Ks_from_cosby(x, psand, pclay = x, ...) calc_Ks_from_ottoni(x, ...) ## S3 method for class 'numeric' calc_Ks_from_ottoni(x, psand, pclay = x, ...)
x |
Numeric vector. In the numeric methods, |
from |
character Name of the method to use for calculation.
Options are |
... |
Additional arguments passed to methods. |
psand |
numeric Percent sand in the soil sample (0-100). |
pclay |
numeric Percent clay in the soil sample (0-100). If
not provided, defaults to |
ref |
data.frame Reference table for the Saxton method, containing soil texture classes, percent sand, percent clay and Ks values. Used only in the Saxton method; a default table is provided. |
The main function calc_Ks() dispatches to the appropriate
method based on the from argument:
Matches the input texture to the closest reference class using Euclidean distance in the (sand, clay) space and returns the corresponding Ks value. Based on Saxton and Rawls (2006).
Uses an empirical formula based on percent sand and clay (Cosby et al., 1984).
Uses an empirical formula based on percent
sand and clay, with silt estimated as
(Ottoni et al., 2019).
All methods return Ks in . For the Saxton method, a small
reference table of texture classes and associated Ks values is used
by default, but can be overridden via the ref argument.
References:
Saxton, K.E., and Rawls, W.J. (2006). Soil water characteristic estimates by texture and organic matter. SSSAJ 70, 1569-1578.
Cosby, B.J. et al. (1984). A statistical exploration of the relationships of soil moisture characteristics to the physical properties of soils. Water Resour. Res. 20(6), 682-690.
Ottoni, M.V. et al. (2019). Pedotransfer functions for saturated hydraulic conductivity. Journal of Hydrology 575, 1214-1223.
A numeric vector of estimated saturated hydraulic conductivity
values (Ks, ), with one value per input texture.
calc_Ks(20, psand = 40, pclay = 20, from = "saxton") calc_Ks(20, psand = 40, pclay = 20, from = "cosby") calc_Ks(20, psand = 40, pclay = 20, from = "ottoni")calc_Ks(20, psand = 40, pclay = 20, from = "saxton") calc_Ks(20, psand = 40, pclay = 20, from = "cosby") calc_Ks(20, psand = 40, pclay = 20, from = "ottoni")
Generic and method-specific functions to calculate root growth ks_root parameters.
calc_ks_root(x, ...) ## S3 method for class 'numeric' calc_ks_root( x, ks_init, theta_raw, iday_crop_dev = rep(1, length(x)), theta = x, ... ) ## S3 method for class 'matrix' calc_ks_root( x, theta = x[iday, "theta"], ks_init = NULL, iday_crop_dev = x[iday, "iday_crop_dev"], theta_raw, iday = seq.int(nrow(x)), ks_name = "ks_root", ... )calc_ks_root(x, ...) ## S3 method for class 'numeric' calc_ks_root( x, ks_init, theta_raw, iday_crop_dev = rep(1, length(x)), theta = x, ... ) ## S3 method for class 'matrix' calc_ks_root( x, theta = x[iday, "theta"], ks_init = NULL, iday_crop_dev = x[iday, "iday_crop_dev"], theta_raw, iday = seq.int(nrow(x)), ks_name = "ks_root", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
ks_init |
numeric Initial root growth parameter. |
theta_raw |
numeric Raw soil moisture content. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
theta |
numeric Current soil moisture content. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
ks_name |
character Layer or column name to store calculated ks_root values. |
An object of the same class as x, with the calculated "ks_root"
values added.
Generic and method-specific functions to calculate the transpiration
reduction coefficient (KTP) from soil water content. KTP
ranges between 0 and 1 and scales potential transpiration according
to water availability between wilting point and readily available
water.
calc_KTP(x, ...) ## S3 method for class 'numeric' calc_KTP(x, theta_wp, theta_raw, theta = x, ...) ## S3 method for class 'matrix' calc_KTP( x, theta = x[iday, theta_name], theta_wp, theta_raw, iday = seq.int(nrow(x)), theta_name = "theta", KTP_name = "KTP", ... )calc_KTP(x, ...) ## S3 method for class 'numeric' calc_KTP(x, theta_wp, theta_raw, theta = x, ...) ## S3 method for class 'matrix' calc_KTP( x, theta = x[iday, theta_name], theta_wp, theta_raw, iday = seq.int(nrow(x)), theta_name = "theta", KTP_name = "KTP", ... )
x |
Input object. Can be a numeric vector or a matrix. |
... |
Additional arguments passed to methods. |
theta_wp |
numeric Volumetric soil water content at wilting
point ( |
theta_raw |
numeric Volumetric soil water content defining
the upper limit of readily available water ( |
theta |
numeric Volumetric soil water content ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character For matrix input, name of the column
containing soil water content (default |
KTP_name |
character For matrix input, name of the column
used to store calculated KTP values (default |
For numeric input, KTP is computed element-wise from theta as:
if :
(no stress, full transpiration);
if :
decreases linearly from 1 to 0:
if :
(no transpiration).
For matrix input, soil water content is taken from the column named
theta_name for rows specified by iday. The calculated
KTP values are stored in a column named KTP_name, which is
created if it does not exist.
For numeric input: a numeric vector of KTP values in [0, 1].
For matrix input: the matrix x with a column KTP_name
created or updated for the selected rows.
calc_theta_wp()
calc_theta()
# Numeric example theta <- c(0.08, 0.12, 0.18) calc_KTP(theta, theta_wp = 0.1, theta_raw = 0.16) # Matrix example mat <- cbind(theta = c(0.08, 0.12, 0.18)) calc_KTP(mat, theta_wp = 0.1, theta_raw = 0.16)# Numeric example theta <- c(0.08, 0.12, 0.18) calc_KTP(theta, theta_wp = 0.1, theta_raw = 0.16) # Matrix example mat <- cbind(theta = c(0.08, 0.12, 0.18)) calc_KTP(mat, theta_wp = 0.1, theta_raw = 0.16)
Generic function and methods to calculate leaf area index
(LAI) from potential LAI (LAIp), its initial value
(LAIp_init) and stress factors affecting leaf growth or
senescence.
calc_LAI(x = NULL, ...) ## S3 method for class ''NULL'' calc_LAI(x = NULL, LAI0, ...) ## S3 method for class 'numeric' calc_LAI( x, LAIp, LAIp_init, stress_LAI, stress_noci_LAI, LAImin = NA_real_, k = NA_real_, iday_crop_dev = rep(1, length(LAIp)), LAI0 = x, ... ) ## S3 method for class 'data.frame' calc_LAI( x, LAI0 = NULL, LAIp = x$LAIp[iday], stress_LAI = x$stress_LAI[iday], stress_noci_LAI = x$stress_noci_LAI[iday], LAImin = NA_real_, k = NA_real_, iday = seq.int(nrow(x)), LAI_name = "LAI", ... ) ## S3 method for class 'matrix' calc_LAI( x, LAI0 = ifelse(iday[1] == 1, 0, x[iday - 1, LAI_name]), LAIp = x[iday, LAIp_name], LAIp_init = ifelse(iday == 1, 0, x[iday - 1, LAIp_name]), stress_LAI = x[iday, "stress_LAI"], stress_noci_LAI = x[iday, "stress_noci_LAI"], LAImin = NA_real_, k = NA_real_, iday = seq.int(nrow(x)), LAIp_name = "LAIp", LAI_name = "LAI", ... )calc_LAI(x = NULL, ...) ## S3 method for class ''NULL'' calc_LAI(x = NULL, LAI0, ...) ## S3 method for class 'numeric' calc_LAI( x, LAIp, LAIp_init, stress_LAI, stress_noci_LAI, LAImin = NA_real_, k = NA_real_, iday_crop_dev = rep(1, length(LAIp)), LAI0 = x, ... ) ## S3 method for class 'data.frame' calc_LAI( x, LAI0 = NULL, LAIp = x$LAIp[iday], stress_LAI = x$stress_LAI[iday], stress_noci_LAI = x$stress_noci_LAI[iday], LAImin = NA_real_, k = NA_real_, iday = seq.int(nrow(x)), LAI_name = "LAI", ... ) ## S3 method for class 'matrix' calc_LAI( x, LAI0 = ifelse(iday[1] == 1, 0, x[iday - 1, LAI_name]), LAIp = x[iday, LAIp_name], LAIp_init = ifelse(iday == 1, 0, x[iday - 1, LAIp_name]), stress_LAI = x[iday, "stress_LAI"], stress_noci_LAI = x[iday, "stress_noci_LAI"], LAImin = NA_real_, k = NA_real_, iday = seq.int(nrow(x)), LAIp_name = "LAIp", LAI_name = "LAI", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
LAI0 |
numeric Initial LAI value(s) ( |
LAIp |
numeric Potential LAI value(s) at each time step
( |
LAIp_init |
numeric Initial potential LAI value(s) used to
compute daily increments |
stress_LAI |
numeric Stress factor(s) for LAI increment
(must be |
stress_noci_LAI |
numeric Exponent(s) applied to
|
LAImin |
numeric Lower asymptote for LAI during senescence.
Use |
k |
numeric Senescence damping coefficient applied when
|
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
LAI_name |
character Name of the LAI column to use or create
in tabular data (default |
LAIp_name |
character Name of the potential LAI column in
matrix input (default |
The numeric method updates LAI based on changes in potential LAI and a stress-modified increment. Let:
For each time step , the
increment is scaled by a stress factor:
and:
When both LAImin and k are provided and
, the senescence step is damped by limiting the
daily loss to:
and the retained LAI becomes:
so that LAI tends progressively towards LAImin instead of
dropping too quickly towards zero.
When LAI0 is a single scalar, the method maintains an
internal cumulative value LAI0 across time:
LAI0 is initialised to the scalar LAI0 (or 0
if LAI0 is NA);
for each time step, LAI0 is updated by the scaled
increment and stored as LAI[i];
when i == 0, LAI[i] is
NA_real_ and the internal LAI0 value is left
unchanged.
When LAI0 is a vector, each time step is computed
independently using the corresponding LAI0[i] (or 0 if
NA).
For data.frame and matrix inputs, LAI is written to a
column named LAI_name. For data.frame, LAI0 is taken
from the argument for the first row and then from the previous
row's LAI for subsequent rows. For matrix, a similar logic
is applied using LAIp_name and LAI_name.
For numeric input: a numeric vector of LAI values ().
For data.frame and matrix input: the object x
with a column LAI_name created or updated.
calc_stress()
calc_stress_noci_LAI()
calc_LT()
calc_LAIp()
# Numeric example calc_LAI( 1, LAIp = 2, LAIp_init = 1, stress_LAI = 0.8, stress_noci_LAI = 1, LAImin = 0.5, k = 0.05 ) # Data frame example df <- data.frame( LAIp = c(1, 2, 3), stress_LAI = 0.8, stress_noci_LAI = 1 ) calc_LAI(df) # Matrix example mat <- as.matrix( data.frame( LAIp = c(1, 2, 3), stress_LAI = 0.8, stress_noci_LAI = 1 ) ) calc_LAI(mat)# Numeric example calc_LAI( 1, LAIp = 2, LAIp_init = 1, stress_LAI = 0.8, stress_noci_LAI = 1, LAImin = 0.5, k = 0.05 ) # Data frame example df <- data.frame( LAIp = c(1, 2, 3), stress_LAI = 0.8, stress_noci_LAI = 1 ) calc_LAI(df) # Matrix example mat <- as.matrix( data.frame( LAIp = c(1, 2, 3), stress_LAI = 0.8, stress_noci_LAI = 1 ) ) calc_LAI(mat)
Generic function and methods to calculate potential leaf area index
(LAIp) from a normalized/logistic temperature index
(LT), maximum LAI (LAImax) and an initial LAI
(LAI0). Implemented for numeric vectors, matrices,
data.frames and model initialisation objects.
calc_LAIp(x = NULL, ...) ## S3 method for class ''NULL'' calc_LAIp(x, LT, ...) ## S3 method for class 'numeric' calc_LAIp(x, LAImax, LAI0, LT = x, ...) ## S3 method for class 'matrix' calc_LAIp( x, LT = x[iday, LT_name], LAImax, LAI0, iday = seq.int(nrow(x)), LT_name = "LT", LAIp_name = "LAIp", ... ) ## S3 method for class 'data.frame' calc_LAIp( x, LT = x[iday, LT_name, drop = TRUE], LAImax = x$LAImax, LAI0 = x$LAI0, iday = seq.int(nrow(x)), LT_name = "LT", LAIp_name = "LAIp", ... ) ## S3 method for class 'model_init' calc_LAIp(x, crop, iday_sowing, iday_harvest, ...)calc_LAIp(x = NULL, ...) ## S3 method for class ''NULL'' calc_LAIp(x, LT, ...) ## S3 method for class 'numeric' calc_LAIp(x, LAImax, LAI0, LT = x, ...) ## S3 method for class 'matrix' calc_LAIp( x, LT = x[iday, LT_name], LAImax, LAI0, iday = seq.int(nrow(x)), LT_name = "LT", LAIp_name = "LAIp", ... ) ## S3 method for class 'data.frame' calc_LAIp( x, LT = x[iday, LT_name, drop = TRUE], LAImax = x$LAImax, LAI0 = x$LAI0, iday = seq.int(nrow(x)), LT_name = "LT", LAIp_name = "LAIp", ... ) ## S3 method for class 'model_init' calc_LAIp(x, crop, iday_sowing, iday_harvest, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
LT |
numeric Logistic or normalized temperature index
( |
LAImax |
numeric Maximum potential leaf area index
( |
LAI0 |
numeric Initial potential leaf area index ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
LT_name |
character Column or layer name containing LT values
(default |
LAIp_name |
character Column or layer name used to store
calculated potential LAI values (default |
crop |
list Crop parameter list for the |
iday_sowing |
integer Index (or indices) of sowing day(s)
for the |
iday_harvest |
integer Index (or indices) of harvest day(s)
for the |
The numeric method computes potential LAI at each time step by a
simple linear interpolation between LAI0 and LAImax
using LT ([0, 1]):
with checks enforcing:
,
,
.
For matrix and data.frame inputs, LT values are read
from the specified column (LT_name) and LAIp is written to a
column named LAIp_name, which is created if missing.
The model_init method typically computes a normalized thermal
time and an LT-like index using helper functions (e.g.
calc_TT_norm(), calc_alpha(), calc_LT()), then
delegates to the appropriate calc_LAIp method (usually the
data.frame or matrix method) to fill LAIp between sowing and
harvest.
A numeric vector, matrix, data.frame or model_init
object (same type as x) with a potential LAI field
(LAIp) computed or updated.
calc_LT()
calc_LAI()
calc_TT_norm()
# Numeric example calc_LAIp(0.5, LAImax = 6, LAI0 = 0.1)# Numeric example calc_LAIp(0.5, LAImax = 6, LAI0 = 0.1)
Generic function and methods to calculate a logistic temperature
index (LT) from a normalised thermal-time variable
(TT_norm) and shape parameters alpha and beta.
calc_LT(x, ...) ## S3 method for class 'numeric' calc_LT(x, alpha, beta, TTnorm_LTsat, TT_norm = x, ...) ## S3 method for class 'data.frame' calc_LT( x, TT_norm = x[iday, TT_norm_name, drop = TRUE], alpha = x[iday, alpha_name, drop = TRUE], beta, TTnorm_LTsat, iday = seq.int(nrow(x)), TT_norm_name = "TT_norm", alpha_name = "alpha", LT_name = "LT", ... ) ## S3 method for class 'matrix' calc_LT( x, TT_norm = x[iday, TT_norm_name], alpha = x[iday, alpha_name], beta, TTnorm_LTsat, iday = seq.int(nrow(x)), TT_norm_name = "TT_norm", alpha_name = "alpha", LT_name = "LT", ... )calc_LT(x, ...) ## S3 method for class 'numeric' calc_LT(x, alpha, beta, TTnorm_LTsat, TT_norm = x, ...) ## S3 method for class 'data.frame' calc_LT( x, TT_norm = x[iday, TT_norm_name, drop = TRUE], alpha = x[iday, alpha_name, drop = TRUE], beta, TTnorm_LTsat, iday = seq.int(nrow(x)), TT_norm_name = "TT_norm", alpha_name = "alpha", LT_name = "LT", ... ) ## S3 method for class 'matrix' calc_LT( x, TT_norm = x[iday, TT_norm_name], alpha = x[iday, alpha_name], beta, TTnorm_LTsat, iday = seq.int(nrow(x)), TT_norm_name = "TT_norm", alpha_name = "alpha", LT_name = "LT", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
alpha |
numeric Alpha parameter(s) controlling curve shape. |
beta |
numeric Beta parameter(s) controlling curve shape. |
TTnorm_LTsat |
numeric Normalised thermal-time value at which the senescence progression is considered complete. Values above 1 stretch the senescence branch to the right. |
TT_norm |
numeric Normalised thermal time |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
TT_norm_name |
character Column or layer name containing
|
alpha_name |
character Column or layer name containing
|
LT_name |
character Column or layer name used to store
calculated logistic temperature values (default |
The numeric method computes LT element-wise from
TT_norm, alpha, and beta using:
where the parameter depends on crop phenological phase:
For data.frame and matrix inputs, TT_norm and
alpha are read from the specified columns for the rows
indexed by iday. The result is written to a column named
LT_name, which is created if missing.
For numeric input: a numeric vector of logistic temperature index
values.
For data.frame and matrix input: the object x
with a column LT_name created or updated.
# Numeric example calc_LT( seq(0, 1, length.out = 5), alpha = 2, beta = 3, TTnorm_LTsat = 1 )# Numeric example calc_LT( seq(0, 1, length.out = 5), alpha = 2, beta = 3, TTnorm_LTsat = 1 )
Generic function and methods to calculate photosynthetically active
radiation (PAR) from incoming solar radiation (Rg).
Implemented for numeric vectors, matrices and data.frames.
calc_PAR(x, ...) ## S3 method for class 'numeric' calc_PAR(x, Rg = x, ...) ## S3 method for class 'matrix' calc_PAR( x, Rg = x[iday, Rg_name], iday = seq.int(nrow(x)), Rg_name = "Rg", PAR_name = "PAR", ... ) ## S3 method for class 'data.frame' calc_PAR( x, Rg = x[iday, Rg_name], iday = seq.int(nrow(x)), Rg_name = "Rg", PAR_name = "PAR", ... )calc_PAR(x, ...) ## S3 method for class 'numeric' calc_PAR(x, Rg = x, ...) ## S3 method for class 'matrix' calc_PAR( x, Rg = x[iday, Rg_name], iday = seq.int(nrow(x)), Rg_name = "Rg", PAR_name = "PAR", ... ) ## S3 method for class 'data.frame' calc_PAR( x, Rg = x[iday, Rg_name], iday = seq.int(nrow(x)), Rg_name = "Rg", PAR_name = "PAR", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
Rg |
numeric Incoming global solar radiation
( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
Rg_name |
character Column or layer name containing incoming
solar radiation (default |
PAR_name |
character Column or layer name used to store
calculated PAR values (default |
The numeric method computes PAR as a fixed fraction of the incoming solar radiation:
PAR is returned in the same unit as Rg, i.e.
.
For matrix and data.frame inputs, Rg values are
read from the column named Rg_name for rows indexed by
iday. The result is written to a column named
PAR_name, which is created if missing.
For numeric input: a numeric vector of PAR values (same length as
Rg).
For matrix and data.frame input: the object x
with a column PAR_name created or updated.
# Numeric example calc_PAR(20) # returns 10 # Matrix example mat <- cbind(Rg = c(10, 20, 30)) calc_PAR(mat) # Data frame example df <- data.frame(Rg = c(15, 25, 35)) calc_PAR(df)# Numeric example calc_PAR(20) # returns 10 # Matrix example mat <- cbind(Rg = c(10, 20, 30)) calc_PAR(mat) # Data frame example df <- data.frame(Rg = c(15, 25, 35)) calc_PAR(df)
This function manages irrigation quota allocation across different strategies and time periods. It supports two modes: a simple global quota cap (mode 0) and an intelligent strategy-based quota distribution (mode 1).
calc_quota( x, dose, quota_max, quota_part, iday, strategy_id, dose_min = NA_real_, quota_mod = 1L )calc_quota( x, dose, quota_max, quota_part, iday, strategy_id, dose_min = NA_real_, quota_mod = 1L )
x |
A matrix or data.frame containing irrigation history with columns:
|
dose |
Numeric. The desired irrigation dose (mm) to apply today. |
quota_max |
Numeric. Maximum total irrigation quota (mm) for the season. |
quota_part |
Numeric. Percentage (0-100) or fraction (0-1) of the total quota allocated to the current strategy/period. |
iday |
Integer. Current day index in the irrigation history matrix. |
strategy_id |
Integer. Identifier for the current irrigation strategy. |
dose_min |
Numeric. Minimum irrigation dose (mm). If the calculated dose
is below this threshold, no irrigation is applied. Default is |
quota_mod |
Integer. Quota management mode:
|
The function implements two quota management strategies:
Mode 0 (Legacy): Applies a simple cap based on remaining global quota, without considering strategy-specific allocations or temporal distribution.
Mode 1 (Intelligent): Distributes quota across strategies and time:
Allocates a fraction of total quota to each strategy
Distributes strategy quota evenly across days in that strategy
Allows catch-up if previous days used less than theoretical allocation
Always respects global quota limits
The minimum dose threshold (dose_min) prevents inefficient small
irrigations when quota is nearly exhausted.
A list with three elements:
Numeric. The actual irrigation dose (mm) to apply, considering quota constraints.
Numeric. Total quota (mm) used by the current strategy including today's dose.
Numeric. Total quota (mm) used across all strategies including today's dose.
Generic function and methods to calculate soil water reserve
(R) from different input representations. Currently, only
computation from volumetric soil water content (theta) is
implemented via from = "theta".
calc_R(x, ...) ## Default S3 method: calc_R(x, from, ...) ## S3 method for class 'model_output' calc_R(x, ...) calc_R_from_theta(x, ...) ## S3 method for class 'numeric' calc_R_from_theta(x, z, theta = x, ...) ## S3 method for class 'matrix' calc_R_from_theta( x, z, theta = x[iday, theta_name], iday = seq.int(nrow(x)), theta_name = "theta", R_name = "R", ... ) ## S3 method for class 'data.frame' calc_R_from_theta( x, z, theta = x[iday, theta_name], iday = seq.int(nrow(x)), theta_name = "theta", R_name = "R", ... )calc_R(x, ...) ## Default S3 method: calc_R(x, from, ...) ## S3 method for class 'model_output' calc_R(x, ...) calc_R_from_theta(x, ...) ## S3 method for class 'numeric' calc_R_from_theta(x, z, theta = x, ...) ## S3 method for class 'matrix' calc_R_from_theta( x, z, theta = x[iday, theta_name], iday = seq.int(nrow(x)), theta_name = "theta", R_name = "R", ... ) ## S3 method for class 'data.frame' calc_R_from_theta( x, z, theta = x[iday, theta_name], iday = seq.int(nrow(x)), theta_name = "theta", R_name = "R", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
from |
character Input type / method selector. Currently only
|
z |
numeric Effective soil depth (m). Can be scalar or the
same length as |
theta |
numeric Volumetric soil water content
( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character For |
R_name |
character For |
When from = "theta", soil water reserve R (mm) is
computed from volumetric water content theta () and
soil depth z (m) as:
where the factor 1000 converts metres of water column to millimetres.
For matrix and data.frame inputs, theta is
read from the column theta_name for rows indexed by
iday, and the result is written to a column R_name,
which is created if missing.
For model_output objects, the current implementation is a
placeholder that returns x unchanged; it can be extended to
compute and attach R based on model internals.
For numeric input: a numeric vector of soil water reserve values
(mm).
For matrix and data.frame input: the object x
with a column R_name created or updated.
For model_output input: the object x unchanged.
# Numeric example: theta = 0.25 (m3/m3), z = 0.6 m -> R = 150 mm calc_R_from_theta(0.25, z = 0.6) # Matrix example mat <- cbind(theta = c(0.2, 0.25, 0.3)) calc_R(mat, from = "theta", z = 0.5)# Numeric example: theta = 0.25 (m3/m3), z = 0.6 m -> R = 150 mm calc_R_from_theta(0.25, z = 0.6) # Matrix example mat <- cbind(theta = c(0.2, 0.25, 0.3)) calc_R(mat, from = "theta", z = 0.5)
Generic helpers to calculate gravitational soil water
(Rgravity) from either total soil water reserve
(from = "R") or from volumetric soil water content and field
capacity (from = "theta"). Currently, only the
"theta"-based methods are implemented.
calc_Rgravity(x, from, ...) calc_Rgravity_from_R(x, ...) calc_Rgravity_from_theta(x, ...) ## S3 method for class 'numeric' calc_Rgravity_from_theta(x, theta_fc, z, theta = x, ...) ## S3 method for class 'matrix' calc_Rgravity_from_theta( x, theta = x[iday, theta_name], theta_fc, z = x[iday, z_name], iday = seq.int(nrow(x)), theta_name = "theta", z_name = "z", Rgravity_name = "Rgravity", ... )calc_Rgravity(x, from, ...) calc_Rgravity_from_R(x, ...) calc_Rgravity_from_theta(x, ...) ## S3 method for class 'numeric' calc_Rgravity_from_theta(x, theta_fc, z, theta = x, ...) ## S3 method for class 'matrix' calc_Rgravity_from_theta( x, theta = x[iday, theta_name], theta_fc, z = x[iday, z_name], iday = seq.int(nrow(x)), theta_name = "theta", z_name = "z", Rgravity_name = "Rgravity", ... )
x |
Input object. For |
from |
character Source of the input data, either
|
... |
Additional arguments passed to methods. |
theta_fc |
numeric Volumetric water content at field
capacity ( |
z |
numeric Soil depth (m); used when |
theta |
numeric Volumetric soil water content
( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character For matrix inputs with
|
z_name |
character For matrix inputs with
|
Rgravity_name |
character For matrix inputs, name of the
column used to store calculated gravitational water
(default |
When from = "theta", gravitational soil water for time step
is computed as:
where is volumetric soil water content
(), is field capacity
(), is soil depth (m), and the factor 1000
converts metres of water column to millimetres.
For matrix inputs, theta and z are read from the
specified columns for rows indexed by iday, and the result
is written to a column named Rgravity_name, which is created
if missing.
The from = "R" path (calc_Rgravity_from_R) is
currently not implemented and will raise an error if used.
For from = "theta" and numeric input: a numeric vector of
gravitational water (mm).
For from = "theta" and matrix input: the matrix x
with a column Rgravity_name created or updated.
For from = "R": an error is raised (not implemented).
# Numeric example: theta = 0.35, theta_fc = 0.30, z = 1 m # -> (0.05 * 1 * 1000) = 50 mm calc_Rgravity(0.35, from = "theta", theta_fc = 0.3, z = 1) # Matrix example mat <- cbind(theta = c(0.28, 0.35)) calc_Rgravity(mat, from = "theta", theta_fc = 0.3, z = 0.1)# Numeric example: theta = 0.35, theta_fc = 0.30, z = 1 m # -> (0.05 * 1 * 1000) = 50 mm calc_Rgravity(0.35, from = "theta", theta_fc = 0.3, z = 1) # Matrix example mat <- cbind(theta = c(0.28, 0.35)) calc_Rgravity(mat, from = "theta", theta_fc = 0.3, z = 0.1)
Generic helpers to calculate soil available water content (RU)
from volumetric soil water content (theta), field capacity
(theta_fc), wilting point (theta_wp) and soil depth
(z). Currently only the "theta"-based method
(from = "theta") is implemented.
calc_RU(x, from = "theta", ...) calc_RU_from_theta(x, ...) ## S3 method for class 'numeric' calc_RU_from_theta(x, theta_fc, theta_wp, z, theta = x, ...) ## S3 method for class 'matrix' calc_RU_from_theta( x, theta = x[iday, theta_name], z = x[iday, z_name], theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], iday = seq.int(nrow(x)), theta_name = "theta", z_name = "z", theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", RU_name = "RU", ... ) ## S3 method for class 'data.frame' calc_RU_from_theta( x, theta = x[iday, theta_name], z = x[iday, z_name], theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], iday = seq.int(nrow(x)), theta_name = "theta", z_name = "z", theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", RU_name = "RU", ... )calc_RU(x, from = "theta", ...) calc_RU_from_theta(x, ...) ## S3 method for class 'numeric' calc_RU_from_theta(x, theta_fc, theta_wp, z, theta = x, ...) ## S3 method for class 'matrix' calc_RU_from_theta( x, theta = x[iday, theta_name], z = x[iday, z_name], theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], iday = seq.int(nrow(x)), theta_name = "theta", z_name = "z", theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", RU_name = "RU", ... ) ## S3 method for class 'data.frame' calc_RU_from_theta( x, theta = x[iday, theta_name], z = x[iday, z_name], theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], iday = seq.int(nrow(x)), theta_name = "theta", z_name = "z", theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", RU_name = "RU", ... )
x |
Input object. Can be a |
from |
character Method used to calculate RU. Currently only
|
... |
Additional arguments passed to specific methods. |
theta_fc |
numeric Volumetric soil water content at field
capacity ( |
theta_wp |
numeric Volumetric soil water content at wilting
point ( |
z |
numeric Soil depth (m). |
theta |
numeric Volumetric soil water content
( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character Column or layer name containing
|
z_name |
character Column or layer name containing soil depth
( |
theta_fc_name |
character Column or layer name containing
field capacity ( |
theta_wp_name |
character Column or layer name containing
wilting point ( |
RU_name |
character Column or layer name used to store
available water content ( |
For from = "theta", available water RU (mm) at time
step is computed from volumetric water contents and depth as:
where , and are in
, is in metres, and the factor 1000 converts
metres of water column to millimetres.
For matrix and data.frame inputs, theta,
theta_fc, theta_wp, and z are read from the
specified columns for rows indexed by iday, and the result is
written to a column named RU_name, which is created if
missing.
For numeric input: a numeric vector of available water (mm).
For matrix and data.frame input: the object x
with a column RU_name created or updated.
calc_theta()
# Numeric example: theta = 0.25, theta_fc = 0.30, theta_wp = 0.10, z = 0.6 m # available fraction = clamp(0.25 - 0.10, 0, 0.20) = 0.15 # RU = 0.15 * 0.6 * 1000 = 90 mm calc_RU_from_theta(0.25, theta_fc = 0.3, theta_wp = 0.1, z = 0.6)# Numeric example: theta = 0.25, theta_fc = 0.30, theta_wp = 0.10, z = 0.6 m # available fraction = clamp(0.25 - 0.10, 0, 0.20) = 0.15 # RU = 0.15 * 0.6 * 1000 = 90 mm calc_RU_from_theta(0.25, theta_fc = 0.3, theta_wp = 0.1, z = 0.6)
Generic function and methods to calculate the maximum soil available
water content (RUmax) from field capacity
(theta_fc), wilting point (theta_wp) and soil depth
(z). RUmax represents the total amount of water that
can be stored between theta_wp and theta_fc.
calc_RUmax(x, ...) ## S3 method for class 'numeric' calc_RUmax(x, theta_fc, theta_wp, z = x, ...) ## S3 method for class 'matrix' calc_RUmax( x, theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], z = x[iday, z_name], iday = seq.int(nrow(x)), theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", z_name = "z", RUmax_name = "RUmax", ... ) ## S3 method for class 'data.frame' calc_RUmax( x, theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], z = x[iday, z_name], iday = seq.int(nrow(x)), theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", z_name = "z", RUmax_name = "RUmax", ... )calc_RUmax(x, ...) ## S3 method for class 'numeric' calc_RUmax(x, theta_fc, theta_wp, z = x, ...) ## S3 method for class 'matrix' calc_RUmax( x, theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], z = x[iday, z_name], iday = seq.int(nrow(x)), theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", z_name = "z", RUmax_name = "RUmax", ... ) ## S3 method for class 'data.frame' calc_RUmax( x, theta_fc = x[iday, theta_fc_name], theta_wp = x[iday, theta_wp_name], z = x[iday, z_name], iday = seq.int(nrow(x)), theta_fc_name = "theta_fc", theta_wp_name = "theta_wp", z_name = "z", RUmax_name = "RUmax", ... )
x |
Input object. Can be a |
... |
Additional arguments passed to methods. |
theta_fc |
numeric Volumetric water content at field capacity
( |
theta_wp |
numeric Volumetric water content at wilting point
( |
z |
numeric Soil depth (m). For the numeric method, defaults
to |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_fc_name |
character Column name containing field
capacity ( |
theta_wp_name |
character Column name containing wilting
point ( |
z_name |
character Column name containing soil depth
( |
RUmax_name |
character Column name used to store calculated
maximum available water content ( |
For each time step , the maximum available water (between
field capacity and wilting point) is computed as:
where and are in
, is in metres, and the factor 1000 converts
metres of water column to millimetres.
For matrix and data.frame inputs, theta_fc,
theta_wp and z are read from the specified columns for
rows indexed by iday, and the result is written to a column
named RUmax_name, which is created if missing.
For numeric input: a numeric vector of maximum available water
(mm).
For matrix and data.frame input: the object x
with a column RUmax_name created or updated.
# Numeric example: # theta_fc = 0.30, theta_wp = 0.10, z = 0.6 m # RUmax = (0.30 - 0.10) * 0.6 * 1000 = 120 mm calc_RUmax(0.6, theta_fc = 0.30, theta_wp = 0.10)# Numeric example: # theta_fc = 0.30, theta_wp = 0.10, z = 0.6 m # RUmax = (0.30 - 0.10) * 0.6 * 1000 = 120 mm calc_RUmax(0.6, theta_fc = 0.30, theta_wp = 0.10)
Generic and method-specific functions to calculate LAI stress values.
calc_stress(x, ...) ## S3 method for class 'numeric' calc_stress( x, stress_T = NA, iday_crop_dev = rep(1, length(x)), stress_TP = x, ... ) ## S3 method for class 'matrix' calc_stress( x, stress_TP = x[iday, stress_TP_name], stress_T = x[iday, stress_T_name], iday = seq.int(nrow(x)), stress_TP_name = "stress_TP", stress_T_name = "stress_T", stress_name = "stress", ... ) ## S3 method for class 'model_output' calc_stress(x, ...)calc_stress(x, ...) ## S3 method for class 'numeric' calc_stress( x, stress_T = NA, iday_crop_dev = rep(1, length(x)), stress_TP = x, ... ) ## S3 method for class 'matrix' calc_stress( x, stress_TP = x[iday, stress_TP_name], stress_T = x[iday, stress_T_name], iday = seq.int(nrow(x)), stress_TP_name = "stress_TP", stress_T_name = "stress_T", stress_name = "stress", ... ) ## S3 method for class 'model_output' calc_stress(x, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
stress_T |
numeric Temperature stress. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
stress_TP |
numeric Water stress from evapotranspiration ratio. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
stress_TP_name |
character Column or layer name of evapotranspiration stress. |
stress_T_name |
character Column or layer name of temperature stress. |
stress_name |
character Column or layer name to store calculated final stress. |
An object of the same class as x, with the calculated LAI stress
values.
Generic function and methods to calculate biomass stress nocivity
(stress_noci_B) from potential biomass (Bp) and a
maximum stress nocivity value (estress_b). The quantity
stress_noci_B scales linearly with the fraction of potential
biomass relative to a reference maximum (Bp_max).
calc_stress_noci_B(x, ...) ## S3 method for class 'numeric' calc_stress_noci_B(x, Bp_max, estress_b, Bp = x, ...) ## S3 method for class 'matrix' calc_stress_noci_B( x, Bp = x[iday, Bp_name], estress_b = x[iday, estress_b_name], Bp_max = max(x[, Bp_name], na.rm = TRUE), iday = seq.int(nrow(x)), Bp_name = "Bp", estress_b_name = "estress_b", stress_noci_B_name = "stress_noci_B", ... ) ## S3 method for class 'data.frame' calc_stress_noci_B( x, Bp = x[iday, Bp_name], estress_b = x[iday, estress_b_name], Bp_max = max(x[, Bp_name], na.rm = TRUE), iday = seq.int(nrow(x)), Bp_name = "Bp", estress_b_name = "estress_b", stress_noci_B_name = "stress_noci_B", ... )calc_stress_noci_B(x, ...) ## S3 method for class 'numeric' calc_stress_noci_B(x, Bp_max, estress_b, Bp = x, ...) ## S3 method for class 'matrix' calc_stress_noci_B( x, Bp = x[iday, Bp_name], estress_b = x[iday, estress_b_name], Bp_max = max(x[, Bp_name], na.rm = TRUE), iday = seq.int(nrow(x)), Bp_name = "Bp", estress_b_name = "estress_b", stress_noci_B_name = "stress_noci_B", ... ) ## S3 method for class 'data.frame' calc_stress_noci_B( x, Bp = x[iday, Bp_name], estress_b = x[iday, estress_b_name], Bp_max = max(x[, Bp_name], na.rm = TRUE), iday = seq.int(nrow(x)), Bp_name = "Bp", estress_b_name = "estress_b", stress_noci_B_name = "stress_noci_B", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
Bp_max |
numeric Maximum potential biomass value used as
reference ( |
estress_b |
numeric Maximum stress nocivity value. |
Bp |
numeric Potential or reference biomass ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
Bp_name |
character Column or layer name containing potential
biomass values (default |
estress_b_name |
character Name of the column containing maximum stress nocivity values (matrix/data.frame methods). |
stress_noci_B_name |
character Name of the column or layer
used to store calculated stress nocivity values
(default |
For each time step or element , the biomass stress nocivity
is computed as:
where is the current potential biomass, is
the reference maximum potential biomass (Bp_max), and
is the maximum stress nocivity value
(estress_b).
For matrix and data.frame inputs, Bp is read
from the column named Bp_name (default "Bp") and the
result is written to a column named stress_noci_B_name, which
is created if missing.
An object of the same class as x, with biomass stress
nocivity values added or updated:
numeric: a numeric vector of stress nocivity values,
matrix/data.frame: the object with a new or updated column
stress_noci_B_name.
calc_B()
calc_Bp()
# Numeric example calc_stress_noci_B(1:100, Bp_max = 200, estress_b = 0.5) # Matrix example calc_stress_noci_B( cbind(Bp = 1:10, estress_b = 0.5) )# Numeric example calc_stress_noci_B(1:100, Bp_max = 200, estress_b = 0.5) # Matrix example calc_stress_noci_B( cbind(Bp = 1:10, estress_b = 0.5) )
Generic and method-specific functions to calculate leaf area index (LAI) stress nocivity.
calc_stress_noci_LAI(x, ...) ## S3 method for class 'numeric' calc_stress_noci_LAI( x, estress_lai, iday_crop_dev = rep(1, length(x)), stress_LAI = x, ... ) ## S3 method for class 'matrix' calc_stress_noci_LAI( x, stress_LAI = x[iday, stress_LAI_name], estress_lai = x[iday, estress_lai_name], iday, stress_LAI_name = "stress_LAI", estress_lai_name = "estress_lai", stress_noci_LAI_name = "stress_noci_LAI", ... )calc_stress_noci_LAI(x, ...) ## S3 method for class 'numeric' calc_stress_noci_LAI( x, estress_lai, iday_crop_dev = rep(1, length(x)), stress_LAI = x, ... ) ## S3 method for class 'matrix' calc_stress_noci_LAI( x, stress_LAI = x[iday, stress_LAI_name], estress_lai = x[iday, estress_lai_name], iday, stress_LAI_name = "stress_LAI", estress_lai_name = "estress_lai", stress_noci_LAI_name = "stress_noci_LAI", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
estress_lai |
numeric Maximum LAI stress nocivity value. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
stress_LAI |
numeric Leaf area index stress values. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
stress_LAI_name |
character Column or layer name of LAI stress values. |
estress_lai_name |
character Column or layer name of maximum LAI stress nocivity values. |
stress_noci_LAI_name |
character Column or layer name to store LAI stress nocivity values. |
An object of the same class as x, with the calculated LAI stress
nocivity values.
# Numeric example calc_stress_noci_LAI(1:100, estress_lai = 0.5) # Matrix example calc_stress_noci_LAI(cbind(stress_LAI = 1:100, estress_lai = 0.5))# Numeric example calc_stress_noci_LAI(1:100, estress_lai = 0.5) # Matrix example calc_stress_noci_LAI(cbind(stress_LAI = 1:100, estress_lai = 0.5))
Generic and method-specific functions for calculating temperature stress.
calc_stress_T(x, ...) ## S3 method for class 'numeric' calc_stress_T(x, Tbase, Tmax, Tgel, T = x, ...) ## S3 method for class 'matrix' calc_stress_T( x, T = x[iday, T_name], Tbase, Tmax, Tgel, iday = seq.int(nrow(x)), T_name = "T", stress_T_name = "stress_T", ... ) ## S3 method for class 'model_output' calc_stress_T(x, crop, ...)calc_stress_T(x, ...) ## S3 method for class 'numeric' calc_stress_T(x, Tbase, Tmax, Tgel, T = x, ...) ## S3 method for class 'matrix' calc_stress_T( x, T = x[iday, T_name], Tbase, Tmax, Tgel, iday = seq.int(nrow(x)), T_name = "T", stress_T_name = "stress_T", ... ) ## S3 method for class 'model_output' calc_stress_T(x, crop, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
Tbase |
numeric Base temperature. |
Tmax |
numeric Maximum temperature. |
Tgel |
numeric Gel temperature. |
T |
numeric Temperature value. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
T_name |
character Layer or column name of temperature. |
stress_T_name |
character Layer or column name to store calculated temperature stress. |
crop |
list Crop parameters. |
An object of the same class as x, with the calculated temperature
stress values added.
This function calculates the stress water ratio for different data types.
calc_stress_water(x, ...) ## S3 method for class 'numeric' calc_stress_water( x, potential, which, iday_crop_dev = rep(1, length(x)), real = x, ... ) ## S3 method for class 'matrix' calc_stress_water( x, which, real = x[iday, which], potential = x[iday, switch(which, ES = "ES0", TP = "TP0", ETR = "ETM")], iday = seq.int(nrow(x)), stress_water_name = sprintf("ratio_%s", which), ... ) ## S3 method for class 'model_output' calc_stress_water(x, which, iday, ...)calc_stress_water(x, ...) ## S3 method for class 'numeric' calc_stress_water( x, potential, which, iday_crop_dev = rep(1, length(x)), real = x, ... ) ## S3 method for class 'matrix' calc_stress_water( x, which, real = x[iday, which], potential = x[iday, switch(which, ES = "ES0", TP = "TP0", ETR = "ETM")], iday = seq.int(nrow(x)), stress_water_name = sprintf("ratio_%s", which), ... ) ## S3 method for class 'model_output' calc_stress_water(x, which, iday, ...)
x |
|
... |
Additional arguments passed to methods. |
potential |
numeric The potential value of the variable. |
which |
character The variable to calculate the stress water ratio for. Accepted values are the strings contained in c("ES", "TP", "ETR"). |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
real |
numeric The actual value of the variable. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
stress_water_name |
character Name of the column or layer to store the stress water ratio. |
A numeric, matrix with the stress water ratio.
Generic S3 function and methods to compute sugar accumulation in root tissues based on thermal time and crop parameters.
calc_sugar_accumulation(x, ...) ## S3 method for class 'matrix' calc_sugar_accumulation(x, crop, ...)calc_sugar_accumulation(x, ...) ## S3 method for class 'matrix' calc_sugar_accumulation(x, crop, ...)
x |
A data object containing simulation time steps. Expected to be a numeric matrix with the columns named "Bp_root" (biomass partitioning to root) together with "TT_sowing" (thermal time since sowing). |
... |
Additional arguments passed to method-specific implementations. |
crop |
A list or named vector of crop parameters. Expected items:
|
The matrix method identifies days with root biomass (Bp_root > 0) and where TT_sowing is at or after the start thermal time (TT_ms or TT_B_root5). Sugar accumulation is computed as a saturating exponential: sugar_rate = (max_sugar_rate / 100) * (1 - exp(-(TT_sowing - TT_ms) / tau)) If tau is not provided it is estimated from the first day with positive Bp_root.
For the matrix method, the input object 'x' with an updated 'sugar_accumulation' column (or field).
Generic S3 function and methods to compute the tau parameter based on thermal time. Methods are provided for numeric and matrix objects. The numeric method handles a single value, while the matrix method processes a time series.
calc_tau(x, ...) ## S3 method for class 'numeric' calc_tau(x, TT_B_root5, ...) ## S3 method for class 'matrix' calc_tau(x, TT_B_root5, ...)calc_tau(x, ...) ## S3 method for class 'numeric' calc_tau(x, TT_B_root5, ...) ## S3 method for class 'matrix' calc_tau(x, TT_B_root5, ...)
x |
Input object (numeric scalar or matrix). |
... |
Additional arguments passed to methods. |
TT_B_root5 |
numeric Thermal-time threshold for 5% root fraction. |
Generic and method-specific functions for calculating root growth taum parameter.
calc_taum(x, ...) ## S3 method for class 'numeric' calc_taum( x, racplus, vroot, vrac, iday_crop_dev = rep(1, length(x)), stress_root = x, ... ) ## S3 method for class 'matrix' calc_taum( x, stress_root = x[iday, stress_root_name], racplus, vroot, vrac, iday = seq.int(nrow(x)), stress_root_name = "stress_ETR", taum_name = "taum", ... ) ## S3 method for class 'model_output' calc_taum(x, crop, iday, ...)calc_taum(x, ...) ## S3 method for class 'numeric' calc_taum( x, racplus, vroot, vrac, iday_crop_dev = rep(1, length(x)), stress_root = x, ... ) ## S3 method for class 'matrix' calc_taum( x, stress_root = x[iday, stress_root_name], racplus, vroot, vrac, iday = seq.int(nrow(x)), stress_root_name = "stress_ETR", taum_name = "taum", ... ) ## S3 method for class 'model_output' calc_taum(x, crop, iday, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
racplus |
numeric Root growth parameter. |
vroot |
numeric Root growth parameter. |
vrac |
numeric Root growth parameter. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
stress_root |
numeric Root growth stress values. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
stress_root_name |
character Layer or column name containing root growth stress values. |
taum_name |
character Layer or column name to store the calculated taum parameter. |
crop |
list Crop parameters. |
An object of the same class as x, with the calculated taum
parameter added.
This is a generic function to calculate the critical temperature (Tcrit) for different types of input data.
The method dispatches based on the class of the input x. The critical temperature is typically used
in crop modeling to determine temperature thresholds for physiological processes.
calc_Tcrit(x, ...) ## S3 method for class 'numeric' calc_Tcrit(x, ...) ## S3 method for class 'matrix' calc_Tcrit(x, iday_sowing, Tcrit_name = "Tcrit", ...)calc_Tcrit(x, ...) ## S3 method for class 'numeric' calc_Tcrit(x, ...) ## S3 method for class 'matrix' calc_Tcrit(x, iday_sowing, Tcrit_name = "Tcrit", ...)
x |
Input object. Can be |
... |
Additional arguments passed to specific methods. |
iday_sowing |
numeric The day index of sowing. Used in the matrix method to calculate Tcrit based on days since sowing. |
Tcrit_name |
character The name of the column to store Tcrit |
The critical temperature (Tcrit) calculated for the input object. The return type depends on the used method
calc_Tcrit.numeric, calc_Tcrit.matrix
This function calculates the soil water content (theta) based on the input parameters. Called function depends on the 'from' argument.
R: calculates theta from soil water reserve (R)
calc_theta(x, from, ...) calc_theta_from_R(x, ...) ## S3 method for class 'numeric' calc_theta_from_R(x, z, R = x, ...) ## S3 method for class 'matrix' calc_theta_from_R( x, R = x[iday, R_name], z = x[iday, z_name], iday = iday, R_name = "R", z_name = "z", theta_name = "theta", ... )calc_theta(x, from, ...) calc_theta_from_R(x, ...) ## S3 method for class 'numeric' calc_theta_from_R(x, z, R = x, ...) ## S3 method for class 'matrix' calc_theta_from_R( x, R = x[iday, R_name], z = x[iday, z_name], iday = iday, R_name = "R", z_name = "z", theta_name = "theta", ... )
x |
Input object. Can be a numeric vector or a data frame. |
from |
character Input type. Can be one of "R". |
... |
Additional arguments passed to methods. |
z |
numeric Soil depth. |
R |
numeric Soil water reserve (only for |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
R_name |
character Name of the column or array for R (default: "R"). |
z_name |
character Name of the column or array for |
theta_name |
character Name of the column or array for output theta (default: "theta"). |
Generic and method-specific functions to calculate the available water capacity at field capacity (theta_fc) from different types of input data:
soil texture (percentage of sand and clay): the default method
calc_theta_fc(x, from = "texture", ...) calc_theta_fc_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_fc_from_texture(x, ratio_sand, ratio_clay = x, ...)calc_theta_fc(x, from = "texture", ...) calc_theta_fc_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_fc_from_texture(x, ratio_sand, ratio_clay = x, ...)
x |
Inputs object. |
from |
character Indicating the type of input data. Possible values are: "texture" (default). |
... |
Further arguments passed to method-specific functions. |
ratio_sand |
numeric Percentage of sand in the soil. |
ratio_clay |
numeric Percentage of clay in the soil. |
The formula used in the texture method is from Roman Dobarco, Mercedes; Bourennane, Hocine; Arrouays, Dominique; Saby, Nicolas; Cousin, Isabelle; Martin, Manuel P., 2021, "Réservoir utile des sols de la France métropolitaine", https://doi.org/10.15454/9IRARJ, Recherche Data Gouv, V1: # nolint: line_length_linter. It is given by:
where ratio_clay and ratio_sand are the fractions of clay and sand
in the soil, respectively.
An object of the same class as x containing the calculated
available water capacity at field capacity (theta_fc).
# Numeric method calc_theta_fc(0.2, ratio_sand = 0.4, from = "texture")# Numeric method calc_theta_fc(0.2, ratio_sand = 0.4, from = "texture")
This set of functions calculates the residual soil water content () based on various input parameters.
calc_theta_r(x, from = "texture", ...) calc_theta_r_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_r_from_texture(x, ratio_clay = x, ...)calc_theta_r(x, from = "texture", ...) calc_theta_r_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_r_from_texture(x, ratio_clay = x, ...)
x |
Input value(s). Interpretation depends on the method used (see |
from |
Character string specifying the method to use for calculation. Default is |
... |
Additional arguments passed to method-specific functions. |
ratio_clay |
Numeric. Percentage of clay in the soil. Defaults to |
Numeric value(s) of residual soil water content ().
Carsel, R.F. and Parrish, R.S. (1988). Developing joint probability distributions of soil water retention characteristics. Water Resources Research, 24(5), 755-769. SoilGrids: doi:10.5194/essd-15-4417-2023
calc_theta_r(25, from = "texture", ratio_sand = 60, ratio_clay = 25)calc_theta_r(25, from = "texture", ratio_sand = 60, ratio_clay = 25)
Computes the relative soil water content ()
by subtracting a reference value () from the observed soil water content (), with a lower bound of zero.
calc_theta_rel(x, ...) ## S3 method for class 'numeric' calc_theta_rel(x, theta_ref, theta = x, ...) ## S3 method for class 'matrix' calc_theta_rel( x, theta = x[iday, theta_name], theta_ref, iday = seq.int(nrow(x)), theta_name = "theta", theta_rel_name = "theta_rel", ... )calc_theta_rel(x, ...) ## S3 method for class 'numeric' calc_theta_rel(x, theta_ref, theta = x, ...) ## S3 method for class 'matrix' calc_theta_rel( x, theta = x[iday, theta_name], theta_ref, iday = seq.int(nrow(x)), theta_name = "theta", theta_rel_name = "theta_rel", ... )
x |
A numeric vector or a matrix containing soil water content data. |
... |
Further arguments passed to or from other methods. |
theta_ref |
numeric A reference soil water content value used for the calculation. |
theta |
numeric Soil water content. For numeric input, this is the observed soil water content value. For matrix input, this is the column name containing the observed soil water content values. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
theta_name |
character Name of the column or array for theta (default: "theta"). |
theta_rel_name |
character Name of the column or array for output theta_rel (default: "theta_rel"). |
The relative soil water content is calculated as .
For numeric input, returns a numeric vector of relative soil water content. For matrix input, returns a matrix with an additional column containing the relative soil water content.
This function estimates the saturated water content (theta_sat) of soil based on input parameters.
The calculation method can be specified via the from argument, with the default being "texture".
calc_theta_sat(x, from = "texture", ...) calc_theta_sat_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_sat_from_texture(x, ratio_sand, ratio_clay = x, ratio_om = 1.5, ...)calc_theta_sat(x, from = "texture", ...) calc_theta_sat_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_sat_from_texture(x, ratio_sand, ratio_clay = x, ratio_om = 1.5, ...)
x |
Numeric value or object containing soil data. |
from |
Character string specifying the method to use for calculation. Default is "texture". |
... |
Additional arguments passed to the specific calculation method. |
ratio_sand |
Numeric. Percent sand in the soil sample. |
ratio_clay |
Numeric. Percent clay in the soil sample. If not provided, defaults to |
ratio_om |
Numeric. Percent organic matter in the soil sample. Default is 1.5%. |
The default method ("texture") uses the Saxton and Rawls (2006) regression equations to estimate theta_sat from soil texture (sand, clay) and organic matter content.
Estimated saturated water content (theta_sat).
Saxton, K. E., and Rawls, W. J. (2006). Soil Water Characteristic Estimates by Texture and Organic Matter for Hydrologic Solutions. Soil Science Society of America Journal, 70(5), 1569-1578. https://doi.org/10.2136/sssaj2005.0117
calc_theta_sat(40, ratio_sand = 40, ratio_clay = 20, from = "texture")calc_theta_sat(40, ratio_sand = 40, ratio_clay = 20, from = "texture")
Generic and method-specific functions to calculate the available water capacity at wilting point (theta_wp) from different types of input data:
soil texture (percentage of sand and clay): the default method
calc_theta_wp(x, from = "texture", ...) calc_theta_wp_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_wp_from_texture(x, ratio_sand, ratio_clay = x, ...)calc_theta_wp(x, from = "texture", ...) calc_theta_wp_from_texture(x, ...) ## S3 method for class 'numeric' calc_theta_wp_from_texture(x, ratio_sand, ratio_clay = x, ...)
x |
Inputs object. |
from |
character Indicating the type of input data. Possible values are: "texture" (default). |
... |
Further arguments passed to method-specific functions. |
ratio_sand |
numeric Percentage of sand in the soil. |
ratio_clay |
numeric Percentage of clay in the soil. |
The formula used in the texture method is from Roman Dobarco, Mercedes; Bourennane, Hocine; Arrouays, Dominique; Saby, Nicolas; Cousin, Isabelle; Martin, Manuel P., 2021, "Réservoir utile des sols de la France métropolitaine", https://doi.org/10.15454/9IRARJ, Recherche Data Gouv, V1: # nolint: line_length_linter. It is given by:
where ratio_clay and ratio_sand are the fractions of clay and sand
in the soil, respectively.
An object of the same class as x containing the calculated
available water capacity at wilting point (theta_wp).
# Numeric method calc_theta_wp(0.2, ratio_sand = 0.4, from = "texture")# Numeric method calc_theta_wp(0.2, ratio_sand = 0.4, from = "texture")
Evaluates multiple threshold-based conditions to determine whether irrigation should be triggered on a given day. Conditions include readily available water, soil moisture, precipitation, temperature, water stress, and evapotranspiration.
calc_threshold( x, iday, RU_thrld, RU_units, THETA_thrld, PI_thrld, PI_ndays, SW_thrld, SW_ndays, T_thrld, T_ndays, ETM_thrld, ETM_ndays, theta_fc, theta_wp )calc_threshold( x, iday, RU_thrld, RU_units, THETA_thrld, PI_thrld, PI_ndays, SW_thrld, SW_ndays, T_thrld, T_ndays, ETM_thrld, ETM_ndays, theta_fc, theta_wp )
x |
A data frame containing daily time series data with columns for soil water variables (RU1, RU2, R1, R2, z1, z2), weather (P, T), irrigation (I1), evapotranspiration (ETR), and stress indicators (stressTP). |
iday |
Integer. The current day index in the time series for which to evaluate trigger conditions. |
RU_thrld |
Numeric or NA. Threshold for readily available water (RU).
Units depend on |
RU_units |
Character or numeric. Unit for RU threshold: "1" for mm, "2" for percent of maximum available water. |
THETA_thrld |
Numeric or NA. Threshold for volumetric soil moisture content
( |
PI_thrld |
Numeric or NA. Threshold for cumulative precipitation plus
irrigation (mm) over the past |
PI_ndays |
Integer. Number of days to sum precipitation and irrigation for the PI condition. |
SW_thrld |
Numeric or NA. Threshold for average water stress over the past
|
SW_ndays |
Integer. Number of days to average water stress for the SW condition. |
T_thrld |
Numeric or NA. Temperature threshold (°C). If NA, this condition is not evaluated. |
T_ndays |
Integer. Number of days to average temperature for the T condition. |
ETM_thrld |
Numeric or NA. Threshold for the ratio of precipitation+irrigation
to evapotranspiration (as percentage) over the past |
ETM_ndays |
Integer. Number of days to evaluate the ETM ratio. |
theta_fc |
Numeric. Volumetric soil moisture content at field capacity ( |
theta_wp |
Numeric. Volumetric soil moisture content at wilting point ( |
The function evaluates up to six different irrigation trigger conditions:
RU: Readily available water in root zone layers
THETA: Combined soil moisture content
PI: Recent precipitation and irrigation inputs
SW: Recent water stress levels
T: Recent temperature conditions
ETM: Water supply vs. demand ratio
All evaluations use data from day iday - 1 or earlier to avoid lookahead bias.
For conditions requiring averaging or summation over multiple days, the period
extends from iday - ndays to iday - 1.
A named list of logical values indicating whether each threshold condition is met. Possible elements include:
TRUE if readily available water is below threshold
TRUE if soil moisture is below threshold
TRUE if cumulative precipitation+irrigation is below threshold
TRUE if water stress is below threshold
TRUE if temperature is above threshold
TRUE if precipitation/evapotranspiration ratio is below threshold
Only conditions with non-NA thresholds are included in the returned list.
Generic S3 method to compute crop transpiration (TP).
calc_TP(x, ...) ## S3 method for class 'numeric' calc_TP(x, TP0, KTP, Rmin = NULL, R = x, ...) ## S3 method for class 'model_output' calc_TP(x, ...)calc_TP(x, ...) ## S3 method for class 'numeric' calc_TP(x, TP0, KTP, Rmin = NULL, R = x, ...) ## S3 method for class 'model_output' calc_TP(x, ...)
x |
Input object. Can be a numeric vector, data.frame, matrix, etc. |
... |
Additional arguments. |
TP0 |
numeric Potential crop transpiration |
KTP |
numeric Crop transpiration coefficient |
Rmin |
numeric Minimum soil water reserve |
R |
numeric Soil water reserve |
Depending on the input type, the function returns a numeric vector, data.frame or matrix with the calculated crop transpiration (TP).
Generic and method-specific functions to calculate potential transpiration (TP0).
calc_TP0(x, ...) ## S3 method for class 'numeric' calc_TP0(x, Kc, Cp, Ksol, ET0 = x, ...) ## S3 method for class 'matrix' calc_TP0( x, ET0 = x[iday, ET0_name], Kc = x[iday, Kc_name], Cp = x[iday, Cp_name], Ksol, iday = seq.int(nrow(x)), ET0_name = "ET0", Kc_name = "Kc", Cp_name = "Cp", TP0_name = "TP0", ... )calc_TP0(x, ...) ## S3 method for class 'numeric' calc_TP0(x, Kc, Cp, Ksol, ET0 = x, ...) ## S3 method for class 'matrix' calc_TP0( x, ET0 = x[iday, ET0_name], Kc = x[iday, Kc_name], Cp = x[iday, Cp_name], Ksol, iday = seq.int(nrow(x)), ET0_name = "ET0", Kc_name = "Kc", Cp_name = "Cp", TP0_name = "TP0", ... )
x |
Input object. Can be a |
... |
Additional arguments passed to methods. |
Kc |
numeric Crop coefficient |
Cp |
numeric Canopy partition coefficient |
Ksol |
numeric Maximum solar radiation |
ET0 |
numeric vector or matrix column. The reference evapotranspiration values. Defaults to |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
ET0_name |
character Layer or column name containing ET0 values. |
Kc_name |
character Layer or column name containing Kc values. |
Cp_name |
character Layer or column name containing Cp values. |
TP0_name |
character Layer or column name to store calculated TP0. |
The updated input object with potential transpiration (TP0) values.
The calcThermTime function calculates the cumulative thermal time (TT)
for the current day based on the daily temperature data and a specified base
temperature. It updates the array initModel by computing the thermal time
using the previous day's value and today's climatic data.
calc_TT(x, ...) ## S3 method for class 'numeric' calc_TT(x, Tbase, T = x, ...) ## S3 method for class 'matrix' calc_TT( x, T = x[iday, T_name], Tbase, iday = seq.int(nrow(x)), T_name = "T", TT_name = "TT", ... ) ## S3 method for class 'data.frame' calc_TT( x, T = x[iday, T_name, drop = TRUE], Tbase, iday = seq.int(nrow(x)), T_name = "T", TT_name = "TT", ... ) ## S3 method for class 'model_init' calc_TT(x, crop, iday_sowing, ...)calc_TT(x, ...) ## S3 method for class 'numeric' calc_TT(x, Tbase, T = x, ...) ## S3 method for class 'matrix' calc_TT( x, T = x[iday, T_name], Tbase, iday = seq.int(nrow(x)), T_name = "T", TT_name = "TT", ... ) ## S3 method for class 'data.frame' calc_TT( x, T = x[iday, T_name, drop = TRUE], Tbase, iday = seq.int(nrow(x)), T_name = "T", TT_name = "TT", ... ) ## S3 method for class 'model_init' calc_TT(x, crop, iday_sowing, ...)
x |
An object representing the data for which thermal time is to be calculated. |
... |
Additional arguments passed to or from other methods. |
Tbase |
numeric Base temperature below which no thermal time accumulates. |
T |
numeric Daily temperature. |
iday |
integer Indices of days to process. Defaults to all rows. |
T_name |
character Name of the column containing daily temperature. |
TT_name |
character Name of the column to store the calculated thermal time. |
crop |
list Crop parameters, used in the |
iday_sowing |
integer Sowing day index, used in the |
A numeric vector or data frame with the cumulative thermal time
This function calculates the normalized thermal time (TT) by dividing the observed TT by the maximum TT (TTmax).
calc_TT_norm(x, ...) ## Default S3 method: calc_TT_norm(x, TTmax, ...) ## S3 method for class 'data.frame' calc_TT_norm( x, TT = x[iday, TT_name, drop = TRUE], TTmax, iday = seq.int(nrow(x)), TT_name = "TT", TT_norm_name = "TT_norm", ... ) ## S3 method for class 'matrix' calc_TT_norm( x, TT = x[iday, TT_name], TTmax, iday = seq.int(nrow(x)), TT_name = "TT", TT_norm_name = "TT_norm", ... )calc_TT_norm(x, ...) ## Default S3 method: calc_TT_norm(x, TTmax, ...) ## S3 method for class 'data.frame' calc_TT_norm( x, TT = x[iday, TT_name, drop = TRUE], TTmax, iday = seq.int(nrow(x)), TT_name = "TT", TT_norm_name = "TT_norm", ... ) ## S3 method for class 'matrix' calc_TT_norm( x, TT = x[iday, TT_name], TTmax, iday = seq.int(nrow(x)), TT_name = "TT", TT_norm_name = "TT_norm", ... )
x |
Input object. Can be a numeric vector, data frame, matrix object. |
... |
Additional arguments. |
TTmax |
numeric Maximum thermal time. |
TT |
numeric Thermal time. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
TT_name |
character Column or attribute name to store the normalized TT. |
TT_norm_name |
character Column or attribute name to store the normalized |
numeric, data.frame, matrix, depending on the input.
Generic function to calculate relative thermal time (TT_rel) based on input.
calc_TT_rel(x, ...) ## S3 method for class 'numeric' calc_TT_rel(x, TT_ref, TT = x, ...) ## S3 method for class 'data.frame' calc_TT_rel( x, TT = x[iday, TT_name, drop = TRUE], TT_ref, iday = seq.int(nrow(x)), TT_name = "TT", TT_rel_name = "TT_rel", ... ) ## S3 method for class 'matrix' calc_TT_rel( x, TT = x[iday, TT_name], TT_ref, iday = seq.int(nrow(x)), TT_name = "TT", TT_rel_name = "TT_rel", ... )calc_TT_rel(x, ...) ## S3 method for class 'numeric' calc_TT_rel(x, TT_ref, TT = x, ...) ## S3 method for class 'data.frame' calc_TT_rel( x, TT = x[iday, TT_name, drop = TRUE], TT_ref, iday = seq.int(nrow(x)), TT_name = "TT", TT_rel_name = "TT_rel", ... ) ## S3 method for class 'matrix' calc_TT_rel( x, TT = x[iday, TT_name], TT_ref, iday = seq.int(nrow(x)), TT_name = "TT", TT_rel_name = "TT_rel", ... )
x |
Object containing thermal time data, either numeric or data frame. |
... |
Additional arguments passed to methods. |
TT_ref |
numeric Reference thermal time value for calculation. |
TT |
numeric Thermal time values. |
iday |
integer Indices of days to process. Defaults to all |
TT_name |
character Column name for thermal time in data frame or matrix. |
TT_rel_name |
character Column name for relative thermal time. |
Relative thermal time values as numeric or data.frame with new column.
TT_ref <- 15 # Numeric method calc_TT_rel(c(10, 20, 30), TT_ref = 15) # Data frame method df <- data.frame(TT = c(10, 20, 30)) calc_TT_rel(df, TT_ref = 15)TT_ref <- 15 # Numeric method calc_TT_rel(c(10, 20, 30), TT_ref = 15) # Data frame method df <- data.frame(TT = c(10, 20, 30)) calc_TT_rel(df, TT_ref = 15)
This function calculates the relative thermal time since sowing by comparing the current thermal time to the thermal time at sowing.
calc_TT_sowing(x, ...) ## S3 method for class 'numeric' calc_TT_sowing(x, iday_sowing, TT = x, ...) ## S3 method for class 'matrix' calc_TT_sowing( x, TT = x[iday, TT_name], iday_sowing, iday = seq.int(nrow(x)), TT_name = "TT", TT_sowing_name = "TT_sowing", ... ) ## S3 method for class 'data.frame' calc_TT_sowing( x, TT = x[iday, TT_name, drop = TRUE], iday_sowing, iday = seq.int(nrow(x)), TT_name = "TT", TT_sowing_name = "TT_sowing", ... )calc_TT_sowing(x, ...) ## S3 method for class 'numeric' calc_TT_sowing(x, iday_sowing, TT = x, ...) ## S3 method for class 'matrix' calc_TT_sowing( x, TT = x[iday, TT_name], iday_sowing, iday = seq.int(nrow(x)), TT_name = "TT", TT_sowing_name = "TT_sowing", ... ) ## S3 method for class 'data.frame' calc_TT_sowing( x, TT = x[iday, TT_name, drop = TRUE], iday_sowing, iday = seq.int(nrow(x)), TT_name = "TT", TT_sowing_name = "TT_sowing", ... )
x |
Input object. Can be a numeric vector, data frame, matrix object. |
... |
Additional arguments. |
iday_sowing |
integer Sowing day index, used in the |
TT |
numeric Thermal time. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
TT_name |
character Column or attribute name containing the thermal time. |
TT_sowing_name |
character Column or attribute name to store the relative thermal time since sowing. |
numeric, data.frame, matrix, depending on the input.
Generic and method-specific functions to calculate crop yield (Y).
calc_Y(x = NULL, ...) ## S3 method for class ''NULL'' calc_Y(x = NULL, HI, ...) ## S3 method for class 'numeric' calc_Y(x, HI, iday_crop_dev = rep(1, length(x)), B = x, ...) ## S3 method for class 'matrix' calc_Y( x, B = x[iday, B_name], HI = x[iday, HI_name], iday = seq.int(nrow(x)), B_name = "B", HI_name = "HI", Y_name = "Y", ... )calc_Y(x = NULL, ...) ## S3 method for class ''NULL'' calc_Y(x = NULL, HI, ...) ## S3 method for class 'numeric' calc_Y(x, HI, iday_crop_dev = rep(1, length(x)), B = x, ...) ## S3 method for class 'matrix' calc_Y( x, B = x[iday, B_name], HI = x[iday, HI_name], iday = seq.int(nrow(x)), B_name = "B", HI_name = "HI", Y_name = "Y", ... )
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
HI |
numeric Harvest Index values. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
B |
numeric Total above-ground biomass ( |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
B_name |
character Column or layer name containing biomass
values (default |
HI_name |
character Column or layer name used to store
calculated harvest index values (default |
Y_name |
character Column or layer name to store calculated yield values. |
An object of the same class as x with calculated yield (Y) values.
# Numeric example calc_Y(1:100, HI = 0.5) # Matrix example calc_Y(cbind(B = 1:100, HI = rep(0.5, 100)))# Numeric example calc_Y(1:100, HI = 0.5) # Matrix example calc_Y(cbind(B = 1:100, HI = rep(0.5, 100)))
Generic and methods to compute Y_sugar = B_root * sugar_accumulation. Methods are provided for numeric, matrix/data.frame.
calc_Y_sugar(x, ...) ## S3 method for class 'numeric' calc_Y_sugar(x, B_root = x, sugar_accumulation, ...) ## S3 method for class 'matrix' calc_Y_sugar( x, B_root = x[iday, B_root_name], sugar_accumulation = x[iday, sugar_accumulation_name], iday = seq.int(nrow(x)), B_root_name = "B_root", sugar_accumulation_name = "sugar_accumulation", Y_sugar_name = "Y_sugar", ... )calc_Y_sugar(x, ...) ## S3 method for class 'numeric' calc_Y_sugar(x, B_root = x, sugar_accumulation, ...) ## S3 method for class 'matrix' calc_Y_sugar( x, B_root = x[iday, B_root_name], sugar_accumulation = x[iday, sugar_accumulation_name], iday = seq.int(nrow(x)), B_root_name = "B_root", sugar_accumulation_name = "sugar_accumulation", Y_sugar_name = "Y_sugar", ... )
x |
Object to dispatch on. |
... |
Additional arguments passed to methods. |
B_root |
numeric Root biomass (numeric or extracted from x). |
sugar_accumulation |
numeric Sugar accumulation factor (numeric or extracted from x). |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
B_root_name, sugar_accumulation_name, Y_sugar_name
|
character Names of layers/columns in x. |
Numeric result (for numeric method) or modified x with Y_sugar updated.
This function calculates the root depth of a plant.
calc_zroot(x, ...) ## S3 method for class 'numeric' calc_zroot( x, zroot_init, zmax, iday_crop_dev = rep(1, length(x)), dzroot = x, ... ) ## S3 method for class 'matrix' calc_zroot( x, dzroot = x[iday, dzroot_name], zroot_init, zmax, iday = seq.int(nrow(x)), dzroot_name = "dzroot", zroot_name = "zroot", ... )calc_zroot(x, ...) ## S3 method for class 'numeric' calc_zroot( x, zroot_init, zmax, iday_crop_dev = rep(1, length(x)), dzroot = x, ... ) ## S3 method for class 'matrix' calc_zroot( x, dzroot = x[iday, dzroot_name], zroot_init, zmax, iday = seq.int(nrow(x)), dzroot_name = "dzroot", zroot_name = "zroot", ... )
x |
Input object. Can be a numeric, data.frame, or matrix. |
... |
Further arguments passed to or from other methods. |
zroot_init |
numeric Initial root depth. |
zmax |
numeric Maximum root or soil depth. |
iday_crop_dev |
integer Used like a boolean to indicate a vector of
days within the crop development period (1) or outside (0). Default is a
vector of 1s with the same length as |
dzroot |
numeric Increment of root depth. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
dzroot_name |
character Name of the column in |
zroot_name |
character Layer or column name to store calculated root depth. |
A numeric, matrix, data.frame or depending on the input type.
This function calculates the potential root depth of a plant.
calc_zrootp(x, ...) ## S3 method for class 'numeric' calc_zrootp( x, degred, TT_root_install, sowing_depth, seuil, zroot_max, TT = x, ... ) ## S3 method for class 'matrix' calc_zrootp( x, TT = x[iday, TT_name], degred = x[iday, degred_name], TT_root_install, sowing_depth = 0, seuil, zroot_max, iday = seq.int(nrow(x)), TT_name = "TT", degred_name = "degred", zrootp_name = "zrootp", ... ) ## S3 method for class 'model_init' calc_zrootp(x, crop, soil, dates, iday_sowing, iday_harvest, ...)calc_zrootp(x, ...) ## S3 method for class 'numeric' calc_zrootp( x, degred, TT_root_install, sowing_depth, seuil, zroot_max, TT = x, ... ) ## S3 method for class 'matrix' calc_zrootp( x, TT = x[iday, TT_name], degred = x[iday, degred_name], TT_root_install, sowing_depth = 0, seuil, zroot_max, iday = seq.int(nrow(x)), TT_name = "TT", degred_name = "degred", zrootp_name = "zrootp", ... ) ## S3 method for class 'model_init' calc_zrootp(x, crop, soil, dates, iday_sowing, iday_harvest, ...)
x |
Input object. Can be a numeric, data.frame, or matrix. |
... |
Further arguments passed to or from other methods. |
degred |
numeric Daily root depth growth rate per degree day. |
TT_root_install |
numeric Thermal time for root installation. |
sowing_depth |
numeric Depth of sowing. |
seuil |
numeric Initial root depth at sowing. |
zroot_max |
numeric Maximum root or soil depth. |
TT |
numeric Thermal time. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
TT_name |
character Name of the column in |
degred_name |
character Name of the column in |
zrootp_name |
character Layer or column name to store calculated potential root depth. |
crop |
list Crop parameters (for model_init method). |
soil |
list Soil parameters (for model_init method). |
dates |
data.frame Data frame with simulation dates (for model_init method). |
iday_sowing |
integer Day of year of sowing (for model_init method). |
iday_harvest |
integer Day of year of harvest (for model_init method). |
A numeric, matrix, data.frame or depending on the input type.
Generic and S3 methods to create model input objects for the Optirrig model. These methods handle different input types, such as file paths, data frames, and lists, and transform them into a standardized model input structure.
create_model_inputs(x, ...) ## S3 method for class 'character' create_model_inputs(x, options = list(log = TRUE), ..., cfg = load_config()) ## S3 method for class 'data.frame' create_model_inputs(x, options = list(log = TRUE), ..., cfg = load_config()) ## S3 method for class 'list' create_model_inputs(x, options = list(log = TRUE), ..., cfg = load_config())create_model_inputs(x, ...) ## S3 method for class 'character' create_model_inputs(x, options = list(log = TRUE), ..., cfg = load_config()) ## S3 method for class 'data.frame' create_model_inputs(x, options = list(log = TRUE), ..., cfg = load_config()) ## S3 method for class 'list' create_model_inputs(x, options = list(log = TRUE), ..., cfg = load_config())
x |
An object to create model inputs from. Can be a file path
(character), a data.frame, or a list. Flat lists are supported for
single runs, including in-memory |
... |
Additional arguments passed to methods. |
options |
list Options for processing model inputs. Currently supports:
|
cfg |
A configuration list, typically loaded using |
Reads a file from the given path and processes it as model input. The file must exist.
Transforms a data frame into model input objects, mapping column names and categories using data correspondence tables. Handles loading of external data files (e.g., climate) as needed.
Validates and processes a list of model
input objects. Single flat run lists are normalized to the categorized
structure expected downstream, including direct data.frame climate and
irrigation inputs. Returns a list of standardized model input objects
with class model_inputs.
A list of model input objects with class model_inputs, each containing
the components: climate, crop, soil, and run.
get_vars_data, get_data_path, load_config
## Not run: # From a data frame df <- data.frame(run_id = 1, ...) model_inputs <- create_model_inputs(df) # From a file path model_inputs <- create_model_inputs("inputs/model_data.csv") ## End(Not run)## Not run: # From a data frame df <- data.frame(run_id = 1, ...) model_inputs <- create_model_inputs(df) # From a file path model_inputs <- create_model_inputs("inputs/model_data.csv") ## End(Not run)
Generic and method-specific functions for processing climate model inputs.
create_model_inputs_climate(x, ...) ## S3 method for class 'list' create_model_inputs_climate(x, ..., cfg = load_config()) ## S3 method for class 'character' create_model_inputs_climate(x, ..., options = list(), cfg = load_config()) ## S3 method for class 'data.frame' create_model_inputs_climate(x, ...)create_model_inputs_climate(x, ...) ## S3 method for class 'list' create_model_inputs_climate(x, ..., cfg = load_config()) ## S3 method for class 'character' create_model_inputs_climate(x, ..., options = list(), cfg = load_config()) ## S3 method for class 'data.frame' create_model_inputs_climate(x, ...)
x |
Input object. Supported classes are |
... |
Additional arguments passed to methods. |
cfg |
A configuration list, typically loaded using |
options |
list Optional options. When |
A data.frame or climate object.
Generic and method-specific functions for processing crop model inputs.
create_model_inputs_crop(x, ...) ## S3 method for class 'list' create_model_inputs_crop(x, ..., cfg = load_config())create_model_inputs_crop(x, ...) ## S3 method for class 'list' create_model_inputs_crop(x, ..., cfg = load_config())
x |
Input object. Can be only a |
... |
Additional arguments passed to methods. |
cfg |
A configuration list, typically loaded using |
Responsible for adding any missing parameters using the default configuration
(previously handled in createInputsParams).
A list of crop parameter
This function serves as a generic interface for creating and processing input
parameters required by irrigation models. It supports multiple input types,
including list, character (e.g., file paths), and data.frame objects,
allowing for flexible integration with various data sources and formats.
Method-specific implementations handle the conversion and validation of these
inputs to ensure they conform to the requirements of the irrigation modeling
workflow.
create_model_inputs_irrigation(x, ...) ## S3 method for class 'list' create_model_inputs_irrigation(x, ..., cfg = load_config()) ## S3 method for class 'character' create_model_inputs_irrigation(x, ..., options = list(), cfg = load_config()) ## S3 method for class 'data.frame' create_model_inputs_irrigation(x, ...)create_model_inputs_irrigation(x, ...) ## S3 method for class 'list' create_model_inputs_irrigation(x, ..., cfg = load_config()) ## S3 method for class 'character' create_model_inputs_irrigation(x, ..., options = list(), cfg = load_config()) ## S3 method for class 'data.frame' create_model_inputs_irrigation(x, ...)
x |
An input object containing data for the irrigation model. Supported types include:
|
... |
Additional arguments passed to specific methods for further customization or processing. |
cfg |
A configuration list, typically loaded using |
options |
list Optional options. When |
The function is designed to be extended via S3 methods, enabling custom handling for different input types. Each method is responsible for extracting, validating, and formatting the input data into a standardized list of irrigation parameters. This ensures consistency and reliability in downstream modeling tasks.
A list containing the processed irrigation model parameters,
ready for use in simulation or analysis.
irrigation <- data.frame( Date = c("2020-06-01", "2020-06-08"), Dose = c(20, 25) ) create_model_inputs_irrigation(irrigation)irrigation <- data.frame( Date = c("2020-06-01", "2020-06-08"), Dose = c(20, 25) ) create_model_inputs_irrigation(irrigation)
Generic and method-specific functions for processing run model inputs.
create_model_inputs_run(x, ...) ## S3 method for class 'list' create_model_inputs_run(x, ..., cfg = load_config())create_model_inputs_run(x, ...) ## S3 method for class 'list' create_model_inputs_run(x, ..., cfg = load_config())
x |
Input object. Must be a |
... |
Additional arguments passed to methods. |
cfg |
A configuration list, typically loaded using |
A list of run parameters.
Generic and method-specific functions for processing soil model inputs.
create_model_inputs_soil(x, ...) ## S3 method for class 'list' create_model_inputs_soil(x, ..., options = list(), cfg = load_config())create_model_inputs_soil(x, ...) ## S3 method for class 'list' create_model_inputs_soil(x, ..., options = list(), cfg = load_config())
x |
Input object. Must be a |
... |
Additional arguments passed to methods. |
options |
list Optional options. Some soil parameters can be provided
as filenames; set |
cfg |
A configuration list, typically loaded using |
A list of soil parameters.
It supports Nextcloud public links in case of using cloud. In this case,
this function can download the file in a temporary
folder and returns the path of the downloaded file.
This functionality is useful for read_excel from the package readxl
(See: https://stackoverflow.com/a/41368947/5300212).
get_data_path( path = NULL, ..., base_dir = NULL, resolve = FALSE, use_cache = FALSE, cache = Sys.getenv("PKG_DATA_CACHE", file.path(dirname(tempdir()), utils::packageName())), cfg = load_config() )get_data_path( path = NULL, ..., base_dir = NULL, resolve = FALSE, use_cache = FALSE, cache = Sys.getenv("PKG_DATA_CACHE", file.path(dirname(tempdir()), utils::packageName())), cfg = load_config() )
path |
character representing the path of the data in the database |
... |
character path elements to add after |
base_dir |
character Optional base directory used when |
resolve |
logical If TRUE, try to resolve the file by checking whether
the provided path (via |
use_cache |
logical download the data and use cache location |
cache |
character path where downloaded files from cloud are cached (See details) |
cfg |
a config object. Configuration to use. See load_config for details |
The cache directory is by default located in the system temporary folder in a subdirectory named as the package name or the value of the environment variable "PKG_DATA_CACHE" if it is defined.
character with the path of the file to read either on:
the local storage if cfg$data$mode == "local"
the cache directory if cfg$data$mode != "local" and use_cache == TRUE
the cloud URL if cfg$data$mode != "local" and use_cache == FALSE
Generic and method-specific functions to get model time indices. These indices include:
iday_emerg: Day of emergence (first day with TT_LAI > 0).
iday_root_install: Day of root installation (first day with TT_root >
0).
iday_crop_dev: Days of crop development (from emergence or root
installation to harvest).
iday_strategy: Irrigation strategy period identifier (0 = none, k =
period k).
iday_constraints: Irrigation constraints period identifier.
iday_no_irrig: Binary indicator for irrigation allowed (1) or not (0).
iday_waterturn: Binary indicator for water turn days.
get_iday(x, ...) ## S3 method for class 'model_init' get_iday(x, crop, irrigation, dates, ...) ## S3 method for class 'matrix' get_iday( x, iday_harvest, iday_strategy_start, iday_strategy_end, iday_constraints_start, iday_constraints_end, iday_no_irrig, WTurn_ndays, LTurn_ndays, tbis_mod, TT_d, ... )get_iday(x, ...) ## S3 method for class 'model_init' get_iday(x, crop, irrigation, dates, ...) ## S3 method for class 'matrix' get_iday( x, iday_harvest, iday_strategy_start, iday_strategy_end, iday_constraints_start, iday_constraints_end, iday_no_irrig, WTurn_ndays, LTurn_ndays, tbis_mod, TT_d, ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
irrigation |
list Irrigation parameters. |
dates |
lubridate::Date Vector of dates corresponding to the simulation period. |
iday_harvest |
integer Harvest day index. |
iday_strategy_start |
integer Start of irrigation strategy period(s). |
iday_strategy_end |
integer End of irrigation strategy period(s). |
iday_constraints_start |
integer Start of irrigation constraints period(s). |
iday_constraints_end |
integer End of irrigation constraints period(s). |
iday_no_irrig |
integer Day indices where irrigation is not allowed. |
WTurn_ndays |
integer Water turn period in days (can be vector for multiple periods). |
LTurn_ndays |
integer Logical turn period in days (can be vector for multiple periods). |
tbis_mod |
integer TBIS (Timing-Based Irrigation Strategy) mode (0 = off, >0 = on). |
TT_d |
numeric Thermal time threshold for TBIS mode (degrees-days). |
An object of the same class as x with added time index columns/layers.
Constructs a file path for saving model output based on the output's type and a given name.
The file extension is determined by the class of model_output:
"csv" for matrices
"RDS" for all other types
get_model_output_path(model_output, model_output_name, path_outputs)get_model_output_path(model_output, model_output_name, path_outputs)
model_output |
The model output object whose type determines the file extension. |
model_output_name |
character string specifying the base name for the output file. |
path_outputs |
character string specifying the directory path where the output file will be saved. |
character string representing the full file path for the model output.
Retrieves metadata for parameters and variables from a CSV file included in the package. The function reads the specified CSV file and extracts information from specified columns based on matching values.
get_vars_data( filename = "params.desc.csv", df = read(system.file("extdata/", filename, package = "OptirrigCORE"), show_col_types = FALSE), match_from, match_with, values = na.omit(unique(df[, match_from, drop = TRUE])), ..., cfg = load_config() )get_vars_data( filename = "params.desc.csv", df = read(system.file("extdata/", filename, package = "OptirrigCORE"), show_col_types = FALSE), match_from, match_with, values = na.omit(unique(df[, match_from, drop = TRUE])), ..., cfg = load_config() )
filename |
Character. Name of the CSV file containing metadata. Defaults to "params.desc.csv". Can also be "vars.desc.csv". |
df |
Data frame. Metadata table. By default, it is read from the specified CSV file. |
match_from |
Character. Name of the column in |
match_with |
Character. Name of the column in |
values |
Character vector. Values to match in the |
... |
Additional arguments (currently unused). |
cfg |
List. Configuration object, typically loaded via |
Named vector of values from the match_with column, matched by values in the
match_from column. Names correspond to the matched values.
Generic and method-specific functions to initialize the model simulation.
init_model(x, ...) ## S3 method for class 'model_inputs' init_model(x, ...) ## S3 method for class 'model_input' init_model(x, options = list(log = TRUE), ...) ## S3 method for class 'matrix' init_model(x, crop, soil, run, dates, irrigation, ...)init_model(x, ...) ## S3 method for class 'model_inputs' init_model(x, ...) ## S3 method for class 'model_input' init_model(x, options = list(log = TRUE), ...) ## S3 method for class 'matrix' init_model(x, crop, soil, run, dates, irrigation, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
options |
list Options for initialization. Currently supports:
|
crop |
list Crop-specific parameters. |
soil |
list Soil-specific parameters. |
run |
list Run-specific parameters. |
dates |
lubridate::Date Simulation dates. |
irrigation |
list Irrigation-specific parameters. |
An object of class model_inits or model_init named with the run
identifier.
The model_inits object is a list of model_init objects.
The model_init object is a list of:
init: The initialized model parameters. This is the main object which is
processed by the model, starting with the climate data.
crop: The crop-specific parameters.
soil: The soil-specific parameters.
run: The run-specific parameters.
dates: The simulation dates.
irrigation: The irrigation-specific parameters.
iday: The day-specific parameters.
Generic and method-specific functions to initialize the model simulation for climate data.
init_model_climate(x, ...) ## S3 method for class 'model_input' init_model_climate(x, soil, irrigation, ...) ## S3 method for class 'data.frame' init_model_climate( x, date_start, date_end, mulch, gge, date_name = "Date", ... ) ## S3 method for class 'matrix' init_model_climate(x, ...) ## S3 method for class 'list' init_model_climate(x, ...)init_model_climate(x, ...) ## S3 method for class 'model_input' init_model_climate(x, soil, irrigation, ...) ## S3 method for class 'data.frame' init_model_climate( x, date_start, date_end, mulch, gge, date_name = "Date", ... ) ## S3 method for class 'matrix' init_model_climate(x, ...) ## S3 method for class 'list' init_model_climate(x, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
irrigation |
list Irrigation parameters. |
date_start |
lubridate::Date Start date of the simulation. |
date_end |
lubridate::Date End date of the simulation. |
mulch |
numeric Soil mulch parameter. |
gge |
numeric Irrigation gge parameter. |
date_name |
character Name of the date column or dimension. |
An object of class model_init backed by a matrix.
climate <- data.frame( Date = as.Date("2020-01-01") + 0:4, ETP = c(1.2, 1.3, 1.1, 1.4, 1.2), Rain = c(0, 2, 0, 1, 0) ) init_model_climate( climate, date_start = as.Date("2020-01-02"), date_end = as.Date("2020-01-04"), mulch = 0, gge = 1 )climate <- data.frame( Date = as.Date("2020-01-01") + 0:4, ETP = c(1.2, 1.3, 1.1, 1.4, 1.2), Rain = c(0, 2, 0, 1, 0) ) init_model_climate( climate, date_start = as.Date("2020-01-02"), date_end = as.Date("2020-01-04"), mulch = 0, gge = 1 )
Generic and method-specific functions to initialize the model simulation for crop development.
init_model_crop_dev(x, ...) ## S3 method for class 'model_init' init_model_crop_dev(x, crop, soil, irrigation, dates, ...)init_model_crop_dev(x, ...) ## S3 method for class 'model_init' init_model_crop_dev(x, crop, soil, irrigation, dates, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
soil |
list Soil parameters. |
irrigation |
list Irrigation parameters. |
dates |
lubridate::Date Dates for the simulation. |
This function initializes the model simulation for crop development by calling:
calc_ET0(): calculate reference evapotranspiration
calc_TT(): calculate thermal time from sowing, emergence and root
installation
calc_LAIp(): calculate potential leaf area index (including TT_norm, LT,
alpha, etc.)
calc_zrootp(): calculate potential root depth (including degred, etc.)
calc_Bp(): calculate potential biomass (including IR, PAR, etc.)
get_iday(): get crop development periods
An object of class model_init backed by a matrix.
Generic and method-specific functions to initialize the model simulation for climate data.
init_model_irrigation(x, ...) ## S3 method for class 'model_input' init_model_irrigation(x, dates, irrigation, ...) ## S3 method for class 'matrix' init_model_irrigation(x, dates, irrigation, ...)init_model_irrigation(x, ...) ## S3 method for class 'model_input' init_model_irrigation(x, dates, irrigation, ...) ## S3 method for class 'matrix' init_model_irrigation(x, dates, irrigation, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods. |
dates |
lubridate::Date Simulation dates. |
irrigation |
list Irrigation parameters. |
An object of class model_init backed by a matrix.
Generic and method-specific functions to initialize variables for the model simulation.
init_model_vars(x, ...) ## S3 method for class 'model_init' init_model_vars(x, ...) ## S3 method for class 'matrix' init_model_vars(x, vars, ...)init_model_vars(x, ...) ## S3 method for class 'model_init' init_model_vars(x, ...) ## S3 method for class 'matrix' init_model_vars(x, vars, ...)
x |
Input object of class |
... |
Additional arguments passed to specific methods. |
vars |
character Vector of variable names to ensure are present in the output. |
An object of class model_init with the specified variables
initialized.
Retrieve inputs metadata (categories, types, subcategories)
inputs_meta()inputs_meta()
A list with elements:
categories: named character vector of parameter categories
types: named character vector of parameter types
subcategories: named character vector of parameter subcategories
Loads and merges the default and user configuration files for the package. The function determines the appropriate configuration file to use, merges it with the package default, and sets up internal paths and metadata.
load_config( path_config_ini = "config.user.ini", path_directory = system.file("extdata", package = pkg), pkg = utils::packageName(), ini_sources = NULL, ..., path_default_cfg = system.file("config.user.ini", package = pkg) )load_config( path_config_ini = "config.user.ini", path_directory = system.file("extdata", package = pkg), pkg = utils::packageName(), ini_sources = NULL, ..., path_default_cfg = system.file("config.user.ini", package = pkg) )
path_config_ini |
Path to the user-specific |
path_directory |
Optional. Directory to look for the configuration file. Defaults to the package's |
pkg |
Name of the package. Defaults to the current package name. |
ini_sources |
Optional named list defining where reference |
... |
Additional arguments passed to |
path_default_cfg |
Path to the default configuration file within the package. Defaults to |
The function first attempts to load a user configuration file from the specified path. If not found, it falls back to the default configuration file provided by the package. The two configurations are merged, with user settings taking precedence. Internal paths and package metadata (such as version and name) are added to the configuration list. If a valid configuration cannot be found, the function stops with an error.
A list containing the merged configuration settings, including internal paths and package metadata.
# Load configuration with defaults cfg <- load_config() str(cfg)# Load configuration with defaults cfg <- load_config() str(cfg)
Daily observed biomass values for the maize 2021 Lavalette project.
data(MAIZE_21LAVALETTE_B)data(MAIZE_21LAVALETTE_B)
A data.frame
Generated as part of the Maize 2021 project.
data(MAIZE_21LAVALETTE_B) head(MAIZE_21LAVALETTE_B)data(MAIZE_21LAVALETTE_B) head(MAIZE_21LAVALETTE_B)
Daily climate inputs (e.g., temperature, radiation, ETP, rainfall) used for the maize 2021 Lavalette project.
data(MAIZE_21LAVALETTE_clim)data(MAIZE_21LAVALETTE_clim)
A data.frame
Generated as part of the Maize 2021 project.
data(MAIZE_21LAVALETTE_clim) head(MAIZE_21LAVALETTE_clim)data(MAIZE_21LAVALETTE_clim) head(MAIZE_21LAVALETTE_clim)
Irrigation schedule used for the maize 2021 Lavalette project.
data(MAIZE_21LAVALETTE_irrig)data(MAIZE_21LAVALETTE_irrig)
A data.frame
Generated as part of the Maize 2021 project.
data(MAIZE_21LAVALETTE_irrig) head(MAIZE_21LAVALETTE_irrig)data(MAIZE_21LAVALETTE_irrig) head(MAIZE_21LAVALETTE_irrig)
Daily observed leaf area index (LAI) for the maize 2021 Lavalette project.
data(MAIZE_21LAVALETTE_LAI)data(MAIZE_21LAVALETTE_LAI)
A data.frame
Generated as part of the Maize 2021 project.
data(MAIZE_21LAVALETTE_LAI) head(MAIZE_21LAVALETTE_LAI)data(MAIZE_21LAVALETTE_LAI) head(MAIZE_21LAVALETTE_LAI)
Daily observed water reservoir values for the maize 2021 Lavalette project.
data(MAIZE_21LAVALETTE_RES)data(MAIZE_21LAVALETTE_RES)
A data.frame
Generated as part of the Maize 2021 project.
data(MAIZE_21LAVALETTE_RES) head(MAIZE_21LAVALETTE_RES)data(MAIZE_21LAVALETTE_RES) head(MAIZE_21LAVALETTE_RES)
This function attempts to parse character date strings using lubridate::parse_date_time with a set of common orders. If a string cannot be parsed it yields NA in the result.
parse_date_time(date_str)parse_date_time(date_str)
date_str |
character vector of date/time strings to parse. |
The parsing orders tried (in no particular priority) are stored in c("dmy", "mdy", "ymd", "Ymd", "dmY", "mdY", "Ydm"). Parsing is performed with exact = FALSE to allow flexible separators and variants supported by lubridate.
A lubridate::Date vector corresponding to parsed input. Unparseable entries are returned as NA.
lubridate::parse_date_time
# Single string parse_date_time("01-02-2003") # Vector of mixed formats parse_date_time(c("2003/02/01", "01 Mar 2004", "31-12-1999"))# Single string parse_date_time("01-02-2003") # Vector of mixed formats parse_date_time(c("2003/02/01", "01 Mar 2004", "31-12-1999"))
A convenience wrapper that dispatches to an appropriate file-reading function based on the extension of the supplied path. Supported extensions and their readers:
csv, dat, tsv: readr::read_delim
ini: ini::read.ini
xls, xlsx: readxl::read_excel
ods: readODS::read_ods
RDS: base::readRDS
The function simply determines the file extension, selects the reader, and forwards the path and any additional arguments to that reader.
read(path, ..., cache_enabled = TRUE)read(path, ..., cache_enabled = TRUE)
path |
character Path to the file to be read. Must include a file extension (e.g. "data.csv"). If the path has no extension the function throws an error. |
... |
Additional arguments passed through to the underlying reader function (for example, delim, col_types for readr or sheet for readxl). |
cache_enabled |
logical Whether to reuse a cached object when the file path, size and modification time are unchanged. |
If the extension is not recognized (i.e. there is no matching reader in the internal switch), the call will fail when attempting to invoke the reader. Ensure the necessary packages (readr, readxl, readODS, ini) are installed when reading those formats.
The object returned by the chosen reader. Typically a data frame or tibble for delimited and spreadsheet formats, a list for INI files, or any R object stored in an RDS file.
readr::read_delim, readxl::read_excel, readODS::read_ods, ini::read.ini, base::readRDS
## Not run: # Read a comma-separated file read("path/to/data.csv") # Read the first sheet of an Excel workbook read("path/to/data.xlsx", sheet = 1) # Read an RDS file read("path/to/object.RDS") ## End(Not run)## Not run: # Read a comma-separated file read("path/to/data.csv") # Read the first sheet of an Excel workbook read("path/to/data.xlsx", sheet = 1) # Read an RDS file read("path/to/object.RDS") ## End(Not run)
Generic and method-specific functions to run Optirrig model simulations. These functions handle different input types, such as file paths, data frames, and lists.
run_model(x = NULL, ...) ## S3 method for class ''NULL'' run_model(x, options = list(), ...) ## S3 method for class 'character' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE, path = NULL, plan = NULL, workers = NULL), ... ) ## S3 method for class 'data.frame' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE, path = NULL, plan = NULL, workers = NULL), ... ) ## S3 method for class 'list' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE, path = NULL, plan = NULL, workers = NULL), ... ) ## S3 method for class 'model_inputs' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE), ... ) ## S3 method for class 'model_input' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE), ... ) ## S3 method for class 'model_inits' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE), ... ) ## S3 method for class 'model_init' run_model(x, options, ...)run_model(x = NULL, ...) ## S3 method for class ''NULL'' run_model(x, options = list(), ...) ## S3 method for class 'character' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE, path = NULL, plan = NULL, workers = NULL), ... ) ## S3 method for class 'data.frame' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE, path = NULL, plan = NULL, workers = NULL), ... ) ## S3 method for class 'list' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE, path = NULL, plan = NULL, workers = NULL), ... ) ## S3 method for class 'model_inputs' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE), ... ) ## S3 method for class 'model_input' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE), ... ) ## S3 method for class 'model_inits' run_model( x, options = list(log = TRUE, save = TRUE, force = FALSE, return_outputs = TRUE), ... ) ## S3 method for class 'model_init' run_model(x, options, ...)
x |
Input object. Can be |
... |
Additional arguments passed to methods as well as to create_model_inputs() and init_model(). |
options |
list A list of options for running the model:
|
The main workflow of the model simulation consists of three steps:
create_model_inputs
init_model
run_model
The model_inputs, model_input, model_inits and model_init methods
are internal functions that handle the main workflow of the model simulation.
The model_init method correspond to the old piloteR function.
An object of class "model_outputs" which is a list. Each entry is a simulation output stored as a matrix tagged with class "model_output".
Generic and method-specific functions to run the crop development module of the Optirrig model. This module includes calculations for stress factors, leaf area index (LAI), biomass (B), yield (Y), and root depth (zroot).
run_model_crop_dev(x, ...) ## S3 method for class 'model_output' run_model_crop_dev( x, crop, soil, iday, is_beetroot = any(crop$crop == "beetroot"), ... )run_model_crop_dev(x, ...) ## S3 method for class 'model_output' run_model_crop_dev( x, crop, soil, iday, is_beetroot = any(crop$crop == "beetroot"), ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
is_beetroot |
logical Whether beetroot-specific root biomass and sugar calculations should be applied. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute biomass (B) during crop development.
run_model_crop_dev_B(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_B(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_B(x, iday, RUE, ...)run_model_crop_dev_B(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_B(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_B(x, iday, RUE, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
iday |
integer Current day index of the simulation. |
RUE |
numeric Radiation use efficiency
( |
An object of class model_output with updated daily variables.
Generic S3 dispatcher and method implementations to compute or update daily root biomass (B_root) within a crop simulation state.
run_model_crop_dev_B_root(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_B_root(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_B_root(x, crop, iday, ...)run_model_crop_dev_B_root(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_B_root(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_B_root(x, crop, iday, ...)
x |
Object to dispatch on. For methods, this is typically:
|
... |
Additional arguments passed to internal helpers (e.g. calc_B_root) or to other methods. |
crop |
List or similar containing crop-specific parameters. The matrix method expects at least TT_B_root5 and TT_B_root70 to compute development. |
iday |
Integer. Index of the current day (row) to update in the state. |
The matrix method computes B_root for the given day using the helper
calc_B_root. It reads the current total biomass (B) at row iday and uses
previous-day values (when available) to set B0 and B_root0; for day 1 these
initial values default to 0. The 'model_output' method forwards to the
matrix implementation. The method is currently a placeholder that
invokes an interactive debugger.
The updated object of the same class with B_root at row/index
is for debugging and does not currently return a transformed object.
Generic and method-specific functions to compute leaf area index (LAI) during crop development.
run_model_crop_dev_LAI(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_LAI(x, crop, soil, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_LAI( x, iday, Kc_max, c1, c2, Ksol, estress_lai, LAImin = NA_real_, k = NA_real_, ... )run_model_crop_dev_LAI(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_LAI(x, crop, soil, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_LAI( x, iday, Kc_max, c1, c2, Ksol, estress_lai, LAImin = NA_real_, k = NA_real_, ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
Kc_max |
numeric Maximum crop coefficient. |
c1 |
numeric Coefficient related to the crop. |
c2 |
numeric Coefficient related to the crop. |
Ksol |
numeric Maximum soil evaporation coefficient. |
estress_lai |
numeric Maximum LAI stress nocivity value. |
LAImin |
numeric Lower asymptote used to damp LAI decline during senescence. |
k |
numeric Damping coefficient controlling the maximum daily LAI loss
when |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute water stress factors during crop development.
run_model_crop_dev_stress_water(x, ...) ## S3 method for class 'matrix' run_model_crop_dev_stress_water(x, iday, ...)run_model_crop_dev_stress_water(x, ...) ## S3 method for class 'matrix' run_model_crop_dev_stress_water(x, iday, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
iday |
integer Current day index of the simulation. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute yield (Y) during crop development.
run_model_crop_dev_Y(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_Y(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_Y(x, iday, HIp, ...)run_model_crop_dev_Y(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_Y(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_Y(x, iday, HIp, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
iday |
integer Current day index of the simulation. |
HIp |
numeric Potential harvest index. Can be scalar or time-varying. |
An object of class model_output with updated daily variables.
Generic S3 dispatcher and methods to compute sugar accumulation (Y_sugar) for sugar beet. The calculation uses calc_Y_sugar and updates the input object (matrix or model_output) in-place (returns the updated object).
run_model_crop_dev_Y_sugar(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_Y_sugar(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_Y_sugar(x, iday, ...)run_model_crop_dev_Y_sugar(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_Y_sugar(x, crop, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_Y_sugar(x, iday, ...)
x |
Object to update: a matrix or a model_output. |
... |
Additional arguments passed to methods. |
crop |
character Crop identifier (used by the model_output method). |
iday |
integer Day index to update. |
The matrix method expects the columns "B_root" together with "sugar_accumulation"
and writes the result to the "Y_sugar" column for the given row iday.
The model_output method delegates to NextMethod, forwarding iday.
The input object x with its "Y_sugar" component updated for the
specified day/index.
calc_Y_sugar
Generic and method-specific functions to compute root depth (zroot) during crop development.
run_model_crop_dev_zroot(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_zroot(x, crop, soil, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_zroot( x, iday, racplus, vroot, vrac, seuil, zmax, theta_raw, ... )run_model_crop_dev_zroot(x, ...) ## S3 method for class 'model_output' run_model_crop_dev_zroot(x, crop, soil, iday, ...) ## S3 method for class 'matrix' run_model_crop_dev_zroot( x, iday, racplus, vroot, vrac, seuil, zmax, theta_raw, ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
crop |
list Crop parameters. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
racplus |
numeric Root growth parameter. |
vroot |
numeric Root growth parameter. |
vrac |
numeric Root growth parameter. |
seuil |
numeric Root growth parameter. |
zmax |
numeric Maximum root or soil depth. |
theta_raw |
numeric Raw soil moisture content. |
An object of class model_output with updated daily variables.
Generic function to run a financial model. This function dispatches methods based on the class of the input object.
run_model_finance(x, ...) ## S3 method for class 'model' run_model_finance(x, ..., cfg = load_config())run_model_finance(x, ...) ## S3 method for class 'model' run_model_finance(x, ..., cfg = load_config())
x |
An object representing the model or data to be used. |
... |
Additional arguments passed to specific methods. |
cfg |
A configuration list, typically loaded using |
The result of the financial model run, depending on the method.
This function serves as a generic method dispatcher for running a model with an irrigation strategy.
run_model_irrig_strat(x, ...) ## S3 method for class 'model_output' run_model_irrig_strat(x, soil, irrigation, iday, ...)run_model_irrig_strat(x, ...) ## S3 method for class 'model_output' run_model_irrig_strat(x, soil, irrigation, iday, ...)
x |
An object representing the irrigation strategy or model input. |
... |
Additional arguments passed to specific methods. |
soil |
list Soil parameters. |
irrigation |
list Irrigation parameters. |
iday |
integer Integer vector. Indices of rows to process (for data.frames) or time steps (f). |
The run_model_irrig_strat function is a generic S3 method dispatcher. It allows for the implementation of specific methods for different classes of irrigation strategy objects. By defining methods for various classes, users can customize how the model is run depending on the type of irrigation strategy provided.
The output depends on the specific method implemented for the class of x.
Generic and S3 methods to run an irrigation strategy dose model on simulation outputs.
run_model_irrig_strat_dose(x, ...) ## S3 method for class 'model_output' run_model_irrig_strat_dose(x, soil, strategy, constraints, iday, ...) ## S3 method for class 'matrix' run_model_irrig_strat_dose( x, theta_fc, theta_wp, RU_target, RU_units, THETA_target, RU_thrld, THETA_thrld, ETM_thrld, ETM_ndays, SW_thrld, SW_ndays, PI_thrld, PI_ndays, T_thrld, T_ndays, dose_fix, dose_min, dose_max, WTurn_mod, LTurn_ndays, quota_max, quota_wind, iday, ... )run_model_irrig_strat_dose(x, ...) ## S3 method for class 'model_output' run_model_irrig_strat_dose(x, soil, strategy, constraints, iday, ...) ## S3 method for class 'matrix' run_model_irrig_strat_dose( x, theta_fc, theta_wp, RU_target, RU_units, THETA_target, RU_thrld, THETA_thrld, ETM_thrld, ETM_ndays, SW_thrld, SW_ndays, PI_thrld, PI_ndays, T_thrld, T_ndays, dose_fix, dose_min, dose_max, WTurn_mod, LTurn_ndays, quota_max, quota_wind, iday, ... )
x |
An object containing model output data. For the default method, a matrix of simulation results. |
... |
Additional arguments passed to methods. |
soil |
A list or object containing soil parameters, including field capacity ( |
strategy |
A list that contains the strategy-specific thresholds, targets, turn configuration, and other rule parameters passed to the matrix method. |
constraints |
A list that defines dose and quota constraints (e.g., fixed/min/max dose, quota mode, quota partitions) applied when |
iday |
Integer. The current simulation day index. |
theta_fc |
Numeric. Soil field capacity (volumetric water content). |
theta_wp |
Numeric. Soil wilting point (volumetric water content). |
RU_target |
Numeric vector. Target readily available water (RU) for each strategy. |
RU_units |
Integer vector. Units for RU thresholds (1: mm, 2: %). |
THETA_target |
Numeric vector. Target soil moisture (RFU) for each strategy. |
RU_thrld |
Numeric vector. Thresholds for RU triggering irrigation. |
THETA_thrld |
Numeric vector. Thresholds for soil moisture triggering irrigation. |
ETM_thrld |
Numeric vector. Thresholds for ETM (evapotranspiration) ratio triggering irrigation. |
ETM_ndays |
Integer vector. Number of days for ETM calculation. |
SW_thrld |
Numeric vector. Thresholds for water stress triggering irrigation. |
SW_ndays |
Integer vector. Number of days for water stress calculation. |
PI_thrld |
Numeric vector. Thresholds for cumulative precipitation + irrigation triggering irrigation. |
PI_ndays |
Integer vector. Number of days for PI calculation. |
T_thrld |
Numeric vector. Thresholds for temperature triggering irrigation. |
T_ndays |
Integer vector. Number of days for temperature calculation. |
dose_fix |
Numeric vector. Fixed irrigation dose for each strategy. |
dose_min |
Numeric vector. Minimum irrigation dose for each strategy. |
dose_max |
Numeric vector. Maximum irrigation dose for each strategy. |
WTurn_mod |
Integer or logical vector. Irrigation turn mode (0/FALSE = strict mode: only irrigate on marked water turn days; 1/TRUE = flexible mode: irrigate if there has been a water turn since last irrigation). |
LTurn_ndays |
Integer vector. Minimum number of days between irrigations for each strategy. |
quota_max |
Numeric. Total available irrigation water quota. |
quota_wind |
Numeric vector. Limited quota for applying on a constraint window (fraction of quota_max). |
The function applies a set of irrigation decision rules based on soil, weather, and management parameters. It supports multiple strategies and thresholds, including soil moisture, water stress, precipitation, temperature, and ETM. The function manages irrigation turns, quotas, and dose calculations, and updates the simulation matrix accordingly.
An updated simulation matrix or model output object with irrigation applied according to the strategy.
calc_dose, calc_theta, calc_threshold, calc_quota
Generic and method-specific functions to compute daily water balance. This module includes calculations for potential evapotranspiration (ETM), soil hydric states (z, theta, R) update, water routing (precipitation and irrigation), drainage, soil evaporation (ES), and plant transpiration (TP).
run_model_water_balance(x, ...) ## S3 method for class 'model_output' run_model_water_balance(x, soil, crop, iday, R0 = NULL, ...) ## S3 method for class 'model_output' run_model_water_balance_others(x, soil, crop, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_others(x, theta_fc, theta_wp, iday, ...)run_model_water_balance(x, ...) ## S3 method for class 'model_output' run_model_water_balance(x, soil, crop, iday, R0 = NULL, ...) ## S3 method for class 'model_output' run_model_water_balance_others(x, soil, crop, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_others(x, theta_fc, theta_wp, iday, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
crop |
list Crop parameters. |
iday |
integer Current day index of the simulation. |
R0 |
numeric Optional initial soil water reservoir used when routing water for the current simulation day. |
theta_fc |
numeric Soil field capacity (volumetric water content). |
theta_wp |
numeric Soil wilting point (volumetric water content). |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute drainage during daily water balance.
run_model_water_balance_drainage(x, ...) ## S3 method for class 'model_output' run_model_water_balance_drainage(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_drainage( x, theta_fc, theta_wp, theta_sat, Ks, iday, ... )run_model_water_balance_drainage(x, ...) ## S3 method for class 'model_output' run_model_water_balance_drainage(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_drainage( x, theta_fc, theta_wp, theta_sat, Ks, iday, ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
theta_fc |
numeric Water content at field capacity ( |
theta_wp |
numeric Water content at permanent wilting point ( |
theta_sat |
numeric Saturated water content ( |
Ks |
numeric Non-Saturated hydraulic conductivity (mm/h). |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute soil evaporation (ES) during daily water balance.
run_model_water_balance_ES(x, ...) ## S3 method for class 'model_output' run_model_water_balance_ES(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_ES(x, theta_r, iday, ...)run_model_water_balance_ES(x, ...) ## S3 method for class 'model_output' run_model_water_balance_ES(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_ES(x, theta_r, iday, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
theta_r |
numeric Residual soil water content ( |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute potential evapotranspiration (ETM) during daily water balance.
run_model_water_balance_ETM(x, ...) ## S3 method for class 'model_output' run_model_water_balance_ETM(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_ETM(x, Ksol, iday, ...)run_model_water_balance_ETM(x, ...) ## S3 method for class 'model_output' run_model_water_balance_ETM(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_ETM(x, Ksol, iday, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
Ksol |
numeric Maximum soil evaporation coefficient. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to initialize soil hydric states at the beginning of the water balance module.
run_model_water_balance_init_states(x, ...) ## S3 method for class 'model_output' run_model_water_balance_init_states(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_init_states( x, theta_fc, R_init = NA, ratio_R_init = NA, zES, zmax, iday, ... )run_model_water_balance_init_states(x, ...) ## S3 method for class 'model_output' run_model_water_balance_init_states(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_init_states( x, theta_fc, R_init = NA, ratio_R_init = NA, zES, zmax, iday, ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
theta_fc |
numeric Soil field capacity (volumetric water content). |
R_init |
numeric Initial soil water reserve (mm). |
ratio_R_init |
numeric Percentage of soil water reserve (R) at the beginning of the simulation. |
zES |
numeric Depth of soil evaporation front (m). |
zmax |
numeric Maximum root or soil depth. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute other daily variables related to water balance, such as actual evapotranspiration (ETR), water reserve (R) over all soil layers, available water capacity (RU) over all soil layers, total available water capacity (RUmax) over all soil layers.
run_model_water_balance_others(x, ...)run_model_water_balance_others(x, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to route water (precipitation and irrigation) through the soil layers during daily water balance.
run_model_water_balance_routing_water(x, ...) ## S3 method for class 'model_output' run_model_water_balance_routing_water(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_routing_water( x, ratio_R_init, R_init, zmax, theta_fc, iday, R0 = NULL, ... )run_model_water_balance_routing_water(x, ...) ## S3 method for class 'model_output' run_model_water_balance_routing_water(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_routing_water( x, ratio_R_init, R_init, zmax, theta_fc, iday, R0 = NULL, ... )
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
ratio_R_init |
numeric initial reservoir ratio (in %) |
R_init |
numeric initial reservoir volume (in mm) |
zmax |
numeric maximum soil root depth (in m) |
theta_fc |
numeric Soil field capacity (volumetric water content). |
R0 |
numeric Optional initial soil water reservoir used when routing water for the current simulation day. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to compute transpiration (TP) during daily water balance.
run_model_water_balance_TP(x, ...) ## S3 method for class 'model_output' run_model_water_balance_TP(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_TP(x, theta_r, theta_wp, theta_raw, iday, ...)run_model_water_balance_TP(x, ...) ## S3 method for class 'model_output' run_model_water_balance_TP(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_TP(x, theta_r, theta_wp, theta_raw, iday, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
theta_r |
numeric Residual soil water content ( |
theta_wp |
numeric Volumetric soil water content at wilting
point ( |
theta_raw |
numeric Differencial of soil water content between readily available water and actual water content. |
An object of class model_output with updated daily variables.
Generic and method-specific functions to update soil hydric states (z, theta, R) with updated root depth (zroot).
run_model_water_balance_update_R(x, ...) ## S3 method for class 'model_output' run_model_water_balance_update_R(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_update_R(x, zES, zmax, iday, ...)run_model_water_balance_update_R(x, ...) ## S3 method for class 'model_output' run_model_water_balance_update_R(x, soil, iday, ...) ## S3 method for class 'matrix' run_model_water_balance_update_R(x, zES, zmax, iday, ...)
x |
Input object. Must be of class |
... |
Additional arguments passed to methods. |
soil |
list Soil parameters. |
iday |
integer Current day index of the simulation. |
zES |
numeric Depth of soil evaporation front (m). |
zmax |
numeric Maximum root or soil depth. |
Generic function to save model outputs. This function dispatches methods based on the class of the input object x.
save_model_outputs(x, ...) ## S3 method for class 'model_outputs' save_model_outputs(x, ...) ## S3 method for class 'model_output' save_model_outputs(x, ...) ## S3 method for class 'matrix' save_model_outputs(x, run_id, path_outputs, overwrite, ...) ## S3 method for class 'data.frame' save_model_outputs(x, run_id, path_outputs, overwrite, ...)save_model_outputs(x, ...) ## S3 method for class 'model_outputs' save_model_outputs(x, ...) ## S3 method for class 'model_output' save_model_outputs(x, ...) ## S3 method for class 'matrix' save_model_outputs(x, run_id, path_outputs, overwrite, ...) ## S3 method for class 'data.frame' save_model_outputs(x, run_id, path_outputs, overwrite, ...)
x |
An object containing model outputs to be saved. Supported classes include
|
... |
Additional arguments passed to specific methods. |
run_id |
character string specifying the run identifier (required for the |
path_outputs |
character directory where outputs will be saved (required for the |
overwrite |
logical whether to overwrite existing files (required for the |
The result of the method dispatched for the class of x.
Generic and method-specific functions to select specific variables from model outputs.
select_output_vars(x, ...) ## S3 method for class 'matrix' select_output_vars(x, dates, vars = NULL, ...)select_output_vars(x, ...) ## S3 method for class 'matrix' select_output_vars(x, dates, vars = NULL, ...)
x |
Input object. Must be a |
... |
Additional arguments passed to methods. |
dates |
lubridate::Date Vector of dates corresponding to the rows of |
vars |
character Names of variables to select. If |
An object of the same class as x with selected variables.