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
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# fireSense_dataPrepPredict (development version)

* A prediction run reads its stored spread fits with `fireSenseUtils::readFitLedger("spread", ..., doFit = FALSE)`: when the ledger file named by `spreadFitFilename` is missing or empty (a hindcast with no ledger of its own), it reads the newest production fits (`"latest"`) instead of stopping. Needs fireSenseUtils with `readFitLedger()` (Depends-on PredictiveEcology/fireSenseUtils, number below); the `reqdPkgs` floor is to be set when it is bumped.

* A hindcast's `youngAge` takes the fires (and cuts) after the data year from `disturbancePixelsByYear` when `fireSense_dataPrepFit` made one (Biomass_borealDataPrep `ageDisturbanceSources = "all"`), as the fit does; otherwise from `historicalFireRaster` or `firePolysForAge`, as before.

* `ELFlabels()` reads the ELF of each cell with `fireSenseUtils::elfCellLabels()`, the lookup `fireSense_spreadPredict` uses too, instead of its own copy. The set it returns is now the labels of the cells (`unique()`, without `NA`): a category no cell has is no longer in it. Needs fireSenseUtils with `elfCellLabels()` (Depends-on PredictiveEcology/fireSenseUtils#244); the `reqdPkgs` floor is set after that merges.
Expand All @@ -19,7 +21,7 @@

* `dataYear` defaults to 2020 (was 2011), the default of Biomass_core, Biomass_borealDataPrep, Biomass_speciesData and burnSummaries, and may be up to 2025. `.inputObjects` stops when another module has a different `dataYear` (`SpaDES.core::paramCheckOtherMods()`). It is read only when `fireSense_dataPrepFit` does not supply the land cover, stand age and non-forest time since disturbance (a run that only predicts), so runs with `fireSense_dataPrepFit` predict as before.

* A run without `fireSense_dataPrepFit` (one that only predicts) now works: `.inputObjects` reads the stored fits of the ELFs the study area touches from the SpreadFit ledger (`predictInputsFromLedger()`, with `fireSenseUtils::readSpreadFitLedger()`), sets the per-ELF `sppEquivs`, `nonForestedLCCGroupsList` and `missingLCCgroupList`, asks canClimateData for the fits' climate variables (`climateVariables`, `climateVariablesForFire`; the 'MDC' default made the ignition covariates fail with "[subset] invalid name(s)"), and makes `lightningMaps` (`fireSenseUtils::prepare_LightningData()`). `prepIgAndEscPredictData` makes `ignitionFitRTM`, the coarse grid of the ignition covariates, unless another module supplies it (`fireSense_ignitionPredict` stopped on a NULL one). New parameters `fitFileSuffix`, `spreadFitFilename`, `spreadFitGoogleDriveFolder` (as in `fireSense_dataPrepFit`). A `studyAreaWithSpreadParams` supplied as `NULL` predicts without stored fits, as before.
* A run without `fireSense_dataPrepFit` (one that only predicts) now works: `.inputObjects` reads the stored fits of the ELFs the study area touches from the SpreadFit ledger (`predictInputsFromLedger()`, with `fireSenseUtils::readFitLedger()`), sets the per-ELF `sppEquivs`, `nonForestedLCCGroupsList` and `missingLCCgroupList`, asks canClimateData for the fits' climate variables (`climateVariables`, `climateVariablesForFire`; the 'MDC' default made the ignition covariates fail with "[subset] invalid name(s)"), and makes `lightningMaps` (`fireSenseUtils::prepare_LightningData()`). `prepIgAndEscPredictData` makes `ignitionFitRTM`, the coarse grid of the ignition covariates, unless another module supplies it (`fireSense_ignitionPredict` stopped on a NULL one). New parameters `fitFileSuffix`, `spreadFitFilename`, `spreadFitGoogleDriveFolder` (as in `fireSense_dataPrepFit`). A `studyAreaWithSpreadParams` supplied as `NULL` predicts without stored fits, as before.
* Over several ELFs (`.ELFind` of a `studyAreaLarge`), each simulated ELF keeps its row of `studyAreaWithSpreadParams` (only the first was kept).

- The ignition covariate event keeps the part of the coarse covariates that does not change from year to year (`fireSenseUtils::fuelCovsStatic()`) in `mod$fuelCovsStatic`, one per fuel set, and passes it to `prepare_FuelCovsCoarse(static = )` each year; it stores the `static` the call hands back, which the package rebuilds when land cover or `flammableRTM` changes. Same covariates, about 0.2 s less per fuel set and simulated year on the 11.3 NRV state. Needs the fireSenseUtils version after PredictiveEcology/fireSenseUtils#191 merges; the `reqdPkgs` floor is set after that merge's version bump.
Expand Down
11 changes: 6 additions & 5 deletions fireSense_dataPrepPredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defineModule(sim, list(
"PredictiveEcology/climateData@development", # latestHistoricalYear()
"data.table",
"googledrive",
"PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9186)", # 9186: elfCellLabels() (fireSenseUtils#244); 9184: addCoreFraction(), coreFractionByYear(); 9142: readSpreadFitLedger() and the other predict-only helpers (#206); fuelCovsToCoarse() hands back the static it used (#191)
"PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9202)", # 9202: readFitLedger() (fireSenseUtils#273); 9186: elfCellLabels() (fireSenseUtils#244); 9184: addCoreFraction(), coreFractionByYear(); 9142: the predict-only helpers (#206); fuelCovsToCoarse() hands back the static it used (#191)
"httr2",
"PredictiveEcology/LandR@development",
"PredictiveEcology/reproducible@development",
Expand Down Expand Up @@ -95,7 +95,8 @@ defineModule(sim, list(
defineParameter("spreadFitFilename", "character", "latest", NA, NA,
paste("As in `fireSense_dataPrepFit`: the SpreadFit ledger file in `spreadFitGoogleDriveFolder`;",
"`\"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`.")),
"experiment's) reads that file only, unless it is missing or empty: this module never fits, so it then reads",
"`\"latest\"` from the production folder. 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 @@ -307,7 +308,7 @@ defineModule(sim, list(
desc = paste("With `.ELFind`: the simulated ELF's row first, then the neighbours `blendNeighbourELFs`",
"keeps; set by the covariate events, before `fireSense_spreadPredict` reads it. In a run",
"without `fireSense_dataPrepFit` (prediction only), `.inputObjects` reads it from the SpreadFit",
"ledger first: the rows whose polygons intersect `studyArea` (`fireSenseUtils::readSpreadFitLedger()`)."))
"ledger first: the rows whose polygons intersect `studyArea` (`fireSenseUtils::readFitLedger()`)."))
)
))

Expand Down Expand Up @@ -1250,8 +1251,8 @@ predictInputsFromLedger <- function(sim) {
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))
rows <- fireSenseUtils::readFitLedger("spread", P(sim)$spreadFitFilename, P(sim)$spreadFitGoogleDriveFolder,
domain = sa, destinationPath = inputPath(sim), doFit = FALSE)
if (!NROW(rows))
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 ",
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-predictInputsFromLedger.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ 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, ...) {
rec$file <- spreadFitFilename
readFitLedger = function(model, filename, cloudFolderID, domain, destinationPath, doFit, ...) {
rec$file <- filename
rec$doFit <- doFit
rows
}, .package = "fireSenseUtils", .env = parent.frame())
list(sim = sim, rec = rec)
Expand All @@ -41,6 +42,7 @@ ledgerSim <- function(rows, objects = toyObjects(), times = list(start = 2021, e
test_that("the stored fits, their per-ELF inputs and climate variables come from the ledger", {
x <- ledgerSim(toyLedgerRows())
sim <- predictInputsFromLedger(x$sim)
expect_false(x$rec$doFit) # a prediction run never fits
expect_identical(as.character(sim$studyAreaWithSpreadParams$polygonID), c("9.1", "9.2"))
expect_setequal(names(sim$sppEquivs), c("9.1", "9.2"))
expect_length(sim$nonForestedLCCGroupsList, 2L)
Expand Down Expand Up @@ -77,7 +79,7 @@ test_that("a ledger without a fit for the study area stops, naming the ledger",

test_that(".inputObjects reads the ledger only when nothing supplies the stored fits", {
read <- 0L
testthat::local_mocked_bindings(readSpreadFitLedger = function(...) { read <<- read + 1L; toyLedgerRows() },
testthat::local_mocked_bindings(readFitLedger = function(...) { read <<- read + 1L; toyLedgerRows() },
.package = "fireSenseUtils")
objs <- toyObjects()
objs["studyAreaWithSpreadParams"] <- NULL # nothing supplies them
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-replay.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## A replay job (`replayFrom`) takes the spread-prediction inputs that do not depend on the spread parameters
## from a reference hindcast job (`replaySave = TRUE`), in place of building them.

## a ledger-shaped row: list columns (a params table, a species table), as readSpreadFitLedger() returns
## a ledger-shaped row: list columns (a params table, a species table), as readFitLedger() returns
ledgerRow <- function() {
poly <- terra::as.polygons(terra::ext(0, 500, 0, 500), crs = toyCRSp)
sfRow <- sf::st_as_sf(poly)
Expand Down