From 25c9687f95b730f029259aaf7a386e53689fd9eb Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 18 Nov 2026 16:16:31 -0700 Subject: [PATCH 1/2] Plot the escape probability beside the ignition probability Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXgg187sAPQZwQT3Mf4 --- NEWS.md | 1 + fireSense_ignitionPredict.R | 8 +++++--- tests/testthat/test-events.R | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7a04f50..b7c1c80 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`. * 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..81ed626 100644 --- a/fireSense_ignitionPredict.R +++ b/fireSense_ignitionPredict.R @@ -40,8 +40,8 @@ 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 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 +208,10 @@ IgnitionPredictRun <- function(sim) { "ignitionYearEffectShape", "escapeYearEffectShape") } + ## the year's ignition and escape probabilities, side by side if (anyPlotting(Par$.plots)) - Plots(igProbRas, types = Par$.plots, filename = paste0("IgnitionProbability_yr", time(sim))) + Plots(sim$fireSense_IgAndEscapeProbRas[[c("ignitionProb", "escapeProb")]], 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))) }) From 5a6e9f6529795e36cf2d173ccfc2cad79eb025c1 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 18 Nov 2026 16:55:10 -0700 Subject: [PATCH 2/2] Map the expected escaped fires per pixel beside the probabilities Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXgg187sAPQZwQT3Mf4 --- NEWS.md | 2 +- fireSense_ignitionPredict.R | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index b7c1c80..d21805a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +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`. +* 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 81ed626..5e4ca1f 100644 --- a/fireSense_ignitionPredict.R +++ b/fireSense_ignitionPredict.R @@ -41,7 +41,8 @@ defineModule(sim, list( ), defineParameter(".plots", "character", "screen", NA, NA, desc = paste("Passed to `types` in `Plots()`, e.g. \"screen\" (default), \"png\": the ignition and escape", - "probability maps are plotted each `run`. `NA` or `NULL`: no plots.") + "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,10 +209,16 @@ IgnitionPredictRun <- function(sim) { "ignitionYearEffectShape", "escapeYearEffectShape") } - ## the year's ignition and escape probabilities, side by side - if (anyPlotting(Par$.plots)) - Plots(sim$fireSense_IgAndEscapeProbRas[[c("ignitionProb", "escapeProb")]], types = Par$.plots, + ## 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)) }