@@ -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