From c97a4f5a9fe30ffc3321681a97eea167cfc427b5 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 23 Jul 2020 12:22:25 +0200 Subject: PEC_sw_drift: Rautmann formula (1 app, Ackerbau) This makes it possible to calculate drift PECsw for other distances than present in the JKI data or the Rautmann paper. --- ChangeLog | 6 ++++ R/PEC_sw_drift.R | 43 ++++++++++++++++++++------- build.log | 2 +- docs/404.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/pkgdown.yml | 2 +- docs/reference/PEC_sw_drift.html | 61 ++++++++++++++++++++++---------------- docs/reference/drift_data_JKI.html | 6 ++-- docs/reference/index.html | 2 +- man/PEC_sw_drift.Rd | 14 +++++++-- man/drift_data_JKI.Rd | 2 +- test.log | 8 ++--- tests/testthat/test_PEC_sw_drift.R | 23 +++++++++++--- 14 files changed, 119 insertions(+), 56 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58e9249..6767e33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +commit 90fa42c86596c85168931148bf8d5fa014fa7794 +Author: Johannes Ranke +Date: 2020-07-23 10:51:39 +0200 + + Update docs, use R6 support of roxygen + commit df70d80d9ef13b69e58de6f47b9041b6a021025e Author: Johannes Ranke Date: 2020-07-21 15:50:21 +0200 diff --git a/R/PEC_sw_drift.R b/R/PEC_sw_drift.R index 6fcaecf..2dfd651 100644 --- a/R/PEC_sw_drift.R +++ b/R/PEC_sw_drift.R @@ -8,7 +8,9 @@ #' @param applications Number of applications for selection of drift percentile #' @param drift_percentages Percentage drift values for which to calculate PECsw. #' 'drift_data' and 'distances' if not NULL. -#' @param drift_data Source of drift percentage data +#' @param drift_data Source of drift percentage data. If 'JKI', the [drift_data_JKI] +#' included in the package is used. If 'RF', the Rautmann formula is used, if +#' implemented for the crop type and number of applications #' @param crop Crop name (use German names for JKI data), defaults to "Ackerbau" #' @param distances The distances in m for which to get PEC values #' @param water_depth Depth of the water body in cm @@ -19,15 +21,23 @@ #' @author Johannes Ranke #' @examples #' PEC_sw_drift(100) -PEC_sw_drift <- function(rate, - applications = 1, - water_depth = 30, - drift_percentages = NULL, - drift_data = "JKI", - crop = "Ackerbau", - distances = c(1, 5, 10, 20), - rate_units = "g/ha", - PEC_units = "\u00B5g/L") +#' # Alternatively, we can use the formula for a single application to "Ackerbau" from the paper +#' PEC_sw_drift(100, drift_data = "RF") +#' +#' # This makes it possible to also use different substances +#' PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF") +#' +#' # Using custom drift percentages is also supported +#' PEC_sw_drift(100, drift_percentages = c(2.77, 0.95, 0.57, 0.48, 0.29, 0.15, 0.06, 0.03)) +PEC_sw_drift <- function(rate, + applications = 1, + water_depth = 30, + drift_percentages = NULL, + drift_data = c("JKI", "RF"), + crop = "Ackerbau", + distances = c(1, 5, 10, 20), + rate_units = "g/ha", + PEC_units = "\u00B5g/L") { rate_units <- match.arg(rate_units) PEC_units <- match.arg(PEC_units) @@ -36,8 +46,19 @@ PEC_sw_drift <- function(rate, PEC_sw_overspray <- rate * 1e6 / water_volume # in µg/L dist_index <- as.character(distances) + RF <- list( + "1" = list("Ackerbau" = function(distance) 2.7705 * distance^-0.9787) # p. 134 + ) + if (drift_data == "RF") { + if (is.null(RF[[as.character(applications)]])) stop("Rautmann formula not included for ", applications, " applications") + if (is.null(RF[[as.character(applications)]][[crop]])) stop("Rautmann formula not included for this case") + } + if (is.null(drift_percentages)) { - drift_percentages <- pfm::drift_data_JKI[[applications]][dist_index, crop] + drift_percentages <- switch(drift_data, + JKI = pfm::drift_data_JKI[[applications]][dist_index, crop], + RF = RF[[applications]][[crop]](distances) + ) names(drift_percentages) <- paste(dist_index, "m") } else { names(drift_percentages) <- paste(drift_percentages, "%") diff --git a/build.log b/build.log index 08c031a..5dccfd7 100644 --- a/build.log +++ b/build.log @@ -8,5 +8,5 @@ Removed empty directory ‘pfm/inst/testdata/SwashProjects/Project_1’ Removed empty directory ‘pfm/inst/testdata/SwashProjects’ NB: this package now depends on R (>= 3.5.0) WARNING: Added dependency on R >= 3.5.0 because serialized objects in serialize/load version 3 cannot be read in older versions of R. File(s) containing such objects: ‘pfm/data/EFSA_GW_interception_2014.RData’ WARNING: Added dependency on R >= 3.5.0 because serialized objects in serialize/load version 3 cannot be read in older versions of R. File(s) containing such objects: ‘pfm/data/EFSA_washoff_2017.RData’ -* building ‘pfm_0.5.7.tar.gz’ +* building ‘pfm_0.5.8.tar.gz’ diff --git a/docs/404.html b/docs/404.html index 37f381e..a98212e 100644 --- a/docs/404.html +++ b/docs/404.html @@ -71,7 +71,7 @@ pfm - 0.5.7 + 0.5.8 diff --git a/docs/authors.html b/docs/authors.html index da75377..d886f2a 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -71,7 +71,7 @@ pfm - 0.5.7 + 0.5.8 diff --git a/docs/index.html b/docs/index.html index 6ffb312..05e6106 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,7 +33,7 @@ pfm - 0.5.7 + 0.5.8 diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 8b86fe9..cfe1fde 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: 2.2.1 pkgdown: 1.5.1 pkgdown_sha: ~ articles: [] -last_built: 2020-07-22T15:06Z +last_built: 2020-07-23T09:34Z urls: reference: https://pkgdown.jrwb.de/pfm/reference article: https://pkgdown.jrwb.de/pfm/articles diff --git a/docs/reference/PEC_sw_drift.html b/docs/reference/PEC_sw_drift.html index 302ab0d..e2c325b 100644 --- a/docs/reference/PEC_sw_drift.html +++ b/docs/reference/PEC_sw_drift.html @@ -10,23 +10,27 @@ - + - + - + + + + + - - + + - + - - + + @@ -39,7 +43,6 @@ - @@ -57,7 +60,7 @@ with input via spray drift." /> - +
@@ -118,7 +121,7 @@ with input via spray drift.

applications = 1, water_depth = 30, drift_percentages = NULL, - drift_data = "JKI", + drift_data = c("JKI", "RF"), crop = "Ackerbau", distances = c(1, 5, 10, 20), rate_units = "g/ha", @@ -147,7 +150,9 @@ with input via spray drift.

drift_data -

Source of drift percentage data

+

Source of drift percentage data. If 'JKI', the [drift_data_JKI] +included in the package is used. If 'RF', the Rautmann formula is used, if +implemented for the crop type and number of applications

crop @@ -173,18 +178,24 @@ with input via spray drift.

Examples

PEC_sw_drift(100)
#> 1 m 5 m 10 m 20 m -#> 0.92333333 0.19000000 0.09666667 0.05000000
+#> 0.92333333 0.19000000 0.09666667 0.05000000
# Alternatively, we can use the formula for a single application to "Ackerbau" from the paper +PEC_sw_drift(100, drift_data = "RF")
#> 1 m 5 m 10 m 20 m +#> 0.92350000 0.19114149 0.09699222 0.04921742
+# This makes it possible to also use different substances +PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF")
#> 1 m 3 m 5 m 6 m 10 m 20 m 50 m +#> 0.92350000 0.31512171 0.19114149 0.15990435 0.09699222 0.04921742 0.02007497 +#> 100 m +#> 0.01018678
+# Using custom drift percentages is also supported +PEC_sw_drift(100, drift_percentages = c(2.77, 0.95, 0.57, 0.48, 0.29, 0.15, 0.06, 0.03))
#> 2.77 % 0.95 % 0.57 % 0.48 % 0.29 % 0.15 % 0.06 % +#> 0.92333333 0.31666667 0.19000000 0.16000000 0.09666667 0.05000000 0.02000000 +#> 0.03 % +#> 0.01000000
- @@ -195,7 +206,7 @@ with input via spray drift.

-

Site built with pkgdown 1.4.1.

+

Site built with pkgdown 1.5.1.

diff --git a/docs/reference/drift_data_JKI.html b/docs/reference/drift_data_JKI.html index dd78451..36472d1 100644 --- a/docs/reference/drift_data_JKI.html +++ b/docs/reference/drift_data_JKI.html @@ -75,7 +75,7 @@ published by the German Julius-Kühn Institute (JKI)." /> pfm - 0.5.7 + 0.5.8 @@ -162,7 +162,7 @@ included.

drift_data_JKI <- list() for (n in 1:8) { - drift_data_raw <- read_excel(abdrift_path, sheet = n + 1, skip = 2) + drift_data_raw <- read_excel(abdrift_path, sheet = n + 1, skip = 2) drift_data <- matrix(NA, nrow = 9, ncol = length(JKI_crops)) dimnames(drift_data) <- list(distance = drift_data_raw[[1]][1:9], crop = JKI_crops) @@ -196,7 +196,7 @@ included.

save(drift_data_JKI, file = "data/drift_data_JKI.RData") } -# And this is the resulting data +# And these are the resulting data drift_data_JKI
#> [[1]] #> crop #> distance Ackerbau Obstbau frueh Obstbau spaet Weinbau frueh Weinbau spaet diff --git a/docs/reference/index.html b/docs/reference/index.html index 186390e..9473a2d 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -71,7 +71,7 @@ pfm - 0.5.7 + 0.5.8
diff --git a/man/PEC_sw_drift.Rd b/man/PEC_sw_drift.Rd index cde3c78..92e0f77 100644 --- a/man/PEC_sw_drift.Rd +++ b/man/PEC_sw_drift.Rd @@ -9,7 +9,7 @@ PEC_sw_drift( applications = 1, water_depth = 30, drift_percentages = NULL, - drift_data = "JKI", + drift_data = c("JKI", "RF"), crop = "Ackerbau", distances = c(1, 5, 10, 20), rate_units = "g/ha", @@ -26,7 +26,9 @@ PEC_sw_drift( \item{drift_percentages}{Percentage drift values for which to calculate PECsw. 'drift_data' and 'distances' if not NULL.} -\item{drift_data}{Source of drift percentage data} +\item{drift_data}{Source of drift percentage data. If 'JKI', the [drift_data_JKI] +included in the package is used. If 'RF', the Rautmann formula is used, if +implemented for the crop type and number of applications} \item{crop}{Crop name (use German names for JKI data), defaults to "Ackerbau"} @@ -46,6 +48,14 @@ with input via spray drift. } \examples{ PEC_sw_drift(100) +# Alternatively, we can use the formula for a single application to "Ackerbau" from the paper +PEC_sw_drift(100, drift_data = "RF") + +# This makes it possible to also use different substances +PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF") + +# Using custom drift percentages is also supported +PEC_sw_drift(100, drift_percentages = c(2.77, 0.95, 0.57, 0.48, 0.29, 0.15, 0.06, 0.03)) } \author{ Johannes Ranke diff --git a/man/drift_data_JKI.Rd b/man/drift_data_JKI.Rd index 181eca6..bde9aad 100644 --- a/man/drift_data_JKI.Rd +++ b/man/drift_data_JKI.Rd @@ -89,7 +89,7 @@ included. save(drift_data_JKI, file = "data/drift_data_JKI.RData") } -# And this is the resulting data +# And these are the resulting data drift_data_JKI } \keyword{datasets} diff --git a/test.log b/test.log index ac21026..07617f9 100644 --- a/test.log +++ b/test.log @@ -5,9 +5,9 @@ Testing pfm ✔ | OK F W S | Context ✔ | 1 | Simple PEC sediment calculations ✔ | 17 | Simple PEC soil calculations [0.2 s] -✔ | 2 | Simple PEC surface water calculations with drift entry +✔ | 6 | Simple PEC surface water calculations with drift entry ✔ | 1 | Actual and time weighted average concentrations for SFO kinetics -✔ | 7 | Read and analyse TOXSWA cwa files [6.6 s] +✔ | 7 | Read and analyse TOXSWA cwa files [6.0 s] ✔ | 12 | UK drainage PEC calculations ✔ | 7 | Exposit calculations ✔ | 6 | Geometric mean calculation @@ -17,9 +17,9 @@ Testing pfm ✔ | 8 | FOCUS Steps 12 input files ══ Results ═════════════════════════════════════════════════════════════════════════════════════════ -Duration: 8.2 s +Duration: 7.5 s -OK: 82 +OK: 86 Failed: 0 Warnings: 0 Skipped: 0 diff --git a/tests/testthat/test_PEC_sw_drift.R b/tests/testthat/test_PEC_sw_drift.R index d09d578..667b402 100644 --- a/tests/testthat/test_PEC_sw_drift.R +++ b/tests/testthat/test_PEC_sw_drift.R @@ -3,13 +3,28 @@ context("Simple PEC surface water calculations with drift entry") test_that("PEC_sw_drift gives the same results as the CRD PEC calculator", { # One application of 30 g/ha to field crops calculated with UK PEC calculator published by CRD - expect_equal(round(PEC_sw_drift(30), 3), + expect_equal(round(PEC_sw_drift(30), 3), c('1 m' = 0.277, '5 m' = 0.057, '10 m' = 0.029, '20 m' = 0.015)) # 7 applications of 30 g/ha to field crops calculated with UK PEC calculator, initial PEC - expect_equal(round(PEC_sw_drift(30, 7), 3), + expect_equal(round(PEC_sw_drift(30, 7), 3), c('1 m' = 0.161, '5 m' = 0.033, '10 m' = 0.017, '20 m' = 0.008)) - # 4 applications of 30 g/ha to late fruit crops calculated with UK PEC calculator published by CRD (uses different drift values from SANCO aquatic guidance) - #expect_equal(round(PEC_sw_drift(30, 4, crop = "Obstbau spät", distances = c(3, 20, 50)), 3), c('3 m' = 1.101, '20 m' = 0.080, '50 m' = 0.013)) + # 4 applications of 30 g/ha to late fruit crops calculated with UK PEC + # calculator published by CRD. CRD uses different drift values from SANCO aquatic + # guidance), except for 50 m + pfm_30_4_obst_spaet <- round(PEC_sw_drift(30, 4, crop = "Obstbau spaet", + distances = c(3, 20, 50)), 3) + crd_30_4_obst_spaet <- c('3 m' = 1.101, '20 m' = 0.080, '50 m' = 0.013) + expect_equal(pfm_30_4_obst_spaet[3], crd_30_4_obst_spaet[3]) +}) + +test_that("The Rautmann formula is correctly implemented", { + pfm_jki <- PEC_sw_drift(100) + pfm_rf <- PEC_sw_drift(100, drift_data = "RF") + expect_equal(pfm_jki, pfm_rf, tolerance = 0.01) + + expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 2), "Rautmann formula not included") + expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop = "Obstbau spaet"), + "Rautmann formula not included") }) -- cgit v1.2.1