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_dataPrepFit (development version)

- The pooled `other_agb` spread covariate is gone and `fuelCovariates = "domSecOther"` is renamed `"domSecWetland"` (now the default): spread fuels are `dom_agb_<class>`, `sec_agb_<class>` and `treedWetland_agb`. Needs the `fireSenseUtils` change that renames the value (PredictiveEcology/fireSenseUtils#116). Spread fits made with `other_agb` need refitting, and cached `prepSpreadFitData` results change.

- New parameter `heldOutFold` (`NA`, `1` or `2`; the same parameter as in `fireSense_spreadFit`). With `1` or `2`, `Init()` does not read the SpreadFit ledger: `sim$spreadFitPreRun` stays NULL and `mod$haveSpreadFit` is FALSE, so the fold derives its own species, fuel and climate objects. `paramCheckOtherMods()` stops if `fireSense_spreadFit` has a different value; set all three modules with `.globals = list(heldOutFold = ...)`.

- `snow` is no longer a `reqdPkgs`: nothing used it, and attaching it printed two "partial argument match of 'along'" warnings per run (from snow's `.onLoad()`) under `warnPartialMatchArgs = TRUE`.
Expand Down
19 changes: 9 additions & 10 deletions fireSense_dataPrepFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defineModule(sim, list(
reqdPkgs = list("data.table", "fastDummies", "Require",
"PredictiveEcology/reproducible@development (>= 3.2.1.9042)", # CacheGeo re-reads a changed local file
"PredictiveEcology/climateData@development (>= 2.2.3.9006)",
"PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9062)",
"PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9070)",
"FOR-CAST/fireregimetools@main (>= 0.1.0.9008)",
"ggplot2", "parallel", "purrr", "raster", "sf", "sp",
"PredictiveEcology/LandR@development (>= 1.2.0.9015)",
Expand Down Expand Up @@ -67,12 +67,11 @@ defineModule(sim, list(
"named `FuelClass` exists in the `LandR::sppEquivalencies_CA` and will be used ",
"by default. To change the `FuelClass` classifications, add a column to that table, ",
"or to `sim$sppEquiv` and then modify this `fuelClassCol` parameter"),
defineParameter("fuelCovariates", "character", c("domSecOther", "species"), NA, NA,
paste("How the spread-fit fuel covariates are represented. `\"domSecOther\"` (default):",
"exactly four AGB columns per ELF, `dom_agb_<class>` and `sec_agb_<class>` (the",
"two fuel classes with the most total treed AGB over the fit study area),",
"`other_agb` (the rest, pooled) and `treedWetland_agb` (all tree AGB on treed-wetland",
"pixels, removed from the other three there); see",
defineParameter("fuelCovariates", "character", c("domSecWetland", "species"), NA, NA,
paste("How the spread-fit fuel covariates are represented. `\"domSecWetland\"` (default):",
"`dom_agb_<class>` and `sec_agb_<class>` (the two fuel classes with the most",
"total treed AGB over the fit study area) and `treedWetland_agb` (all tree AGB on",
"treed-wetland pixels, removed from dom/sec there); other classes are not covariates; see",
"`fireSenseUtils::fireSenseCovariatesCreate()`. `\"species\"`: the previous one",
"column per fuel class. `fireSense_dataPrepPredict` follows whichever a fit used;",
"this is not a parameter there.")),
Expand Down Expand Up @@ -255,7 +254,7 @@ defineModule(sim, list(
createsOutput("fireSense_spreadFormula", "character",
"formula for spread, using climate and vegetation covariates, as character"),
createsOutput("fuelClassRoles", "list",
paste("Only when `fuelCovariates = \"domSecOther\"`: `list(domClass =, secClass =)`,",
paste("Only when `fuelCovariates = \"domSecWetland\"`: `list(domClass =, secClass =)`,",
"the fuel classes chosen once for this ELF by `fireSenseUtils::chooseDomSecFuelClasses()`.",
"Both `NA` with `fuelCovariates = \"species\"` or when the ELF has no tree fuel class.")),
createsOutput("ignitionFirePoints", "SpatVector",
Expand Down Expand Up @@ -715,9 +714,9 @@ prepare_SpreadFit <- function(sim) {
dig1a <- .robustDigest(list(sim$cohortDatas, sim$pixelGroupMaps, sim$nonForest_timeSinceDisturbances))
dig2 <- append(dig1, dig1a)

fuelCovariates <- match.arg(P(sim)$fuelCovariates, c("domSecOther", "species"))
fuelCovariates <- match.arg(P(sim)$fuelCovariates, c("domSecWetland", "species"))
sim$fuelClassRoles <- list(domClass = NA_character_, secClass = NA_character_)
if (identical(fuelCovariates, "domSecOther")) {
if (identical(fuelCovariates, "domSecWetland")) {
## chosen once per ELF (the most recent data year, as with sim$rstLCC/sim$rstLCC_RTM elsewhere
## in this module), not independently for every data year -- a prediction must build the same
## dom_agb_*/sec_agb_* columns whichever year it is predicting
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## fireSense_dataPrepFit.R ~690 (prepare_SpreadFit()): fireSenseCovariatesCreate() was never given
## `rstLCC`, so `treedWetland` never appeared, and there was no way to ask for the new
## dom/sec/other AGB fuel representation. `fuelCovariates` (default "domSecOther") now picks the
## dom/sec AGB (plus treedWetland_agb) fuel representation. `fuelCovariates` (default "domSecWetland") now picks the
## representation, and the dominant/secondary classes are chosen once per ELF (not once per data
## year, or every prediction would build a different pair of columns) via
## fireSenseUtils::chooseDomSecFuelClasses(), stored in sim$fuelClassRoles.
Expand All @@ -14,17 +14,17 @@ walkCalls <- function(expr, f) {
invisible(NULL)
}

test_that("fuelCovariates defaults to domSecOther, with species as the only other choice", {
test_that("fuelCovariates defaults to domSecWetland, with species as the only other choice", {
md <- SpaDES.core::moduleMetadata(module = moduleName, path = modulePath)
def <- stats::setNames(md$parameters$default, md$parameters$paramName)
expect_identical(def$fuelCovariates, c("domSecOther", "species"))
expect_identical(def$fuelCovariates, c("domSecWetland", "species"))
})

test_that("reqdPkgs floors fireSenseUtils at >= 0.2.3.9062 (chooseDomSecFuelClasses, fireSenseSharedDefaults etc.)", {
test_that("reqdPkgs floors fireSenseUtils at >= 0.2.3.9070 (domSecWetland fuels)", {
md <- SpaDES.core::moduleMetadata(module = moduleName, path = modulePath)
fsu <- grep("fireSenseUtils", md$reqdPkgs, value = TRUE)
expect_length(fsu, 1L)
expect_match(fsu, "0\\.2\\.3\\.9062")
expect_match(fsu, "0\\.2\\.3\\.9070")
})

test_that("prepare_SpreadFit() picks fuelClassRoles once per ELF via chooseDomSecFuelClasses()", {
Expand Down Expand Up @@ -72,3 +72,11 @@ test_that("the fireSenseCovariatesCreate() Map() call passes rstLCC, fuelCovaria
expect_match(moreArgsTxt, "domClass = sim$fuelClassRoles$domClass", fixed = TRUE)
expect_match(moreArgsTxt, "secClass = sim$fuelClassRoles$secClass", fixed = TRUE)
})

test_that("the module no longer mentions the pooled other_agb covariate", {
md <- SpaDES.core::moduleMetadata(module = moduleName, path = modulePath)
expect_false(any(grepl("other_agb", unlist(md$parameters$paramDesc), fixed = TRUE)))
expect_false(any(grepl("other_agb", unlist(md$outputObjects$desc), fixed = TRUE)))
expect_false(any(grepl("domSecOther", readLines(file.path(modulePath, moduleName, paste0(moduleName, ".R"))),
fixed = TRUE)))
})
Loading