diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2018-07-10 17:57:33 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2018-07-10 17:59:19 +0200 |
commit | cb3695dd434b3a3273217fb22c5ffb86065ae96d (patch) | |
tree | c37fbe68273e25d2741c0845665458357ac05450 /tests | |
parent | c4c3ca282c6aadca82e392692ae4100fec1dd834 (diff) |
EFSA PEC soil guidance from 2017
- Implement the new guidance as well as possible
- Maintenance work addressing CRAN checks
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testthat/test_PEC_soil.R | 68 | ||||
-rw-r--r-- | tests/testthat/test_PELMO.R | 10 | ||||
-rw-r--r-- | tests/testthat/test_TOXSWA.R | 49 |
3 files changed, 91 insertions, 36 deletions
diff --git a/tests/testthat/test_PEC_soil.R b/tests/testthat/test_PEC_soil.R index 0661a52..34b4749 100644 --- a/tests/testthat/test_PEC_soil.R +++ b/tests/testthat/test_PEC_soil.R @@ -1,4 +1,5 @@ library(pfm) +library(testthat) context("Simple PEC soil calculations") test_that("PEC_soil calculates correctly", { @@ -6,40 +7,73 @@ test_that("PEC_soil calculates correctly", { expect_equal(as.numeric(PEC_soil(100)), 0.1 * 4/3) # or 0.1 mg/kg assuming 25% interception - expect_equal(as.numeric(PEC_soil(100, interception = 0.25)), 0.1) + expect_equal(as.numeric(PEC_soil(100, interception = 0.25)), 0.1) # Mixing depth of 1 cm gives five-fold PEC expect_equal(as.numeric(PEC_soil(100, interception = 0.25, mixing_depth = 1)), 0.5) }) -test_that("Tier 1 PEC soil example for Pesticide A in EFSA guidance can be reproduced", { +test_that("Tier 1 PEC soil example for Pesticide A in EFSA guidance from 2017 can be reproduced", { # Calculate total soil concentrations for tier 1 scenarios - results_pfm <- PEC_soil(1000, interval = 365, DT50 = 250, t_avg = c(0, 21), - scenarios = "EFSA_2015") + # Leaching is calculated from the 5 cm layer to be able to reproduce the + # results from the guidance + results_pfm_2017 <- PEC_soil(1000, interval = 365, DT50 = 250, t_avg = c(0, 21), + scenarios = "EFSA_2017", Kom = 1000, + leaching_depth = 5) + + # From Table G.2, p. 92 + results_guidance_2017 <- matrix(c(18.6, 13.0, 9.9, 18.2, 12.7, 9.6), + ncol = 3, byrow = TRUE) + dimnames(results_guidance_2017) <- list(t_avg = c(0, 21), + scenario = c("CTN", "CTC", "CTS")) + + + expect_equal(round(results_pfm_2017, 1)[1, ], results_guidance_2017[1, ]) + # I do not get the same TWA concentrations as in the 2017 guidance on p. 92 + + # Calculate porewater soil concentrations for tier 1 scenarios + results_pfm_pw_2017 <- PEC_soil(1000, interval = 365, DT50 = 250, t_av = c(0, 21), + Kom = 1000, scenarios = "EFSA_2017", porewater = TRUE, + leaching_depth = 5) # From Table I.5, p. 80 - results_guidance <- matrix(c(22.0, 11.5, 9.1, 21.8, 11.4, 9.0), - ncol = 3, byrow = TRUE) - dimnames(results_guidance) <- list(t_avg = c(0, 21), - scenario = c("CTN", "CTC", "CTS")) + results_guidance_pw_2017 <- matrix(c(0.48, 0.60, 0.91, 0.47, 0.58, 0.86), + ncol = 3, byrow = TRUE) + dimnames(results_guidance_pw_2017) <- list(t_avg = c(0, 21), + scenario = c("CLN", "CLC", "CLS")) + expect_equal(round(results_pfm_pw_2017, 2)[1, ], results_guidance_pw_2017[1, ]) + # Here I also do not get the same TWA concentrations as in the guidance p. 92 +}) + +test_that("Tier 1 PEC soil example for Pesticide A in EFSA guidance from 2015 can be reproduced", { + # Calculate total soil concentrations for tier 1 scenarios + results_pfm_2015 <- PEC_soil(1000, interval = 365, DT50 = 250, t_avg = c(0, 21), + scenarios = "EFSA_2015") + + # From Table I.5, p. 80 + results_guidance_2015 <- matrix(c(22.0, 11.5, 9.1, 21.8, 11.4, 9.0), + ncol = 3, byrow = TRUE) + dimnames(results_guidance_2015) <- list(t_avg = c(0, 21), + scenario = c("CTN", "CTC", "CTS")) - expect_equal(round(results_pfm, 1), results_guidance) + + expect_equal(round(results_pfm_2015, 1), results_guidance_2015) # Calculate porewater soil concentrations for tier 1 scenarios - results_pfm_pw <- PEC_soil(1000, interval = 365, DT50 = 250, t_av = c(0, 21), - Kom = 1000, scenarios = "EFSA_2015", porewater = TRUE) + results_pfm_pw_2015 <- PEC_soil(1000, interval = 365, DT50 = 250, t_av = c(0, 21), + Kom = 1000, scenarios = "EFSA_2015", porewater = TRUE) # From Table I.5, p. 80 - results_guidance_pw <- matrix(c(0.76, 0.67, 0.91, 0.75, 0.66, 0.90), - ncol = 3, byrow = TRUE) - dimnames(results_guidance_pw) <- list(t_avg = c(0, 21), - scenario = c("CLN", "CLC", "CLS")) + results_guidance_pw_2015 <- matrix(c(0.76, 0.67, 0.91, 0.75, 0.66, 0.90), + ncol = 3, byrow = TRUE) + dimnames(results_guidance_pw_2015) <- list(t_avg = c(0, 21), + scenario = c("CLN", "CLC", "CLS")) - expect_equal(round(results_pfm_pw, 2), results_guidance_pw) + expect_equal(round(results_pfm_pw_2015, 2), results_guidance_pw_2015) }) -test_that("Tier 1 PEC soil example for Pesticide F in EFSA guidance can be reproduced", { +test_that("Tier 1 PEC soil example for Pesticide F in EFSA guidance from 2015 can be reproduced", { # Parent F # Calculate total and porewater soil concentrations for tier 1 scenarios results_pfm <- PEC_soil(1000, interval = 365, DT50 = 25, t_avg = c(0, 21), diff --git a/tests/testthat/test_PELMO.R b/tests/testthat/test_PELMO.R index be0b410..49c03d3 100644 --- a/tests/testthat/test_PELMO.R +++ b/tests/testthat/test_PELMO.R @@ -45,6 +45,7 @@ test_that("PELMO runs are correctly set up", { } # Prepare runs in analogy to the test archive + skip_on_cran() PELMO_runs(runs, psm_dir = PELMO_base, execute = FALSE, evaluate = FALSE, overwrite = TRUE) # Check that input files are correctly generated in the right location @@ -70,6 +71,7 @@ test_that("PELMO runs can be run and give the expected result files", { skip("A wine installation is needed for this test") } + skip_on_cran() run_PELMO(runs, cores = 7) plm_files <- c("CHEM.PLM", "ECHO.PLM", @@ -89,8 +91,12 @@ test_that("PELMO runs can be run and give the expected result files", { new <- readLines(file.path(PELMO_base, "FOCUS", pp, plm)) test <- readLines(file.path(test_dir, pp, plm)) + # Don't check for differences in the PESTICIDE BALANCE ERROR + pest_balance_error <- suppressWarnings(grep("PESTICIDE BALANCE ERROR", new)) + # Suppress warnings about invalid strings in this locale caused by the files + # Check if the ouput files are correctly reproduced - expect_identical(new, test) + expect_identical(new[!pest_balance_error], test[!pest_balance_error]) } } } @@ -105,6 +111,7 @@ test_that("PELMO runs are correctly evaluated", { skip("A wine installation is needed for this test") } + skip_on_cran() # Check that if output is the same as in the test archive for (run in runs) { psm <- run$psm @@ -164,6 +171,7 @@ test_that("PECgw from FOCUS summary files can be reproduced", { if (!wine_installed) { skip("A wine installation is needed for this test") } + skip_on_cran() focus_summary <- list() for (run in runs) { diff --git a/tests/testthat/test_TOXSWA.R b/tests/testthat/test_TOXSWA.R index 7c9a73c..de60d48 100644 --- a/tests/testthat/test_TOXSWA.R +++ b/tests/testthat/test_TOXSWA.R @@ -1,26 +1,23 @@ library(pfm) context("Read and analyse TOXSWA cwa files") -zipfile_test = system.file("testdata/SwashProjects.zip", package = "pfm") -basedir_test = "SwashProjects/project_H_sw/TOXSWA" - -H_sw_D4_pond <- read.TOXSWA_cwa("00001p_pa.cwa", - basedir = basedir_test, - zipfile = zipfile_test) - -H_sw_R1_stream <- read.TOXSWA_cwa("00003s_pa.cwa", - basedir = basedir_test, - zipfile = zipfile_test) +# zipfile_test = tempfile() +# download.file("https://cgit.jrwb.de/pfm/plain/inst/testdata/SwashProjects.zip", zipfile_test) +zipfile_test <- system.file("testdata/SwashProjects.zip", package = "pfm") +basedir_test = "SwashProjects/project_H_sw/TOXSWA" # cwa files from TOXSWA 3.x +# .out file produced with TOXSWA 4.4.2 basedir_test_2 = "SwashProjects/Project_1/TOXSWA" -EXSW2_R1_stream <- read.TOXSWA_cwa("3.out", - basedir = basedir_test_2, - zipfile = zipfile_test) - +H_sw_D4_pond <- read.TOXSWA_cwa("00001p_pa.cwa", + basedir = basedir_test, + zipfile = zipfile_test) +H_sw_R1_stream <- read.TOXSWA_cwa("00003s_pa.cwa", + basedir = basedir_test, + zipfile = zipfile_test) -test_that("TOXSWA cwa file is correctly read and printed", { +test_that("Old TOXSWA cwa and out files are correctly read and printed", { # This was the setting when printing the output into text files options(width = 100) @@ -37,15 +34,31 @@ test_that("TOXSWA cwa file is correctly read and printed", { # The basedir is not printed, therefore tested separately expect_equal(H_sw_D4_pond$basedir, basedir_test) + + EXSW2_R1_stream <- read.TOXSWA_cwa("3.out", + basedir = basedir_test_2, + zipfile = zipfile_test) EXSW2_R1_stream_printed <- capture.output(print(EXSW2_R1_stream)) expect_equal(EXSW2_R1_stream_printed, readLines("EXSW2_R1_stream_printed.txt")) +}) - # The basedir is not printed, therefore tested separately - expect_equal(H_sw_D4_pond$basedir, basedir_test) +test_that("A TOXSWA 5.5.3 out file is correctly read and printed", { + # zipfile_test_3 = tempfile() + # download.file("https://cgit.jrwb.de/pfm/plain/inst/testdata/SwashProjects_TOXSWA_553.zip", + # zipfile_test_3) + zipfile_test_3 <- system.file("testdata/SwashProjects_TOXSWA_553.zip", package = "pfm") + basedir_test_3 = "SwashProjects/Project_1/TOXSWA" + + EXSW2_R1_stream_TOXSWA_553 <- read.TOXSWA_cwa("3.out", + basedir = basedir_test_3, + zipfile = zipfile_test_3) + EXSW2_R1_stream_printed_TOXSWA_553 <- capture.output(print(EXSW2_R1_stream_TOXSWA_553)) + + # We actually get the same results, at least judged by the printed object + expect_equal(EXSW2_R1_stream_printed_TOXSWA_553, readLines("EXSW2_R1_stream_printed.txt")) }) test_that("Getting events and moving window analysis works", { - # Event analysis with two different thresholds H_sw_R1_stream$get_events(c(2, 10)) expect_equal_to_reference(H_sw_R1_stream$events, file = "H_sw_R1_stream_events.rds") |