diff --git a/CHANGELOG.md b/CHANGELOG.md index cbcd5f9e0e8..1d7899f14e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha - Added statewide synthetic fertilization and compost amendment event workflows for CA ag parcels. Outputs share an ensemble naming so a downstream cleaner unions them into one fertilization event type for SIPNET. ### Fixed +- `PEcAn.RothC::write.config.RothC()` ignored the `opt_SMDbare` setting and used `opt_RMmoist` for both options (#4217). - `PEcAn.uncertainty::read.ensemble.output()` uses `NA` for missing variables, so each member’s result uses only its own output (#4204). - Fixed broken meteorological data, flux network, and API documentation links in the PEcAn book and data.atmosphere package (#4071). - `PEcAn.uncertainty::generate_joint_ensemble_design(sobol = TRUE)` now errors on looped inputs and quasi-random parameter methods, which split into dependent `X1` and `X2` halves and gave wrong Sobol indices (#4134). diff --git a/models/rothc/NEWS.md b/models/rothc/NEWS.md index cc686419188..5367331c482 100644 --- a/models/rothc/NEWS.md +++ b/models/rothc/NEWS.md @@ -1,3 +1,5 @@ # PEcAn.RothC 0.0.0.9000 -Initial development version \ No newline at end of file +Initial development version + +* `write.config.RothC()` now reads the `opt_SMDbare` setting for the bare-soil moisture deficit option. It previously used `opt_RMmoist` for both options, so `opt_SMDbare` was ignored (#4217). \ No newline at end of file diff --git a/models/rothc/R/write.config.RothC.R b/models/rothc/R/write.config.RothC.R index d645ecb012b..4a85741dd75 100644 --- a/models/rothc/R/write.config.RothC.R +++ b/models/rothc/R/write.config.RothC.R @@ -137,7 +137,7 @@ write.config.RothC <- function(defaults, trait.values, settings, run.id) { # Bare SMD: wilting point configuration # 1: Standard RothC bareSMD # 2: bareSMD is set to wilting point -15bar (could be better for dry soils) - smdbare <- settings$model$opt_RMmoist %||% 1 + smdbare <- settings$model$opt_SMDbare %||% 1 config.text <- gsub("@OPT_SMDBARE@", smdbare, config.text) # min_RM_moist: Lowest value taken by the soil moisture rate modifier, diff --git a/models/rothc/tests/testthat/test-write.config.RothC.R b/models/rothc/tests/testthat/test-write.config.RothC.R new file mode 100644 index 00000000000..5f5906ba177 --- /dev/null +++ b/models/rothc/tests/testthat/test-write.config.RothC.R @@ -0,0 +1,62 @@ +test_that("write.config.RothC writes opt_RMmoist and opt_SMDbare as separate flags", { + pth <- withr::local_tempdir() + dir.create(file.path(pth, "run", "r1"), recursive = TRUE) + dir.create(file.path(pth, "out", "r1"), recursive = TRUE) + met <- file.path(pth, "met.dat") + data.frame( + year = 2020, month = 1:12, Tmp_C = 10, Rain_mm = 50, Evap_mm = 0 + ) |> + utils::write.table(met, row.names = FALSE, quote = FALSE) + + fake_soil <- function(...) { + dat <- data.frame( + depth = c(0.1, 0.2, 0.3, 0.4), # m + fraction_of_clay_in_soil = 0.3, + fraction_of_silt_in_soil = 0.3, + soil_bulk_density = 1350, + soil_organic_carbon_stock = 2 + ) + attr(dat, "units") <- c( + depth = "meters", + fraction_of_clay_in_soil = "1", + fraction_of_silt_in_soil = "1", + soil_bulk_density = "kg m-3", + soil_organic_carbon_stock = "kg m-2" + ) + dat + } + + run_config <- function(model_opts) { + s <- list( + rundir = file.path(pth, "run"), + host = list(rundir = file.path(pth, "run"), outdir = file.path(pth, "out")), + model = c(list(binary = "rothc"), model_opts), + run = list( + start.date = "2020-01-01", + end.date = "2020-12-31", + site = list( + lat = 1, lon = 1, met.start = "2020-01-01", met.end = "2020-12-31" + ), + inputs = list( + met = list(path = met), + soil_physics = list(path = "ignored") + ) + ) + ) + with_mocked_bindings( + write.config.RothC(NULL, NULL, s, "r1"), + netcdf2df = fake_soil + ) + lines <- readLines(file.path(pth, "run", "r1", "RothC_input.dat")) + lines <- lines[!grepl("^#", lines)] + list( + flags = scan(text = lines[[1]], quiet = TRUE), + soil = scan(text = lines[[2]], quiet = TRUE) + ) + } + + res <- run_config(list(opt_RMmoist = 2, opt_SMDbare = 1)) + expect_equal(res$flags, c(2, 1)) + res <- run_config(list(opt_RMmoist = 1, opt_SMDbare = 2)) + expect_equal(res$flags, c(1, 2)) +})