Counts burned pixels of currentBurn within each FRI zone and converts to hectares.

landmine_area_burned_by_zone(
  currentBurn,
  fireReturnInterval,
  time,
  pixelAreaHa
)

Arguments

currentBurn

SpatRaster of this year's burn; burned pixels are 1, unburned 0.

fireReturnInterval

SpatRaster of per-pixel FRI values (the zone labels).

time

numeric, the simulation time recorded in the returned table.

pixelAreaHa

numeric, the area of one pixel in hectares.

Value

A data.frame with columns time, nPixelsBurned, haBurned, FRI (a factor).

Details

Fixes a bug. This previously counted burned pixels with unname(table(currBurn[ids])[2]) – positional indexing into a table(), which assumes the levels are always {0, 1} in that order. When a zone burns completely there is only one level, so [2] is NA, and the following npix[is.na(npix)] <- 0 (whose comment says it handles the no-burn case) silently converted it to its exact opposite: a fully-burned zone was recorded as zero hectares burned. Counting with sum(vals == 1, na.rm = TRUE) is correct in all three cases.