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

* `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.

* A hindcast of year Y built `youngAge` differently from the fit, for the spread and the ignition covariates: it used the cohort ages and the data year's time since disturbance as they were, and did not see a fire between the data year and Y (youngAge was 2.8% of burned pixels in ELF 6.6.2 in 2010, 1.5% in the fit). It now resolves it as `fireSense_dataPrepFit` does: the data year's time since disturbance aged to Y and every fire after it, from `fireSenseUtils::youngAgeAtYear()` (spread) and `fireSenseUtils::prepare_FuelCovsCoarseByYear()` (ignition), with the fires from `historicalFireRaster`, else `firePolysForAge` (`fireSenseUtils::firePixelsByYear()`, as the fit chooses). Fuel, non-forest land cover and treed wetland are cleared where `youngAge` is 1 in the covariate table itself (`fireSenseUtils::clearYoungAge()`, which the ignition fit uses), so a fit on log-scale fuel, for which `fireSense_spreadPredict` clears only the indicators, is right too. A hindcast with `nonForestCanBeYoungAge = FALSE` stops, as the fit does (`fireSenseUtils::stopIfNonForestCannotBeYoung()`). New inputs `firePolysForAge` and `historicalFireRaster` (from `fireSense_dataPrepFit`); a hindcast with neither stops. Hindcast covariates, and so their cache keys, change. Forecasts (a module simulates `cohortData`) are unchanged. Needs the fireSenseUtils version after PredictiveEcology/fireSenseUtils#239 merges; the `reqdPkgs` floor is set after that merge's version bump.

* New parameters `replaySave` (default `FALSE`) and `replayFrom` (default `NA`): no change unless set. `replaySave = TRUE` writes, once after the first covariate build, the spread-prediction inputs that do not depend on the spread parameters to `outputPath(sim)` through SpaDES.core's `outputs()` (its `save` event): `fireSense_SpreadCovariates`, `flammableRTM`, `rasterToMatch`, `rasterToMatchELF`, `rasterToMatchLargeELF`, `studyAreaWithSpreadParams`, `nonEscapedFireSizesHa`, `ignitionFirePoints` and `firePolys` (those present), as `replay_<name>_year<time>.<ext>`: `.tif` (`terra::writeRaster()`, keeps categories), `.gpkg` for vectors (`terra::writeVector()`; `firePolys` stacked into one, element names in a column), `.qs2` for tables and `studyAreaWithSpreadParams` (its list columns survive). `replayFrom = <that folder>` reads them back in `.inputObjects` through `inputs()`/`loadFiles()` and schedules no covariate event, so a job needs no climate, vegetation, fit or ELF module. The module declares the objects other modules make as inputs only. `qs2` is now in `reqdPkgs`.
Expand Down
9 changes: 4 additions & 5 deletions fireSense_dataPrepPredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -1091,13 +1091,12 @@ selectSpreadParamRows <- function(sa, ownELF, blend, placeableELFs, fuelInputELF
sa[c(own, keep), , drop = FALSE]
}

## The ELFs a raster labels: its categories, else its values (as fireSense_spreadPredict's ELFblendWeights()
## reads `sim$rasterToMatchLargeELF`)
## The ELFs a raster labels: the labels of its cells (fireSenseUtils::elfCellLabels(), which fireSense_spreadPredict's
## ELFblendWeights() reads `sim$rasterToMatchLargeELF` with)
ELFlabels <- function(r) {
if (is.null(r)) return(character(0))
lv <- terra::levels(r[[1]])[[1]]
if (is.data.frame(lv) && NCOL(lv) >= 2) return(as.character(lv[[2]]))
as.character(unique(terra::values(r[[1]], mat = FALSE)))
lab <- unique(fireSenseUtils::elfCellLabels(r[[1]]))
lab[!is.na(lab)]
}

#' Reduce `sim$studyAreaWithSpreadParams` to the simulated ELF's row and the neighbours to blend
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-ELFlabels.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## ELFlabels() is the set of ELFs a raster labels, from fireSenseUtils::elfCellLabels() (the cell lookup
## fireSense_spreadPredict uses too).

test_that("ELFlabels() gives a categorical raster's labels, or a plain raster's values, without NA", {
expect_identical(ELFlabels(NULL), character(0))
r <- terra::rast(nrows = 1, ncols = 4, vals = c(2, 1, 2, NA))
expect_setequal(ELFlabels(r), c("1", "2"))
levels(r) <- data.frame(id = 1:2, ELFind = c("A", "B"))
expect_setequal(ELFlabels(r), c("A", "B"))
})