summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRanke Johannes <johannes.ranke@agroscope.admin.ch>2024-12-16 10:31:41 +0100
committerRanke Johannes <johannes.ranke@agroscope.admin.ch>2024-12-16 10:31:41 +0100
commitb0491cb4953ae752b7d14b1085222defee3b4505 (patch)
tree47e525db000778aee681faa32b6696376ae8cda1
parent72b426cc767e9737cc66e3d41edb064011ab009d (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.
-rw-r--r--DESCRIPTION4
-rw-r--r--NEWS.md4
-rw-r--r--R/PEC_sw_drainage_UK.R25
-rw-r--r--log/build.log4
-rw-r--r--log/check.log30
-rw-r--r--log/test.log10
-rw-r--r--man/PEC_sw_drainage_UK.Rd3
-rw-r--r--tests/testthat/test_UK_drainage.R8
8 files changed, 55 insertions, 33 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index e0f6664..a51e404 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
Package: pfm
Type: Package
Title: Utilities for Pesticide Fate Modelling
-Version: 0.6.3
-Date: 2024-08-26
+Version: 0.6.4
+Date: 2024-12-16
Authors@R: person("Johannes Ranke", email = "johannes.ranke@agroscope.admin.ch",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4371-6538"))
diff --git a/NEWS.md b/NEWS.md
index d8c5cd2..193514e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,7 @@
+## version 0.6.4
+
+- R/PEC_sw_drainage_uk.R: Fix a bug leading to increased PEC values in the case the application date is after the beginning of the drainage period and `soil_DT50` was specified.
+
## version 0.6.3
- R/{PEC_sw_drift,PEC_sw_exposit_runoff,PEC_sw_sed}.R: Make use of the `units` package.
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
+ }
}
}
diff --git a/log/build.log b/log/build.log
index d5832bf..45bd696 100644
--- a/log/build.log
+++ b/log/build.log
@@ -4,5 +4,7 @@
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* re-saving image files
-* building ‘pfm_0.6.3.tar.gz’
+* building ‘pfm_0.6.4.tar.gz’
+Warning: invalid uid value replaced by that for user 'nobody'
+Warning: invalid gid value replaced by that for user 'nobody'
diff --git a/log/check.log b/log/check.log
index c4dbfac..85a4ddc 100644
--- a/log/check.log
+++ b/log/check.log
@@ -1,5 +1,5 @@
-* using log directory ‘/home/agsad.admin.ch/f80868656/projects/pfm/pfm.Rcheck’
-* using R version 4.4.1 (2024-06-14)
+* using log directory ‘/home/f80868656@agsad.admin.ch/projects/pfm/pfm.Rcheck’
+* using R version 4.4.2 (2024-10-31)
* using platform: x86_64-pc-linux-gnu
* R was compiled by
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
@@ -9,14 +9,12 @@
* using options ‘--no-tests --as-cran’
* checking for file ‘pfm/DESCRIPTION’ ... OK
* checking extension type ... Package
-* this is package ‘pfm’ version ‘0.6.3’
+* this is package ‘pfm’ version ‘0.6.4’
* package encoding: UTF-8
* checking CRAN incoming feasibility ... NOTE
Maintainer: ‘Johannes Ranke <johannes.ranke@agroscope.admin.ch>’
-The Date field is over a month old.
-
-Size of tarball: 8532216 bytes
+Size of tarball: 8532039 bytes
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
@@ -31,10 +29,10 @@ Size of tarball: 8532216 bytes
sub-directories of 1Mb or more:
testdata 9.9Mb
* checking package directory ... OK
-* checking for future file timestamps ... OK
+* checking for future file timestamps ... NOTE
+unable to verify current time
* checking DESCRIPTION meta-information ... OK
-* checking top-level files ... NOTE
-Files ‘README.md’ or ‘NEWS.md’ cannot be checked without ‘pandoc’ being installed.
+* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
@@ -51,7 +49,7 @@ Files ‘README.md’ or ‘NEWS.md’ cannot be checked without ‘pandoc’ be
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
-* checking R code for possible problems ... [16s/12s] OK
+* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd line widths ... OK
@@ -65,7 +63,13 @@ Files ‘README.md’ or ‘NEWS.md’ cannot be checked without ‘pandoc’ be
* checking data for non-ASCII characters ... OK
* checking LazyData ... OK
* checking data for ASCII and uncompressed saves ... OK
-* checking examples ... [17s/18s] OK
+* checking examples ... NOTE
+Examples with CPU (user + system) or elapsed time > 5s
+ user system elapsed
+one_box 1.287 4.642 0.795
+max_twa 1.121 4.715 0.586
+sawtooth 1.272 4.425 0.740
+plot.one_box 1.271 4.314 0.706
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ... SKIPPED
* checking PDF version of manual ... OK
@@ -75,8 +79,8 @@ Skipping checking HTML validation: no command 'tidy' found
* checking for detritus in the temp directory ... OK
* DONE
-Status: 4 NOTEs
+Status: 5 NOTEs
See
- ‘/home/agsad.admin.ch/f80868656/projects/pfm/pfm.Rcheck/00check.log’
+ ‘/home/f80868656@agsad.admin.ch/projects/pfm/pfm.Rcheck/00check.log’
for details.
diff --git a/log/test.log b/log/test.log
index 5f60406..367d456 100644
--- a/log/test.log
+++ b/log/test.log
@@ -2,17 +2,17 @@
✔ | F W S OK | Context
✔ | 7 | Exposit calculations
✔ | 6 | Geometric mean calculation
-✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions [2.0s]
+✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions
✔ | 1 | Simple PEC sediment calculations
✔ | 17 | Simple PEC soil calculations
✔ | 8 | Simple PEC surface water calculations with drift entry
✔ | 1 | Actual and time weighted average concentrations for SFO kinetics
✔ | 9 | FOCUS Step 1 calculations
✔ | 8 | FOCUS Steps 12 input files
-✔ | 7 | Read and analyse TOXSWA cwa files [6.3s]
-✔ | 12 | UK drainage PEC calculations
+✔ | 7 | Read and analyse TOXSWA cwa files [4.8s]
+✔ | 13 | UK drainage PEC calculations
══ Results ═════════════════════════════════════════════════════════════════════════════════════════
-Duration: 9.5 s
+Duration: 6.6 s
-[ FAIL 0 | WARN 0 | SKIP 0 | PASS 77 ]
+[ FAIL 0 | WARN 0 | SKIP 0 | PASS 78 ]
diff --git a/man/PEC_sw_drainage_UK.Rd b/man/PEC_sw_drainage_UK.Rd
index f3d6169..058e068 100644
--- a/man/PEC_sw_drainage_UK.Rd
+++ b/man/PEC_sw_drainage_UK.Rd
@@ -35,7 +35,8 @@ The predicted concentration in surface water in µg/L
}
\description{
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
+\code{latest_application} is specified and the degradation parameters are given either as a \code{soil_DT50} or a \code{model}.
}
\examples{
PEC_sw_drainage_UK(150, Koc = 100)
diff --git a/tests/testthat/test_UK_drainage.R b/tests/testthat/test_UK_drainage.R
index 2789819..05c59b2 100644
--- a/tests/testthat/test_UK_drainage.R
+++ b/tests/testthat/test_UK_drainage.R
@@ -33,4 +33,12 @@ test_that("UK drainflow PECs are correct", {
expect_equal(round(PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550,
latest_application = "01 July",
soil_DT50 = 200), 2), 0.84)
+
+ # Test that PECsw do not increase if the application is after the beginning
+ # of the drainflow period
+ expect_equal(
+ PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550),
+ PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550,
+ latest_application = "01 November", soil_DT50 = 200))
+
})

Contact - Imprint