Calculates up to 35 bioclimatic variables from average monthly climate SpatRasters (or other temporal units). This function serves as a smart wrapper that automatically selects the most efficient processing workflow (in-memory vs. tiled) based on data size and user-defined region of interest.
derive_bioclim(
bios,
tmin = NULL,
tmax = NULL,
prcp = NULL,
tavg = NULL,
srad = NULL,
mois = NULL,
output_dir = tempdir(),
period_length = 3,
circular = TRUE,
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE,
...
)An SpatRaster with 35 bioclimatic variables or a subset of them:
Mean Temperature of Units
Mean Diurnal Range
Isothermality
Temperature Seasonality
Max Temperature of Warmest Unit
Min Temperature of Coldest Unit
Temperature Range of Units
Mean Temperature of Wettest Period
Mean Temperature of Driest Period
Mean Temperature of Warmest Period
Mean Temperature of Coldest Period
Precipitation Sum
Precipitation of Wettest Unit
Precipitation of Driest Unit
Precipitation Seasonality
Precipitation of Wettest Period
Precipitation of Driest Period
Precipitation of Warmest Period
Precipitation of Coldest Period
Mean Radiation of Units
Highest Radiation Unit
Lowest Radiation Unit
Radiation Seasonality
Radiation of Wettest Period
Radiation of Driest Period
Radiation of Warmest Period
Radiation of Coldest Period
Mean Moisture Content Of Units
Highest Moisture Content Unit
Lowest Moisture Content Unit
Moisture Content Seasonality
Mean Moisture Content of Most Moist Period
Mean Moisture Content of Least Moist Period
Mean Moisture Content of Warmest Period
Mean Moisture Content of Coldest Period
Numeric vector specifying which bioclimatic variables (1-35) to compute.
(Optional) `terra::SpatRaster` objects containing the climate data for each temporal unit (e.g., 12 monthly layers). All provided rasters must have the same geometry and number of layers.
The directory where the final bioclimatic variable rasters will be saved. The directory will be created if it does not exist. The default is temporal directory created by `tempdir`.
Integer. The number of temporal units (e.g., months) that define a "period" for calculating summary variables like BIO8 (Mean Temp of Wettest Quarter). Defaults to 3, representing quarters for monthly data.
Logical. If `TRUE` (the default), period calculations will wrap around the beginning and end of the time series (e.g., for monthly data, Dec-Jan-Feb is considered a valid period).
(Optional) An `sf` or `terra::SpatVector` object defining the area of interest. If provided, all calculations will be clipped to this region.
The processing method. See Details for more information.
(Tiled method only) The approximate size of processing tiles in degrees. Ignored if the 'terra' workflow is used.
(Optional) A character vector of GDAL creation options for the output GeoTIFF files. Controls compression, threading, etc.
(Optional) Logical. If `FALSE` (the default), the function will stop immediately if any target output files already exist.
Logical, If `TRUE`, prints messages.
Additional arguments, primarily for passing static index rasters. See the "Static Indices" section for details.
For advanced use cases, such as time-series analysis or defining specific seasons, you can provide pre-calculated index rasters to override the dynamic calculations. These are passed as named `SpatRaster` objects via the `...` argument (e.g., `warmest_period = my_warmest_idx_rast`). The wrapper function automatically handles passing them to the appropriate workflow.
When using the "tiled" workflow, these static index rasters **must** be file-backed (i.e., not held entirely in memory). Supported static indices include:
`warmest_unit`, `coldest_unit`, `wettest_unit`, `driest_unit`
`high_rad_unit`, `low_rad_unit`, `high_mois_unit`, `low_mois_unit`
`warmest_period`, `coldest_period`, `wettest_period`, `driest_period`
`high_mois_period`, `low_mois_period`
This function unifies two processing backends. The `method` argument controls which is used:
`"auto"`: (Default) Intelligently chooses between "terra" and "tiled" based on estimated memory requirements.
`"terra"`: Forces the fast, in-memory workflow. May fail on very large datasets.
`"tiled"`: Forces the memory-safe, out-of-core workflow. Ideal for very large datasets. Requires that the input SpatRasters point to files on disk.
Period-based variables (e.g., BIO8, BIO10) are calculated using a moving window defined by `period_length`.
O’Donnell, M. S., & Ignizio, D. A. (2012). Bioclimatic predictors for supporting ecological applications in the conterminous United States. ANUCLIM 6.1 User Guide. Centre for Resource and Environmental Studies, The Australian National University.
`validate_climate_inputs()` to check data integrity before processing.
# This is a conceptual example, requires data setup
if (FALSE) {
# Assume tmin_rast, tmax_rast, prcp_rast are 12-layer SpatRasters
bioclim_vars <- derive_bioclim(
bios = 1:19,
tmin = tmin_rast,
tmax = tmax_rast,
prcp = prcp_rast,
output_dir = "./bioclim_output",
overwrite = TRUE
)
plot(bioclim_vars[[c("bio01", "bio12")]])
}
Run the code above in your browser using DataLab