From 6e4a152925011528c21937f12bc53042a53f72de Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 10:13:18 +0200 Subject: JKI drift percentage data for field crops and pome/stone fruit --- pkg/.Rbuildignore | 1 + pkg/DESCRIPTION | 2 +- pkg/R/drift_data_JKI.R | 42 ++++++++++++++++++++++++++++++++++++++ pkg/data/drift_data_JKI.RData | Bin 0 -> 972 bytes pkg/man/drift_data_JKI.Rd | 46 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 pkg/R/drift_data_JKI.R create mode 100644 pkg/data/drift_data_JKI.RData create mode 100644 pkg/man/drift_data_JKI.Rd (limited to 'pkg') diff --git a/pkg/.Rbuildignore b/pkg/.Rbuildignore index c56e58e..c48d8e3 100644 --- a/pkg/.Rbuildignore +++ b/pkg/.Rbuildignore @@ -1,2 +1,3 @@ inst/testdata/SwashProjects/project_H_sw/MACRO/*/*.bin inst/testdata/Swash/ +inst/extdata/Tabelle\ der\ Abdrifteckwerte.xls diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index a6880f2..98e9142 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -2,7 +2,7 @@ Package: pfm Type: Package Title: Utilities for pesticide fate modelling Version: 0.1-3 -Date: 2015-05-07 +Date: 2015-06-11 Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de", role = c("aut", "cre", "cph")) Description: Utilities for simple PEC calculations and for dealing with data diff --git a/pkg/R/drift_data_JKI.R b/pkg/R/drift_data_JKI.R new file mode 100644 index 0000000..44a959b --- /dev/null +++ b/pkg/R/drift_data_JKI.R @@ -0,0 +1,42 @@ +#' Deposition from spray drift expressed as percent of the applied dose as +#' published by the JKI +#' +#' Deposition from spray drift expressed as percent of the applied dose as +#' published by the German Julius-Kühn Institute (JKI). +#' +#' The data were extracted from the spreadsheet cited below using the R code +#' given in the example section. The spreadsheet is not included in the package +#' as its licence is not clear. +#' +#' +#' @name drift_data_JKI +#' @docType data +#' @format A list currently containing matrices with spray drift percentage +#' data for field crops (Ackerbau), and Pome/stone fruit, early and late +#' (Obstbau früh, spät). +#' @source JKI (2010) Spreadsheet 'Tabelle der Abdrifteckwerte.xls', retrieved +#' from +#' http://www.jki.bund.de/no_cache/de/startseite/institute/anwendungstechnik/abdrift-eckwerte.html +#' on 2015-06-11 +#' @keywords datasets +#' @examples +#' +#' \dontrun{ +#' # This is the code that was used to extract the data +#' library(readxl) +#' abdrift_path <- "../inst/extdata/Tabelle der Abdrifteckwerte.xls" +#' JKI_crops <- c("Ackerbau", "Obstbau früh", "Obstbau spät") +#' names(JKI_crops) <- c("Field crops", "Pome/stone fruit, early", "Pome/stone fruit, late") +#' drift_data_JKI <- list() +#' +#' for (n in 1:8) { +#' drift_data_raw <- read_excel(abdrift_path, sheet = n + 1, skip = 2) +#' drift_data <- as.matrix(drift_data_raw[1:9, 2:4]) +#' dimnames(drift_data) <- list(distance = as.integer(drift_data_raw[1:9, 1]), +#' crop = JKI_crops) +#' drift_data_JKI[[n]] <- drift_data +#' } +#' save(drift_data_JKI, file = "../data/drift_data_JKI.RData") +#' } +#' +NULL diff --git a/pkg/data/drift_data_JKI.RData b/pkg/data/drift_data_JKI.RData new file mode 100644 index 0000000..061ca27 Binary files /dev/null and b/pkg/data/drift_data_JKI.RData differ diff --git a/pkg/man/drift_data_JKI.Rd b/pkg/man/drift_data_JKI.Rd new file mode 100644 index 0000000..a2bbb77 --- /dev/null +++ b/pkg/man/drift_data_JKI.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/drift_data_JKI.R +\docType{data} +\name{drift_data_JKI} +\alias{drift_data_JKI} +\title{Deposition from spray drift expressed as percent of the applied dose as +published by the JKI} +\format{A list currently containing matrices with spray drift percentage +data for field crops (Ackerbau), and Pome/stone fruit, early and late +(Obstbau früh, spät).} +\source{ +JKI (2010) Spreadsheet 'Tabelle der Abdrifteckwerte.xls', retrieved +from +http://www.jki.bund.de/no_cache/de/startseite/institute/anwendungstechnik/abdrift-eckwerte.html +on 2015-06-11 +} +\description{ +Deposition from spray drift expressed as percent of the applied dose as +published by the German Julius-Kühn Institute (JKI). +} +\details{ +The data were extracted from the spreadsheet cited below using the R code +given in the example section. The spreadsheet is not included in the package +as its licence is not clear. +} +\examples{ +\dontrun{ + # This is the code that was used to extract the data + library(readxl) + abdrift_path <- "../inst/extdata/Tabelle der Abdrifteckwerte.xls" + JKI_crops <- c("Ackerbau", "Obstbau früh", "Obstbau spät") + names(JKI_crops) <- c("Field crops", "Pome/stone fruit, early", "Pome/stone fruit, late") + drift_data_JKI <- list() + + for (n in 1:8) { + drift_data_raw <- read_excel(abdrift_path, sheet = n + 1, skip = 2) + drift_data <- as.matrix(drift_data_raw[1:9, 2:4]) + dimnames(drift_data) <- list(distance = as.integer(drift_data_raw[1:9, 1]), + crop = JKI_crops) + drift_data_JKI[[n]] <- drift_data + } + save(drift_data_JKI, file = "../data/drift_data_JKI.RData") +} +} +\keyword{datasets} + -- cgit v1.2.1 From ea9b75183bcf41fcdd6f61ec6060e94c4bc321a2 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 12:13:47 +0200 Subject: Add simple drift PEC ini calculations These are tested for field crops with the CRD spreadsheet --- pkg/NAMESPACE | 1 + pkg/R/PEC_sw_drift.R | 55 ++++++++++++++++++++++++++++++++++ pkg/man/PEC_sw_drift.Rd | 42 ++++++++++++++++++++++++++ pkg/tests/testthat/test_PEC_sw_drift.R | 14 +++++++++ 4 files changed, 112 insertions(+) create mode 100644 pkg/R/PEC_sw_drift.R create mode 100644 pkg/man/PEC_sw_drift.Rd create mode 100644 pkg/tests/testthat/test_PEC_sw_drift.R (limited to 'pkg') diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE index 86b85da..00b0022 100644 --- a/pkg/NAMESPACE +++ b/pkg/NAMESPACE @@ -2,6 +2,7 @@ S3method(plot,TOXSWA_cwa) export(PEC_soil) +export(PEC_sw_drift) export(TOXSWA_cwa) export(geomean) export(read.TOXSWA_cwa) diff --git a/pkg/R/PEC_sw_drift.R b/pkg/R/PEC_sw_drift.R new file mode 100644 index 0000000..ce57f79 --- /dev/null +++ b/pkg/R/PEC_sw_drift.R @@ -0,0 +1,55 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' Calculate predicted environmental concentrations in surface water due to drift +#' +#' This is a basic, vectorised form of a simple calculation of a contaminant +#' concentration in surface water based on complete, instantaneous mixing +#' with input via spray drift. +#' +#' @param rate Application rate in units specified below +#' @param applications Number of applications for selection of drift percentile +#' @param drift_data Source of drift percentage data +#' @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 +#' @param rate_units Defaults to g/ha +#' @param PEC_units Requested units for the calculated PEC. Only µg/L currently supported +#' @return The predicted concentration in surface water +#' @export +#' @author Johannes Ranke +#' @examples +#' PEC_sw_drift(100) +PEC_sw_drift <- function(rate, + applications = 1, + water_depth = 30, + drift_data = "JKI", + 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) + drift_data <- match.arg(drift_data) + water_volume <- 100 * 100 * (water_depth/100) * 1000 # in L (for 1 ha) + PEC_sw_overspray <- rate * 1e6 / water_volume # in µg/L + dist_index <- as.character(distances) + PEC_sw_drift <- PEC_sw_overspray * pfm::drift_data_JKI[[applications]][dist_index, crop] / 100 + names(PEC_sw_drift) <- paste(dist_index, "m") + return(PEC_sw_drift) +} diff --git a/pkg/man/PEC_sw_drift.Rd b/pkg/man/PEC_sw_drift.Rd new file mode 100644 index 0000000..20299a5 --- /dev/null +++ b/pkg/man/PEC_sw_drift.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/PEC_sw_drift.R +\name{PEC_sw_drift} +\alias{PEC_sw_drift} +\title{Calculate predicted environmental concentrations in surface water due to drift} +\usage{ +PEC_sw_drift(rate, applications = 1, water_depth = 30, drift_data = "JKI", + crop = "Ackerbau", distances = c(1, 5, 10, 20), rate_units = "g/ha", + PEC_units = "µg/L") +} +\arguments{ +\item{rate}{Application rate in units specified below} + +\item{applications}{Number of applications for selection of drift percentile} + +\item{water_depth}{Depth of the water body in cm} + +\item{drift_data}{Source of drift percentage data} + +\item{crop}{Crop name (use German names for JKI data), defaults to "Ackerbau"} + +\item{distances}{The distances in m for which to get PEC values} + +\item{rate_units}{Defaults to g/ha} + +\item{PEC_units}{Requested units for the calculated PEC. Only µg/L currently supported} +} +\value{ +The predicted concentration in surface water +} +\description{ +This is a basic, vectorised form of a simple calculation of a contaminant +concentration in surface water based on complete, instantaneous mixing +with input via spray drift. +} +\examples{ +PEC_sw_drift(100) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/tests/testthat/test_PEC_sw_drift.R b/pkg/tests/testthat/test_PEC_sw_drift.R new file mode 100644 index 0000000..390df34 --- /dev/null +++ b/pkg/tests/testthat/test_PEC_sw_drift.R @@ -0,0 +1,14 @@ +library(pfm) +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), 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), 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)) +}) + -- cgit v1.2.1 From cb0d72e2c2d431bd32ffb129b62ea1a522cbdfeb Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 13:09:10 +0200 Subject: Rename PEC_sw_drift() to PEC_sw_drift_ini() --- pkg/R/PEC_sw_drift_ini.R | 55 ++++++++++++++++++++++++++++++ pkg/tests/testthat/test_PEC_sw_drift.R | 14 -------- pkg/tests/testthat/test_PEC_sw_drift_ini.R | 15 ++++++++ 3 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 pkg/R/PEC_sw_drift_ini.R delete mode 100644 pkg/tests/testthat/test_PEC_sw_drift.R create mode 100644 pkg/tests/testthat/test_PEC_sw_drift_ini.R (limited to 'pkg') diff --git a/pkg/R/PEC_sw_drift_ini.R b/pkg/R/PEC_sw_drift_ini.R new file mode 100644 index 0000000..67e00d9 --- /dev/null +++ b/pkg/R/PEC_sw_drift_ini.R @@ -0,0 +1,55 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' Calculate initial predicted environmental concentrations in surface water due to drift +#' +#' This is a basic, vectorised form of a simple calculation of a contaminant +#' concentration in surface water based on complete, instantaneous mixing +#' with input via spray drift. +#' +#' @param rate Application rate in units specified below +#' @param applications Number of applications for selection of drift percentile +#' @param drift_data Source of drift percentage data +#' @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 +#' @param rate_units Defaults to g/ha +#' @param PEC_units Requested units for the calculated PEC. Only µg/L currently supported +#' @return The predicted concentration in surface water +#' @export +#' @author Johannes Ranke +#' @examples +#' PEC_sw_drift_ini(100) +PEC_sw_drift_ini <- function(rate, + applications = 1, + water_depth = 30, + drift_data = "JKI", + 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) + drift_data <- match.arg(drift_data) + water_volume <- 100 * 100 * (water_depth/100) * 1000 # in L (for 1 ha) + PEC_sw_overspray <- rate * 1e6 / water_volume # in µg/L + dist_index <- as.character(distances) + PEC_sw_drift <- PEC_sw_overspray * pfm::drift_data_JKI[[applications]][dist_index, crop] / 100 + names(PEC_sw_drift) <- paste(dist_index, "m") + return(PEC_sw_drift) +} diff --git a/pkg/tests/testthat/test_PEC_sw_drift.R b/pkg/tests/testthat/test_PEC_sw_drift.R deleted file mode 100644 index 390df34..0000000 --- a/pkg/tests/testthat/test_PEC_sw_drift.R +++ /dev/null @@ -1,14 +0,0 @@ -library(pfm) -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), 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), 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)) -}) - diff --git a/pkg/tests/testthat/test_PEC_sw_drift_ini.R b/pkg/tests/testthat/test_PEC_sw_drift_ini.R new file mode 100644 index 0000000..2480e5c --- /dev/null +++ b/pkg/tests/testthat/test_PEC_sw_drift_ini.R @@ -0,0 +1,15 @@ +library(pfm) +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_ini(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_ini(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)) +}) -- cgit v1.2.1 From 3aa5fb86772c28402047c7ebd07841061dbcdbba Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 15:23:22 +0200 Subject: Add facilities to calculate decline curves --- pkg/DESCRIPTION | 2 +- pkg/NAMESPACE | 4 +++ pkg/R/SFO_actual_twa.R | 36 ++++++++++++++++++++++++ pkg/R/pfm_degradation.R | 48 ++++++++++++++++++++++++++++++++ pkg/man/PEC_sw_drift_ini.Rd | 42 ++++++++++++++++++++++++++++ pkg/man/SFO_actual_twa.Rd | 29 +++++++++++++++++++ pkg/man/pfm_degradation.Rd | 35 +++++++++++++++++++++++ pkg/tests/testthat/test_SFO_actual_twa.R | 13 +++++++++ 8 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 pkg/R/SFO_actual_twa.R create mode 100644 pkg/R/pfm_degradation.R create mode 100644 pkg/man/PEC_sw_drift_ini.Rd create mode 100644 pkg/man/SFO_actual_twa.Rd create mode 100644 pkg/man/pfm_degradation.Rd create mode 100644 pkg/tests/testthat/test_SFO_actual_twa.R (limited to 'pkg') diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 98e9142..4c41019 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -7,7 +7,7 @@ Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de", role = c("aut", "cre", "cph")) Description: Utilities for simple PEC calculations and for dealing with data from some FOCUS pesticide fate modelling software. -Depends: R6 +Depends: R6, mkin Suggests: testthat License: GPL LazyLoad: yes diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE index 00b0022..2d95da4 100644 --- a/pkg/NAMESPACE +++ b/pkg/NAMESPACE @@ -3,7 +3,11 @@ S3method(plot,TOXSWA_cwa) export(PEC_soil) export(PEC_sw_drift) +export(PEC_sw_drift_ini) +export(SFO_actual_twa) export(TOXSWA_cwa) export(geomean) +export(pfm_degradation) export(read.TOXSWA_cwa) +import(mkin) importFrom(R6,R6Class) diff --git a/pkg/R/SFO_actual_twa.R b/pkg/R/SFO_actual_twa.R new file mode 100644 index 0000000..7facb6a --- /dev/null +++ b/pkg/R/SFO_actual_twa.R @@ -0,0 +1,36 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' Actual and maximum moving window time average concentrations for SFO kinetics +#' +#' @param DT50 The half-life. +#' @param times The output times, and window sizes for time weighted average concentrations +#' @export +#' @author Johannes Ranke +#' @source FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation +#' Kinetics from Environmental Fate Studies on Pesticides in EU Registratin, Version 1.1, +#' 18 December 2014, p. 251 +#' @examples +#' SFO_actual_twa(10) +SFO_actual_twa <- function(DT50 = 1000, times = c(0, 1, 2, 4, 7, 14, 21, 28, 42, 50, 100)) +{ + k = log(2)/DT50 + result <- data.frame(actual = 1 * exp(-k * times), + twa = (1 - exp(-k * times))/(k * times), + row.names = times) + return(result) +} diff --git a/pkg/R/pfm_degradation.R b/pkg/R/pfm_degradation.R new file mode 100644 index 0000000..d1d2f9d --- /dev/null +++ b/pkg/R/pfm_degradation.R @@ -0,0 +1,48 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' Calculate a time course of relative concentrations based on an mkinmod model +#' +#' @import mkin +#' @param model The degradation model to be used. Either a parent only model like +#' 'SFO' or 'FOMC', or an mkinmod object +#' @param DT50 The half-life. This is only used when simple exponential decline +#' is calculated (SFO model). +#' @param parms The parameters used for the degradation model +#' @param years For how many years should the degradation be predicted? +#' @param step_days What step size in days should the output have? +#' @param times The output times +#' @export +#' @author Johannes Ranke +#' @examples +#' pfm_degradation("SFO", DT50 = 10) +pfm_degradation <- function(model = "SFO", DT50 = 1000, parms = c(k_parent_sink = log(2)/DT50), + years = 1, step_days = 1, + times = seq(0, years * 365, by = step_days)) +{ + if (model %in% c("SFO", "FOMC", "DFOP", "HS", "IORE")) { + model <- mkinmod(parent = list(type = model)) + } + initial_state = c(1, rep(0, length(model$diffs) - 1)) + names(initial_state) <- names(model$diffs) + time_course <- mkinpredict(model, odeparms = parms, + odeini = initial_state, + outtimes = times, + solution_type = ifelse(length(model$spec) == 1, + "analytical", "deSolve")) + invisible(time_course) +} diff --git a/pkg/man/PEC_sw_drift_ini.Rd b/pkg/man/PEC_sw_drift_ini.Rd new file mode 100644 index 0000000..0bcbf97 --- /dev/null +++ b/pkg/man/PEC_sw_drift_ini.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/PEC_sw_drift_ini.R +\name{PEC_sw_drift_ini} +\alias{PEC_sw_drift_ini} +\title{Calculate initial predicted environmental concentrations in surface water due to drift} +\usage{ +PEC_sw_drift_ini(rate, applications = 1, water_depth = 30, + drift_data = "JKI", crop = "Ackerbau", distances = c(1, 5, 10, 20), + rate_units = "g/ha", PEC_units = "µg/L") +} +\arguments{ +\item{rate}{Application rate in units specified below} + +\item{applications}{Number of applications for selection of drift percentile} + +\item{water_depth}{Depth of the water body in cm} + +\item{drift_data}{Source of drift percentage data} + +\item{crop}{Crop name (use German names for JKI data), defaults to "Ackerbau"} + +\item{distances}{The distances in m for which to get PEC values} + +\item{rate_units}{Defaults to g/ha} + +\item{PEC_units}{Requested units for the calculated PEC. Only µg/L currently supported} +} +\value{ +The predicted concentration in surface water +} +\description{ +This is a basic, vectorised form of a simple calculation of a contaminant +concentration in surface water based on complete, instantaneous mixing +with input via spray drift. +} +\examples{ +PEC_sw_drift_ini(100) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/man/SFO_actual_twa.Rd b/pkg/man/SFO_actual_twa.Rd new file mode 100644 index 0000000..967b60f --- /dev/null +++ b/pkg/man/SFO_actual_twa.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/SFO_actual_twa.R +\name{SFO_actual_twa} +\alias{SFO_actual_twa} +\title{Actual and maximum moving window time average concentrations for SFO kinetics} +\source{ +FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation + Kinetics from Environmental Fate Studies on Pesticides in EU Registratin, Version 1.1, + 18 December 2014, p. 251 +} +\usage{ +SFO_actual_twa(DT50 = 1000, times = c(0, 1, 2, 4, 7, 14, 21, 28, 42, 50, + 100)) +} +\arguments{ +\item{DT50}{The half-life.} + +\item{times}{The output times, and window sizes for time weighted average concentrations} +} +\description{ +Actual and maximum moving window time average concentrations for SFO kinetics +} +\examples{ +SFO_actual_twa(10) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/man/pfm_degradation.Rd b/pkg/man/pfm_degradation.Rd new file mode 100644 index 0000000..b875434 --- /dev/null +++ b/pkg/man/pfm_degradation.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/pfm_degradation.R +\name{pfm_degradation} +\alias{pfm_degradation} +\title{Calculate a time course of relative concentrations based on an mkinmod model} +\usage{ +pfm_degradation(model = "SFO", DT50 = 1000, parms = c(k_parent_sink = + log(2)/DT50), years = 1, step_days = 1, times = seq(0, years * 365, by = + step_days)) +} +\arguments{ +\item{model}{The degradation model to be used. Either a parent only model like +'SFO' or 'FOMC', or an mkinmod object} + +\item{DT50}{The half-life. This is only used when simple exponential decline +is calculated (SFO model).} + +\item{parms}{The parameters used for the degradation model} + +\item{years}{For how many years should the degradation be predicted?} + +\item{step_days}{What step size in days should the output have?} + +\item{times}{The output times} +} +\description{ +Calculate a time course of relative concentrations based on an mkinmod model +} +\examples{ +pfm_degradation("SFO", DT50 = 10) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/tests/testthat/test_SFO_actual_twa.R b/pkg/tests/testthat/test_SFO_actual_twa.R new file mode 100644 index 0000000..b0a5537 --- /dev/null +++ b/pkg/tests/testthat/test_SFO_actual_twa.R @@ -0,0 +1,13 @@ +library(pfm) +context("Actual and time weighted average concentrations for SFO kinetics") + +test_that("SFO_actual_twa calculates correctly", { + test_times <- c(0, 1, 7, 21, 42) + # This was calculated with the CRD spreadsheet for multiple applications + reference <- data.frame( + actual = c(10, 9.330, 6.156, 2.333, 0.544), + twa = c(NaN, 9.661, 7.923, 5.267, 3.248), + row.names = test_times) + result <- round(10 * SFO_actual_twa(10, times = test_times), 3) + expect_equal(result, reference) +}) -- cgit v1.2.1 From 09cf970942706cfab43753d298b42e8d85216d80 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 15:25:22 +0200 Subject: Now there is enough content to warrant 0.2-x --- pkg/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 4c41019..9c4b276 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -1,7 +1,7 @@ Package: pfm Type: Package Title: Utilities for pesticide fate modelling -Version: 0.1-3 +Version: 0.2-1 Date: 2015-06-11 Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de", role = c("aut", "cre", "cph")) -- cgit v1.2.1 From dd803b191062925eda830543236836e7822fd884 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 16:57:43 +0200 Subject: Add UK tier 1 drainage PEC calculations --- pkg/NAMESPACE | 2 ++ pkg/R/PEC_sw_drainage_UK.R | 53 ++++++++++++++++++++++++++++++++ pkg/R/SSLRC_mobility_classification.R | 42 +++++++++++++++++++++++++ pkg/man/PEC_sw_drainage_UK_ini.Rd | 30 ++++++++++++++++++ pkg/man/SSLRC_mobility_classification.Rd | 26 ++++++++++++++++ pkg/tests/testthat/test_UK_drainage.R | 33 ++++++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 pkg/R/PEC_sw_drainage_UK.R create mode 100644 pkg/R/SSLRC_mobility_classification.R create mode 100644 pkg/man/PEC_sw_drainage_UK_ini.Rd create mode 100644 pkg/man/SSLRC_mobility_classification.Rd create mode 100644 pkg/tests/testthat/test_UK_drainage.R (limited to 'pkg') diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE index 2d95da4..771739a 100644 --- a/pkg/NAMESPACE +++ b/pkg/NAMESPACE @@ -2,9 +2,11 @@ S3method(plot,TOXSWA_cwa) export(PEC_soil) +export(PEC_sw_drainage_UK_ini) export(PEC_sw_drift) export(PEC_sw_drift_ini) export(SFO_actual_twa) +export(SSLRC_mobility_classification) export(TOXSWA_cwa) export(geomean) export(pfm_degradation) diff --git a/pkg/R/PEC_sw_drainage_UK.R b/pkg/R/PEC_sw_drainage_UK.R new file mode 100644 index 0000000..03c56c0 --- /dev/null +++ b/pkg/R/PEC_sw_drainage_UK.R @@ -0,0 +1,53 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' 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 +#' +#' @param rate Application rate in g/ha +#' @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 +#' @return The predicted concentration in surface water in µg/L +#' @export +#' @author Johannes Ranke +#' @examples +#' PEC_sw_drainage_UK_ini(100) +PEC_sw_drainage_UK_ini <- function(rate, interception = 0, Koc, + latest_application = NULL, soil_DT50 = NULL) +{ + percentage_lost <- SSLRC_mobility_classification(Koc)[[2]] + amount_available <- rate * (1 - interception) # g/ha + + if (!missing(latest_application)) { + if (missing(soil_DT50)) stop("You need to supply a soil DT50 value") + k = log(2)/soil_DT50 + as.Date(paste(latest_application, "1999"), "%d %B %Y") + + lct <- Sys.getlocale("LC_TIME") + tmp <- Sys.setlocale("LC_TIME", "C") + 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)) + amount_available <- amount_available * exp(-k * degradation_time) + } + + volume = 130000 # L/ha + PEC = 1e6 * (percentage_lost/100) * amount_available / volume + return(PEC) +} diff --git a/pkg/R/SSLRC_mobility_classification.R b/pkg/R/SSLRC_mobility_classification.R new file mode 100644 index 0000000..e04d472 --- /dev/null +++ b/pkg/R/SSLRC_mobility_classification.R @@ -0,0 +1,42 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' Determine the SSLRC mobility classification for a chemical substance from its Koc +#' +#' This implements the method specified in the UK data requirements handbook and was +#' checked against the spreadsheet published on the CRC website +#' +#' @param Koc The sorption coefficient normalised to organic carbon in L/kg +#' @return A list containing the classification and the percentage of the +#' compound transported per 10 mm drain water +#' @export +#' @author Johannes Ranke +#' @examples +#' SSLRC_mobility_classification(Koc) +SSLRC_mobility_classification <- function(Koc) +{ + if (!is.numeric(Koc) | length(Koc) != 1) stop("Please give a single number") + result <- list("Non mobile", 0.01) + if (Koc < 4000) result <- list("Slightly mobile", 0.02) + if (Koc < 1000) result <- list("Slightly mobile", 0.5) + if (Koc < 500) result <- list("Moderately mobile", 0.7) + if (Koc < 75) result <- list("Mobile", 1.9) + if (Koc < 15) result <- list("Very mobile", 1.9) + names(result) <- c("Mobility classification", + "Percentage drained per mm of drain water") + return(result) +} diff --git a/pkg/man/PEC_sw_drainage_UK_ini.Rd b/pkg/man/PEC_sw_drainage_UK_ini.Rd new file mode 100644 index 0000000..c39a5c9 --- /dev/null +++ b/pkg/man/PEC_sw_drainage_UK_ini.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/PEC_sw_drainage_UK.R +\name{PEC_sw_drainage_UK_ini} +\alias{PEC_sw_drainage_UK_ini} +\title{Calculate initial predicted environmental concentrations in surface water due to drainage using the UK method} +\usage{ +PEC_sw_drainage_UK_ini(rate, interception = 0, Koc, + latest_application = NULL, soil_DT50 = NULL) +} +\arguments{ +\item{rate}{Application rate in g/ha} + +\item{interception}{The fraction of the application rate that does not reach the soil} + +\item{Koc}{The sorption coefficient normalised to organic carbon in L/kg} +} +\value{ +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 +} +\examples{ +PEC_sw_drainage_UK_ini(100) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/man/SSLRC_mobility_classification.Rd b/pkg/man/SSLRC_mobility_classification.Rd new file mode 100644 index 0000000..a1bb413 --- /dev/null +++ b/pkg/man/SSLRC_mobility_classification.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/SSLRC_mobility_classification.R +\name{SSLRC_mobility_classification} +\alias{SSLRC_mobility_classification} +\title{Determine the SSLRC mobility classification for a chemical substance from its Koc} +\usage{ +SSLRC_mobility_classification(Koc) +} +\arguments{ +\item{Koc}{The sorption coefficient normalised to organic carbon in L/kg} +} +\value{ +A list containing the classification and the percentage of the + compound transported per 10 mm drain water +} +\description{ +This implements the method specified in the UK data requirements handbook and was +checked against the spreadsheet published on the CRC website +} +\examples{ +SSLRC_mobility_classification(Koc) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/tests/testthat/test_UK_drainage.R b/pkg/tests/testthat/test_UK_drainage.R new file mode 100644 index 0000000..3a57db8 --- /dev/null +++ b/pkg/tests/testthat/test_UK_drainage.R @@ -0,0 +1,33 @@ +library(pfm) +context("UK drainage PEC calculations") + +test_that("The mobility classification and the drained percentage are correct", { + # Expected results are from the CRD drainage calculator, retrieved 2015-06-11 + + expect_equivalent(SSLRC_mobility_classification(1), list("Very mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(15), list("Mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(30), list("Mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(74.9), list("Mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(75), list("Moderately mobile", 0.7)) + expect_equivalent(SSLRC_mobility_classification(100), list("Moderately mobile", 0.7)) + expect_equivalent(SSLRC_mobility_classification(800), list("Slightly mobile", 0.5)) + expect_equivalent(SSLRC_mobility_classification(2000), list("Slightly mobile", 0.02)) + expect_equivalent(SSLRC_mobility_classification(5000), list("Non mobile", 0.01)) +}) + +test_that("UK drainflow PECs are correct", { + # Expected results are from the CRD drainage calculator, retrieved 2015-06-11, except + # for the third example from the data requirements handbook + + # This is the first example calculation from the data requirements handbook, where they give + # 8.07 µg/L as the result (obviously a rounding error). + expect_equal(round(PEC_sw_drainage_UK_ini(150, interception = 0, Koc = 100), 4), 8.0769) + + # This is the second example calculation from the data requirements handbook + expect_equal(round(PEC_sw_drainage_UK_ini(90, interception = 0, Koc = 10), 4), 13.1538) + + # This is the third example calculation from the data requirements handbook, + expect_equal(round(PEC_sw_drainage_UK_ini(60, interception = 0.5, Koc = 550, + latest_application = "01 July", + soil_DT50 = 200), 2), 0.84) +}) -- cgit v1.2.1 From 9b8e5cb80ba4a89578d979bee134f8342ca0a527 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 11 Jun 2015 17:38:01 +0200 Subject: Now we pass R CMD check --- pkg/R/PEC_sw_drainage_UK.R | 33 +++++++++++++++++++++----------- pkg/R/SSLRC_mobility_classification.R | 2 +- pkg/man/PEC_sw_drainage_UK_ini.Rd | 14 ++++++++++++-- pkg/man/SSLRC_mobility_classification.Rd | 2 +- 4 files changed, 36 insertions(+), 15 deletions(-) (limited to 'pkg') diff --git a/pkg/R/PEC_sw_drainage_UK.R b/pkg/R/PEC_sw_drainage_UK.R index 03c56c0..8402d95 100644 --- a/pkg/R/PEC_sw_drainage_UK.R +++ b/pkg/R/PEC_sw_drainage_UK.R @@ -23,28 +23,39 @@ #' @param rate Application rate in g/ha #' @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 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 model The 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 #' @return The predicted concentration in surface water in µg/L #' @export #' @author Johannes Ranke #' @examples -#' PEC_sw_drainage_UK_ini(100) +#' PEC_sw_drainage_UK_ini(150, Koc = 100) PEC_sw_drainage_UK_ini <- function(rate, interception = 0, Koc, - latest_application = NULL, soil_DT50 = NULL) + latest_application = NULL, soil_DT50 = NULL, + model = NULL, model_parms = NULL) { percentage_lost <- SSLRC_mobility_classification(Koc)[[2]] amount_available <- rate * (1 - interception) # g/ha if (!missing(latest_application)) { - if (missing(soil_DT50)) stop("You need to supply a soil DT50 value") - k = log(2)/soil_DT50 - as.Date(paste(latest_application, "1999"), "%d %B %Y") + if (!missing(soil_DT50)) { + k = log(2)/soil_DT50 + as.Date(paste(latest_application, "1999"), "%d %B %Y") - lct <- Sys.getlocale("LC_TIME") - tmp <- Sys.setlocale("LC_TIME", "C") - 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)) - amount_available <- amount_available * exp(-k * degradation_time) + lct <- Sys.getlocale("LC_TIME") + tmp <- Sys.setlocale("LC_TIME", "C") + 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)) + 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)) { + amount_available <- pfm_degradation(model, parms = model_parms, times = degradation_time) + } } volume = 130000 # L/ha diff --git a/pkg/R/SSLRC_mobility_classification.R b/pkg/R/SSLRC_mobility_classification.R index e04d472..deda5cf 100644 --- a/pkg/R/SSLRC_mobility_classification.R +++ b/pkg/R/SSLRC_mobility_classification.R @@ -26,7 +26,7 @@ #' @export #' @author Johannes Ranke #' @examples -#' SSLRC_mobility_classification(Koc) +#' SSLRC_mobility_classification(100) SSLRC_mobility_classification <- function(Koc) { if (!is.numeric(Koc) | length(Koc) != 1) stop("Please give a single number") diff --git a/pkg/man/PEC_sw_drainage_UK_ini.Rd b/pkg/man/PEC_sw_drainage_UK_ini.Rd index c39a5c9..1b2009d 100644 --- a/pkg/man/PEC_sw_drainage_UK_ini.Rd +++ b/pkg/man/PEC_sw_drainage_UK_ini.Rd @@ -5,7 +5,8 @@ \title{Calculate initial predicted environmental concentrations in surface water due to drainage using the UK method} \usage{ PEC_sw_drainage_UK_ini(rate, interception = 0, Koc, - latest_application = NULL, soil_DT50 = NULL) + latest_application = NULL, soil_DT50 = NULL, model = NULL, + model_parms = NULL) } \arguments{ \item{rate}{Application rate in g/ha} @@ -13,6 +14,15 @@ PEC_sw_drainage_UK_ini(rate, interception = 0, Koc, \item{interception}{The fraction of the application rate that does not reach the soil} \item{Koc}{The sorption coefficient normalised to organic carbon in L/kg} + +\item{latest_application}{Latest application date, formatted as e.g. "01 July"} + +\item{soil_DT50}{Soil degradation half-life, if SFO kinetics are to be used} + +\item{model}{The degradation model to be used. Either one of "FOMC", "DFOP", +"HS", or "IORE", or an mkinmod object} + +\item{model_parms}{A named numeric vector containing the model parameters} } \value{ The predicted concentration in surface water in µg/L @@ -22,7 +32,7 @@ This implements the method specified in the UK data requirements handbook and wa published on the CRC website } \examples{ -PEC_sw_drainage_UK_ini(100) +PEC_sw_drainage_UK_ini(150, Koc = 100) } \author{ Johannes Ranke diff --git a/pkg/man/SSLRC_mobility_classification.Rd b/pkg/man/SSLRC_mobility_classification.Rd index a1bb413..62a345b 100644 --- a/pkg/man/SSLRC_mobility_classification.Rd +++ b/pkg/man/SSLRC_mobility_classification.Rd @@ -18,7 +18,7 @@ This implements the method specified in the UK data requirements handbook and wa checked against the spreadsheet published on the CRC website } \examples{ -SSLRC_mobility_classification(Koc) +SSLRC_mobility_classification(100) } \author{ Johannes Ranke -- cgit v1.2.1 From 5b32c30549bfa3cb42ffde7e13f75608b98c79c2 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 12 Jun 2015 02:19:01 +0200 Subject: Make UK drainage with non-SFO soil degradation work --- pkg/R/PEC_sw_drainage_UK.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'pkg') diff --git a/pkg/R/PEC_sw_drainage_UK.R b/pkg/R/PEC_sw_drainage_UK.R index 8402d95..43c732e 100644 --- a/pkg/R/PEC_sw_drainage_UK.R +++ b/pkg/R/PEC_sw_drainage_UK.R @@ -41,20 +41,22 @@ PEC_sw_drainage_UK_ini <- function(rate, interception = 0, Koc, amount_available <- rate * (1 - interception) # g/ha if (!missing(latest_application)) { + lct <- Sys.getlocale("LC_TIME") + tmp <- Sys.setlocale("LC_TIME", "C") + 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") - lct <- Sys.getlocale("LC_TIME") - tmp <- Sys.setlocale("LC_TIME", "C") - 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)) 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)) { - amount_available <- pfm_degradation(model, parms = model_parms, times = degradation_time) + fraction_left <- pfm_degradation(model, parms = model_parms, + times = degradation_time)[1, "parent"] + amount_available <- fraction_left * amount_available } } -- cgit v1.2.1 From fef0bb7fe916f91dcff089c17aa3290c0ea1ab1f Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 12 Jun 2015 02:19:38 +0200 Subject: Add sediment PEC calculations using the percentage method --- pkg/DESCRIPTION | 2 +- pkg/NAMESPACE | 1 + pkg/R/PEC_sw_sed.R | 50 +++++++++++++++++++++++++++++++++++++++ pkg/man/PEC_sw_sed.Rd | 42 ++++++++++++++++++++++++++++++++ pkg/tests/testthat/test_PEC_sed.R | 9 +++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 pkg/R/PEC_sw_sed.R create mode 100644 pkg/man/PEC_sw_sed.Rd create mode 100644 pkg/tests/testthat/test_PEC_sed.R (limited to 'pkg') diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 9c4b276..39b8c20 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -2,7 +2,7 @@ Package: pfm Type: Package Title: Utilities for pesticide fate modelling Version: 0.2-1 -Date: 2015-06-11 +Date: 2015-06-12 Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de", role = c("aut", "cre", "cph")) Description: Utilities for simple PEC calculations and for dealing with data diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE index 771739a..a1796f5 100644 --- a/pkg/NAMESPACE +++ b/pkg/NAMESPACE @@ -5,6 +5,7 @@ export(PEC_soil) export(PEC_sw_drainage_UK_ini) export(PEC_sw_drift) export(PEC_sw_drift_ini) +export(PEC_sw_sed) export(SFO_actual_twa) export(SSLRC_mobility_classification) export(TOXSWA_cwa) diff --git a/pkg/R/PEC_sw_sed.R b/pkg/R/PEC_sw_sed.R new file mode 100644 index 0000000..56396e8 --- /dev/null +++ b/pkg/R/PEC_sw_sed.R @@ -0,0 +1,50 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package pfm + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' Calculate initial predicted environmental concentrations in sediment from +#' surface water concentrations +#' +#' The method 'percentage' is equivalent to what is used in the CRD spreadsheet +#' PEC calculator +#' +#' @param PEC_sw Numeric vector or matrix of surface water concentrations in µg/L for +#' which the corresponding sediment concentration is to be estimated +#' @param percentage The percentage in sediment, used for the percentage method +#' @param method The method used for the calculation +#' @param sediment_depth Depth of the sediment layer +#' @param water_depth Depth of the water body in cm +#' @param sediment_density The density of the sediment in L/kg (equivalent to +#' g/cm3) +#' @param PEC_sed_units The units of the estimated sediment PEC value +#' @return The predicted concentration in sediment +#' @export +#' @author Johannes Ranke +#' @examples +#' PEC_sw_sed(PEC_sw_drift_ini(100, distances = 1), percentage = 50) +PEC_sw_sed <- function(PEC_sw, percentage = 100, method = "percentage", + sediment_depth = 5, water_depth = 30, + sediment_density = 1.3, + PEC_sed_units = c("\u00B5g/kg", "mg/kg")) +{ + method = match.arg(method) + PEC_sed_units = match.arg(PEC_sed_units) + if (method == "percentage") { + PEC_sed = PEC_sw * (percentage/100) * (water_depth / sediment_depth) * (1 / sediment_density) + if (PEC_sed_units == "mg/kg") PEC_sed <- PEC_sed / 1000 + } + return(PEC_sed) +} diff --git a/pkg/man/PEC_sw_sed.Rd b/pkg/man/PEC_sw_sed.Rd new file mode 100644 index 0000000..ee496d1 --- /dev/null +++ b/pkg/man/PEC_sw_sed.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2 (4.1.0.9001): do not edit by hand +% Please edit documentation in R/PEC_sw_sed.R +\name{PEC_sw_sed} +\alias{PEC_sw_sed} +\title{Calculate initial predicted environmental concentrations in sediment from +surface water concentrations} +\usage{ +PEC_sw_sed(PEC_sw, percentage = 100, method = "percentage", + sediment_depth = 5, water_depth = 30, sediment_density = 1.3, + PEC_sed_units = c("µg/kg", "mg/kg")) +} +\arguments{ +\item{PEC_sw}{Numeric vector or matrix of surface water concentrations in µg/L for +which the corresponding sediment concentration is to be estimated} + +\item{percentage}{The percentage in sediment, used for the percentage method} + +\item{method}{The method used for the calculation} + +\item{sediment_depth}{Depth of the sediment layer} + +\item{water_depth}{Depth of the water body in cm} + +\item{sediment_density}{The density of the sediment in L/kg (equivalent to +g/cm3)} + +\item{PEC_sed_units}{The units of the estimated sediment PEC value} +} +\value{ +The predicted concentration in sediment +} +\description{ +The method 'percentage' is equivalent to what is used in the CRD spreadsheet +PEC calculator +} +\examples{ +PEC_sw_sed(PEC_sw_drift_ini(100, distances = 1), percentage = 50) +} +\author{ +Johannes Ranke +} + diff --git a/pkg/tests/testthat/test_PEC_sed.R b/pkg/tests/testthat/test_PEC_sed.R new file mode 100644 index 0000000..d83be0f --- /dev/null +++ b/pkg/tests/testthat/test_PEC_sed.R @@ -0,0 +1,9 @@ +context("Simple PEC sediment calculations") + +test_that("PEC_sw_sed calculates correctly using the percentage method", { + # Application of 100 g/ha, 1 m spray drift distance (2.77% drift input), 50% in sediment, + # default assumptions of CRD spreadsheet (5 cm sediment depth, 1.3 kg/L sediment density) + # Reference value calculated with CRD spreadsheet + PEC_sw_100_1_m <- PEC_sw_drift_ini(100, distances = 1) + expect_equivalent(round(PEC_sw_sed(PEC_sw_100_1_m, percentage = 50), 3), 2.131) +}) -- cgit v1.2.1