aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2017-05-16 18:40:25 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2017-05-16 18:40:25 +0200
commit3e26a8ab76a434c3465ea1db1b4a2a2ff3ea8ec8 (patch)
treec1830d0d479574f037f86b127cee809c350d163a
parent36036b5901223591e7e21e8b73d8cd1fb034f4cb (diff)
Add TWA concentrations for days > 1, fix link
Now we have seven test calculations for the Step 1 calculator, all perfectly passing. This provides confidence that this is a correct reimplementation of the Step 1 part of the Step 1/2 calculator.
-rw-r--r--ChangeLog9
-rw-r--r--R/PEC_sw_focus.R31
-rw-r--r--R/PELMO_runs.R2
-rw-r--r--man/PEC_sw_focus.Rd15
-rw-r--r--man/PELMO_runs.Rd2
-rw-r--r--tests/testthat/test_step_1.R28
6 files changed, 59 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index b1eddf2..3297522 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+commit 36036b5901223591e7e21e8b73d8cd1fb034f4cb
+Author: Johannes Ranke <jranke@uni-bremen.de>
+Date: 2017-05-16 15:43:50 +0200
+
+ Finish the Step 1 calculator including tests
+
+ Some cleaning up. PELMO facilities do not currently work at my end,
+ as I have no working wine installation on this computer
+
commit d042f8f06b313e8595087587455daac73d84f17b
Author: Johannes Ranke <jranke@uni-bremen.de>
Date: 2017-05-15 20:01:28 +0200
diff --git a/R/PEC_sw_focus.R b/R/PEC_sw_focus.R
index 21ed514..c614593 100644
--- a/R/PEC_sw_focus.R
+++ b/R/PEC_sw_focus.R
@@ -15,19 +15,24 @@
#' http://esdac.jrc.ec.europa.eu/projects/stepsonetwo
#' @note The formulas for input to the waterbody via runoff/drainage of the
#' parent and subsequent formation of the metabolite in water is not
-#' documented in the model description coming with the calculator
-#' @note Step 2 is not implemented
+#' documented in the model description coming with the calculator. As one would
+#' expecte, this additional input appears to be (as we get the same results)
+#' calculated by multiplying the application rate with the molar weight
+#' correction and the formation fraction in water/sediment systems.
+#' @note Step 2 is not implemented.
#' @export
-#' @param parent A list containing substance specific parameters
+#' @param parent A list containing substance specific parameters, e.g.
+#' conveniently generated by \code{\link{chent_focus_sw}}.
#' @param rate The application rate in g/ha. Overriden when
#' applications are given explicitly
#' @param n The number of applications
#' @param i The application interval
-#' @param met A list containing metabolite specific parameters. If not NULL,
+#' @param met A list containing metabolite specific parameters. e.g.
+#' conveniently generated by \code{\link{chent_focus_sw}}. If not NULL,
#' the PEC is calculated for this compound, not the parent.
#' @param f_drift The fraction of the application rate reaching the waterbody
#' via drift. If NA, this is derived from the scenario name and the number
-#' of applications via the drift data defined by the
+#' of applications via the drift data defined by the
#' \code{\link{FOCUS_Step_12_scenarios}}
#' @param f_rd The fraction of the amount applied reaching the waterbody via
#' runoff/drainage. At Step 1, it is assumed to be 10%, be it the
@@ -138,8 +143,20 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA,
PEC[as.character(t_out[-1]), "PECsed"] = PEC_sed_0_part * exp( - k_ws * t_out[-1])
# TWA concentrations
- PEC["1", "TWAECsw"] = (PEC_sw_0 + PEC["1", "PECsw"]) / 2
- PEC["1", "TWAECsed"] = (PEC_sed_0 + PEC["1", "PECsed"]) / 2
+ PEC_sw_1 = PEC["1", "PECsw"]
+ PEC_sed_1 = PEC["1", "PECsed"]
+ TWAEC_sw_1 = (PEC_sw_0 + PEC_sw_1) / 2
+ TWAEC_sed_1 = (PEC_sed_0 + PEC_sed_1) / 2
+
+ TWAEC_after = function(TWAEC_1, PEC_1, t) {
+ (TWAEC_1 + PEC_1 * (1 - exp(- k_ws * (t - 1))) / k_ws) / t
+ }
+
+ PEC["1", "TWAECsw"] = TWAEC_sw_1
+ PEC["1", "TWAECsed"] = TWAEC_sed_1
+
+ PEC[as.character(t_out[-1]), "TWAECsw"] = TWAEC_after(TWAEC_sw_1, PEC_sw_1, t_out[-1])
+ PEC[as.character(t_out[-1]), "TWAECsed"] = TWAEC_after(TWAEC_sed_1, PEC_sed_1, t_out[-1])
# Check if PEC_sw_max is above water solubility
PEC_sw_max = max(PEC[, "PECsw"])
diff --git a/R/PELMO_runs.R b/R/PELMO_runs.R
index b152b4d..c0d1266 100644
--- a/R/PELMO_runs.R
+++ b/R/PELMO_runs.R
@@ -26,7 +26,7 @@
#' @param cores The number of cores to execute PELMO runs in parallel
#' @param evaluate Should the results be returned?
#' @param overwrite Should existing run directories be overwritten?
-#' @references PELMO.installeR \url{https://jranke.github.io/PELMO.installeR}
+#' @references PELMO.installeR \url{https://pkgdown.jrwb.de/PELMO.installeR}
#'
#' Wine \url{https://winehq.org}
#'
diff --git a/man/PEC_sw_focus.Rd b/man/PEC_sw_focus.Rd
index 22c20c5..656bd6d 100644
--- a/man/PEC_sw_focus.Rd
+++ b/man/PEC_sw_focus.Rd
@@ -8,7 +8,8 @@ PEC_sw_focus(parent, rate, n = 1, i = NA, met = NULL, f_drift = NA,
f_rd = 0.1, scenario = FOCUS_Step_12_scenarios$names)
}
\arguments{
-\item{parent}{A list containing substance specific parameters}
+\item{parent}{A list containing substance specific parameters, e.g.
+conveniently generated by \code{\link{chent_focus_sw}}.}
\item{rate}{The application rate in g/ha. Overriden when
applications are given explicitly}
@@ -17,12 +18,13 @@ applications are given explicitly}
\item{i}{The application interval}
-\item{met}{A list containing metabolite specific parameters. If not NULL,
+\item{met}{A list containing metabolite specific parameters. e.g.
+conveniently generated by \code{\link{chent_focus_sw}}. If not NULL,
the PEC is calculated for this compound, not the parent.}
\item{f_drift}{The fraction of the application rate reaching the waterbody
via drift. If NA, this is derived from the scenario name and the number
-of applications via the drift data defined by the
+of applications via the drift data defined by the
\code{\link{FOCUS_Step_12_scenarios}}}
\item{f_rd}{The fraction of the amount applied reaching the waterbody via
@@ -42,9 +44,12 @@ this implementation.
\note{
The formulas for input to the waterbody via runoff/drainage of the
parent and subsequent formation of the metabolite in water is not
- documented in the model description coming with the calculator
+ documented in the model description coming with the calculator. As one would
+ expecte, this additional input appears to be (as we get the same results)
+ calculated by multiplying the application rate with the molar weight
+ correction and the formation fraction in water/sediment systems.
-Step 2 is not implemented
+Step 2 is not implemented.
}
\examples{
# Parent only
diff --git a/man/PELMO_runs.Rd b/man/PELMO_runs.Rd
index a0d0df8..a86e0fd 100644
--- a/man/PELMO_runs.Rd
+++ b/man/PELMO_runs.Rd
@@ -81,7 +81,7 @@ print(PECgw_2)
}
}
\references{
-PELMO.installeR \url{https://jranke.github.io/PELMO.installeR}
+PELMO.installeR \url{https://pkgdown.jrwb.de/PELMO.installeR}
Wine \url{https://winehq.org}
diff --git a/tests/testthat/test_step_1.R b/tests/testthat/test_step_1.R
index b067e8f..14045f5 100644
--- a/tests/testthat/test_step_1.R
+++ b/tests/testthat/test_step_1.R
@@ -10,9 +10,9 @@ test_that("Results of Steps 1/2 calculator for Dummy 1 are reproduced", {
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_1[, "PECsw"] = c(685.06, 610.32, 543.73, 431.56)
- PEC_orig_1["1", "TWAECsw"] = 647.69 # Later TWAEC not implemented
+ PEC_orig_1[, "TWAECsw"] = c(NA, 647.69, 612.03, 548.76)
PEC_orig_1[, "PECsed"] = c(2.36, 2.1, 1.87, 1.49) * 1e3
- PEC_orig_1["1", "TWAECsed"] = 2.23e3 # Later TWAEC not implemented
+ PEC_orig_1[, "TWAECsed"] = c(NA, 2.23e3, 2.11e3, 1.89e3)
expect_equal(res_dummy_1$PEC[1:4, c(1, 2)], PEC_orig_1[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_dummy_1$PEC[1:4, c(3, 4)], PEC_orig_1[, c(3, 4)], tolerance = 10, scale = 1)
@@ -26,9 +26,9 @@ test_that("Results of Steps 1/2 calculator for Dummy 2 are reproduced", {
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_2[, "PECsw"] = c(299.89, 290.86, 283.21, 268.50)
- PEC_orig_2["1", "TWAECsw"] = 295.38 # Later TWAEC not implemented
+ PEC_orig_2[, "TWAECsw"] = c(NA, 295.38, 291.20, 283.49)
PEC_orig_2[, "PECsed"] = c(319.77, 319.95, 311.53, 295.35)
- PEC_orig_2["1", "TWAECsed"] = 319.86 # Later TWAEC not implemented
+ PEC_orig_2[, "TWAECsed"] = c(NA, 319.86, 317.79, 310.58)
expect_equal(res_dummy_2$PEC[1:4, c(1, 2)], PEC_orig_2[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_dummy_2$PEC[1:4, c(3, 4)], PEC_orig_2[, c(3, 4)], tolerance = 0.01, scale = 1)
@@ -43,9 +43,9 @@ test_that("Results of Steps 1/2 calculator for Dummy 4 are reproduced", {
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_4[, "PECsw"] = c(1.82, 1.18, 1.00, 0.70)
- PEC_orig_4["1", "TWAECsw"] = 1.50 # Later TWAEC not implemented
+ PEC_orig_4[, "TWAECsw"] = c(NA, 1.50, 1.29, 1.07)
PEC_orig_4[, "PECsed"] = c(10.57, 11.49, 9.66, 6.83)
- PEC_orig_4["1", "TWAECsed"] = 11.03 # Later TWAEC not implemented
+ PEC_orig_4[, "TWAECsed"] = c(NA, 11.03, 10.79, 9.48)
expect_equal(res_dummy_4$PEC[1:4, c(1, 2)], PEC_orig_4[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_dummy_4$PEC[1:4, c(3, 4)], PEC_orig_4[, c(3, 4)], tolerance = 0.01, scale = 1)
@@ -60,9 +60,9 @@ test_that("Results of Steps 1/2 calculator for Dummy 5 are reproduced", {
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_5[, "PECsw"] = c(61.60, 59.45, 59.10, 58.41)
- PEC_orig_5["1", "TWAECsw"] = 60.53 # Later TWAEC not implemented
+ PEC_orig_5[, "TWAECsw"] = c(NA, 60.53, 59.90, 59.33)
PEC_orig_5[, "PECsed"] = c(500.78, 511.28, 508.29, 502.35)
- PEC_orig_5["1", "TWAECsed"] = 506.03 # Later TWAEC not implemented
+ PEC_orig_5[, "TWAECsed"] = c(NA, 506.03, 507.90, 506.61)
expect_equal(res_dummy_5$PEC[1:4, c(1, 2)], PEC_orig_5[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_dummy_5$PEC[1:4, c(3, 4)], PEC_orig_5[, c(3, 4)], tolerance = 0.01, scale = 1)
@@ -77,9 +77,9 @@ test_that("Results of Steps 1/2 calculator for Dummy 7 are reproduced", {
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_7[, "PECsw"] = c(626.99, 601.13, 586.43, 558.10)
- PEC_orig_7["1", "TWAECsw"] = 614.06 # Later TWAEC not implemented
+ PEC_orig_7[, "TWAECsw"] = c(NA, 614.06, 603.90, 588.03)
PEC_orig_7[, "PECsed"] = c(3.0, 3.01, 2.93, 2.79) * 1e3
- PEC_orig_7["1", "TWAECsed"] = 3.01e3 # Later TWAEC not implemented
+ PEC_orig_7[, "TWAECsed"] = c(NA, 3.01e3, 2.99e3, 2.92e3)
expect_equal(res_dummy_7$PEC[1:4, c(1, 2)], PEC_orig_7[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_dummy_7$PEC[1:4, c(3, 4)], PEC_orig_7[, c(3, 4)], tolerance = 10, scale = 1)
@@ -95,9 +95,9 @@ test_that("Results of Steps 1/2 calculator for New Dummy (M1-M3) are reproduced"
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_M1[, "PECsw"] = c(62.5, 62.07, 61.64, 60.79)
- PEC_orig_M1["1", "TWAECsw"] = 62.28 # Later TWAEC not implemented
+ PEC_orig_M1[, "TWAECsw"] = c(NA, 62.28, 62.07, 61.64)
PEC_orig_M1[, "PECsed"] = c(31.25, 31.03, 30.82, 30.40)
- PEC_orig_M1["1", "TWAECsed"] = 31.14 # Later TWAEC not implemented
+ PEC_orig_M1[, "TWAECsed"] = c(NA, 31.14, 31.03, 30.82)
expect_equal(res_M1$PEC[1:4, c(1, 2)], PEC_orig_M1[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_M1$PEC[1:4, c(3, 4)], PEC_orig_M1[, c(3, 4)], tolerance = 0.01, scale = 1)
@@ -110,9 +110,9 @@ test_that("Results of Steps 1/2 calculator for New Dummy (M1-M3) are reproduced"
dimnames = list(Time = t_out, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed")))
PEC_orig_M2[, "PECsw"] = c(64.34, 63.78, 63.34, 62.47)
- PEC_orig_M2["1", "TWAECsw"] = 64.06 # Later TWAEC not implemented
+ PEC_orig_M2[, "TWAECsw"] = c(NA, 64.06, 63.81, 63.36)
PEC_orig_M2[, "PECsed"] = c(31.25, 31.89, 31.67, 31.23)
- PEC_orig_M2["1", "TWAECsed"] = 31.57 # Later TWAEC not implemented
+ PEC_orig_M2[, "TWAECsed"] = c(NA, 31.57, 31.68, 31.56)
expect_equal(res_M2$PEC[1:4, c(1, 2)], PEC_orig_M2[, c(1, 2)], tolerance = 0.01, scale = 1)
expect_equal(res_M2$PEC[1:4, c(3, 4)], PEC_orig_M2[, c(3, 4)], tolerance = 0.01, scale = 1)

Contact - Imprint