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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# fireSense_ignitionPredict (development version)

* The yearly map shows the escape probability beside the ignition probability (`IgnitionEscapeProbability_yr<year>`, was `IgnitionProbability_yr<year>`), 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".
Expand Down
17 changes: 13 additions & 4 deletions fireSense_ignitionPredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down Expand Up @@ -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))
}
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-events.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})
Loading