Original Landscape

plot(fm)

names(fm)
## [1] "US_ELEV2020"  "US_SLPD2020"  "US_ASP2020"   "US_230FBFM40" "US_230CC"    
## [6] "US_230CH"     "US_230CBH"    "US_230CBD"
# US_230FBFM40 is for the fuel model

Set Landscape to constants

fm[["US_ELEV2020"]][] <- 0 # Elevation
fm[["US_SLPD2020"]][] <- 0 # Slope
fm[["US_ASP2020"]][] <- -1 # Aspect
fm[["US_230CC"]][] <- 30 # Canopy Cover
fm[["US_230CH"]][] <- 10 # Canopy Height
fm[["US_230CBH"]][] <- 4.35 # Canopy Base Height
fm[["US_230CBD"]][] <- 0.25 # Canopy Bulk Density

Focal area

buffer_cells <- 50

fm_layer <- fm[["US_230FBFM40"]]

nrows <- nrow(fm_layer)
ncols <- ncol(fm_layer)

focal_mask <- rast(fm_layer)
values(focal_mask) <- NA

# interior rows and columns
interior_rows <- (buffer_cells + 1):(nrows - buffer_cells)
interior_cols <- (buffer_cells + 1):(ncols - buffer_cells)

focal_mask[interior_rows, interior_cols] <- 1

plot(focal_mask, main = "Focal Area Mask (Interior)")

Spatial Fuel Arrangement

Set seed to 123 for first iterations, and 122 for second iterations. 121 for third.

set.seed(121)

clustered <- nlm_randomcluster(
  ncol = ncols,
  nrow = nrows,
  p    = 0.55,
  ai   = c(0.5, 0.5)  # 50% cogongrass
)
## Loading required namespace: igraph
clustered <- rast(clustered)
ext(clustered) <- ext(fm_layer)
crs(clustered) <- crs(fm_layer)

# Binary conversion
binary <- clustered
values(binary) <- ifelse(values(clustered) > 0.5, 1, 0)

# Mask to interior only
binary_focal <- mask(binary, focal_mask)

plot(binary_focal, main = "Clustered Pattern (Interior Only)")

fm_new <- fm
fm_vals <- values(fm_layer)

# Default everything to 101
fm_vals[] <- 101

# Apply clustered pattern only in focal area
fm_vals[values(binary_focal) == 1] <- 107
fm_vals[values(binary_focal) == 0] <- 144

values(fm_new[["US_230FBFM40"]]) <- fm_vals

table(values(fm_new[["US_230FBFM40"]]))
## 
##    101    107    144 
## 135500 196775 184991
plot(fm_new[["US_230FBFM40"]], main = "Fuel Model with 101 Buffer + Clustered Interior")

New Landscape

plot(fm_new)

writeRaster(
  fm_new,
  "C:/Users/DrewIvory/OneDrive - University of Florida/Desktop/School/PHD/Data/FlamMap/WSF_Cluster50_3_144_107.tif",
  overwrite = TRUE
)