From 3c82d26206e2f2e74600acd71a49c70eaed555c4 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 27 Jan 2017 08:17:08 +0100 Subject: Also test run with metabolites --- ChangeLog | 11 ++++++-- R/PELMO_runs.R | 5 ++-- tests/testthat/test_PELMO.R | 63 ++++++++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19fe18d..762acf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,17 @@ -commit 8f943c9dd2322482f64e1c6348c1ad7cfd253ee8 +commit 8fd050e57b7babfbdb1ccfabb468a0398396d466 +Author: Johannes Ranke +Date: 2017-01-27 07:54:53 +0100 + + Include a run with metabolites in PELMO test data + +commit b38055278d4a801598ece9d2c93716a9bf67134a Author: Johannes Ranke Date: 2017-01-27 01:00:07 +0100 Set up FOCUS PELMO runs and run them in parallel - - This works on Linux using wine. + - This works on Linux using wine + - PELMO runs (including pelmo.inp files) are correctly generated - The PLM files for FOCUS Pesticide_D in the test data archive are correctly reproduced - The data files (including FOCUS groundwater scenario data) are now diff --git a/R/PELMO_runs.R b/R/PELMO_runs.R index 7430b40..f599110 100644 --- a/R/PELMO_runs.R +++ b/R/PELMO_runs.R @@ -158,7 +158,7 @@ PELMO_runs <- function(runs, psm_dir = ".", version = "5.5.3", PELMO_base = "aut #' @inheritParams PELMO_runs #' @importFrom parallel mclapply #' @export -run_PELMO <- function(runs, psm_dir = ".", version = "5.5.3", PELMO_base = "auto", +run_PELMO <- function(runs, version = "5.5.3", PELMO_base = "auto", cores = getOption("mc.cores", 2L)) { @@ -204,7 +204,8 @@ run_PELMO <- function(runs, psm_dir = ".", version = "5.5.3", PELMO_base = "auto # We need to go the directory to simplify calling pelmo with wine setwd(run_dir_exe) - psm_file <- file.path(psm_dir, paste0(psm, ".psm")) + psm_file <- paste0(psm, ".psm") + message("Starting ", pelmo_exe, " with ", psm_file) system(paste("wine", pelmo_exe, psm_file), ignore.stdout = TRUE) # Copy the results to the original run directory diff --git a/tests/testthat/test_PELMO.R b/tests/testthat/test_PELMO.R index 4bd36ef..7b7e2b6 100644 --- a/tests/testthat/test_PELMO.R +++ b/tests/testthat/test_PELMO.R @@ -1,10 +1,4 @@ -# Remove when the test is ready to be run by testthat -#library(testthat) -#test_dir <- "/tmp/Rtmp8DFCT5" -#psm_name <- "D_rel_1" -#source("~/git/pfm/inst/extdata/FOCUS_PELMO_data.R") -#source("~/git/pfm/R/PELMO_runs.R") - +library(testthat) library(pfm) context("Create PELMO runs from psm files and execute them") PELMO_base <- system.file("FOCUSPELMO.553", package = "PELMO.installeR") @@ -22,22 +16,26 @@ runs <- list( psm = "Pesticide_D_1_day_pre_em_every_third_year", pot = c("Cha", "Ham")), list( - psm = "Pesticide_D_1_May_every_other_year", + psm = "Pesticide_D_1_May_every_other_year_mets", mai = c("Cha"))) -psm_paths = c( - D_rel_1 = PELMO_path(runs[1]$psm, "fbe", "Por"), - D_rel_3 = PELMO_path(runs[2]$psm, "pot", "Ham"), - D_abs_2 = PELMO_path(runs[3]$psm, "mai", "Cha")) -# Get psm files and put them into PELMO_base -psm_new_locations <- character(0) -for (psm_name in names(psm_paths)) { - psm_file <- file.path(test_dir, psm_paths[psm_name], paste0(runs[1]$psm, ".psm")) - psm_new_location <- file.path(PELMO_base, basename(psm_file)) - psm_new_locations[psm_name] <- psm_new_location - file.copy(psm_file, psm_new_location) -} +test_that("PELMO paths are correctly created", { + psm_paths = c( + PELMO_path(runs[[1]]$psm, "fbe", "Por"), + PELMO_path(runs[[2]]$psm, "pot", "Ham"), + PELMO_path(runs[[3]]$psm, "mai", "Cha")) + + # Check for psm files and put them into PELMO_base + psm_new_locations <- character(0) + for (i in seq_along(psm_paths)) { + psm_file <- file.path(test_dir, psm_paths[i], paste0(runs[[i]]$psm, ".psm")) + expect_true(file.exists(psm_file)) + psm_new_location <- file.path(PELMO_base, basename(psm_file)) + psm_new_locations[i] <- psm_new_location + file.copy(psm_file, psm_new_location) + } +}) test_that("PELMO runs are correctly set up", { @@ -47,12 +45,12 @@ test_that("PELMO runs are correctly set up", { # Check that input files are correctly generated in the right location for (run in runs) { psm <- run$psm - message(psm) + # message(psm) crops <- setdiff(names(run), "psm") for (crop in crops) { - message(crop) + # message(crop) for (scenario in run[[crop]]) { - message(scenario) + # message(scenario) pp <- PELMO_path(psm, crop, scenario) input_new <- readLines(file.path(PELMO_base, "FOCUS", pp, "pelmo.inp")) @@ -66,10 +64,11 @@ test_that("PELMO runs are correctly set up", { }) test_that("PELMO runs can be run and give the expected result files", { - run_PELMO(runs, psm_dir = PELMO_base, cores = 5) + run_PELMO(runs, cores = 5) - plm_files <- c("CHEM.PLM", "ECHO.PLM", "KONZCHEM.PLM", "PLNTPEST.plm", - "PLOT.PLM", "WASSER.PLM") + plm_files <- c("CHEM.PLM", "ECHO.PLM", + "KONZCHEM.PLM", "KONZC_A1", "KONZC_B1", + "PLNTPEST.plm", "PLOT.PLM", "WASSER.PLM") # Check that if output is the same as in the test archive for (run in runs) { @@ -82,11 +81,13 @@ test_that("PELMO runs can be run and give the expected result files", { pp <- PELMO_path(psm, crop, scenario) for (plm in plm_files) { - new <- readLines(file.path(PELMO_base, "FOCUS", pp, plm)) - test <- readLines(file.path(test_dir, pp, plm)) + if (file.exists(file.path(test_dir, pp, plm))) { + new <- readLines(file.path(PELMO_base, "FOCUS", pp, plm)) + test <- readLines(file.path(test_dir, pp, plm)) - # Check if the ouput files are correctly reproduced - expect_identical(new, test) + # Check if the ouput files are correctly reproduced + expect_identical(new, test) + } } } } @@ -94,6 +95,8 @@ test_that("PELMO runs can be run and give the expected result files", { }) test_that("PELMO runs are correctly evaluated", { + evaluate_PELMO(runs, psm_dir = PELMO_base) + }) -- cgit v1.2.1