Skip to content

Commit 5a7bdf6

Browse files
committed
makeFireSenseLCC -- convert some steps to memory-safe
1 parent 3ca6587 commit 5a7bdf6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export(oom)
5959
export(paramsSeparate)
6060
export(plotBurnSummary)
6161
export(plotCumulativeBurns)
62+
export(plotELFs)
6263
export(plotHistoricFires)
6364
export(predictIgnition)
6465
export(pw)

R/makeFireSenseLCC.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ makeFireSenseLCC <- function(neededYear, to, maskTo = NULL, # to, maskTo = NULL,
111111
nonFlamMap <- terra::classify(rstLCC, matrix(c(nonflammableLCC, rep(0, length(nonflammableLCC))), ncol = 2))
112112

113113
# Convert remaining LCC codes (flammable ones) to 1
114-
nonFlamMap[nonFlamMap > 0] <- 1 # Now 1 = flammable, 0 = non-flammable
114+
allVals <- freq(nonFlamMap)$value
115+
allVals <- setdiff(allVals, 0)
116+
# not memory safe:
117+
# nonFlamMap[nonFlamMap > 0] <- 1 # Now 1 = flammable, 0 = non-flammable
118+
if (length(allVals) > 1)
119+
nonFlamMap <- terra::subst(nonFlamMap, from = allVals, to = 1L)
115120

116121
# Project using average to get proportion of flammable pixels
117122
flammableProp <- terra::project(nonFlamMap, to, method = "average")
@@ -120,6 +125,7 @@ makeFireSenseLCC <- function(neededYear, to, maskTo = NULL, # to, maskTo = NULL,
120125
# - Where the proportion of flammable cover is less than the threshold,
121126
# set the LCC value in the result raster ('allFlam') to 0 (non-flammable).
122127
message("Applying flammability threshold...")
128+
# not memory safe
123129
allFlam[flammableProp < flammabilityThreshold] <- 0
124130

125131
# 5. Optionally write the result to disk

0 commit comments

Comments
 (0)