diff options
author | Ranke Johannes <johannes.ranke@agroscope.admin.ch> | 2024-12-16 10:31:41 +0100 |
---|---|---|
committer | Ranke Johannes <johannes.ranke@agroscope.admin.ch> | 2024-12-16 10:31:41 +0100 |
commit | b0491cb4953ae752b7d14b1085222defee3b4505 (patch) | |
tree | 47e525db000778aee681faa32b6696376ae8cda1 /R/PEC_sw_drainage_UK.R | |
parent | 72b426cc767e9737cc66e3d41edb064011ab009d (diff) |
Fix a bug in UK drainage calculations
If a soil_DT50 was specified, and the application date was later than
the beginning of the drainage period (1 October), PECsw would increase.
Now the amount available at the time of the drainage period is equal
to the applied amount (minus interception) if application is later than
the beginning of the drainage period. Fixes #4. Thanks to @lutzeli for
spotting the problem.
Diffstat (limited to 'R/PEC_sw_drainage_UK.R')
-rw-r--r-- | R/PEC_sw_drainage_UK.R | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/R/PEC_sw_drainage_UK.R b/R/PEC_sw_drainage_UK.R index d773f40..b935dea 100644 --- a/R/PEC_sw_drainage_UK.R +++ b/R/PEC_sw_drainage_UK.R @@ -1,7 +1,8 @@ #' Calculate initial predicted environmental concentrations in surface water due to drainage using the UK method #' #' This implements the method specified in the UK data requirements handbook and was checked against the spreadsheet -#' published on the CRC website +#' 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 interception The fraction of the application rate that does not reach the soil @@ -37,17 +38,19 @@ PEC_sw_drainage_UK <- function(rate, interception = 0, Koc, latest <- as.Date(paste(latest_application, "1999"), "%d %b %Y") tmp <- Sys.setlocale("LC_TIME", lct) degradation_time <- as.numeric(difftime(as.Date("1999-10-01"), units = "days", latest)) - if (!missing(soil_DT50)) { - k = log(2)/soil_DT50 - as.Date(paste(latest_application, "1999"), "%d %B %Y") + if (degradation_time > 0) { + if (!missing(soil_DT50)) { + k = log(2)/soil_DT50 + 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, - times = degradation_time)[1, "parent"] - amount_available <- fraction_left * amount_available + 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, + times = degradation_time)[1, "parent"] + amount_available <- fraction_left * amount_available + } } } |