diff options
| author | Johannes Ranke <johannes.ranke@jrwb.de> | 2026-02-06 17:52:07 +0100 |
|---|---|---|
| committer | Johannes Ranke <johannes.ranke@jrwb.de> | 2026-02-06 17:52:07 +0100 |
| commit | 4134a2aa07b819a6dbe59129880402395c7a484a (patch) | |
| tree | 1c70d07f19629bfe9580de396406118747584cdf /R | |
| parent | 8fd8f9c04492cce60c1cd1e6b9a53057990ec31e (diff) | |
| parent | 1bbaa8ecc33d70e84a8e2c8ece4619ef3aa60029 (diff) | |
Merge branch 'UK_drainage_with_units' into patch-1
Diffstat (limited to 'R')
| -rw-r--r-- | R/PEC_sw_drainage_UK.R | 50 | ||||
| -rw-r--r-- | R/PEC_sw_exposit.R | 3 | ||||
| -rw-r--r-- | R/TOXSWA_cwa.R | 2 |
3 files changed, 36 insertions, 19 deletions
diff --git a/R/PEC_sw_drainage_UK.R b/R/PEC_sw_drainage_UK.R index 2c7e28f..d5f0bab 100644 --- a/R/PEC_sw_drainage_UK.R +++ b/R/PEC_sw_drainage_UK.R @@ -4,11 +4,14 @@ #' published on the CRC website. Degradation before the start of the drainage period is taken into account if #' `latest_application` is specified and the degradation parameters are given either as a `soil_DT50` or a `model`. #' -#' @param rate Application rate in g/ha +#' @param rate Application rate in g/ha or with a compatible unit specified +#' with the units package #' @param interception The fraction of the application rate that does not reach the soil -#' @param Koc The sorption coefficient normalised to organic carbon in L/kg +#' @param Koc The sorption coefficient normalised to organic carbon in L/kg or a unit specified +#' with the units package #' @param latest_application Latest application date, formatted as e.g. "01 July" -#' @param soil_DT50 Soil degradation half-life, if SFO kinetics are to be used +#' @param soil_DT50 Soil degradation half-life, if SFO kinetics are to be used, in +#' days or a time unit specified with the units package #' @param model The soil degradation model to be used. Either one of "FOMC", #' "DFOP", "HS", or "IORE", or an mkinmod object #' @param model_parms A named numeric vector containing the model parameters @@ -27,42 +30,55 @@ #' PEC_sw_drainage_UK(150, Koc = 100) #' PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550, #' latest_application = "01 July", soil_DT50 = 200) - -PEC_sw_drainage_UK <- function(rate, interception = 0, Koc, - latest_application = NULL, soil_DT50 = NULL, - model = NULL, model_parms = NULL) +PEC_sw_drainage_UK <- function(rate, + interception = 0, Koc, + latest_application = NULL, soil_DT50 = NULL, + model = NULL, model_parms = NULL) { - percentage_lost <- SSLRC_mobility_classification(Koc)[[2]] - if (inherits(rate, "units") && !identical(as.character(units(rate)), "g/ha")) stop("rate must have units g/ha, not ", units(rate)) - amount_available <- as.numeric(rate) * (1 - interception) # g/ha + # Set default units if not specified and convert to units used in the calculations + if (!inherits(rate, "units")) rate <- set_units(rate, "g/ha") + rate_g_ha <- as.numeric(set_units(rate, "g/ha")) + + if (!inherits(Koc, "units")) Koc <- set_units(Koc, "L/kg") + Koc_L_kg <- as.numeric(set_units(Koc, "L/kg")) + + if (!missing(soil_DT50)) { + if (!inherits(soil_DT50, "units")) { + soil_DT50_d <- soil_DT50 + } + soil_DT50_d <- as.numeric(set_units(soil_DT50, "d")) + } + + percentage_lost <- SSLRC_mobility_classification(Koc_L_kg)[[2]] + amount_available <- rate_g_ha * (1 - interception) # amount in g for 1 ha if (!missing(latest_application)) { lct <- Sys.getlocale("LC_TIME") tmp <- Sys.setlocale("LC_TIME", "C") - if (latest_application == "29 February") { + if (latest_application == "29 February") { # Use a leap year ref_year <- 2000 - } else { ref_year <- 1999} + } else { ref_year <- 1999} # Use a non-leap year latest <- as.Date(paste(latest_application, ref_year), "%d %b %Y") if (is.na(latest)) stop("Please specify the latest application in the format '%d %b', e.g. '01 July'") tmp <- Sys.setlocale("LC_TIME", lct) degradation_time <- as.numeric(difftime(as.Date(paste0(ref_year,"-10-01")), units = "days", latest)) if (degradation_time > 0) { if (!missing(soil_DT50)) { - k = log(2)/soil_DT50 + k = log(2)/soil_DT50_d as.Date(paste(latest_application, "1999"), "%d %B %Y") amount_available <- amount_available * exp(-k * degradation_time) if (!missing(model)) stop("You already supplied a soil_DT50 value, implying SFO kinetics") - } + } if (!missing(model)) { - fraction_left <- pfm_degradation(model, parms = model_parms, + fraction_left <- pfm_degradation(model, parms = model_parms, times = degradation_time)[1, "parent"] amount_available <- fraction_left * amount_available } } - } + } volume = 130000 # L/ha - PEC = set_units(1e6 * (percentage_lost/100) * amount_available / volume, "µg/L") + PEC = set_units(1e6 * (percentage_lost/100) * amount_available / volume, "\u00B5g/L") return(PEC) } diff --git a/R/PEC_sw_exposit.R b/R/PEC_sw_exposit.R index 282a1ac..a157189 100644 --- a/R/PEC_sw_exposit.R +++ b/R/PEC_sw_exposit.R @@ -52,7 +52,8 @@ #' #' @importFrom units as_units set_units drop_units #' @importFrom dplyr across mutate -#' @param rate The application rate in g/ha +#' @param rate Application rate in g/ha or with a compatible unit specified +#' with the units package #' @param interception The fraction intercepted by the crop #' @param Koc The sorption coefficient to soil organic carbon #' @param DT50 The soil half-life in days diff --git a/R/TOXSWA_cwa.R b/R/TOXSWA_cwa.R index b132beb..b2f7619 100644 --- a/R/TOXSWA_cwa.R +++ b/R/TOXSWA_cwa.R @@ -147,7 +147,7 @@ plot.TOXSWA_cwa <- function(x, time_column = c("datetime", "t", "t_firstjan", "t #' and some associated statistics. like maximum moving window average #' concentrations, and dataframes holding the events exceeding specified #' thresholds. Usually, an instance of this class will be generated -#' by \code{\link{read.TOXSWA_cwa}}. +#' by [read.TOXSWA_cwa]. #' #' @export #' @format An [R6::R6Class] generator object. |
