From 06e194bf5c416485f1cabc61f23756cb5f3b2635 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 19 Nov 2026 13:29:57 -0700 Subject: [PATCH] Save the yearly probability png at 1440 x 1152 px, not png()'s 480 x 480 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXcxmq3mSxenWLiFbBD --- NEWS.md | 1 + fireSense_ignitionPredict.R | 3 ++- tests/testthat/test-events.R | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index d21805a..70a256e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # fireSense_ignitionPredict (development version) +* The yearly ignition and escape probability map (`.plots = "png"`) is bigger. Its png is now 10 x 8 inches at 144 dpi (1440 x 1152 pixels), as fireSense_burn's; it was R's `png()` default of 480 x 480, which looked small in `SpaDES.shiny::shine()`. * 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). diff --git a/fireSense_ignitionPredict.R b/fireSense_ignitionPredict.R index 5e4ca1f..66e3c64 100644 --- a/fireSense_ignitionPredict.R +++ b/fireSense_ignitionPredict.R @@ -217,7 +217,8 @@ IgnitionPredictRun <- function(sim) { expectedEscapes <- probs[["ignitionProb"]] * probs[["escapeProb"]] names(expectedEscapes) <- "expectedEscapes" Plots(c(probs, expectedEscapes), types = Par$.plots, - filename = paste0("IgnitionEscapeProbability_yr", time(sim))) + filename = paste0("IgnitionEscapeProbability_yr", time(sim)), + deviceArgs = list(width = 10, height = 8, units = "in", res = 144)) # png() alone is 480 x 480 px } return(invisible(sim)) diff --git a/tests/testthat/test-events.R b/tests/testthat/test-events.R index cf8a565..dac7e71 100644 --- a/tests/testthat/test-events.R +++ b/tests/testthat/test-events.R @@ -64,6 +64,11 @@ test_that("`.plots` saves the ignition and escape probability maps each run, and pngs <- SpaDES.core::outputs(withPng)$file expect_true(any(grepl("IgnitionEscapeProbability_yr2001", pngs))) expect_true(all(file.exists(pngs[grepl("IgnitionEscapeProbability", pngs)]))) + pngSize <- function(f) { # width, height in pixels, from the PNG header + con <- file(f, "rb"); on.exit(close(con)); h <- readBin(con, "raw", 24L) + readBin(h[17:24], "integer", 2L, size = 4L, endian = "big") + } + expect_equal(pngSize(pngs[grepl("IgnitionEscapeProbability", pngs)][1]), c(1440L, 1152L)) # not png()'s 480 x 480 without <- toyIgRun(ins, params = list(.plots = NA), times = list(start = 2001, end = 2002)) expect_false(any(grepl("IgnitionEscapeProbability", SpaDES.core::outputs(without)$file))) })