diff --git a/NEWS.md b/NEWS.md index 7a04f50..d21805a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # fireSense_ignitionPredict (development version) +* The yearly map shows the escape probability beside the ignition probability (`IgnitionEscapeProbability_yr`, was `IgnitionProbability_yr`), both layers of `fireSense_IgAndEscapeProbRas`, and their product, the expected number of escaped fires starting in each pixel that year (`expectedEscapes`). * New parameter `.plots` (default `"screen"`): the ignition probability map is plotted each `run` with `Plots(types = .plots)`; `NA` or `NULL` for none. The plot was gated on `.saveInterval` instead, so `.plots` (e.g. `"png"` from `.globals`) drew and saved nothing. `.saveInterval`, used for nothing else, is removed. * Before predicting, every stored ignition and escape fit (each ELF's, with several) is checked against the covariates to predict (`fireSenseUtils::storedFitProblem()`): a fit that is not Poisson or uses features the covariates lack stops the run, naming the ELF, process and features, and saying to refit or to choose another ledger (`fitFileSuffix`). Needs fireSenseUtils (>= 0.2.3.9177). * With a fit that has fitted year effects (`modelList$yearEffects`, from fireSense_ignitionFit), `fireSense_IgAndEscapeProbRas` has two more layers for the year `floor(time(sim))`, `ignitionYearEffect` and `escapeYearEffect` (`NA` in an ELF without one) and `ignitionYearEffectShape` and `escapeYearEffectShape` (the shape of their gamma posteriors), for `fireSense_burn`'s `yearEffects = "fitted"` in hindcasts. Without them the raster is as before. `foldModels()` and `foldMeanPrediction()` moved to fireSenseUtils (same predictions), so fireSense_ignitionFit predicts exactly as this module does; a fit without fold models stops with "no fold models". diff --git a/fireSense_ignitionPredict.R b/fireSense_ignitionPredict.R index 226b0b0..5e4ca1f 100644 --- a/fireSense_ignitionPredict.R +++ b/fireSense_ignitionPredict.R @@ -40,8 +40,9 @@ defineModule(sim, list( desc = "Time of the `save` event, which does nothing. `NA` means never." ), defineParameter(".plots", "character", "screen", NA, NA, - desc = paste("Passed to `types` in `Plots()`, e.g. \"screen\" (default), \"png\": the ignition probability", - "raster is plotted each `run`. `NA` or `NULL`: no plots.") + desc = paste("Passed to `types` in `Plots()`, e.g. \"screen\" (default), \"png\": the ignition and escape", + "probability maps, and their product (the expected escaped fires per pixel), are plotted each `run`.", + "`NA` or `NULL`: no plots.") ), defineParameter(".studyAreaName", "character", NA, NA, NA, "Human-readable name for the study area used."), @@ -208,8 +209,16 @@ IgnitionPredictRun <- function(sim) { "ignitionYearEffectShape", "escapeYearEffectShape") } - if (anyPlotting(Par$.plots)) - Plots(igProbRas, types = Par$.plots, filename = paste0("IgnitionProbability_yr", time(sim))) + ## the year's ignition and escape probabilities, side by side, and their product: the expected number of escaped + ## fires starting in each pixel this year. Where a pixel burns also depends on spread from other pixels, which + ## only fireSense_burn's simulation gives. + if (anyPlotting(Par$.plots)) { + probs <- sim$fireSense_IgAndEscapeProbRas[[c("ignitionProb", "escapeProb")]] + expectedEscapes <- probs[["ignitionProb"]] * probs[["escapeProb"]] + names(expectedEscapes) <- "expectedEscapes" + Plots(c(probs, expectedEscapes), types = Par$.plots, + filename = paste0("IgnitionEscapeProbability_yr", time(sim))) + } return(invisible(sim)) } diff --git a/tests/testthat/test-events.R b/tests/testthat/test-events.R index 38d20e9..cf8a565 100644 --- a/tests/testthat/test-events.R +++ b/tests/testthat/test-events.R @@ -57,13 +57,13 @@ test_that("nothing is predicted before the first run event", { expect_null(sim$fireSense_IgAndEscapeDistribution) }) -test_that("`.plots` saves the ignition probability map each run, and NA plots nothing (default: screen)", { +test_that("`.plots` saves the ignition and escape probability maps each run, and NA plots nothing (default: screen)", { ## The plot was gated on `.saveInterval`, not `.plots`, so `.plots = "png"` (e.g. from .globals) drew nothing ins <- toyIgInputs(list(byPixel(c(0, 3, 0, 2))), list(constant(0.5))) withPng <- toyIgRun(ins, params = list(.plots = "png"), times = list(start = 2001, end = 2002)) pngs <- SpaDES.core::outputs(withPng)$file - expect_true(any(grepl("IgnitionProbability_yr2001", pngs))) - expect_true(all(file.exists(pngs[grepl("IgnitionProbability", pngs)]))) + expect_true(any(grepl("IgnitionEscapeProbability_yr2001", pngs))) + expect_true(all(file.exists(pngs[grepl("IgnitionEscapeProbability", pngs)]))) without <- toyIgRun(ins, params = list(.plots = NA), times = list(start = 2001, end = 2002)) - expect_false(any(grepl("IgnitionProbability", SpaDES.core::outputs(without)$file))) + expect_false(any(grepl("IgnitionEscapeProbability", SpaDES.core::outputs(without)$file))) })