Skip to contents

This function computes lapse rates (a linear relationship of a climate variable to elevation) across user-provided rasters. Lapse rates are calculated using simple linear regression (without the intercept) using the focal cell and its eight neighbors as observations. These gridded lapse rates are used in downscale() and downscale_core() for elevation adjustment of climate values during downscaling to user-specified locations. The method is illustrated in the vignette vignette("lapse_rates")

Usage

lapse_rate(reference, dem, NA_replace = TRUE, nthread = 1L, rasterize = TRUE)

Arguments

reference

a SpatRaster stack. climate rasters to compute lapse rates for. Build with this package functions.

dem

SpatRaster. A digital elevation model raster. Only needed if normal is a SpatRaster. Defaults to NULL.

NA_replace

logical. Should NA lapse rate results be replaced by zeros. Default to TRUE.

nthread

integer. Number of parallel threads to use to compute lapse rates.

rasterize

logical. Return an object of the same class category as reference with the same extent? Default to TRUE.

Value

SpatRaster of lapse rate values.

Details

Formulas
beta_coef = sum(xy) / sum(x²)
mss = sum(x * beta_coef)², sum of squared fitted values
rss = sum(ε²), sum of squared (y minus fitted), sum of absolute errors
R² = mss / (mss + rss)
Lapse rate = beta_coef * R²