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.PEPRMT::write.config.PEPRMT()` failed with a date conversion error when the event file had no supported events for the site (an empty `events` list, or only unsupported event types); such events are now simply skipped (#4255).
- `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
10 changes: 6 additions & 4 deletions models/peprmt/R/write.config.PEPRMT.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ write.config.PEPRMT <- function(defaults, trait.values, settings, run.id) {
)
evts <- evts[use_evt]
}
evt_order <- sapply(evts, \(x) x$date) |>
as.Date() |>
order()
evts <- evts[evt_order]
if (length(evts) > 0) {
evt_order <- sapply(evts, \(x) x$date) |>
as.Date() |>
order()
evts <- evts[evt_order]
}

# need to handle events sequentially so effects can stack
# TODO think about efficiency, like, at all
Expand Down
39 changes: 39 additions & 0 deletions models/peprmt/tests/testthat/test-write.config.PEPRMT.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,42 @@ test_that("impose_event", {
c(33, 30, 30, 30)
)
})

test_that("write.config.PEPRMT accepts event files with no supported events", {
d <- withr::local_tempdir()
rundir <- file.path(d, "run", "r1")
dir.create(rundir, recursive = TRUE)
met <- file.path(d, "met.dat")
data.frame(
Year = 2020, DOY_disc = 1:3, DOY = 1:3, TA_C = 10, PAR_umol_m2_day = 5
) |>
utils::write.table(met, row.names = FALSE, quote = FALSE)
peprmt_in <- file.path(d, "peprmt.csv")
data.frame(
Year = 2020, DOY_disc = 1:3, WTD_cm = 0, Salinity_daily_ave_ppt = 30
) |>
utils::write.csv(peprmt_in, row.names = FALSE)
evt_file <- file.path(d, "events.json")
writeLines(
'[{"site_id": "S1", "events": [{"event_type": "planting", "date": "2020-01-02"}]}]',
evt_file
)
settings <- list(
host = list(rundir = file.path(d, "run"), outdir = file.path(d, "out")),
model = list(binary = "peprmt"),
run = list(
site = list(id = "S1", lat = 1, lon = 2),
start.date = "2020-01-01",
end.date = "2020-01-03",
inputs = list(
met = list(path = met),
PEPRMT = list(path = peprmt_in),
event_json = list(path = evt_file)
)
)
)
suppressMessages(
write.config.PEPRMT(list(), list(pft1 = list(a0 = 1)), settings, "r1")
)
expect_true(file.exists(file.path(rundir, "run_data.csv")))
})
Loading