Learn R Programming

fastbioclim: Scalable Derivation of Climate Variables

fastbioclim is an R package for efficiently deriving standard bioclimatic and custom summary variables from large-scale climate raster data. It is designed to overcome the memory limitations of traditional approaches by intelligently switching between processing backends.

Overview

Working with large climate datasets often presents a major challenge: the data is too large to fit into memory. fastbioclim solves this problem by providing a powerful and unified interface with a dual-backend architecture:

  1. In-Memory ("terra"): For datasets that fit comfortably in RAM, fastbioclim uses the highly optimized terra package for maximum speed.
  2. In-Disk ("tiled"): For datasets that exceed available RAM, it automatically switches to a memory-safe tiled workflow. This backend uses exactextractr and Rfast to process the data chunk by chunk, ensuring that even continent-scale analyses can run on a standard computer.

The core of the package is a set of "smart" wrapper functions—derive_bioclim() and derive_statistics()—that automatically select the best backend, providing a seamless experience for the user.

Key Features

  • Smart auto Method: Automatically detects data size and chooses the optimal processing workflow (in-memory vs. tiled).
  • Scalability: Robustly handles raster datasets of any size, from small study areas to global extents.
  • Comprehensive Bioclimatic Variables: Calculates the full set of 35 standard bioclimatic variables, including those based on temperature, precipitation, solar radiation, and moisture.
  • Custom Statistics: Provides a flexible derive_statistics() function to compute custom summaries (mean, max, min, standard deviation, etc.) for any climate variable.
  • Flexible Time Periods: Easily define custom periods (e.g., weeks, semesters) instead of being limited to standard quarters.
  • Advanced Control: Supports static index rasters for advanced time-series analysis and defining specific seasonal periods.

Installation

You can install the development version of fastbioclim from GitHub with:

# install.packages("remotes")
remotes::install_github("gepinillab/fastbioclim")
# Install to get the package example data 
remotes::install_github("gepinillab/egdata.fastbioclim")

Usage

The package provides two primary, user-facing functions:

  • derive_bioclim(): For calculating the standard set of 19-35 bioclimatic variables.
  • derive_statistics(): For calculating custom summary statistics on any variable.

Example: A Quick Demonstration

This example demonstrates the core functionality using simple, self-contained mock data.

library(fastbioclim)
library(terra)
library(future.apply)
library(progressr)

tmin_ecu <- system.file("extdata/ecuador/", package = "egdata.fastbioclim") |>
  list.files("tmin", full.names = TRUE) |> rast()
tmax_ecu <- system.file("extdata/ecuador/", package = "egdata.fastbioclim") |>
  list.files("tmax", full.names = TRUE) |> rast()
prcp_ecu <- system.file("extdata/ecuador/", package = "egdata.fastbioclim") |>
  list.files("prcp", full.names = TRUE) |> rast()

# The function will automatically use the fast "terra" method for this small dataset
output_dir_bioclim <- file.path(tempdir(), "bioclim_ecuador")

bioclim_vars <- derive_bioclim(
  bios = 1:19,
  tmin = tmin_ecu,
  tmax = tmax_ecu,
  prcp = prcp_ecu,
  output_dir = output_dir_bioclim,
  overwrite = TRUE
)

plot(bioclim_vars[[c("bio01", "bio12")]])
# 3. Derive custom summary statistics for a different variable (e.g., wind speed)
wind_rast <- system.file("extdata/ecuador/", package = "egdata.fastbioclim") |>
  list.files("wind", full.names = TRUE) |> rast()
output_dir_custom <- file.path(tempdir(), "wind_ecuador")

custom_stats <- derive_statistics(
  variable = wind_rast,
  stats = c("mean", "max", "stdev"),
  prefix_variable = "wind",
  output_dir = output_dir_custom,
  overwrite = TRUE
)

plot(custom_stats)

Handling Large-Scale Data (The Tiled Workflow)

The real power of fastbioclim shines with large datasets. The method = "auto" setting in derive_bioclim() and derive_statistics() handles this automatically.

When the wrapper function detects that the input rasters are too large to fit in memory, it seamlessly switches to the tiled workflow.

Important Requirement: For the tiled workflow to function, your input SpatRaster objects must be pointing to files on disk, not held entirely in memory.

# Conceptual example for large, file-based rasters
tmin_neo <- system.file("extdata/neotropics/", package = "egdata.fastbioclim") |>
  list.files("tmin", full.names = TRUE) |> rast()
tmax_neo <- system.file("extdata/neotropics/", package = "egdata.fastbioclim") |>
  list.files("tmax", full.names = TRUE) |> rast()
prcp_neo <- system.file("extdata/neotropics/", package = "egdata.fastbioclim") |>
  list.files("prcp", full.names = TRUE) |> rast()
output_dir_bios <- file.path(tempdir(), "bioclim_neotropics")

# Optional: ACTIVATE PROGRESS BAR
progressr::handlers(global = TRUE)
# Optional: DEFINE PARALLEL PLAN FOR EVEN FASTER PROCESSING
future::plan("multisession", workers = 4)

# The call is identical. `derive_bioclim` will detect the large file size
# and automatically use the memory-safe tiled method.
large_scale_vars <- derive_bioclim(
  bios = 1:19,
  tmin = tmin_neo,
  tmax = tmax_neo,
  prcp = prcp_neo,
  output_dir = output_dir_bios,
  tile_degrees = 20,
  overwrite = TRUE
)
print(large_scale_vars)
plot(large_scale_vars[["bio11"]])

Under Active Development

This R package is currently under active development. While it is functional, it may contain bugs or undergo changes to the API.

Contributions, bug reports, and feature requests are highly encouraged. Please open an issue on our GitHub repository to provide feedback.

Copy Link

Version

Install

install.packages('fastbioclim')

Monthly Downloads

200

Version

0.3.0

License

GPL (>= 3)

Maintainer

Gonzalo E. Pinilla-Buitrago

Last Published

November 26th, 2025

Functions in fastbioclim (0.3.0)

bio01_fast

bio01_fast: Mean Temperature of Units
bio01_terra

bio01_terra: Mean Temperature of Units
bio11_terra

bio11_terra: Mean Temperature of Coldest Period
bio11_fast

bio11_fast: Mean Temperature of Coldest Period
bio17_fast

bio17_fast: Precipitation of Driest Period
bio03_terra

bio03_terra: Isothermality
bio03_fast

bio03_fast: Isothermality
bio28_terra

bio28_terra: Mean Moisture of Units
bio22_terra

bio22_terra: Lowest Solar Radiation Unit
bio28_fast

bio28_fast: Mean Moisture of Units
bio17_terra

bio17_terra: Precipitation of Driest Period
bio22_fast

bio22_fast: Lowest Solar Radiation Unit
bio05_fast

bio05_fast: Max Temperature of Warmest Unit
bio05_terra

bio05_terra: Max Temperature of Warmest Unit
bio19_terra

bio19_terra: Precipitation of Coldest Period
bio19_fast

bio19_fast: Precipitation of Coldest Period
bio12_terra

bio12_terra: Total Precipitation
bio29_fast

bio29_fast: Highest Moisture Unit
bio12_fast

bio12_fast: Total Precipitation
bio31_fast

bio31_fast: Moisture Seasonality (Standard Deviation)
calculate_roll

Calculate Rolling Temporal Averages for SpatRasters
bio33_fast

bio33_fast: Moisture of the Least Moist Period
bio29_terra

bio29_terra: Highest Moisture Unit
bio31_terra

bio31_terra: Moisture Seasonality (Standard Deviation)
bio09_fast

bio09_fast: Mean Temperature of Driest Period
bio33_terra

bio33_terra: Moisture of the Least Moist Period
bio09_terra

bio09_terra: Mean Temperature of Driest Period
bionames

Print Bioclimatic Variable Names
bio13_fast

bio13_fast: Precipitation of Wettest Unit
bio04_fast

bio04_fast: Temperature Seasonality (Std Dev * 100)
bio08_fast

bio08_fast: Mean Temperature of Wettest Period
average_terra

In-Memory Time Series Averaging (Internal)
bio04_terra

bio04_terra: Temperature Seasonality (Std Dev * 100)
bio14_fast

bio14_fast: Precipitation of Driest Unit
average_fast

Tiled, Out-of-Core Time Series Averaging (Internal)
bio24_terra

bio24_terra: Solar Radiation of Wettest Period
bio06_fast

bio06_fast: Min Temperature of Coldest Unit
bio08_terra

bio08_terra: Mean Temperature of Wettest Period
bio06_terra

bio06_terra: Min Temperature of Coldest Unit
bio24_fast

bio24_fast: Solar Radiation of Wettest Period
bio30_terra

bio30_terra: Lowest Moisture Unit
bio30_fast

bio30_fast: Lowest Moisture Unit
bio02_fast

bio02_fast: Mean Diurnal Range
check_evar

Standardize Environmental Variable Input Format
bio02_terra

bio02_terra: Mean Diurnal Range
bioclim_fast

Tiled, Out-of-Core Bioclimatic Variable Calculation
bio23_fast

bio23_fast: Solar Radiation Seasonality (CV)
calculate_average

Calculate Averages for SpatRasters
derive_statistics

Derive Custom Summary Statistics from Climate Variables
bio14_terra

bio14_terra: Precipitation of Driest Unit
bio18_fast

bio18_fast: Precipitation of Warmest Period
bio18_terra

bio18_terra: Precipitation of Warmest Period
get_window

Windows
bio26_fast

bio26_fast: Solar Radiation of Warmest Period
bio13_terra

bio13_terra: Precipitation of Wettest Unit
bio23_terra

bio23_terra: Solar Radiation Seasonality (CV)
define_translate

Create an Inverse Cell ID Translation Function
bio26_terra

bio26_terra: Solar Radiation of Warmest Period
check_rasters

Validate Climate Input Rasters
derive_bioclim

Derive Comprehensive Bioclimatic Variables
bioclim_terra

In-Memory Bioclimatic Variable Calculation
compute_periods

Calculate Sliding Periods for Temporal Analysis
stats_fast

Tiled, Out-of-Core Custom Variable Summarization
stats_terra

In-Memory Custom Variable Summarization
bio20_terra

bio20_terra: Mean Solar Radiation of Units
bio16_fast

bio16_fast: Precipitation of Wettest Period
bio07_fast

bio07_fast: Temperature Annual Range (bio05 - bio06)
bio15_fast

bio15_fast: Precipitation Seasonality (CV)
bio10_terra

bio10_terra: Mean Temperature of Warmest Period
bio07_terra

bio07_terra: Temperature Annual Range (bio05 - bio06)
bio15_terra

bio15_terra: Precipitation Seasonality (CV)
bio34_fast

bio34_fast: Moisture of Warmest Period
bio21_fast

bio21_fast: Highest Solar Radiation Unit
bio16_terra

bio16_terra: Precipitation of Wettest Period
bio25_terra

bio25_terra: Solar Radiation of Driest Period
bio10_fast

bio10_fast: Mean Temperature of Warmest Period
bio35_fast

bio35_fast: Moisture of Coldest Period
bio27_fast

bio27_fast: Solar Radiation of Coldest Period
bio25_fast

bio25_fast: Solar Radiation of Driest Period
bio35_terra

bio35_terra: Moisture of Coldest Period
roll_terra

In-Memory Rolling Time Series Averaging (Internal)
bio21_terra

bio21_terra: Highest Solar Radiation Unit
roll_fast

Tiled, Out-of-Core Rolling Time Series Averaging (Internal)
bio20_fast

bio20_fast: Mean Solar Radiation of Units
bio27_terra

bio27_terra: Solar Radiation of Coldest Period
write_layers

Export Bioclimatic Variables to GeoTIFF
var_periods

Calculate Temporal Period Aggregates
bio34_terra

bio34_terra: Moisture of Warmest Period
bio32_fast

bio32_fast: Moisture of the Most Moist Period
bio32_terra

bio32_terra: Moisture of the Most Moist Period