Skip to contents

Fit climniche to terra raster data

Usage

fit_climniche_terra(
  current,
  future,
  occupied = NULL,
  occupied_threshold = NULL,
  domain = NULL,
  domain_threshold = 0,
  cnfa = NULL,
  center = NULL,
  sensitivity = NULL,
  A = NULL,
  metric = c("diag", "factor"),
  boundary = 0.95,
  scale = TRUE,
  preprocess = TRUE,
  preprocess_correlation = 0.95,
  preprocess_min_sd = 1e-08,
  global_mean = NULL,
  global_sd = NULL,
  tolerance = NULL,
  tolerance_quantile = 0.1,
  boundary_exceedance_tolerance = 0
)

Arguments

current

terra SpatRaster of current climate layers.

future

terra SpatRaster of future climate layers with the same geometry and layer order as current.

occupied

Optional one layer SpatRaster with binary or continuous occurrence, range, or SDM suitability values.

occupied_threshold

Values at or below this threshold receive zero reference weight. Values above it keep their original value.

domain

Optional one layer SpatRaster limiting cells where exposure is analysed.

domain_threshold

Values greater than this threshold define the domain.

cnfa

Optional CENFA cnfa object. Its marginality and sensitivity slots are used when center, sensitivity, or A are not supplied.

center

Optional realised niche centre in the climate space used by the fit. If omitted, the centre is the weighted mean of current reference rows.

sensitivity

Optional non-negative variable weights. Used to build a diagonal metric when A is not supplied.

A

Optional square metric matrix. When supplied, it overrides sensitivity, cnfa, and metric for distance calculations.

metric

Method used to build A when A is missing. "diag" uses variable-level sensitivity weights. "factor" uses the factor metric available from a compatible CENFA object.

boundary

Quantile used to define the empirical boundary of the current realised niche. Must be between 0 and 1.

scale

Logical. If TRUE, current and future values are centred and scaled with the current-layer mean and standard deviation before distances are calculated.

preprocess

Logical. If TRUE, remove near-zero variance variables and highly correlated variables before metric fitting.

preprocess_correlation

Maximum absolute pairwise correlation retained among current climate variables during preprocessing.

preprocess_min_sd

Minimum current-climate standard deviation retained during preprocessing.

global_mean

Optional means used for centering. If omitted, column means of current are used.

global_sd

Optional standard deviations used for scaling. If omitted, column standard deviations of current are used.

tolerance

Optional tolerance around zero for Niche Distance Shift. If NULL, the fitted object uses tolerance_quantile.

tolerance_quantile

Quantile of absolute Niche Distance Shift used to set tolerance when tolerance = NULL.

boundary_exceedance_tolerance

Tolerance used to label whether Niche Boundary Exceedance is greater than zero for descriptor summaries.

Value

An object of class climniche_fit with SpatRaster outputs stored in x$rasters.

Details

fit_climniche_terra() is the SpatRaster workflow for users working with terra. It extracts aligned cell values, applies domain and occupied rasters, calls the matrix workflow, and writes the fitted quantities back to SpatRaster outputs.