aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2024-04-10 16:32:06 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2024-04-10 16:32:06 +0200
commit9e62ed638e530a5cebebf491de055caca49a56ef (patch)
treeb65c10389b80e69fcbfd36dcbae35c239d06e720
parentdd203e9f266e50bb457bc0fc247267115ae941d2 (diff)
Improve docs, fail with erroneus crop_group arguments
PEC_sw_drift: The argument 'crop_group_focus' was renamed to 'crop_group_RF' to make it easier to understand the relation to the 'drift_data' argument.
-rw-r--r--DESCRIPTION4
-rw-r--r--R/PEC_sw_drift.R50
-rw-r--r--R/PEC_sw_exposit_runoff.R8
-rw-r--r--log/build.log2
-rw-r--r--log/check.log25
-rw-r--r--log/test.log6
-rw-r--r--man/PEC_sw_drift.Rd12
-rw-r--r--man/PEC_sw_exposit_drainage.Rd8
-rw-r--r--man/drift_percentages_rautmann.Rd18
-rw-r--r--tests/testthat/test_PEC_sw_drift.R4
10 files changed, 73 insertions, 64 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index 95ab31e..2757d8b 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
Package: pfm
Type: Package
Title: Utilities for Pesticide Fate Modelling
-Version: 0.6.2
-Date: 2024-03-06
+Version: 0.6.3
+Date: 2024-04-10
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/R/PEC_sw_drift.R b/R/PEC_sw_drift.R
index 22aa012..c1b24d3 100644
--- a/R/PEC_sw_drift.R
+++ b/R/PEC_sw_drift.R
@@ -14,7 +14,7 @@
#' either in the original form or integrated over the width of the water body, depending
#' on the 'formula' argument.
#' @param crop_group_JKI When using the 'JKI' drift data, one of the German names
-#' as used in [drift_parameters_focus].
+#' as used in [drift_parameters_focus]. Will only be used if drift_data is 'JKI'.
#' @param water_depth Depth of the water body in cm
#' @param rate_units Defaults to g/ha
#' @param PEC_units Requested units for the calculated PEC. Only µg/L currently supported
@@ -34,13 +34,13 @@
#' PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF")
#'
#' # or consider aerial application
-#' PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF",
-#' crop_group_focus = "aerial")
+#' PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF",
+#' crop_group_RF = "aerial")
#'
#' # 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))
#'
-#' # The influence of assuming a 45° angle of the sides of the waterbody and the width of the
+#' # The influence of assuming a 45° angle of the sides of the waterbody and the width of the
#' # waterbody can be illustrated
#' PEC_sw_drift(100)
#' PEC_sw_drift(100, drift_data = "RF")
@@ -52,10 +52,10 @@ PEC_sw_drift <- function(rate,
water_depth = 30,
drift_percentages = NULL,
drift_data = c("JKI", "RF"),
- crop_group_JKI = c("Ackerbau",
+ crop_group_JKI = c("Ackerbau",
"Obstbau frueh", "Obstbau spaet", "Weinbau frueh", "Weinbau spaet",
"Hopfenbau", "Flaechenkulturen > 900 l/ha", "Gleisanlagen"),
- crop_group_focus = c("arable", "hops", "vines, late", "vines, early",
+ crop_group_RF = c("arable", "hops", "vines, late", "vines, early",
"fruit, late", "fruit, early", "aerial"),
distances = c(1, 5, 10, 20),
formula = c("Rautmann", "FOCUS"),
@@ -68,7 +68,13 @@ PEC_sw_drift <- function(rate,
PEC_units <- match.arg(PEC_units)
drift_data <- match.arg(drift_data)
crop_group_JKI <- match.arg(crop_group_JKI)
- crop_group_focus <- match.arg(crop_group_focus)
+ crop_group_RF <- match.arg(crop_group_RF)
+ if (drift_data == "JKI" & crop_group_RF != "arable") {
+ stop("Specifying crop_group_RF only makes sense if 'RF' is used for 'drift_data'")
+ }
+ if (drift_data == "RF" & crop_group_JKI != "Ackerbau") {
+ stop("Specifying crop_group_JKI only makes sense if 'JKI' is used for 'drift_data'")
+ }
formula <- match.arg(formula)
if (side_angle < 0 | side_angle > 90) stop("The side anglemust be between 0 and 90 degrees")
mean_water_width <- if (side_angle == 90) water_width
@@ -80,9 +86,9 @@ PEC_sw_drift <- function(rate,
if (is.null(drift_percentages)) {
drift_percentages <- switch(drift_data,
JKI = pfm::drift_data_JKI[[applications]][dist_index, crop_group_JKI],
- RF = drift_percentages_rautmann(distances, applications,
+ RF = drift_percentages_rautmann(distances, applications,
formula = formula,
- crop_group_focus, widths = water_width/100)
+ crop_group_RF, widths = water_width/100)
)
names(drift_percentages) <- paste(dist_index, "m")
} else {
@@ -101,14 +107,14 @@ PEC_sw_drift <- function(rate,
#' @param distances The distances in m for which to get PEC values
#' @param widths The widths of the water bodies (only used in the FOCUS formula)
#' @param applications Number of applications for selection of drift percentile
-#' @param crop_group_focus One of the crop groups as used in [drift_parameters_focus]
+#' @param crop_group_RF One of the crop groups as used in [drift_parameters_focus]
#' @seealso [drift_parameters_focus], [PEC_sw_drift]
#' @references FOCUS (2014) Generic guidance for Surface Water Scenarios (version 1.4).
#' FOrum for the Co-ordination of pesticde fate models and their USe.
#' <http://esdac.jrc.ec.europa.eu/public_path/projects_data/focus/sw/docs/Generic%20FOCUS_SWS_vc1.4.pdf>
#' @export
#' @examples
-#' # Compare JKI data with Rautmann formula
+#' # Compare JKI data with Rautmann and FOCUS formulas for arable crops (default)
#' # One application on field crops, for 1 m, 3 m and 5 m distance
#' drift_data_JKI[[1]][as.character(c(1, 3, 5)), "Ackerbau"]
#' drift_percentages_rautmann(c(1, 3, 5))
@@ -116,31 +122,31 @@ PEC_sw_drift <- function(rate,
#'
#' # One application to early or late fruit crops
#' drift_data_JKI[[1]][as.character(c(3, 5, 20, 50)), "Obstbau frueh"]
-#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, early")
-#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, early",
+#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, early")
+#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, early",
#' formula = "FOCUS")
#' drift_data_JKI[[1]][as.character(c(3, 5, 20, 50)), "Obstbau spaet"]
-#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, late")
-#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, late",
+#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, late")
+#' drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, late",
#' formula = "FOCUS")
-#'
+#'
#' # We get a continuum if the waterbody covers the hinge distance
#' # (11.4 m for 1 early app to fruit)
#' x <- seq(3, 30, by = 0.1)
-#' d <- drift_percentages_rautmann(x, crop_group = "fruit, early", formula = "FOCUS")
+#' d <- drift_percentages_rautmann(x, crop_group_RF = "fruit, early", formula = "FOCUS")
#' plot(x, d, type = "l",
-#' xlab = "Distance of near edge [m]",
+#' xlab = "Distance of near edge [m]",
#' ylab = "Mean drift percentage over waterbody width",
#' main = "One application to fruit, early")
#' abline(v = 11.4, lty = 2)
-drift_percentages_rautmann <- function(distances, applications = 1,
- crop_group_focus = c("arable", "hops", "vines, late", "vines, early", "fruit, late",
+drift_percentages_rautmann <- function(distances, applications = 1,
+ crop_group_RF = c("arable", "hops", "vines, late", "vines, early", "fruit, late",
"fruit, early", "aerial"),
formula = c("Rautmann", "FOCUS"),
widths = 1
)
{
- cg <- match.arg(crop_group_focus)
+ cg <- match.arg(crop_group_RF)
if (!applications %in% 1:8) stop("Only 1 to 8 applications are supported")
formula <- match.arg(formula)
@@ -161,7 +167,7 @@ drift_percentages_rautmann <- function(distances, applications = 1,
ifelse(z2 < hinge,
# farther edge closer than hinge distance
A/(widths * (B + 1)) * (z2^(B + 1) - z1^(B + 1)),
- ifelse(z1 < hinge,
+ ifelse(z1 < hinge,
# hinge distance in waterbody (between z1 and z2)
(A/(B + 1) * (H^(B + 1) - z1^(B + 1)) + C/(D + 1) * (z2^(D + 1) - H^(D + 1)))/widths,
# z1 >= hinge, i.e. near edge farther than hinge distance
diff --git a/R/PEC_sw_exposit_runoff.R b/R/PEC_sw_exposit_runoff.R
index 8b89cd9..877dd92 100644
--- a/R/PEC_sw_exposit_runoff.R
+++ b/R/PEC_sw_exposit_runoff.R
@@ -137,10 +137,10 @@ PEC_sw_exposit_runoff <- function(rate, interception = 0, Koc, DT50 = Inf, t_run
#' @param dilution The dilution factor
#' @return A list containing the following components
#' \describe{
-#' \item{perc_runoff}{The runoff percentages for dissolved and bound substance}
-#' \item{runoff}{A matrix containing dissolved and bound input for the different distances}
-#' \item{PEC_sw_runoff}{A matrix containing PEC values for dissolved and bound substance
-#' for the different distances. If the rate was given in g/ha, the PECsw are in microg/L.}
+#' \item{perc_drainage_total}{Gesamtaustrag (total fraction of the residue drained)}
+#' \item{perc_peak}{Stoßbelastung (fraction drained at event)}
+#' \item{PEC_sw_drainage}{A matrix containing PEC values for the spring and autumn
+#' scenarios. If the rate was given in g/ha, the PECsw are in microg/L.}
#' }
#' @export
#' @source Excel 3.02 spreadsheet available from
diff --git a/log/build.log b/log/build.log
index 2c3c139..edca7f6 100644
--- a/log/build.log
+++ b/log/build.log
@@ -3,5 +3,5 @@
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
-* building ‘pfm_0.6.2.tar.gz’
+* building ‘pfm_0.6.3.tar.gz’
diff --git a/log/check.log b/log/check.log
index 93948df..f6d14ce 100644
--- a/log/check.log
+++ b/log/check.log
@@ -1,22 +1,24 @@
-* using log directory ‘/home/agsad.admin.ch/f80868656/projects/pfm/pfm.Rcheck’
+* using log directory ‘/home/jranke/git/pfm/pfm.Rcheck’
* using R version 4.3.3 (2024-02-29)
* using platform: x86_64-pc-linux-gnu (64-bit)
* R was compiled by
- gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
-* running under: Ubuntu 22.04.4 LTS
+ gcc (Debian 12.2.0-14) 12.2.0
+ GNU Fortran (Debian 12.2.0-14) 12.2.0
+* running under: Debian GNU/Linux 12 (bookworm)
* using session charset: UTF-8
* using options ‘--no-tests --as-cran’
* checking for file ‘pfm/DESCRIPTION’ ... OK
* checking extension type ... Package
-* this is package ‘pfm’ version ‘0.6.2’
+* this is package ‘pfm’ version ‘0.6.3’
* package encoding: UTF-8
-* checking CRAN incoming feasibility ... [2s/14s] NOTE
+* checking CRAN incoming feasibility ... [1s/103s] NOTE
Maintainer: ‘Johannes Ranke <johannes.ranke@agroscope.admin.ch>’
-Size of tarball: 8530336 bytes
+Size of tarball: 8530180 bytes
* checking package namespace information ... OK
-* checking package dependencies ... OK
+* checking package dependencies ...Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
+ cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
+ OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
@@ -29,7 +31,8 @@ Size of tarball: 8530336 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 ... OK
* checking for left-over files ... OK
@@ -72,9 +75,9 @@ Skipping checking HTML validation: no command 'tidy' found
* checking for detritus in the temp directory ... OK
* DONE
-Status: 3 NOTEs
+Status: 4 NOTEs
See
- ‘/home/agsad.admin.ch/f80868656/projects/pfm/pfm.Rcheck/00check.log’
+ ‘/home/jranke/git/pfm/pfm.Rcheck/00check.log’
for details.
diff --git a/log/test.log b/log/test.log
index 71834bd..8393cf9 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 [1.1s]
+✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions
✔ | 1 | Simple PEC sediment calculations
✔ | 17 | Simple PEC soil calculations
✔ | 7 | 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 [4.7s]
+✔ | 7 | Read and analyse TOXSWA cwa files [4.2s]
✔ | 12 | UK drainage PEC calculations
══ Results ═════════════════════════════════════════════════════════════════════════════════════════
-Duration: 6.4 s
+Duration: 5.5 s
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 76 ]
diff --git a/man/PEC_sw_drift.Rd b/man/PEC_sw_drift.Rd
index c576753..a24b783 100644
--- a/man/PEC_sw_drift.Rd
+++ b/man/PEC_sw_drift.Rd
@@ -12,7 +12,7 @@ PEC_sw_drift(
drift_data = c("JKI", "RF"),
crop_group_JKI = c("Ackerbau", "Obstbau frueh", "Obstbau spaet", "Weinbau frueh",
"Weinbau spaet", "Hopfenbau", "Flaechenkulturen > 900 l/ha", "Gleisanlagen"),
- crop_group_focus = c("arable", "hops", "vines, late", "vines, early", "fruit, late",
+ crop_group_RF = c("arable", "hops", "vines, late", "vines, early", "fruit, late",
"fruit, early", "aerial"),
distances = c(1, 5, 10, 20),
formula = c("Rautmann", "FOCUS"),
@@ -38,9 +38,9 @@ either in the original form or integrated over the width of the water body, depe
on the 'formula' argument.}
\item{crop_group_JKI}{When using the 'JKI' drift data, one of the German names
-as used in \link{drift_parameters_focus}.}
+as used in \link{drift_parameters_focus}. Will only be used if drift_data is 'JKI'.}
-\item{crop_group_focus}{One of the crop groups as used in \link{drift_parameters_focus}}
+\item{crop_group_RF}{One of the crop groups as used in \link{drift_parameters_focus}}
\item{distances}{The distances in m for which to get PEC values}
@@ -75,13 +75,13 @@ PEC_sw_drift(100, drift_data = "RF")
PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF")
# or consider aerial application
-PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF",
- crop_group_focus = "aerial")
+PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF",
+ crop_group_RF = "aerial")
# 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))
-# The influence of assuming a 45° angle of the sides of the waterbody and the width of the
+# The influence of assuming a 45° angle of the sides of the waterbody and the width of the
# waterbody can be illustrated
PEC_sw_drift(100)
PEC_sw_drift(100, drift_data = "RF")
diff --git a/man/PEC_sw_exposit_drainage.Rd b/man/PEC_sw_exposit_drainage.Rd
index c809e08..b145d5c 100644
--- a/man/PEC_sw_exposit_drainage.Rd
+++ b/man/PEC_sw_exposit_drainage.Rd
@@ -44,10 +44,10 @@ autumn/winter/early spring.}
\value{
A list containing the following components
\describe{
-\item{perc_runoff}{The runoff percentages for dissolved and bound substance}
-\item{runoff}{A matrix containing dissolved and bound input for the different distances}
-\item{PEC_sw_runoff}{A matrix containing PEC values for dissolved and bound substance
-for the different distances. If the rate was given in g/ha, the PECsw are in microg/L.}
+\item{perc_drainage_total}{Gesamtaustrag (total fraction of the residue drained)}
+\item{perc_peak}{Stoßbelastung (fraction drained at event)}
+\item{PEC_sw_drainage}{A matrix containing PEC values for the spring and autumn
+scenarios. If the rate was given in g/ha, the PECsw are in microg/L.}
}
}
\description{
diff --git a/man/drift_percentages_rautmann.Rd b/man/drift_percentages_rautmann.Rd
index 5fb2586..e2a50d1 100644
--- a/man/drift_percentages_rautmann.Rd
+++ b/man/drift_percentages_rautmann.Rd
@@ -7,7 +7,7 @@
drift_percentages_rautmann(
distances,
applications = 1,
- crop_group_focus = c("arable", "hops", "vines, late", "vines, early", "fruit, late",
+ crop_group_RF = c("arable", "hops", "vines, late", "vines, early", "fruit, late",
"fruit, early", "aerial"),
formula = c("Rautmann", "FOCUS"),
widths = 1
@@ -18,7 +18,7 @@ drift_percentages_rautmann(
\item{applications}{Number of applications for selection of drift percentile}
-\item{crop_group_focus}{One of the crop groups as used in \link{drift_parameters_focus}}
+\item{crop_group_RF}{One of the crop groups as used in \link{drift_parameters_focus}}
\item{formula}{By default, the original Rautmann formula is used. If you
specify "FOCUS", mean drift input over the width of the water body is
@@ -30,7 +30,7 @@ calculated as described in Chapter 5.4.5 of the FOCUS surface water guidance}
Calculate drift percentages based on Rautmann data
}
\examples{
-# Compare JKI data with Rautmann formula
+# Compare JKI data with Rautmann and FOCUS formulas for arable crops (default)
# One application on field crops, for 1 m, 3 m and 5 m distance
drift_data_JKI[[1]][as.character(c(1, 3, 5)), "Ackerbau"]
drift_percentages_rautmann(c(1, 3, 5))
@@ -38,20 +38,20 @@ drift_percentages_rautmann(c(1, 3, 5), formula = "FOCUS")
# One application to early or late fruit crops
drift_data_JKI[[1]][as.character(c(3, 5, 20, 50)), "Obstbau frueh"]
-drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, early")
-drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, early",
+drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, early")
+drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, early",
formula = "FOCUS")
drift_data_JKI[[1]][as.character(c(3, 5, 20, 50)), "Obstbau spaet"]
-drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, late")
-drift_percentages_rautmann(c(3, 5, 20, 50), crop_group = "fruit, late",
+drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, late")
+drift_percentages_rautmann(c(3, 5, 20, 50), crop_group_RF = "fruit, late",
formula = "FOCUS")
# We get a continuum if the waterbody covers the hinge distance
# (11.4 m for 1 early app to fruit)
x <- seq(3, 30, by = 0.1)
-d <- drift_percentages_rautmann(x, crop_group = "fruit, early", formula = "FOCUS")
+d <- drift_percentages_rautmann(x, crop_group_RF = "fruit, early", formula = "FOCUS")
plot(x, d, type = "l",
- xlab = "Distance of near edge [m]",
+ xlab = "Distance of near edge [m]",
ylab = "Mean drift percentage over waterbody width",
main = "One application to fruit, early")
abline(v = 11.4, lty = 2)
diff --git a/tests/testthat/test_PEC_sw_drift.R b/tests/testthat/test_PEC_sw_drift.R
index a0972eb..7e3b965 100644
--- a/tests/testthat/test_PEC_sw_drift.R
+++ b/tests/testthat/test_PEC_sw_drift.R
@@ -25,7 +25,7 @@ test_that("The Rautmann formula is correctly implemented", {
expect_equal(pfm_jki, pfm_rf, tolerance = 0.01)
expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 10), "Only 1 to 8 applications")
- expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_focus = "Obstbau spaet"),
+ expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_RF = "Obstbau spaet"),
"should be one of")
- expect_silent(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_focus = "fruit, late"))
+ expect_silent(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_RF = "fruit, late"))
})

Contact - Imprint