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

- New parameter `.plots` (default `"screen"`): the spread probability map (`fireSense_SpreadPredicted`) is plotted each `run` (`SpreadProbability_yr<year>`). `NA` or `NULL` for none.

- A ledger row with an interaction coefficient (`a:b`, e.g. `CMD:dom_agb_Pice_mar`, from a `fireSense_spreadFit` fitted with `fireSense_dataPrepFit`'s `spreadInteractions = "climate:fuel"`) predicts with it: `spreadProbOneELF()` needs the covariates `a` and `b` (and their ranges in `covMinMax_spread`), and `fireSenseUtils::spreadProbFromIntegerCovs()` forms their product after each is rescaled and centred with the row's `covCentre_spread` entry for it (0 where `youngAge` cleared the fuel), and multiplies it by the coefficient, as the fit does. A row without interactions predicts exactly as before. Needs fireSenseUtils >= 0.2.3.9177 (#242).

- With `paramSets`: the cache of a parameter set's surface no longer reads all the values of `flammableRTM` and `rasterToMatchLargeELF` every replicate (a new raster object or a change at 1000 sampled cells is a change) and returns the stored surface without copying it (a changed stored surface is recomputed). On a 20-million-cell raster a replicate that reuses a surface takes 0.35 s instead of 0.9 s, most of it SpaDES. `paramSets` stops if the ledger rows have the simulated ELF twice, or if a file of ledger rows has none for it.
Expand Down
7 changes: 7 additions & 0 deletions fireSense_spreadPredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ defineModule(sim, list(
desc = "Time of the first prediction."),
defineParameter(name = ".runInterval", class = "numeric", default = 1,
desc = "Interval between predictions, in years. `NA` predicts once."),
defineParameter(".plots", "character", "screen", NA, NA,
desc = paste("Passed to `types` in `Plots()`, e.g. \"screen\" (default), \"png\": the spread probability",
"map is plotted each `run`. `NA` or `NULL`: no plots.")),
defineParameter(name = ".saveInitialTime", class = "numeric", default = NA,
desc = "Time of the `save` event, which does nothing. `NA` means never."),
defineParameter(".studyAreaName", "character", NA, NA, NA,
Expand Down Expand Up @@ -165,6 +168,10 @@ doEvent.fireSense_spreadPredict <- function(sim, eventTime, eventType, debug = F
},
run = {
sim <- spreadPredictRun(sim)
## the year's spread probability
if (anyPlotting(P(sim)$.plots))
Plots(sim$fireSense_SpreadPredicted, types = P(sim)$.plots,
filename = paste0("SpreadProbability_yr", time(sim)))

if (!is.na(P(sim)$.runInterval)) {
sim <- scheduleEvent(sim, time(sim) + P(sim)$.runInterval, moduleName, "run",
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/setup-toySpread.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ toyInputs <- function(covs = toyCovariates(), params = toyParams(),
studyAreaWithSpreadParams = sa)
}

## `.plots = NA` unless given: the default "screen" would plot the spread probability in every toy run
toySim <- function(objects = toyInputs(), params = list(), times = list(start = 1, end = 1)) {
if (!".plots" %in% names(params)) params$.plots <- NA
SpaDES.core::simInit(
times = c(times, timeunit = "year"),
modules = moduleName,
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-events.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ test_that("the prediction follows the covariates from year to year", {
expect_equal(predVals(sim)[4], 0.1622730, tolerance = 1e-6)
expect_equal(predVals(sim)[1], 0.19, tolerance = 1e-7)
})

test_that("`.plots` saves the spread probability map each run (default \"screen\"), and NA plots nothing", {
sim <- toyRun(params = list(.plots = "png"), times = list(start = 1, end = 2))
f <- SpaDES.core::outputs(sim)$file
expect_setequal(basename(f), c("SpreadProbability_yr1.png", "SpreadProbability_yr2.png"))
expect_true(all(file.exists(f)))
expect_length(SpaDES.core::outputs(toyRun())$file, 0L) # toySim() sets NA
})

6 changes: 3 additions & 3 deletions tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ paramTable <- function(md) {
test_that("parameters have the expected names, classes and defaults", {
md <- SpaDES.core::moduleMetadata(module = moduleName, path = modulePath)
expected <- data.frame(
class = c("integer", "numeric", "numeric", "numeric", "character", "logical", "numeric", "numeric", "character", "numeric", "numeric", "logical", "character", "integer"),
class = c("character", "integer", "numeric", "numeric", "numeric", "character", "logical", "numeric", "numeric", "character", "numeric", "numeric", "logical", "character", "integer"),
## .runInitialTime defaults to start(sim), which is 0 when only metadata is parsed
default = c("1L", "0", "1", "NA", "NA", "FALSE", "20000", "50", "c(\"natural\", \"unknown\")", "0.13", "0.276", "FALSE", "NA", "1L"),
row.names = c(".rep", ".runInitialTime", ".runInterval", ".saveInitialTime", ".studyAreaName", ".useCache",
default = c("\"screen\"", "1L", "0", "1", "NA", "NA", "FALSE", "20000", "50", "c(\"natural\", \"unknown\")", "0.13", "0.276", "FALSE", "NA", "1L"),
row.names = c(".plots", ".rep", ".runInitialTime", ".runInterval", ".saveInitialTime", ".studyAreaName", ".useCache",
"ELFblendWidth", "escapeSizeHa", "fireCauses", "lowerSpreadProb", "maxFireSpread", "paramSetByReplicate", "paramSets", "repsPerSet")
)
expect_identical(paramTable(md), expected)
Expand Down
Loading