Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only write params with priors and/or data to config.xml #3125

Closed
wants to merge 12 commits into from
38 changes: 20 additions & 18 deletions models/ed/R/write.configs.ed.R
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,22 @@ write.config.xml.ED2 <- function(settings, trait.values, defaults = settings$con
# a new history file, add the .csv file to models/ed/data-raw and run the
# sysdata.R script in that folder

if(is.null(settings$model$revision)) {
PEcAn.logger::logger.debug("--- Using Generic ED2 History File")
edhistory <- history
} else {
histfile <- paste0("history.r", settings$model$revision)
edhistory <- try(eval(str2lang(histfile)), silent = TRUE)
}

if(inherits(edhistory, "try-error")) {
PEcAn.logger::logger.debug("--- Using Generic ED2 History File")
edhistory <- history
} else {
PEcAn.logger::logger.debug(paste0("--- Using ED2 History File: ", histfile))
}

edtraits <- names(edhistory)
# if(is.null(settings$model$revision)) {
# PEcAn.logger::logger.debug("--- Using Generic ED2 History File")
# edhistory <- history
# } else {
# histfile <- paste0("history.r", settings$model$revision)
# edhistory <- try(eval(str2lang(histfile)), silent = TRUE)
# }
#
# if(inherits(edhistory, "try-error")) {
# PEcAn.logger::logger.debug("--- Using Generic ED2 History File")
# edhistory <- history
# } else {
# PEcAn.logger::logger.debug(paste0("--- Using ED2 History File: ", histfile))
# }
#
# edtraits <- names(edhistory)
pftmapping <- PEcAn.ED2::pftmapping

## Get ED2 specific model settings and put into output config xml file
Expand Down Expand Up @@ -542,13 +542,15 @@ write.config.xml.ED2 <- function(settings, trait.values, defaults = settings$con

} else {
## Get default trait values from ED history
vals <- as.list(edhistory[edhistory$num == pft.number, ])
# vals <- as.list(edhistory[edhistory$num == pft.number, ])

## Convert trait values to ED units
converted.trait.values <- convert.samples.ED(trait.values[[i]])

## Selectively replace defaults with trait values
vals <- modifyList(vals, converted.trait.values)
# vals <- modifyList(vals, converted.trait.values)
vals <- converted.trait.values
vals$num <- pft.number #keep the ED2 pft number

## Convert settings constants to ED units
converted.defaults <- convert.samples.ED(defaults[[pft]]$constants)
Expand Down
56 changes: 28 additions & 28 deletions models/ed/tests/testthat/test.write.configs.ed.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,34 +183,34 @@ test_that("New ED2IN tags get added at bottom of file", {
})


test_that("write.config.xml.ED2() uses correct history file", {
#1. read in pecan.xml in data/pecan_checked.xml
settings <- PEcAn.settings::read.settings("data/pecan_checked.xml")
#for debugging:
# settings <- PEcAn.settings::read.settings("models/ed/tests/testthat/data/pecan_checked.xml")

#2. Set rundir to tempdir
rundir <- tempfile()
dir.create(rundir)
on.exit(unlink(rundir, recursive = TRUE))
settings$rundir <- rundir
run.id <- "ENS-00001-76"
dir.create(file.path(rundir, run.id))
#3. set revision to 81
settings$model$revision <- "81"

x <- capture.output(
write.config.xml.ED2(
settings = settings,
trait.values = trait.values,
defaults = defaults
),
type = "message"
)

expect_true(any(stringr::str_detect(x, "history.r81")))

})
# test_that("write.config.xml.ED2() uses correct history file", {
# #1. read in pecan.xml in data/pecan_checked.xml
# settings <- PEcAn.settings::read.settings("data/pecan_checked.xml")
# #for debugging:
# # settings <- PEcAn.settings::read.settings("models/ed/tests/testthat/data/pecan_checked.xml")
#
# #2. Set rundir to tempdir
# rundir <- tempfile()
# dir.create(rundir)
# on.exit(unlink(rundir, recursive = TRUE))
# settings$rundir <- rundir
# run.id <- "ENS-00001-76"
# dir.create(file.path(rundir, run.id))
# #3. set revision to 81
# settings$model$revision <- "81"
#
# x <- capture.output(
# write.config.xml.ED2(
# settings = settings,
# trait.values = trait.values,
# defaults = defaults
# ),
# type = "message"
# )
#
# expect_true(any(stringr::str_detect(x, "history.r81")))
#
# })


## test_that("remove.configs.ED2 works with remote host",{
Expand Down