R/current-conditions.R
cc_age_composite.RdCrops the primary age raster to the study area, converts its NoData sentinel to NA, and
optionally fills the cells it leaves empty from a second age raster aged forward to the same
epoch. Promoted from LandWeb_preamble, where base is fRI Research's age_in2025 and fill
is NTEMS forest age.
cc_age_composite(
base,
studyArea,
fill = NULL,
fillYear = NULL,
epoch = 2025L,
baseNAflag = 65535,
fillNAflag = 255
)SpatRaster of stand age at epoch; authoritative wherever it has a value.
SpatVector or sf polygon(s). Both rasters are cropped to it before any
other work (see Details).
optional SpatRaster of stand age at fillYear, in any CRS.
the year fill represents. Required with fill.
the year base represents; fill is aged forward by epoch - fillYear.
the NoData sentinel of each source (age_in2025: 65535; NTEMS: 255,
meaning non-treed). NA if the source has none.
A SpatRaster on base's grid, cropped and masked to studyArea.
base stays authoritative: fill only supplies cells base left empty. A cell-wise minimum
would instead let a modelled age drag inventory ages younger, and because a minimum is
one-directional that is a systematic young bias into exactly the areas where the data is best.
A sentinel left unconverted is read as a real age – 65,535 years, or a 255-year stand on every
non-treed pixel – and silently poisons every downstream aggregate. terra does not read
age_in2025's NoData tag, so the sentinel must be supplied. It is converted with
terra::classify() after cropping rather than with NAflag<-: for an in-memory raster,
NAflag<- converts the values but NAflag() still reports NaN, so an assertion on the flag
fails on correct data, and whether the flag "took" depends on how the raster is stored.
fill's sentinel is converted before it is reprojected and aged, so it can never surface as
sentinel + (epoch - fillYear) (e.g. 258).
Cropping first matters: age_in2025 alone is about 6.5e9 cells, so aligning a fill at full
extent would move billions of cells to produce one study area's output. fill is reprojected
with method = "near", so the result contains only the source's own ages.
cc_age_pct_missing() to check the result is complete enough to use.