Function to calculate the magnitude and direction of the spatial gradient associated to a climatic variable after Burrows et al. (2011). This trend is to be used for the calculation of the gradient-based climate velocity using gVoCC.
Arguments
- r
RasterStackwith the annual climatic values for the period of interest. Alternatively, arasterwith the annual climatic values averaged over the period of interest.- th
Integerindicating a lower threshold to truncate the spatial gradient with. Use -Inf (default) if no threshold required.- projected
Logicalis the source raster in a projected coordinate system? If FALSE (default) a correction will be made to account for latitudinal distortion.
Value
A RasterStack with the magnitude of the spatial gradient
(Grad in C per km for unprojected rasters and C per spatial unit for projected rasters),
and the associated angle (Ang in degrees).
References
Burrows et al. 2011. The pace of shifting climate in marine and terrestrial ecosystems. Science, 334, 652-655.
Examples
if (FALSE) { # \dontrun{
HSST <- VoCC_get_data("HSST.tif")
yrSST <- sumSeries(HSST,
p = "1969-01/2009-12", yr0 = "1955-01-01", l = terra::nlyr(HSST),
fun = function(x) colMeans(x, na.rm = TRUE), freqin = "months", freqout = "years"
)
# Spatial gradient (magnitude and angle) for the average mean annual SST.
sg <- spatGrad(yrSST, th = 0.0001, projected = FALSE)
terra::plot(sg)
} # }