From fe551bb1575ae98b4775e0d0e2b908c88008b9a7 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Tue, 1 Dec 2026 14:37:25 -0700 Subject: [PATCH 1/2] ageDisturbanceSources: pass the record names to LandR (adds Pre-CanLaD to "all") Any value other than a lone "NFDB" goes to LandR::prepInputsDisturbanceYear(sources = ...), which uses Pre-CanLaD before 1985 with "all" (LandR#301) and accepts record names. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXfVqAugcusGHygZGJ3 --- NEWS.md | 1 + fireSense_dataPrepFit.R | 17 +++++++++-------- tests/testthat/test-disturbanceAgeSources.R | 5 ++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9180d66..70be0c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # fireSense_dataPrepFit 1.3.0.9011 (development version) +* `ageDisturbanceSources = "all"` now also uses Pre-CanLaD (Landsat fire and harvest 1950-1984) before 1985, through `LandR::prepInputsDisturbanceYear()`, for the per-year stand ages and `disturbancePixelsByYear`. The parameter also takes record names (any of `"NFDB"`, `"NBAC"`, `"CanLaD"`, `"PreCanLaD"`); `c("NFDB", "NBAC", "CanLaD")` is the previous `"all"`. 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. * The per-year stand age maps (`standAgeMaps`, which the fits' vegetation and the hindcasts use) reset age at the last stand-replacing disturbance from `LandR::prepInputsDisturbanceYear()` (NFDB, NBAC and CanLaD fire and harvest) with the new parameter `ageDisturbanceSources = "all"` (opt in; same parameter as Biomass_borealDataPrep's, checked to match, so set it in `.globals`), so they match the simulation's own starting ages; `youngAge` then follows the same fires and cuts (new `disturbancePixelsByYear`). It is this module's own parameter because a hindcast runs without Biomass_borealDataPrep. With `"NFDB"` (the default) nothing changes. Opting in changes the vegetation the fits are made with. diff --git a/fireSense_dataPrepFit.R b/fireSense_dataPrepFit.R index ec57906..f58b53b 100644 --- a/fireSense_dataPrepFit.R +++ b/fireSense_dataPrepFit.R @@ -8,7 +8,7 @@ defineModule(sim, list( person(c("Alex", "M"), "Chubaty", role = "ctb", email = "achubaty@for-cast.ca") ), childModules = character(0), - version = list(fireSense_dataPrepFit = "1.3.0.9045"), + version = list(fireSense_dataPrepFit = "1.3.0.9046"), timeframe = as.POSIXlt(c(NA, NA)), timeunit = "year", citation = list("citation.bib"), @@ -20,7 +20,7 @@ defineModule(sim, list( "PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9196)", # 9196 (fireSenseUtils#265): climateCurvePars(), addClimateCurve(), softplus(), climateTermCols(), isClimateTermCol(), ledgerClimateCurvePars(); 9190: modelledFires() (fireSenseUtils#261; set to the real version after merge); 9186: splitSpreadClimate(), climateSplitCols(), climateSplitRefPixels(), isClimateSplitCol() (fireSenseUtils#244); 9184: addCoreFraction(), coreFractionByYear() (moved from this module); 9179: readSpreadFitLedger(escapeDefinition); 9169: fitDataNeeded() (#234); 9161: coreFractionTxt; 9159: climateCovRanges Tmaxsm, PPTsm (#224); 9141: spreadFitLedgerInputs(), spreadFitLedgerInputLists(); 9135: fireSenseFireCauses; 9131: fireCauseCodes(); 9130: climateRasterToDataTable(Index) reads only those cells; 9128: burnableHaTxt "FOR-CAST/fireregimetools@main (>= 0.1.0.9008)", "ggplot2", "methods", "parallel", "purrr", "raster", "sf", "sp", "stats", "utils", - "PredictiveEcology/LandR@development (>= 1.2.0.9067)", # prepInputsDisturbanceYear() + "PredictiveEcology/LandR@development (>= 1.2.0.9069)", # prepInputsDisturbanceYear(sources) "PredictiveEcology/SpaDES.core@development (>= 3.2.1.9073)", "PredictiveEcology/SpaDES.project@development", "PredictiveEcology/SpaDES.tools@development (>= 2.1.1.9000)", @@ -45,8 +45,9 @@ defineModule(sim, list( paste("Which records reset stand age and `youngAge` at the last stand-replacing disturbance.", "`\"NFDB\"` (default): as before (NFDB fire polygons for the per-year stand ages; `firePolysForAge`", "or `historicalFireRaster` for `youngAge`). `\"all\"` (opt in): every record", - "`LandR::prepInputsDisturbanceYear()` uses (currently NFDB, NBAC and CanLaD fire and harvest),", - "for the per-year `standAgeMaps` and a new `disturbancePixelsByYear`. Same parameter as in", + "`LandR::prepInputsDisturbanceYear()` uses (NFDB, NBAC, CanLaD and Pre-CanLaD fire and harvest), or", + "record names (any of `\"NFDB\"`, `\"NBAC\"`, `\"CanLaD\"`, `\"PreCanLaD\"`; a lone `\"NFDB\"` is the", + "default), for the per-year `standAgeMaps` and a new `disturbancePixelsByYear`. Same parameter as in", "Biomass_borealDataPrep, which must match when both are in the simulation", "(`SpaDES.core::paramCheckOtherMods()`); set it in `.globals` to set both. Its own parameter, so a", "hindcast without Biomass_borealDataPrep builds `youngAge` as the fit did.")), @@ -2046,9 +2047,9 @@ runBorealDP_forCohortData <- function(sim) { ## the last stand-replacing disturbance that resets age (ageDisturbanceSources); ## NULL: prepInputsStandAgeMap() reads the NFDB fires itself, as before bbdp <- params(sim)$Biomass_borealDataPrep - distYear <- if (identical(ageSources, "all")) { + distYear <- if (!identical(ageSources, "NFDB")) { LandR::prepInputsDisturbanceYear(rasterToMatch = sim$rasterToMatch_biomassParam, latestYear = dy, - destinationPath = dPath, + destinationPath = dPath, sources = ageSources, earliestYear = if (is.null(bbdp$earliestFireYear)) 1950L else bbdp$earliestFireYear) |> Cache(omitArgs = "destinationPath", .functionName = paste0("prepInputsDisturbanceYear", dy), userTags = c(cacheTags, "prepInputsDisturbanceYear"), @@ -2078,11 +2079,11 @@ runBorealDP_forCohortData <- function(sim) { list2env(outsRev, envir = envir(sim)) # nolint: vars standAgeMaps propFlammables rstLCCs ## every stand-replacing disturbance by year, for youngAge, from the records the stand ages use - if (!suppliedElsewhere("disturbancePixelsByYear", sim) && identical(ageSources, "all")) { + if (!suppliedElsewhere("disturbancePixelsByYear", sim) && !identical(ageSources, "NFDB")) { bbdp <- params(sim)$Biomass_borealDataPrep sim$disturbancePixelsByYear <- LandR::prepInputsDisturbanceYear( rasterToMatch = sim$rasterToMatch, latestYear = max(P(sim)$fireYears), destinationPath = dPath, - earliestYear = if (is.null(bbdp$earliestFireYear)) 1950L else bbdp$earliestFireYear, byYear = TRUE) |> + sources = ageSources, earliestYear = if (is.null(bbdp$earliestFireYear)) 1950L else bbdp$earliestFireYear, byYear = TRUE) |> Cache(omitArgs = "destinationPath", .functionName = "prepInputsDisturbanceYear_byYear", userTags = c(cacheTags, "disturbancePixelsByYear"), .cacheExtra = list(LandR::disturbancesByYear)) diff --git a/tests/testthat/test-disturbanceAgeSources.R b/tests/testthat/test-disturbanceAgeSources.R index 034db65..61cb1a6 100644 --- a/tests/testthat/test-disturbanceAgeSources.R +++ b/tests/testthat/test-disturbanceAgeSources.R @@ -8,7 +8,10 @@ test_that(".inputObjects builds the per-year age maps from this module's ageDist io <- paste(deparse(moduleDefs()[[".inputObjects"]], width.cutoff = 500L), collapse = "\n") expect_match(io, 'ageSources <- SpaDES.core::paramCheckOtherMods(sim, "ageDisturbanceSources", ifSetButDifferent = "error")', fixed = TRUE) - expect_match(io, 'identical(ageSources, "all")', fixed = TRUE) + ## anything but the default "NFDB" ("all", or record names) goes to LandR's rule, with those sources + expect_match(io, '!identical(ageSources, "NFDB")', fixed = TRUE) + expect_no_match(io, 'identical(ageSources, "all")', fixed = TRUE) + expect_identical(lengths(regmatches(io, gregexpr("sources = ageSources", io, fixed = TRUE))), 2L) expect_no_match(io, "bbdp$ageDisturbanceSources", fixed = TRUE) expect_match(io, "LandR::prepInputsDisturbanceYear(rasterToMatch = sim$rasterToMatch_biomassParam, latestYear = dy", fixed = TRUE) From 315baba81994ef00f3758b849da0e9d318842afb Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Tue, 1 Dec 2026 16:55:23 -0700 Subject: [PATCH 2/2] Describe the new "all" (NTEMS, NFDB-NBAC agreement, NFDB before 1972) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXfVqAugcusGHygZGJ3 --- NEWS.md | 2 +- fireSense_dataPrepFit.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 70be0c9..a820764 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # fireSense_dataPrepFit 1.3.0.9011 (development version) -* `ageDisturbanceSources = "all"` now also uses Pre-CanLaD (Landsat fire and harvest 1950-1984) before 1985, through `LandR::prepInputsDisturbanceYear()`, for the per-year stand ages and `disturbancePixelsByYear`. The parameter also takes record names (any of `"NFDB"`, `"NBAC"`, `"CanLaD"`, `"PreCanLaD"`); `c("NFDB", "NBAC", "CanLaD")` is the previous `"all"`. The default `"NFDB"` is unchanged. Needs LandR >= 1.2.0.9069. +* `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. * The per-year stand age maps (`standAgeMaps`, which the fits' vegetation and the hindcasts use) reset age at the last stand-replacing disturbance from `LandR::prepInputsDisturbanceYear()` (NFDB, NBAC and CanLaD fire and harvest) with the new parameter `ageDisturbanceSources = "all"` (opt in; same parameter as Biomass_borealDataPrep's, checked to match, so set it in `.globals`), so they match the simulation's own starting ages; `youngAge` then follows the same fires and cuts (new `disturbancePixelsByYear`). It is this module's own parameter because a hindcast runs without Biomass_borealDataPrep. With `"NFDB"` (the default) nothing changes. Opting in changes the vegetation the fits are made with. diff --git a/fireSense_dataPrepFit.R b/fireSense_dataPrepFit.R index f58b53b..9082c37 100644 --- a/fireSense_dataPrepFit.R +++ b/fireSense_dataPrepFit.R @@ -45,8 +45,8 @@ defineModule(sim, list( paste("Which records reset stand age and `youngAge` at the last stand-replacing disturbance.", "`\"NFDB\"` (default): as before (NFDB fire polygons for the per-year stand ages; `firePolysForAge`", "or `historicalFireRaster` for `youngAge`). `\"all\"` (opt in): every record", - "`LandR::prepInputsDisturbanceYear()` uses (NFDB, NBAC, CanLaD and Pre-CanLaD fire and harvest), or", - "record names (any of `\"NFDB\"`, `\"NBAC\"`, `\"CanLaD\"`, `\"PreCanLaD\"`; a lone `\"NFDB\"` is the", + "`LandR::prepInputsDisturbanceYear()` uses (NFDB, NBAC, CanLaD, NTEMS and Pre-CanLaD fire and harvest), or", + "record names (any of `\"NFDB\"`, `\"NBAC\"`, `\"CanLaD\"`, `\"NTEMS\"`, `\"PreCanLaD\"`; a lone `\"NFDB\"` is the", "default), for the per-year `standAgeMaps` and a new `disturbancePixelsByYear`. Same parameter as in", "Biomass_borealDataPrep, which must match when both are in the simulation", "(`SpaDES.core::paramCheckOtherMods()`); set it in `.globals` to set both. Its own parameter, so a",