diff --git a/NEWS.md b/NEWS.md index d8a34f5..3ee6ed9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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`). diff --git a/fireSense_dataPrepPredict.R b/fireSense_dataPrepPredict.R index bf2f2f2..0233b7d 100644 --- a/fireSense_dataPrepPredict.R +++ b/fireSense_dataPrepPredict.R @@ -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, @@ -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`.")), @@ -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) diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index b3ac142..de7b3c0 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -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")) diff --git a/tests/testthat/test-predictInputsFromLedger.R b/tests/testthat/test-predictInputsFromLedger.R index a0dee2b..b9c9d5f 100644 --- a/tests/testthat/test-predictInputsFromLedger.R +++ b/tests/testthat/test-predictInputsFromLedger.R @@ -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) @@ -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", { @@ -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", {