From 3ca54b8de6ec3e37521b01410f3ca00de3bd2912 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 3 Dec 2026 15:11:38 -0700 Subject: [PATCH] doFit may differ between the spread and ignition fits: checked only against fireSense_spreadFit fitPrepNeeded() stopped when any module's doFit differed (paramCheckOtherMods over all modules), so a run could not read the spread fit and refit ignition. Test: test-skipUnusedFitPrep.R. Co-Authored-By: Claude Opus 5.5 --- NEWS.md | 1 + fireSense_dataPrepFit.R | 8 +++++--- tests/testthat/test-skipUnusedFitPrep.R | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 73e847c..b75d403 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/fireSense_dataPrepFit.R b/fireSense_dataPrepFit.R index 3b770a5..bc077ff 100644 --- a/fireSense_dataPrepFit.R +++ b/fireSense_dataPrepFit.R @@ -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, @@ -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))) diff --git a/tests/testthat/test-skipUnusedFitPrep.R b/tests/testthat/test-skipUnusedFitPrep.R index 8f43ea7..1431668 100644 --- a/tests/testthat/test-skipUnusedFitPrep.R +++ b/tests/testthat/test-skipUnusedFitPrep.R @@ -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)