Skip to content
Open
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 NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# canClimateData (development version)

- Fixed: with `outputDir` set, the cached climate preparation still ignored the output folder, so a cache entry made with the per-run folder was hit and its rasters were restored under each run's `outputPath()`, not in `outputDir`. `outputDir` is now part of the cache key when set; the default (per-run folder) is unchanged.
- Rerunning this module on a finished run whose years are not calendar years (NRV), with that run's `climateYearRecord` (from the climateYear module), now prepares the climate years the record holds for the simulation years the rerun serves (the load times of its inputs, `inputs(sim)`, which `alreadyRun` sets to the finished run's save times), not the years in `climateVariables` or `historicalClimateYears`/`projectedClimateYears`. Variables by period, and `calcCumMDC` ones (which need consecutive years), keep their years. `times` are not checked as calendar years then. `climateYearRecord` is a new optional input; in a normal run climateYear writes it after this module's `init`, and `loadOrder` keeps that order.
- `climateData` is now required from its modsForFireSense branch (>= 2.2.3.9011). `checkCalendarYears()` is only there; climateData development reached 2.2.3.9011 without it, so the old floor installed a climateData whose `init` failed with "could not find function".
- `projectedClimateYears` now defaults to 2017:2100 instead of 2011:2100. The projected archive for tile 39 (CNRM-ESM2-1 ssp370) has no 2013-2016 files, and observed climate now covers 1901-2024, so projections before 2017 are not needed.
Expand Down
11 changes: 7 additions & 4 deletions canClimateData.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ Init <- function(sim) {
## separate intermediate outputs from raw inputs, to reduce file conflicts on shared drives
climatePath <- file.path(inputPath(sim), "climate") |> checkPath(create = TRUE) |> asPath(1)
# climatePath <- file.path(inputPath(sim), "climate", Par$.studyAreaName) |> checkPath(create = TRUE) |> asPath(1)
climatePathOut <- if (is.null(P(sim)$outputDir) || is.na(P(sim)$outputDir)) {
file.path(outputPath(sim), "climate") |> checkPath(create = TRUE) |> asPath(1)
} else {
sharedOut <- !(is.null(P(sim)$outputDir) || is.na(P(sim)$outputDir))
climatePathOut <- if (sharedOut) {
file.path(P(sim)$outputDir) |> checkPath(create = TRUE) |> asPath(1)
} else {
file.path(outputPath(sim), "climate") |> checkPath(create = TRUE) |> asPath(1)
}

if (is.na(P(sim)$.studyAreaName)) {
Expand Down Expand Up @@ -276,7 +277,9 @@ Init <- function(sim) {
rasterToMatch = sim$rasterToMatch,
currentModuleName = "canClimateData"
) |>
Cache(omitArgs = c("srcdir", "dstdir"), useCloud = Par$.useCloud) ## TODO: improve use of cache
## dstdir is keyed only for a shared outputDir: omitted, an entry made with the per-run default
## would be hit and its files restored under outputPath(sim), leaving outputDir unused
Cache(omitArgs = c("srcdir", if (!sharedOut) "dstdir"), useCloud = Par$.useCloud) ## TODO: improve use of cache

## rename list elements and layers to match expected names downstream
names(climateRasters) <- names(sim$climateVariables)
Expand Down
14 changes: 13 additions & 1 deletion tests/testthat/test-cacheOmitArgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ test_that("Init(): omitArgs of the cached prepClimateLayers() call are its forma
calls <- unlist(lapply(exprs, cacheCallsOf, fn = "prepClimateLayers"), recursive = FALSE)
expect_length(calls, 1L)

omitArgs <- eval(calls[[1]]$omitArgs)
## default (no `outputDir`): per-run folder, so both folders stay out of the key
omitArgs <- eval(calls[[1]]$omitArgs, list(sharedOut = FALSE))
expect_true(all(c("srcdir", "dstdir") %in% omitArgs))
expect_true(all(omitArgs %in% formalArgs(climateData::prepClimateLayers)),
info = paste("not formals of prepClimateLayers():",
paste(setdiff(omitArgs, formalArgs(climateData::prepClimateLayers)),
collapse = ", ")))
})

## With `outputDir` set, a cache entry made with another dstdir (the per-run default) must not
## be hit: reproducible restores its files under the run's outputPath, so the shared folder
## stayed unused and every run restored its own copy of the rasters.
test_that("Init(): dstdir is in the cache key when outputDir is set", {
exprs <- parse(file.path(moduleRoot, paste0(moduleName, ".R")), keep.source = FALSE)
calls <- unlist(lapply(exprs, cacheCallsOf, fn = "prepClimateLayers"), recursive = FALSE)
omitArgs <- eval(calls[[1]]$omitArgs, list(sharedOut = TRUE))
expect_false("dstdir" %in% omitArgs)
expect_true("srcdir" %in% omitArgs)
})
Loading