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..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.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", @@ -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")) +})