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

* `fireSense_ignitionFit`'s `doFit` may now differ from this module's, so a run can refit one model and read the other's fit (e.g. spread `FALSE`, ignition `NA`). With `skipUnusedFitPrep` (the default) init stopped when they differed; `doFit` is now checked only against `fireSense_spreadFit`'s, the other spread module.
* The SpreadFit ledger is read with `fireSenseUtils::readFitLedger()`: with `doFit` FALSE and a `spreadFitFilename` that is missing or has no rows, the newest production fits (`"latest"`) are read, so a run that only reads a fit needs no ledger of its own. `doFit` is resolved with `fireSenseUtils::moduleDoFit()` (the deprecated aliases count) where the module reads it. Needs fireSenseUtils >= 0.2.3.9202.
* `ageDisturbanceSources = "all"` changes with LandR's rule (Pre-CanLaD or NFDB before 1972; Pre-CanLaD 1972-1984; CanLaD or NTEMS, or NFDB and NBAC agreeing, from 1985), for the per-year stand ages and `disturbancePixelsByYear`, through `LandR::prepInputsDisturbanceYear()`. The parameter also takes record names (any of `"NFDB"`, `"NBAC"`, `"CanLaD"`, `"NTEMS"`, `"PreCanLaD"`). The default `"NFDB"` is unchanged. Needs LandR >= 1.2.0.9069.
* Biomass_borealDataPrep now gets the stand age map and land cover of its own `dataYear` from `dataPrepBuild` (`vegStartYearName()`), not those of the last of `dataYears`. A run whose vegetation starts before the last data year (the attribution hindcasts, `dataYear` 1985) got the 2020 stand ages on 1985 biomass and species: stands burned in 1980-1985 started at about 38 years, and stands that burn in 1986-2020 at about 11. Fits, hindcast validation and NRV runs are unchanged: they read the per-year lists, or start from the last data year.
Expand Down
8 changes: 5 additions & 3 deletions fireSense_dataPrepFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ defineModule(sim, list(
"TRUE or NA. `ignitionFirePoints` and `nonEscapedFireSizesHa` are still made, from the input points.",
"FALSE: prepare everything, as before this parameter existed.",
"The same parameter of `fireSense_spreadFit`: set it for both with",
"`.globals = list(skipUnusedFitPrep = FALSE)`; init stops if they differ on it or on `doFit`.",
"`.globals = list(skipUnusedFitPrep = FALSE)`; init stops if they differ on it or on `doFit`",
"(`fireSense_ignitionFit`'s `doFit` may differ: refit one model, read the other's ledger fit).",
"Not part of the cache keys."),
cacheKey = FALSE),
defineParameter("saveFitTables", "character", character(0), NA, NA,
Expand Down Expand Up @@ -1743,8 +1744,9 @@ prepEventsToSchedule <- function(which, fitPrep = TRUE, ignitionPrep = TRUE) {
#' @return logical, length one.
fitPrepNeeded <- function(sim, module = "fireSense_spreadFit") {
if (!isTRUE(P(sim)$skipUnusedFitPrep)) return(TRUE)
for (nm in c("skipUnusedFitPrep", "doFit"))
SpaDES.core::paramCheckOtherMods(sim, nm, ifSetButDifferent = "error")
SpaDES.core::paramCheckOtherMods(sim, "skipUnusedFitPrep", ifSetButDifferent = "error")
## doFit is the spread fit's (this module and fireSense_spreadFit); fireSense_ignitionFit's may differ
SpaDES.core::paramCheckOtherMods(sim, "doFit", moduleToUse = "fireSense_spreadFit", ifSetButDifferent = "error")
if (module == "fireSense_ignitionFit") {
ign <- params(sim)[[module]]
return(fireSenseUtils::fitDataNeeded(if (is.null(ign)) NA else fireSenseUtils::moduleDoFit(ign, module)))
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-skipUnusedFitPrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ test_that("skipUnusedFitPrep: the ignition and escape prep follows fireSense_ign
expect_identical(scheduled(prepSim(FALSE, skip = FALSE, ignitionFit = list(doFit = FALSE))), all4)
})

test_that("the spread and ignition fits can have different doFit (refit one model, read the other's fit)", {
sp <- list(mode = "fit")
## spread read from the ledger, ignition and escape refit: the spread fire data and the ignition and escape data
expect_identical(scheduled(prepSim(FALSE, spreadFit = sp, ignitionFit = list(doFit = NA))), fireOnly)
expect_identical(scheduled(prepSim(FALSE, spreadFit = sp, ignitionFit = list(doFit = TRUE))), fireOnly)
## spread refit, ignition read from the ledger
expect_identical(scheduled(prepSim(TRUE, spreadFit = sp, ignitionFit = list(doFit = FALSE))), "prepSpreadFitData")
## the spread fit's own doFit must still match this module's: both are the spread model
sim <- prepSim(FALSE, spreadFit = sp)
sim@params$fireSense_spreadFit$doFit <- TRUE
expect_error(fitPrepNeeded(sim))
})

test_that("a project that prepares only the ignition fit and skips its prep schedules nothing", {
expect_length(prepEventsToSchedule("fireSense_ignitionFit", FALSE, FALSE), 0L)
expect_length(prepEventsToSchedule(bothFits, TRUE, FALSE), 1L)
Expand Down