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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# fireSense_dataPrepPredict (development version)

- `studyArea` is now a declared input. `.inputObjects` used it to mask the fire polygons, land cover and stand age it
makes, but an undeclared object is not visible there, so it was always `NULL` and nothing was masked. It also made
an unset `.studyAreaName` come from the extent of `rasterToMatch` in `.inputObjects` but from `studyArea` in `Init`.
That `rasterToMatch` fallback is removed: without a `studyArea`, an unset `.studyAreaName` stays `NA`.
- New parameter `.studyAreaName` (default `NA`). The module already read `P(sim)$.studyAreaName` without defining it,
so it was always `NULL`, whatever the user set. Left `NA`, it becomes a hash of `studyArea` (or of the extent of
`rasterToMatch`), as in Biomass_borealDataPrep. It names the study area in the landcover file
Expand Down
30 changes: 15 additions & 15 deletions fireSense_dataPrepPredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defineModule(sim, list(
person("Alex M", "Chubaty", role = "ctb", email = "achubaty@for-cast.ca")
),
childModules = character(0),
version = list(fireSense_dataPrepPredict = "1.0.4.9002"),
version = list(fireSense_dataPrepPredict = "1.0.4.9003"),
timeframe = as.POSIXlt(c(NA, NA)),
timeunit = "year",
citation = list("citation.bib"),
Expand Down Expand Up @@ -133,6 +133,9 @@ defineModule(sim, list(
desc = "Table of LandR species equivalencies; must have columns `sppEquivCol` and `fuelClassCol`."),
expectsInput("standAgeMap", "SpatRaster", sourceURL = NA,
desc = "Stand age (years) at `start(sim)`."),
expectsInput("studyArea", "SpatVector", sourceURL = NA,
desc = paste("Polygon of the study area. The fire polygons, land cover and stand age made in",
"`.inputObjects` are masked to it.")),
expectsInput("landcoverDT", "data.table", sourceURL = NA,
desc = paste(
"`pixelID` plus one binary column per non-forest landcover group, for flammable pixels,",
Expand Down Expand Up @@ -576,20 +579,6 @@ unionLCCGroups <- function(fuelSets) {
#' @param sim A `simList`.
#'
#' @return The `simList`, invisibly.
## An NA `.studyAreaName` becomes a hash of the study area (as in Biomass_borealDataPrep), so NA never
## reaches a file name or cache tag. Without `studyArea`, the extent of `rasterToMatch` stands in for it.
resolveStudyAreaName <- function(sim) {
if (is.na(P(sim)$.studyAreaName)) {
sa <- sim$studyArea
if (is.null(sa))
sa <- terra::as.polygons(terra::ext(sim$rasterToMatch), crs = terra::crs(sim$rasterToMatch))
params(sim)[[currentModule(sim)]][[".studyAreaName"]] <- reproducible::studyAreaName(sa)
message("The .studyAreaName is not supplied; derived name from the study area: ",
params(sim)[[currentModule(sim)]][[".studyAreaName"]])
}
sim
}

.inputObjects <- function(sim) {
cacheTags <- c(currentModule(sim), "otherFunctions:.inputObjects")
dPath <- asPath(inputPath(sim), 1)
Expand Down Expand Up @@ -661,3 +650,14 @@ resolveStudyAreaName <- function(sim) {

return(invisible(sim))
}

## An NA `.studyAreaName` becomes a hash of `studyArea`, as in Biomass_borealDataPrep. Without a
## `studyArea` it stays NA (see PredictiveEcology/LandR#246).
resolveStudyAreaName <- function(sim) {
if (is.na(P(sim)$.studyAreaName) && !is.null(sim$studyArea)) {
params(sim)[[currentModule(sim)]][[".studyAreaName"]] <- reproducible::studyAreaName(sim$studyArea)
message("The .studyAreaName is not supplied; derived name from the study area: ",
params(sim)[[currentModule(sim)]][[".studyAreaName"]])
}
sim
}
3 changes: 2 additions & 1 deletion tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ test_that("inputs are the expected names and classes", {
rstLCCs = "list",
sppEquiv = "data.table",
sppEquivs = "list",
standAgeMap = "SpatRaster")
standAgeMap = "SpatRaster",
studyArea = "SpatVector")
)
})

Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test-studyAreaName.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ test_that("an unset .studyAreaName becomes a hash of the study area", {
expect_identical(nm, reproducible::studyAreaName(objs$studyArea))
})

test_that("without studyArea, the extent of rasterToMatch names it", {
test_that("without studyArea, an unset .studyAreaName stays NA", {
objs <- toyObjects()
objs$studyArea <- NULL
sim <- SpaDES.core::spades(toyPrepSim(objs), events = "init", debug = FALSE)
nm <- SpaDES.core::P(sim, module = moduleName)$.studyAreaName
expect_false(is.na(nm))
expect_type(nm, "character")
expect_true(is.na(SpaDES.core::P(sim, module = moduleName)$.studyAreaName))
})

test_that("a supplied .studyAreaName is kept", {
Expand Down
Loading