Skip to content
Merged
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 @@
# fireSense_dataPrepPredict (development version)

* `fitFileSuffix` is removed: in a run without `fireSense_dataPrepFit`, name the ledger to predict from in full (`spreadFitFilename`); `"latest"` takes each ELF's newest usable fit from any ledger file. The stop for a ledger with no fit for the study area names `spreadFitFilename`.
* `lightningMaps` and `ignitionFitRTM` are now built here whenever they are NULL when the ignition covariates are made, not only when no other module declares them. `fireSense_dataPrepFit` declares both but makes neither when it skips its ignition prep (`skipUnusedFitPrep`, a ledger ignition fit reused), which left `fireSense_ignitionPredict` without `ignitionFitRTM`. Runs where `fireSense_dataPrepFit` makes them, or is absent, are unchanged.

* A hindcast or forecast with a `~ 1` spread fit (no spread climate variable, so `climateVariablesForFire$spread` is empty) stopped when the covariates were built (`terra` cannot select no layer). The spread covariate table now has `pixelID` and `youngAge` and the fuels, with no climate column; the ignition covariates are unchanged. Together with `fireSenseUtils::climateRasterToDataTable()` returning a table for no raster (PredictiveEcology/fireSenseUtils, null-arm hindcasts of `fireSense_dataPrepFit`).
Expand Down
19 changes: 7 additions & 12 deletions fireSense_dataPrepPredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ defineModule(sim, list(
"Biomass_core, Biomass_borealDataPrep, Biomass_speciesData and burnSummaries (2020);",
"a module with another value is an error. Set it for all with `.globals = list(dataYear = )`.")),
defineParameter("fireTimeStep", "numeric", 1, NA, NA, desc = "Interval between events of this module, in years."),
defineParameter("fitFileSuffix", "character", "", NA, NA,
paste("The ledger to predict from, in a run without `fireSense_dataPrepFit` (`.inputObjects` then",
"reads the stored fits itself): the text after the model tag in the ledger file names.",
"The same parameter of `fireSense_ELFs`, `fireSense_dataPrepFit`, `fireSense_spreadFit` and",
"`fireSense_ignitionFit`; set it for all with `.globals = list(fitFileSuffix = ...)`.")),
defineParameter("forestedLCC", "numeric", fireSenseUtils::fireSenseForestedLCC, NA, NA,
"Forested landcover classes in `rstLCC_RTM`. Only used if `landcoverDT` is not supplied."),
defineParameter("flammabilityThreshold", "numeric", fireSenseUtils::fireSenseFlammabilityThreshold, 0, 1,
Expand Down Expand Up @@ -99,8 +94,8 @@ defineModule(sim, list(
desc = "Column of `sppEquiv` with the species names used in `cohortData`."),
defineParameter("spreadFitFilename", "character", "latest", NA, NA,
paste("As in `fireSense_dataPrepFit`: the SpreadFit ledger file in `spreadFitGoogleDriveFolder`;",
"`\"latest\"` takes each ELF's fit from the most recent file that has it. Read only in a",
"run without `fireSense_dataPrepFit`.")),
"`\"latest\"` takes each ELF's newest fit this run can use, from any ledger file; a name (e.g. an",
"experiment's) reads that file only. Read only in a run without `fireSense_dataPrepFit`.")),
defineParameter("spreadFitGoogleDriveFolder", "character", fireSenseUtils::spreadFitLedgerFolder(), NA, NA,
paste("As in `fireSense_dataPrepFit`: the Google Drive folder of the SpreadFit ledger",
"(`fireSenseUtils::spreadFitLedgerFolder()`). Read only in a run without `fireSense_dataPrepFit`.")),
Expand Down Expand Up @@ -1231,15 +1226,15 @@ unionLCCGroups <- function(fuelSets) {
#'
#' @return The `simList`.
predictInputsFromLedger <- function(sim) {
sfx <- SpaDES.core::paramCheckOtherMods(sim, "fitFileSuffix", ifSetButDifferent = "error")
sa <- sim$studyArea
if (inherits(sa, "SpatVector")) sa <- sf::st_as_sf(sa)
## the escape definition is not checked here (this module has none); fireSense_burn checks it against the fit's
rows <- fireSenseUtils::readSpreadFitLedger(P(sim)$spreadFitFilename, P(sim)$spreadFitGoogleDriveFolder,
domain = sa, destinationPath = inputPath(sim), fitFileSuffix = sfx)
domain = sa, destinationPath = inputPath(sim))
if (!NROW(rows))
stop("fireSense_dataPrepPredict: the SpreadFit ledger with fitFileSuffix \"", sfx, "\" has no stored fit ",
"for this study area, so there is nothing to predict from. Use a fitFileSuffix whose ledger has one, ",
"or fit first (fireSense_dataPrepFit and fireSense_spreadFit with doFit = NA).", call. = FALSE)
stop("fireSense_dataPrepPredict: the SpreadFit ledger (spreadFitFilename \"", P(sim)$spreadFitFilename,
"\") has no stored fit for this study area, so there is nothing to predict from. Name a ledger file ",
"that has one, or fit first (fireSense_dataPrepFit and fireSense_spreadFit with doFit = NA).", call. = FALSE)
sim$studyAreaWithSpreadParams <- rows
ins <- fireSenseUtils::spreadFitLedgerInputs(rows, sppEquivCol = P(sim)$sppEquivCol,
fuelClassCol = P(sim)$fuelClassCol, studyArea = sim$studyArea)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test_that("parameters are the expected names", {
expect_identical(
sort(md$parameters$paramName),
sort(c(".runInitialTime", ".studyAreaName", ".useCache", "blendNeighbourELFs", "cutoffForYoungAge", "dataYear",
"fireTimeStep", "fitFileSuffix", "flammabilityThreshold", "forestedLCC", "fuelClassCol",
"fireTimeStep", "flammabilityThreshold", "forestedLCC", "fuelClassCol",
"igAggFactor", "nonflammableLCC", "nonForestCanBeYoungAge", "scanfiVersion",
"spreadFitFilename", "spreadFitGoogleDriveFolder", "sppEquivCol", "whichModulesToPrepare",
"replayFrom", "replaySave"))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-predictInputsFromLedger.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ ledgerSim <- function(rows, objects = toyObjects(), times = list(start = 2021, e
sim@current <- list(moduleName = moduleName, eventType = ".inputObjects", eventTime = 2021) # as in .inputObjects
rec <- new.env()
testthat::local_mocked_bindings(
readSpreadFitLedger = function(spreadFitFilename, cloudFolderID, domain, destinationPath, fitFileSuffix = "") {
rec$suffix <- fitFileSuffix
readSpreadFitLedger = function(spreadFitFilename, cloudFolderID, domain, destinationPath, ...) {
rec$file <- spreadFitFilename
rows
}, .package = "fireSenseUtils", .env = parent.frame())
list(sim = sim, rec = rec)
Expand All @@ -53,7 +53,7 @@ test_that("the stored fits, their per-ELF inputs and climate variables come from
cv <- sim$climateVariables
expect_setequal(names(cv), paste0("historical_", c("CMD", "cumMDC", "CMDsm", "CMDsp")))
expect_identical(cv$historical_CMD$.dots$historical_years, 2021:2023)
expect_identical(x$rec$suffix, "") # the module default; .globals sets it for every module
expect_identical(x$rec$file, "latest") # the module default
})

test_that("climate variables a user supplies are kept", {
Expand All @@ -72,7 +72,7 @@ test_that("years after the last historical climate year ask for no historical cl

test_that("a ledger without a fit for the study area stops, naming the ledger", {
x <- ledgerSim(NULL)
expect_error(predictInputsFromLedger(x$sim), "fitFileSuffix \"\" has no stored fit for this study area")
expect_error(predictInputsFromLedger(x$sim), "spreadFitFilename \"latest\"\\) has no stored fit for this study area")
})

test_that(".inputObjects reads the ledger only when nothing supplies the stored fits", {
Expand Down
Loading