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
5 changes: 3 additions & 2 deletions Biomass_borealDataPrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defineModule(sim, list(
"archive", "assertthat", "cli", "crayon", "curl", "data.table", "dplyr", "ggplot2", "httr", "httr2",
"lme4", "merTools", "plyr", "qs2", "rasterVis", "Require", "sf", "terra", "tidyterra", "googledrive", "quickPlot",
"reproducible (>= 2.1.0)", "SpaDES.core (>= 2.1.0)", "SpaDES.tools (>= 2.0.0)",
"PredictiveEcology/LandR@development (>= 1.2.0.9046)", # makeAndCleanInitialCohortData(minSpeciesEcoregionShare), LandR#264
"PredictiveEcology/LandR@development (>= 1.2.0.9057)", # makeAndCleanInitialCohortData(minSpeciesEcoregionShare), LandR#264; prepInputsFireYear(latestYear)
"PredictiveEcology/pemisc@development",
"PredictiveEcology/SpaDES.project@development (>= 0.0.8.9026)"
),
Expand Down Expand Up @@ -1812,7 +1812,8 @@ Save <- function(sim) {
studyArea = sa,
rasterToMatch = sim$rasterToMatch_biomassParam,
url = extractURL("firePerimeters"),
fireField = "YEAR"
fireField = "YEAR",
latestYear = P(sim)$dataYear ## the latest fire at or before dataYear, not the most recent
) |>
Cache(
omitArgs = "destinationPath",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Known issues: <https://github.com/PredictiveEcology/Biomass_borealDataPrep/issue

# Biomass_borealDataPrep (development version)

* Stand age inside fire perimeters is now the time since the latest fire at or before `dataYear`. The fire raster used to hold each pixel's most recent fire of any year, so a pixel that burned in 1980 and 2015 was skipped for `dataYear` 1990 and kept its satellite age. It now uses `LandR::prepInputsFireYear(latestYear = dataYear)`, which needs LandR (>= 1.2.0.9057). The biomass re-estimate inside fire perimeters uses the same raster, so it now covers those pixels too. A `firePerimeters` input supplied by another module is used as given.

* Without Biomass_speciesData, a study area with no tree species no longer stops in `.inputObjects` ("unable to find an inherited method for function `cover`"): the `NULL` species layers from SCANFI now pass through to the no-species branch.
* `quickPlot` is now in `reqdPkgs` (`dev()`, `clearPlot()` are used).
* The spin-up that re-estimates biomass of young cohorts inside fire perimeters now starts each cohort at `initialB` (new parameter, default 10 g/m2, must match Biomass_core's; `NA` starts at `maxANPP`) instead of 0, so growthcurve-1 species such as spruce are no longer held to the 1 g/m2/yr growth floor while pioneers take the pixel. The sanity check on the result now allows 1.2 x the age-based limit, capped at the raw biomass map maximum, so fast-growing pioneers no longer stop runs.
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-dataYear.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ test_that("the SCANFI species-layer call passes dataYear, not year", {
expect_true("dataYear" %in% argNames)
expect_false("year" %in% argNames)
})

## `prepInputsFireYear()` rasterizes with fun = max, so each pixel holds its most recent fire of any
## year; replaceAgeInFires() then skipped a pixel that burned in 1980 and 2015 for dataYear 1990.
## The data year must reach the fire raster as `latestYear`. Static, so it needs no download.
test_that("the fire-year call passes dataYear as latestYear", {
skip_if_not_installed("LandR")
expect_true("latestYear" %in% names(formals(LandR::prepInputsFireYear)))

code <- parse(file.path(moduleRoot, paste0(moduleName, ".R")))
found <- list()
walk <- function(x) {
if (is.call(x)) {
if (identical(x[[1]], as.name("prepInputsFireYear"))) {
found[[length(found) + 1L]] <<- x
}
lapply(as.list(x), walk)
}
invisible(NULL)
}
lapply(as.list(code), walk)
expect_length(found, 1L)
expect_identical(found[[1L]]$latestYear, quote(P(sim)$dataYear))
})
Loading