Create the standAgeMap raster containing age estimates for pixelCohortData. A separate reproducible::prepInputs() call will source Canadian National Fire Data Base data to update ages of recently burned pixels. To suppress this, pass NULL/NA fireURL

prepInputsStandAgeMap(
  ...,
  ageURL = NULL,
  ageFun = "raster::raster",
  maskWithRTM = TRUE,
  method = "bilinear",
  datatype = "INT2U",
  destinationPath = NULL,
  filename2 = NULL,
  firePerimeters = NULL,
  fireURL = paste0("https://cwfis.cfs.nrcan.gc.ca/downloads/nfdb/",
    "fire_poly/current_version/NFDB_poly.zip"),
  fireFun = "terra::vect",
  fireField = "YEAR",
  rasterToMatch = NULL,
  startTime
)

Arguments

...

additional arguments passed to reproducible::prepInputs()

ageURL

url where age map is downloaded

ageFun

passed to 'fun' arg of reproducible::prepInputs() of stand age map

maskWithRTM

passed to reproducible::prepInputs() of stand age map

method

passed to reproducible::prepInputs() of stand age map

datatype

passed to reproducible::prepInputs() of stand age map

destinationPath

path to data directory where objects will be downloaded or saved to

filename2

passed to reproducible::prepInputs() of stand age map

firePerimeters

fire raster layer fire year values.

fireURL

url to download fire polygons used to update age map. If NULL or NA age imputation is bypassed. Requires passing rasterToMatch. Only used if firePerimeters is missing.

fireFun

passed to reproducible::prepInputs() of fire data. Only used if firePerimeters is missing.

fireField

field used to rasterize fire polys. Only used if firePerimeters is missing.

rasterToMatch

A RasterLayer objects to use as the template for all subsequent raster operations (i.e., the one used throughout the simulation).

startTime

date of the last fire year to be considered (e.g., start of fire period counting backwards). If missing, last fire year available will be used.

Value

a raster layer stand age map corrected for fires, with an attribute vector of pixel IDs for which ages were corrected. If no corrections were applied the attribute vector is integer(0).

Examples

if (FALSE) {
library(SpaDES.tools)
library(terra)
library(reproducible)
randomPoly <- vect(randomStudyArea(size = 1e7))
randomPoly
ras2match <- rast(res = 250, ext = ext(randomPoly), crs = crs(randomPoly))
ras2match <- rasterize(randomPoly, ras2match)
tempDir <- tempdir()

## NOT USING FIRE PERIMETERS TO CORRECT STAND AGE
## rasterToMatch does not need to be provided, but can be for masking/cropping.
standAge <- prepInputsStandAgeMap(destinationPath = tempDir,
                                  rasterToMatch = ras2match,
                                  fireURL = NA)   ## or NULL
attr(standAge, "imputedPixID")

## USING FIRE PERIMETERS TO CORRECT STAND AGE
## ideally, get the firePerimenters layer first
firePerimeters <- Cache(prepInputsFireYear,
                        url = paste0("https://cwfis.cfs.nrcan.gc.ca/downloads",
                        "/nfdb/fire_poly/current_version/NFDB_poly.zip"),
                        destinationPath = tempDir,
                        rasterToMatch = ras2match)

standAge <- prepInputsStandAgeMap(destinationPath = tempDir,
                                  firePerimeters = firePerimeters,
                                  rasterToMatch = ras2match)
attr(standAge, "imputedPixID")

## not providing firePerimeters is still possible, but will be deprecated
## in this case 'rasterToMatch' MUST be provided
standAge <- prepInputsStandAgeMap(destinationPath = tempDir,
                                  rasterToMatch = ras2match)
attr(standAge, "imputedPixID")
}