Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 3 additions & 1 deletion models/rothc/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# PEcAn.RothC 0.0.0.9000

Initial development version
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).
2 changes: 1 addition & 1 deletion models/rothc/R/write.config.RothC.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions models/rothc/tests/testthat/test-write.config.RothC.R
Original file line number Diff line number Diff line change
@@ -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))
})
Loading