Skip to contents

Overview

xbioclim computes the 19 standard bioclimatic variables (BIO01–BIO19) from monthly climate data, following the WorldClim specification. It is an R implementation of the xbioclim C++ library and exposes both a unified function (bioclim()) and individual variable functions (bio01() … bio19()).

Input data format

Every function expects four numeric vectors of length 12, one value per calendar month (January = 1, …, December = 12):

Argument Meaning Units
tas Monthly mean temperature °C
tasmax Monthly maximum temperature °C
tasmin Monthly minimum temperature °C
pr Monthly precipitation mm

Real-world example: Mexico City climate normals

The values below are approximate 1991–2020 climate normals for Mexico City (19.4°N, 99.1°W, ~2240 m a.s.l.) drawn from publicly available records.

# Monthly mean temperature (°C), Jan–Dec
tas    <- c(12.0, 13.3, 15.8, 17.0, 17.5, 16.5,
            15.6, 15.6, 15.2, 14.5, 12.9, 12.0)

# Monthly maximum temperature (°C)
tasmax <- c(21.2, 23.0, 25.7, 26.6, 26.3, 24.4,
            22.8, 22.9, 22.3, 21.7, 20.5, 20.4)

# Monthly minimum temperature (°C)
tasmin <- c( 3.5,  4.5,  6.9,  9.4, 10.8, 11.4,
            10.8, 10.7,  9.9,  8.2,  5.9,  4.1)

# Monthly precipitation (mm)
pr     <- c(10,  7, 11, 21, 52, 132,
           163, 152, 116, 62, 16,   8)

Computing all 19 variables at once

bioclim() returns a named numeric vector of length 19:

result <- bioclim(tas, tasmax, tasmin, pr)
print(result)
#>     bio01     bio02     bio03     bio04     bio05     bio06     bio07     bio08 
#>  14.82500  15.14167  65.54834 180.46814  26.60000   3.50000  23.10000  15.90000 
#>     bio09     bio10     bio11     bio12     bio13     bio14     bio15     bio16 
#>  12.43333  17.00000  12.30000 750.00000 163.00000   7.00000  93.81627 447.00000 
#>     bio17     bio18     bio19 
#>  25.00000 205.00000  34.00000

You can index by name or position:

result[["bio01"]]   # Mean Annual Temperature
#> [1] 14.825
result["bio12"]     # Annual Precipitation
#> bio12 
#>   750
result[c("bio04", "bio15")]  # Both seasonality indices
#>     bio04     bio15 
#> 180.46814  93.81627

Computing individual variables

Each variable has its own function. Use these when you only need one or a few variables to avoid computing the full set.

Temperature variables

bio01(tas)              # BIO01: Mean Annual Temperature
#> [1] 14.825
bio02(tasmax, tasmin)   # BIO02: Mean Diurnal Range
#> [1] 15.14167
bio03(tasmax, tasmin)   # BIO03: Isothermality
#> [1] 65.54834
bio04(tas)              # BIO04: Temperature Seasonality
#> [1] 180.4681
bio05(tasmax)           # BIO05: Max Temperature of Warmest Month
#> [1] 26.6
bio06(tasmin)           # BIO06: Min Temperature of Coldest Month
#> [1] 3.5
bio07(tasmax, tasmin)   # BIO07: Temperature Annual Range
#> [1] 23.1
bio08(tas, pr)          # BIO08: Mean Temp of Wettest Quarter
#> [1] 15.9
bio09(tas, pr)          # BIO09: Mean Temp of Driest Quarter
#> [1] 12.43333
bio10(tas)              # BIO10: Mean Temp of Warmest Quarter
#> [1] 17
bio11(tas)              # BIO11: Mean Temp of Coldest Quarter
#> [1] 12.3

Precipitation variables

bio12(pr)               # BIO12: Annual Precipitation
#> [1] 750
bio13(pr)               # BIO13: Precipitation of Wettest Month
#> [1] 163
bio14(pr)               # BIO14: Precipitation of Driest Month
#> [1] 7
bio15(pr)               # BIO15: Precipitation Seasonality (CV)
#> [1] 93.81627
bio16(pr)               # BIO16: Precipitation of Wettest Quarter
#> [1] 447
bio17(pr)               # BIO17: Precipitation of Driest Quarter
#> [1] 25
bio18(tas, pr)          # BIO18: Precipitation of Warmest Quarter
#> [1] 205
bio19(tas, pr)          # BIO19: Precipitation of Coldest Quarter
#> [1] 34

Multi-pixel (matrix) processing

When you have climate data for many locations, the simplest approach is to store each monthly variable as a matrix with rows = pixels and columns = months, then apply bioclim() (or individual functions) row-wise with apply().

# Simulate data for 5 locations
set.seed(42)
n_pixels <- 5

make_climate <- function(n) {
  tas_base <- runif(n, 5, 20)
  matrix(
    outer(tas_base, sin(seq(0, pi, length.out = 12)) * 10, "+"),
    nrow = n, ncol = 12
  )
}

TAS    <- make_climate(n_pixels)
TASMAX <- TAS + matrix(runif(n_pixels * 12, 3, 8), nrow = n_pixels)
TASMIN <- TAS - matrix(runif(n_pixels * 12, 3, 8), nrow = n_pixels)
PR     <- abs(matrix(rnorm(n_pixels * 12, mean = 50, sd = 30), nrow = n_pixels))

# Debugging: print dimensions
print(dim(TAS))    # Debug step: expect (5, 12)
#> [1]  5 12
print(dim(TASMAX))
#> [1]  5 12
print(dim(TASMIN))
#> [1]  5 12
print(dim(PR))
#> [1]  5 12

# Apply processing
results <- t(
  vapply(seq_len(nrow(TAS)), function(i) {
    bioclim(TAS[i, ], TASMAX[i, ], TASMIN[i, ], PR[i, ])
  }, FUN.VALUE = numeric(19))
)

head(results)
#>         bio01    bio02    bio03    bio04    bio05     bio06    bio07    bio08
#> [1,] 24.51805 12.07961 55.29333 349.8596 35.78489 13.938481 21.84640 21.46334
#> [2,] 24.85209 10.35917 47.07286 349.8596 36.00962 14.002956 22.00667 21.79738
#> [3,] 15.08805 10.54462 44.36886 349.8596 25.91710  2.151301 23.76580 16.64550
#> [4,] 23.25268 12.08505 50.57088 349.8596 34.88794 10.990690 23.89725 27.08763
#> [5,] 20.42214 10.92082 47.74208 349.8596 30.90252  8.027896 22.87463 17.36743
#>         bio09    bio10    bio11    bio12     bio13     bio14    bio15    bio16
#> [1,] 28.35301 28.35301 19.66120 637.6438  79.68062  1.542833 49.01868 232.9230
#> [2,] 27.90681 28.68705 19.99524 597.2454 103.43974  6.832069 64.83082 215.1007
#> [3,] 16.64550 18.92301 10.23120 598.4818  87.23349 18.787355 43.43224 186.4083
#> [4,] 20.19796 27.08763 18.39582 564.6472  82.76632  7.901155 45.36868 207.6379
#> [5,] 23.47686 24.25710 15.56529 522.2079 103.03933  3.594509 70.54080 211.0647
#>          bio17     bio18    bio19
#> [1,]  88.64237 109.58775 195.2510
#> [2,]  99.55772 167.25197 210.3788
#> [3,] 106.06153 128.50025 141.2916
#> [4,]  96.25190 199.66878 132.5545
#> [5,]  65.35681  95.22874 135.1650

Complete variable reference

Variable Description
BIO01 Mean Annual Temperature
BIO02 Mean Diurnal Range (mean of monthly tasmax − tasmin)
BIO03 Isothermality (100 × BIO02 / BIO07)
BIO04 Temperature Seasonality (100 × population SD of monthly tas)
BIO05 Max Temperature of Warmest Month
BIO06 Min Temperature of Coldest Month
BIO07 Temperature Annual Range (BIO05 − BIO06)
BIO08 Mean Temperature of Wettest Quarter
BIO09 Mean Temperature of Driest Quarter
BIO10 Mean Temperature of Warmest Quarter
BIO11 Mean Temperature of Coldest Quarter
BIO12 Annual Precipitation
BIO13 Precipitation of Wettest Month
BIO14 Precipitation of Driest Month
BIO15 Precipitation Seasonality (Coefficient of Variation)
BIO16 Precipitation of Wettest Quarter
BIO17 Precipitation of Driest Quarter
BIO18 Precipitation of Warmest Quarter
BIO19 Precipitation of Coldest Quarter

Input validation

All functions validate their inputs and produce informative error messages:

bio01(1:6)                    # Wrong length
#> Error:
#> ! 'tas' must have length 12 (one value per month), got 6
bio01(letters[1:12])          # Non-numeric
#> Error:
#> ! 'tas' must be numeric
bioclim(1:12, 2:13, 0:11, 1:11)  # pr has length 11
#> Error:
#> ! 'pr' must have length 12 (one value per month), got 11