Skip to contents

This function allows you to extract climate variables from the TerraClimate dataset for specific geographic coordinates. TerraClimate is a global dataset of monthly climate data covering the years 1958-present. The function retrieves climate variables directly from the hosting server provided by the University of Idaho, avoiding the need to download large raster files in netCDF format. Additionally, the function calculates bioclimatic variables using the calc_biovars function, derived from the dismo R package.

The TerraClimate dataset is compared with WorldClim in several aspects:

  • TerraClimate: 1958-present vs. WorldClim: 1970-2000

  • 14 climate variables vs. 7 climate variables in WorldClim

  • Spatial resolution: ~4 km (TerraClimate) vs. ~1 km (WorldClim)

  • Need to calculate bioclimatic variables (TerraClimate) vs. pre-calculated (WorldClim)

Usage

get_terraclimate(
  lat,
  lon,
  from = "1958-01-01",
  to = "2022-12-31",
  clim_vars = NULL,
  month_mask = NULL,
  offline = FALSE,
  data_path = "./data/"
)

Arguments

lat

Vector of Latitude(s) in decimal degree format. Each entry corresponds to a location of interest.

lon

Vector of Longitude(s) in decimal degree format. Each entry corresponds to a location of interest.

from

Start date as a string in 'YYYY-MM-DD' format. Defines the beginning of the time range for data extraction.

to

End date as a string in 'YYYY-MM-DD' format. Defines the end of the time range for data extraction.

clim_vars

List of climate variables to extract. Valid options include: aet, def, pet, ppt, q, soil, srad, swe, tmax, tmin, vap, ws, vpd, and PDSI. Default is NULL, which retrieves all variables.

month_mask

A vector specifying the months of interest, e.g., for specific seasons (e.g., planting season: c(10:12, 1:5)). Default is NULL, which retrieves data for all months.

offline

Logical value indicating whether to extract TerraClimate data from pre-downloaded netCDF files. Default is FALSE, meaning data is fetched from the remote server.

data_path

String specifying the directory path where downloaded netCDF files are stored when working offline. Default is './data/'.

Value

A list of two data frames for each coordinate pair (latitude and longitude):

  • climate: A data frame containing the requested climate variables for each month and location.

  • biovars: A data frame with calculated bioclimatic variables, based on the extracted climate data.

Each data frame is in a format ready for further analysis in R.

References

Abatzoglou, J., Dobrowski, S., Parks, S. et al. TerraClimate, a high-resolution global dataset of monthly climate and climatic water balance from 1958-2015. Sci Data 5, 170191 (2018). doi:10.1038/sdata.2017.191

Author

Khaled Al-Shamaa, k.el-shamaa@cgiar.org

Examples

if (interactive()) {
  # data <- get_terraclimate(36.016, 36.943, '1979-09-01', '2012-06-30', 
  #                          c('ppt', 'tmin', 'tmax'), c(10:12,1:5))
  data <- get_terraclimate(36.016, 36.943, '1979-09-01', '2012-06-30')

  View(data$climate[[1]])  # View the climate data
  View(data$biovars[[1]])  # View the bioclimatic variables
}