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)

* `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.

Expand Down
17 changes: 9 additions & 8 deletions fireSense_dataPrepFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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)",
Expand All @@ -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, 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",
"hindcast without Biomass_borealDataPrep builds `youngAge` as the fit did.")),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-disturbanceAgeSources.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down