Climate variables

Code
library(terra)
library(sf)

Climate data were obtained from the CHELSA-Bioclim v2.1 database at a spatial resolution of 1 km (Brun et al. 2022). We extracted mean annual temperature (BIO1, in °C) and mean annual precipitation (BIO12, in mm/year), both calculated as long-term averages over the 1981–2010 reference period.

Code
if (!require(Rchelsa)) {
  remotes::install_git("https://gitlabext.wsl.ch/karger/rchelsa.git")
  library(Rchelsa)
}
clim <- lapply(
  c("bio01", "bio12"),
  function(rs) {
    getChelsa(
      rs,
      extent = ext(c(110, 130, 0, 20)),
      date = "1981-2010", dataset = "chelsa-bioclim"
    )
  }
) |>
  rast()
names(clim) <- c("mean_temperature", "mean_precipitation")

if (!dir.exists("data/chelsa")) dir.create("data/chelsa")
writeRaster(clim, file = "data/chelsa/climate_variables.tif", overwrite = TRUE)
Code
"data/chelsa/climate_variables.tif" |>
  rast() |>
  plot()

Brun, P., N. E. Zimmermann, C. Hari, L. Pellissier, and D. N. Karger. 2022. CHELSA-BIOCLIM+ A novel set of global climate-related predictors at kilometre-resolution.” https://doi.org/https://www.doi.org/10.16904/envidat.332.