diff --git a/DESCRIPTION b/DESCRIPTION index 655958a..81c870d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Builds landscape inputs for Canadian forest models from national disturbances. URL: https://github.com/PredictiveEcology/forestInputs BugReports: https://github.com/PredictiveEcology/forestInputs/issues -Version: 0.0.1.9000 +Version: 0.0.1.9001 Authors@R: c( person("Eliot J B", "McIntire", email = "eliot.mcintire@nrcan-rncan.gc.ca", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6914-8316")), diff --git a/NEWS.md b/NEWS.md index e5d2f49..4c24db6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,11 @@ `prescribed` (keep prescribed burns), `harvest` (which Landsat records give harvest, or a layer of harvest years such as BC cutblocks that replaces them), `unknownYear` (Pre-CanLaD's year 999) and `withType` (a second layer, the type of the last disturbance: 1 fire, 2 harvest). A 30 m `rasterToMatch` gives 30 m output. +* `replaceAgeInFires()` uses a `startTime` after 2023. It treated any year after 2023 as missing and dated + each fire from the latest fire year in `firePerimeters` instead, so `prepInputsStandAgeMap()` with a + `dataYear` after 2023 made burned stands too young by the years between that fire and `dataYear`, unless + the area burned in `dataYear` itself. A `startTime` earlier than 1950 (e.g., a simulation time of 0) still + falls back to the latest fire year. # forestInputs 0.0.1 diff --git a/R/standAge.R b/R/standAge.R index d8bf6aa..b795f10 100644 --- a/R/standAge.R +++ b/R/standAge.R @@ -541,8 +541,9 @@ replaceAgeInFires <- function(standAgeMap, firePerimeters, startTime) { if (missing(startTime)) { startTime <- 0 } - if (startTime < 1950 || startTime > 2023) { - message("'startTime' is missing or is not within a reasonable range of 1950 to 2023, ") + ## a startTime before 1950 is taken to be a simulation time (e.g. 0), not a year + if (startTime < 1950) { + message("'startTime' is missing or earlier than 1950, ") message(" --> The most recent fire year will be used.") startTime <- max(firePerimeters[], na.rm = TRUE) } diff --git a/man-roxygen/startTime.R b/man-roxygen/startTime.R index 9987c9c..1f158de 100644 --- a/man-roxygen/startTime.R +++ b/man-roxygen/startTime.R @@ -1,2 +1,3 @@ #' @param startTime date of the last fire year to be considered (e.g., start of fire -#' period counting backwards). If missing, last fire year available will be used. +#' period counting backwards). If missing or earlier than 1950 (e.g., a simulation +#' time of 0), the last fire year available is used. diff --git a/man/replaceAgeInFires.Rd b/man/replaceAgeInFires.Rd index 4e9ef90..55c6d62 100644 --- a/man/replaceAgeInFires.Rd +++ b/man/replaceAgeInFires.Rd @@ -12,7 +12,8 @@ replaceAgeInFires(standAgeMap, firePerimeters, startTime) \item{firePerimeters}{the earliest fire date to allow} \item{startTime}{date of the last fire year to be considered (e.g., start of fire -period counting backwards). If missing, last fire year available will be used.} +period counting backwards). If missing or earlier than 1950 (e.g., a simulation +time of 0), the last fire year available is used.} } \value{ a raster layer stand age map corrected for fires, with an attribute vector of pixel IDs diff --git a/tests/testthat/test-standAge.R b/tests/testthat/test-standAge.R new file mode 100644 index 0000000..6f81732 --- /dev/null +++ b/tests/testthat/test-standAge.R @@ -0,0 +1,13 @@ +test_that("replaceAgeInFires() dates fires from a startTime after 2023", { + ages <- terra::rast(nrows = 1, ncols = 3, vals = 100L) + fires <- terra::rast(ages, vals = c(2010, 2020, NA)) + out <- replaceAgeInFires(ages, fires, startTime = 2025) + expect_equal(terra::values(out, mat = FALSE), c(15, 5, 100)) +}) + +test_that("replaceAgeInFires() dates fires from the latest fire when startTime is not a year", { + ages <- terra::rast(nrows = 1, ncols = 3, vals = 100L) + fires <- terra::rast(ages, vals = c(2010, 2020, NA)) + out <- suppressMessages(replaceAgeInFires(ages, fires, startTime = 0)) + expect_equal(terra::values(out, mat = FALSE), c(10, 0, 100)) +})