From f453c7ebd9106a5a377fc68dd2b8bd137606004d Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Mon, 28 Sep 2026 15:58:28 -0700 Subject: [PATCH] Take shared defaults from fireSenseUtils; add scanfiVersion parameter fireSense_dataPrepPredict.R hard-coded its own copies of forestedLCC, cutoffForYoungAge, nonForestCanBeYoungAge, flammabilityThreshold, fuelClassCol and igAggFactor, duplicating fireSense_dataPrepFit's defaults. A fit and its predictions are only consistent if both modules use the same values, so each now defaults from fireSenseUtils's exported constants, as nonflammableLCC already did. Values are unchanged. Adds parameter scanfiVersion (default fireSenseUtils::fireSenseSCANFIVersion), the SCANFI land-cover version used when this module builds its own land cover, passed to the Cache(makeFireSenseLCC, ...) call in .inputObjects(). fireSenseUtils:::fireSenseCovariatesCreate becomes ::, since it is exported. reqdPkgs floors fireSenseUtils@development (>= 0.2.3.9062). Version 1.0.4.9006. Rmd docs re-rendered. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CwcjqqK59FmTJscyi7xUqv --- NEWS.md | 10 ++++++++++ fireSense_dataPrepPredict.R | 24 +++++++++++++++--------- fireSense_dataPrepPredict.html | 22 +++++++++++++++++++++- fireSense_dataPrepPredict.md | 10 +++++++++- tests/testthat/test-metadata.R | 4 ++-- tests/testthat/test-sharedDefaults.R | 19 +++++++++++++++++++ 6 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 tests/testthat/test-sharedDefaults.R diff --git a/NEWS.md b/NEWS.md index cf5989c..e6db5b0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,15 @@ # fireSense_dataPrepPredict (development version) +- `forestedLCC`, `cutoffForYoungAge`, `nonForestCanBeYoungAge`, `flammabilityThreshold`, + `fuelClassCol` and `igAggFactor` now default to `fireSenseUtils`'s shared constants + (`fireSenseForestedLCC`, `fireSenseYoungAgeCutoff`, `fireSenseNonForestCanBeYoungAge`, + `fireSenseFlammabilityThreshold`, `fireSenseFuelClassCol`, `fireSenseIgAggFactor`), as + `nonflammableLCC` already did, so a fit and its predictions cannot silently use different + values. Values are unchanged. New parameter `scanfiVersion` (default + `fireSenseUtils::fireSenseSCANFIVersion`), the SCANFI land-cover version used when this module + builds its own land cover, passed to `makeFireSenseLCC()`. `fireSenseCovariatesCreate()` is now + called with `::`, not `:::` (it is exported). Needs `fireSenseUtils@development (>= 0.2.3.9062)`. + Version 1.0.4.9006. - Fixed: `nonflammableLCC`'s default (`c(0, 20, 31, 32, 33)`) missed SCANFI's rock/exposed code (`30`), so rock entered predictions as flammable non-forest. The default now comes from `fireSenseUtils::fireSenseNonflammableLCC`, the single source of truth `makeFireSenseLCC()` diff --git a/fireSense_dataPrepPredict.R b/fireSense_dataPrepPredict.R index 3a1742d..3099c65 100644 --- a/fireSense_dataPrepPredict.R +++ b/fireSense_dataPrepPredict.R @@ -10,7 +10,7 @@ defineModule(sim, list( person("Alex M", "Chubaty", role = "ctb", email = "achubaty@for-cast.ca") ), childModules = character(0), - version = list(fireSense_dataPrepPredict = "1.0.4.9005"), + version = list(fireSense_dataPrepPredict = "1.0.4.9006"), timeframe = as.POSIXlt(c(NA, NA)), timeunit = "year", citation = list("citation.bib"), @@ -19,11 +19,11 @@ defineModule(sim, list( "fireSense_IgnitionFit", "fireSense_SpreadFit")), reqdPkgs = list( "data.table", - "PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9060)", + "PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9062)", "terra" ), parameters = rbind( - defineParameter("cutoffForYoungAge", "numeric", 15, NA, NA, + defineParameter("cutoffForYoungAge", "numeric", fireSenseUtils::fireSenseYoungAgeCutoff, NA, NA, desc = paste( "Age at and below which pixels are considered 'young'", "(i.e., `age <= cutoffForYoungAge`)." @@ -33,14 +33,14 @@ defineModule(sim, list( paste("Year of the default landcover and stand age maps, and last year of the fires", "used to initialise `nonForest_timeSinceDisturbance`.")), defineParameter("fireTimeStep", "numeric", 1, NA, NA, desc = "Interval between events of this module, in years."), - defineParameter("forestedLCC", "numeric", c(81, 210, 220, 230, 240), NA, NA, + defineParameter("forestedLCC", "numeric", fireSenseUtils::fireSenseForestedLCC, NA, NA, "Forested landcover classes in `rstLCC_RTM`. Only used if `landcoverDT` is not supplied."), - defineParameter("flammabilityThreshold", "numeric", 0.1, 0, 1, + defineParameter("flammabilityThreshold", "numeric", fireSenseUtils::fireSenseFlammabilityThreshold, 0, 1, paste("Minimum proportion of flammable pixels for an upscaled pixel to be flammable,", "when building the default landcover.")), - defineParameter("fuelClassCol", "character", "FuelClass", NA, NA, + defineParameter("fuelClassCol", "character", fireSenseUtils::fireSenseFuelClassCol, NA, NA, "Column of `sppEquiv` that defines the fuel classes, for both ignition and spread."), - defineParameter("igAggFactor", "numeric", 4, 1, NA, + defineParameter("igAggFactor", "numeric", fireSenseUtils::fireSenseIgAggFactor, 1, NA, paste("Aggregation factor for the ignition and escape covariates.", "Overwritten in `init` by the value set in other modules.")), defineParameter("nonflammableLCC", "numeric", fireSenseUtils::fireSenseNonflammableLCC, NA, NA, @@ -50,8 +50,13 @@ defineModule(sim, list( "water, rock, snow/ice and barren land." ) ), - defineParameter("nonForestCanBeYoungAge", "logical", TRUE, NA, NA, + defineParameter("nonForestCanBeYoungAge", "logical", fireSenseUtils::fireSenseNonForestCanBeYoungAge, NA, NA, desc = "Should burned non-forest pixels be `youngAge` until `cutoffForYoungAge`?"), + defineParameter("scanfiVersion", "character", fireSenseUtils::fireSenseSCANFIVersion, NA, NA, + desc = paste( + "SCANFI land-cover version for non-forest land cover, when this module builds its own", + "landcover (only used if `rstLCC_RTM`/`rstLCCs` is not supplied)." + )), defineParameter("sppEquivCol", "character", "LandR", NA, NA, desc = "Column of `sppEquiv` with the species names used in `cohortData`."), defineParameter("whichModulesToPrepare", "character", @@ -471,7 +476,7 @@ prepare_SpreadPredict <- function(sim) { ## its fit used even where a different class dominates here. domClass = NA (a fit made with ## fuelCovariates = "species", or with no fitted parameters yet) predicts with the previous ## per-fuel-class columns. - covs <- fireSenseUtils:::fireSenseCovariatesCreate( + covs <- fireSenseUtils::fireSenseCovariatesCreate( cohortData = sim$cohortData, pixelGroupMap = sim$pixelGroupMap, flammableRTM = sim$flammableRTM, @@ -676,6 +681,7 @@ unionLCCGroups <- function(fuelSets) { overwrite= TRUE, nonflammableLCC = P(sim)$nonflammableLCC, flammabilityThreshold = P(sim)$flammabilityThreshold, + scanfiVersion = P(sim)$scanfiVersion, userTags = c("makeFireSenseLCC", "predict") ) sim$rstLCC_RTM <- rstLCC$lcc diff --git a/fireSense_dataPrepPredict.html b/fireSense_dataPrepPredict.html index 2f56acc..7b1d27f 100644 --- a/fireSense_dataPrepPredict.html +++ b/fireSense_dataPrepPredict.html @@ -2994,7 +2994,7 @@

fireSense_dataPrepPredict Manual

-

v.1.0.4.9005

+

v.1.0.4.9006

Last updated: 2026-09-28

@@ -3571,6 +3571,26 @@

Module inputs and parameters

+scanfiVersion + + +character + + +V3 + + +NA + + +NA + + +SCANFI land-cover version for non-forest land cover, when this module builds its own landcover (only used if rstLCC_RTM/rstLCCs is not supplied). + + + + sppEquivCol diff --git a/fireSense_dataPrepPredict.md b/fireSense_dataPrepPredict.md index 12c99d2..d6b2902 100644 --- a/fireSense_dataPrepPredict.md +++ b/fireSense_dataPrepPredict.md @@ -1,6 +1,6 @@ --- title: "fireSense_dataPrepPredict Manual" -subtitle: "v.1.0.4.9005" +subtitle: "v.1.0.4.9006" date: "Last updated: 2026-09-28" output: bookdown::html_document2: @@ -288,6 +288,14 @@ Summary of user-visible parameters (Table \@ref(tab:moduleParams-fireSense-dataP NA Should burned non-forest pixels be `youngAge` until `cutoffForYoungAge`? + + scanfiVersion + character + V3 + NA + NA + SCANFI land-cover version for non-forest land cover, when this module builds its own landcover (only used if `rstLCC_RTM`/`rstLCCs` is not supplied). + sppEquivCol character diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-metadata.R index 7b37e15..fb916d1 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-metadata.R @@ -60,7 +60,7 @@ test_that("parameters are the expected names", { sort(md$parameters$paramName), sort(c(".runInitialTime", ".studyAreaName", ".useCache", "cutoffForYoungAge", "dataYear", "fireTimeStep", "flammabilityThreshold", "forestedLCC", "fuelClassCol", - "igAggFactor", "nonflammableLCC", "nonForestCanBeYoungAge", "sppEquivCol", - "whichModulesToPrepare")) + "igAggFactor", "nonflammableLCC", "nonForestCanBeYoungAge", "scanfiVersion", + "sppEquivCol", "whichModulesToPrepare")) ) }) diff --git a/tests/testthat/test-sharedDefaults.R b/tests/testthat/test-sharedDefaults.R new file mode 100644 index 0000000..4a176ac --- /dev/null +++ b/tests/testthat/test-sharedDefaults.R @@ -0,0 +1,19 @@ +## Root cause: fireSense_dataPrepPredict.R hard-coded its own copies of `forestedLCC`, +## `cutoffForYoungAge`, `nonForestCanBeYoungAge`, `flammabilityThreshold`, `fuelClassCol` and +## `igAggFactor`, the same defaults fireSense_dataPrepFit hard-codes separately. A fit and its +## predictions are only consistent if both modules use the same values, so each now takes its +## default from `fireSenseUtils`'s shared constants (`?fireSenseUtils::fireSenseSharedDefaults`), +## as `nonflammableLCC` already did. + +test_that("parameter defaults come from fireSenseUtils's shared constants", { + md <- SpaDES.core::moduleMetadata(module = moduleName, path = modulePath) + default <- function(name) md$parameters$default[md$parameters$paramName == name][[1]] + + expect_identical(default("forestedLCC"), fireSenseUtils::fireSenseForestedLCC) + expect_identical(default("cutoffForYoungAge"), fireSenseUtils::fireSenseYoungAgeCutoff) + expect_identical(default("nonForestCanBeYoungAge"), fireSenseUtils::fireSenseNonForestCanBeYoungAge) + expect_identical(default("flammabilityThreshold"), fireSenseUtils::fireSenseFlammabilityThreshold) + expect_identical(default("fuelClassCol"), fireSenseUtils::fireSenseFuelClassCol) + expect_identical(default("igAggFactor"), fireSenseUtils::fireSenseIgAggFactor) + expect_identical(default("scanfiVersion"), fireSenseUtils::fireSenseSCANFIVersion) +})