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

* `fireSense_igAndEscapePred_Covariates` has a `coreFraction` column, the share of each coarse pixel's flammable cells that are core (`fireSenseUtils::addCoreFraction()` on `flammableRTM` and `rasterToMatchLargeELF`, with `igAggFactor`, which is forced to the fit module's value), as `fireSense_dataPrepFit` gives it to the fit. `fireSense_ignitionPredict`'s year climate term averages the core pixels only, as the fit does; without the column it would average the buffer too. It does not depend on the year, so it is kept in the module and remade only when `flammableRTM`, `rasterToMatchLargeELF` or `igAggFactor` change. A pixel with no flammable cell gets 0 with one warning. A multi-ELF categorical raster or none gives 1. Needs fireSenseUtils (>= 0.2.3.9183).
* `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.
Expand Down
11 changes: 5 additions & 6 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.9184)", # 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.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)
"httr2",
"PredictiveEcology/LandR@development",
"PredictiveEcology/reproducible@development",
Expand Down Expand Up @@ -1120,13 +1120,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"))
})
Loading