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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions R/standAge.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion man-roxygen/startTime.R
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion man/replaceAgeInFires.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/test-standAge.R
Original file line number Diff line number Diff line change
@@ -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))
})
Loading