Skip to content

Commit a99b818

Browse files
committed
fix prepInputsFireYear
1 parent 128329d commit a99b818

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ URL:
99
https://landr.predictiveecology.org,
1010
https://github.com/PredictiveEcology/LandR
1111
Date: 2025-06-04
12-
Version: 1.1.5.9046
12+
Version: 1.1.5.9047
1313
Authors@R: c(
1414
person("Eliot J B", "McIntire", email = "[email protected]",
1515
role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6914-8316")),

R/prepInputObjects.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,23 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
664664

665665
## invalid NFDB polygons will cause Rstudio to crash during postProcess as of 8/21/2024
666666
## removing invalid polygons is far faster than fixing the 0.1% of data
667-
postProcessArgs <- dots[names(dots) %in% c("to", "maskTo", "projectTo", "cropTo")]
667+
#projectTo must be rasterToMatch due to terra rasterize
668+
#but don't project yet because of NFDB
669+
postProcessArgs <- dots[names(dots) %in% c("to", "projectTo", "studyArea", "maskTo")]
668670
if (length(postProcessArgs) == 0) {
669-
postProcessArgs$to <- rasterToMatch
671+
postProcessArgs$cropTo <- rasterToMatch
672+
postProcessArgs$projectTo <- rasterToMatch
673+
postProcessArgs$maskTo = rasterToMatch
670674
}
675+
postProcessArgs$projectTo <- rasterToMatch
671676

672677
preProcessArgs <- dots[!names(dots) %in% names(postProcessArgs)]
678+
#you can crop without worrying about geometry
679+
preProcessArgs$cropTo <- rasterToMatch
680+
673681
allFires <- do.call(prepInputs, append(list(fun = fun), preProcessArgs))
682+
683+
#the reason this isn't combined into one function is due to geometry issues in NFDB
674684
allFires <- allFires[terra::is.valid(allFires), ] ## drop invalid geometries
675685

676686
## This may potentially result in dots intended for postProcess being lost.
@@ -692,7 +702,9 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
692702
if (!is(d, "SpatVector")) {
693703
d <- vect(d)
694704
}
695-
fireRas <- terra::rasterize(d, rasterToMatch, field = fireField)
705+
706+
#fun = max to take the most recent fire year
707+
fireRas <- terra::rasterize(d, rasterToMatch, field = fireField, fun = max)
696708
fireRas[!is.na(terra::values(fireRas, mat = FALSE)) &
697709
terra::values(fireRas, mat = FALSE) < earliestYear] <- NA
698710
} else {

R/prepInputs_NTEMS.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ prepInputs_NTEMS_DominantSpecies <- function(year = 2011, destinationPath, sppEq
207207
}
208208

209209
domSpp <- lapply(uniqueVals[["NTEMS_Species_Code"]], FUN = function(spp, ras = domSpp,
210-
template = projectTo) { # converting each species to binary layers and reprojecting to save user computation time
210+
template = projectTo) {
211+
# converting each species to binary layers and reprojecting to save user computation time
211212
newMap <- domSpp
212213
newMap[!domSpp[] == spp] <- 0
213214
newMap[domSpp[] == spp] <- 1

0 commit comments

Comments
 (0)