From 527f67826721e26d43d58420a2061e1237d42520 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Mon, 16 Nov 2026 17:36:14 -0700 Subject: [PATCH 1/3] ELFlabels() reads the cell labels with fireSenseUtils::elfCellLabels() Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6 --- NEWS.md | 2 ++ fireSense_dataPrepPredict.R | 9 ++++----- tests/testthat/test-ELFlabels.R | 10 ++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/testthat/test-ELFlabels.R diff --git a/NEWS.md b/NEWS.md index 0c2bf90..0c9e466 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/fireSense_dataPrepPredict.R b/fireSense_dataPrepPredict.R index 057240f..3ae5d2b 100644 --- a/fireSense_dataPrepPredict.R +++ b/fireSense_dataPrepPredict.R @@ -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 diff --git a/tests/testthat/test-ELFlabels.R b/tests/testthat/test-ELFlabels.R new file mode 100644 index 0000000..4fe668e --- /dev/null +++ b/tests/testthat/test-ELFlabels.R @@ -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")) +}) From a6fe8f46e773a8a5c617a53938383a481450777c Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Fri, 20 Nov 2026 16:43:41 -0700 Subject: [PATCH 2/3] fireSenseUtils floor 0.2.3.9185 (fireSenseUtils#244) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh --- fireSense_dataPrepPredict.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fireSense_dataPrepPredict.R b/fireSense_dataPrepPredict.R index 3ae5d2b..bbd6333 100644 --- a/fireSense_dataPrepPredict.R +++ b/fireSense_dataPrepPredict.R @@ -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.9185)", # 9185: elfCellLabels() (fireSenseUtils#244, version not yet released; CHECK after it merges); 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", From 1b0510454b9784d1c339c4d99445aca3ec52c2c7 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Fri, 20 Nov 2026 21:11:34 -0700 Subject: [PATCH 3/3] fireSenseUtils floor 0.2.3.9186 (#244 merged as 9186; 9185 is #256) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh --- fireSense_dataPrepPredict.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fireSense_dataPrepPredict.R b/fireSense_dataPrepPredict.R index bbd6333..13a9fed 100644 --- a/fireSense_dataPrepPredict.R +++ b/fireSense_dataPrepPredict.R @@ -21,7 +21,7 @@ defineModule(sim, list( "PredictiveEcology/climateData@development", # latestHistoricalYear() "data.table", "googledrive", - "PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9185)", # 9185: elfCellLabels() (fireSenseUtils#244, version not yet released; CHECK after it merges); 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",