diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2017-06-22 08:23:13 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2017-06-22 08:43:14 +0200 |
commit | dffa31a5ad5026d4d67327da622f45c00be40584 (patch) | |
tree | cd2831e92a0b9523397937c7acc3c53e44bb004b | |
parent | 0d60c88ba7e0693a832056ea3db5cc0eaf3b0819 (diff) |
Add scenario, region and season to run name
-rw-r--r-- | ChangeLog | 33 | ||||
-rw-r--r-- | DESCRIPTION | 2 | ||||
-rw-r--r-- | R/PEC_sw_focus.R | 15 | ||||
-rw-r--r-- | man/PEC_sw_focus.Rd | 3 | ||||
-rw-r--r-- | tests/testthat/test_step_1.R | 42 |
5 files changed, 70 insertions, 25 deletions
@@ -1,3 +1,36 @@ +commit 7df0f45b785841e9e490a945a9f6091a68e6333c +Author: Johannes Ranke <jranke@uni-bremen.de> +Date: 2017-06-22 08:23:13 +0200 + + Add region and season to run name + +commit 0d60c88ba7e0693a832056ea3db5cc0eaf3b0819 +Author: Johannes Ranke <jranke@uni-bremen.de> +Date: 2017-06-20 14:16:14 +0200 + + Fix line endings and allow all interception classes + +commit dc1e49c8bb27cac81268719055bc4336843c0506 +Author: Johannes Ranke <jranke@uni-bremen.de> +Date: 2017-06-20 06:16:19 +0200 + + Keep dos format for pesticide.txt test data + +commit fd40f74907e89077bd81af5d779ae93e1434d8c6 +Author: Johannes Ranke <jranke@uni-bremen.de> +Date: 2017-06-20 06:11:12 +0200 + + Now the errors in PELMO output are gone - not reproducible + +commit 88044fd98c5b95d3f3f9bbef7416af66552189c1 +Author: Johannes Ranke <jranke@uni-bremen.de> +Date: 2017-06-20 06:04:14 +0200 + + Tests for Step 1 and 2 (input file only) pass, PELMO fails + + There are spurious errors in the output PELMO generates. Two examples + are in the test.log + commit 34d4915297faf6236479f0e6474f8aa6b8d4b416 Author: Johannes Ranke <jranke@uni-bremen.de> Date: 2017-06-20 04:30:52 +0200 diff --git a/DESCRIPTION b/DESCRIPTION index c456607..379f8a8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: pfm Type: Package Title: Utilities for Pesticide Fate Modelling Version: 0.4-3 -Date: 2017-06-20 +Date: 2017-06-22 Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de", role = c("aut", "cre", "cph")) Description: Utilities for simple calculations of predicted environmental diff --git a/R/PEC_sw_focus.R b/R/PEC_sw_focus.R index aed83a0..1dd5340 100644 --- a/R/PEC_sw_focus.R +++ b/R/PEC_sw_focus.R @@ -70,8 +70,8 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA, scenario = FOCUS_Step_12_scenarios$names, region = c("n", "s"), season = c(NA, "of", "mm", "js"), - interception = c("no interception", "minimal crop cover", - "average crop cover", "full canopy"), + interception = c("no interception", "minimal crop cover", + "average crop cover", "full canopy"), txt_file = "pesticide.txt", overwrite = FALSE, append = TRUE) { if (n > 1 & is.na(i)) stop("Please specify the interval i if n > 1") @@ -102,7 +102,7 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA, "DT50 water", "DT50 sediment", "Region / Season", "Interception class") - add_line <- function(x) cat(x, sep = "\r\n", + add_line <- function(x) cat(x, sep = "\r\n", file = txt, append = TRUE) if (file.exists(txt_file)) { if (append) { @@ -169,8 +169,15 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA, reg_sea = reg_code + sea_code } + if (is.null(met)) { + name_input <- paste(parent$name, scenario, region, season) + } else { + name_input <- paste(met$name, scenario, region, season) + } + if (comment != "") name_input = paste(name_input, comment) + run_txt <- c( - ai = parent$name, compound = compound, + ai = name_input, compound = name_input, comment = comment) run_numeric <- c( diff --git a/man/PEC_sw_focus.Rd b/man/PEC_sw_focus.Rd index e9f638d..f55fccc 100644 --- a/man/PEC_sw_focus.Rd +++ b/man/PEC_sw_focus.Rd @@ -7,7 +7,8 @@ PEC_sw_focus(parent, rate, n = 1, i = NA, comment = "", met = NULL, f_drift = NA, f_rd = 0.1, scenario = FOCUS_Step_12_scenarios$names, region = c("n", "s"), season = c(NA, "of", "mm", "js"), - interception = "no interception", txt_file = "pesticide.txt", + interception = c("no interception", "minimal crop cover", + "average crop cover", "full canopy"), txt_file = "pesticide.txt", overwrite = FALSE, append = TRUE) } \arguments{ diff --git a/tests/testthat/test_step_1.R b/tests/testthat/test_step_1.R index 024a25a..23358dd 100644 --- a/tests/testthat/test_step_1.R +++ b/tests/testthat/test_step_1.R @@ -26,19 +26,6 @@ M2 <- chent_focus_sw("Metabolite M2", Koc = 50, max_ws = 0.5, max_soil = 0, DT50_soil = 20, DT50_water = 10, DT50_sediment = 100) -# When we compare the generated input file with the test file, -# we can ignore some fields if we are looking at the parent ai -field_index <- c(ai = 1, compound = 2, comment = 3, - mw_ai = 4, mw_met = 5, - cwsat = 6, Koc_assessed = 7, - Koc_parent = 8, - DT50_ws = 9, - max_ws = 10, max_soil = 11, - rate = 12, n = 13, i = 14, app_type = 15, - DT50_soil_parent = 16, DT50_soil = 17, DT50_water = 18, DT50_sediment = 19, - reg_sea = 20, int_class = 21) -field_index_parent <- field_index[-c(4:5, 8, 10:11, 16)] - t_out_1 <- c(0, 1, 2, 4) # Checking the first four days is sufficient for Step 1 PEC_template_1 <- matrix(NA, nrow = length(t_out_1), ncol = 4, dimnames = list(Time = t_out_1, type = c("PECsw", "TWAECsw", "PECsed", "TWAECsed"))) @@ -176,6 +163,23 @@ test_that("Results of Steps 1/2 calculator for New Dummy (M1-M2) are reproduced" }) context("FOCUS Steps 12 input files") # {{{1 +# When we compare the generated input file with the test file, +# we can ignore some fields if we are looking at the parent ai +# Also, the ai and compound names are not checked, as we append +# scenario, region and season in order to get unique names +# for Step 2 result files of the Step12 calculator +field_index <- c(ai = 1, compound = 2, comment = 3, + mw_ai = 4, mw_met = 5, + cwsat = 6, Koc_assessed = 7, + Koc_parent = 8, + DT50_ws = 9, + max_ws = 10, max_soil = 11, + rate = 12, n = 13, i = 14, app_type = 15, + DT50_soil_parent = 16, DT50_soil = 17, DT50_water = 18, DT50_sediment = 19, + reg_sea = 20, int_class = 21) +field_index_mets <- field_index[-c(1, 2)] +field_index_parent <- field_index[-c(1:2, 4:5, 8, 10:11, 16)] + test_that("Runs are correctly defined in the Steps 12 input file", { # {{{1 pest_txt <- readLines("pesticide.txt") @@ -207,14 +211,14 @@ test_that("Runs are correctly defined in the Steps 12 input file", { # {{{1 expect_equal(test_7, pest_7) # Parent fields # New Dummy / M1 - test_m1 <- strsplit(test_txt[10], "\t")[[1]] - pest_m1 <- strsplit(pest_txt[7], "\t")[[1]] - expect_equal(test_m1, pest_m1) # All fields + test_m1 <- strsplit(test_txt[10], "\t")[[1]][field_index_mets] + pest_m1 <- strsplit(pest_txt[7], "\t")[[1]][field_index_mets] + expect_equal(test_m1, pest_m1) # All fields except ai and met names # New Dummy / M2 - test_m2 <- strsplit(test_txt[11], "\t")[[1]] - pest_m2 <- strsplit(pest_txt[8], "\t")[[1]] - expect_equal(test_m2, pest_m2) # All fields + test_m2 <- strsplit(test_txt[11], "\t")[[1]][field_index_mets] + pest_m2 <- strsplit(pest_txt[8], "\t")[[1]][field_index_mets] + expect_equal(test_m2, pest_m2) # All fields except ai and met names }) unlink("pesticide.txt") |