R/current-conditions.R
cc_age_pct_missing.RdThe completeness check for a current-condition age raster: of the forest inside the study area,
what share has no age? Promoted from LandWeb_preamble's ccAgeMaxMissing gate.
cc_age_pct_missing(
age,
studyArea,
landcover,
forestClasses = lcc2020_classes()$forest
)SpatRaster of stand age, e.g. from cc_age_composite().
SpatVector or sf polygon(s).
SpatRaster of land cover, in any CRS and at any resolution; it is cropped
and reprojected onto age's grid with method = "near".
the landcover codes that count as forest. Defaults to the LCC 2020 forest
classes from lcc2020_classes().
A single number, the percent (0-100) of forest cells with no age, with attributes
nForest and nAged giving the counts behind it.
The denominator is the part of the study area that is forest. It took three attempts to get there, and each wrong version is pinned by a test:
Not the raster. Cropping with mask = TRUE sets every cell outside the polygon to NA,
indistinguishable from a cell that genuinely lacks an age, so mean(is.na(age)) measures the
shape of the bounding box. LandWeb's study-area groups fill only 30-44% of theirs:
WesternAlbertaUpland read 71.4% missing against a true 3.9%.
Not the whole study area. Stand age is only defined for forest, and a treed-only source such as NTEMS leaves water and wetland empty by design, so the polygon-wide figure mostly measures lakes. ChurchillRiverUpland read 39.4% missing after filling; 76% of that was water, barren or wetland.
Not on a coarser grid. Aggregating with average fills a coarse cell from any one of its
children, so a cell only counts as missing when all of them are. At 240 m that loosened the
figure 3-20x and let an unfilled study area pass.
Counting uses terra::global(), which works in chunks, so no full-resolution vector is held in
memory.