Skip to contents

Aggregates ERA5-Land hourly reanalysis data to CHELSA-compatible monthly climate variables. The four output variables (tas, tasmax, tasmin, pr) can be fed directly into bioclim or bioclim_raster to compute bioclimatic variables BIO01–BIO19.

Usage

era5_t2m_to_monthly_r(hourly_t2m, n_days, to_celsius = FALSE)

era5_tp_to_monthly_r(hourly_tp)

era5_to_monthly_r(hourly_t2m, hourly_tp, n_days, to_celsius = FALSE)

era5_t2m_to_monthly(hourly_t2m, n_days, to_celsius = FALSE, ncores = 1L)

era5_tp_to_monthly(hourly_tp, ncores = 1L)

era5_to_monthly(hourly_t2m, hourly_tp, n_days, to_celsius = FALSE, ncores = 1L)

Arguments

hourly_t2m

Numeric matrix (n_pixels × n_hours) of hourly 2-m temperatures (K), or a numeric vector for a single pixel.

n_days

Integer: number of days in the month.

to_celsius

Logical: convert temperatures from Kelvin to Celsius? Default FALSE.

hourly_tp

Numeric matrix (n_pixels × n_hours) of hourly total precipitation (m), or a numeric vector for a single pixel.

ncores

Integer: OpenMP thread count. Default 1L.

Value

Named list: tas, tasmax, tasmin.

Numeric scalar: monthly precipitation in mm (kg m-2).

Named list: tas, tasmax, tasmin, pr.

Named list with tas, tasmax, tasmin — each a numeric vector of length n_pixels.

Numeric vector of length n_pixels: monthly precipitation in kg m-2 (mm).

Named list with tas, tasmax, tasmin, pr — each a numeric vector of length n_pixels (or scalar for single pixel).

Details

Temperature aggregation. ERA5-Land provides instantaneous 2-m temperature (t2m) at hourly resolution in Kelvin. The hourly values are first grouped into calendar days (24 hours each):

  • tas — monthly mean of daily means

  • tasmax — monthly mean of daily maxima

  • tasmin — monthly mean of daily minima

Precipitation aggregation. ERA5-Land provides total precipitation (tp) as hourly accumulations in metres of water equivalent. The hourly values are summed over the month and converted to \(\mathrm{kg\,m^{-2}\,month^{-1}}\) (= mm) by multiplying by 1000.

Unit conventions. By default, temperatures are returned in Kelvin to match the CHELSA convention. Set to_celsius = TRUE to obtain degrees Celsius instead (common for WorldClim-style bioclimatic variables).

Functions

  • era5_t2m_to_monthly_r(): Reference implementation: hourly t2m → monthly temperature statistics. Pure-R, single-pixel.

  • era5_tp_to_monthly_r(): Reference implementation: hourly tp → monthly precipitation. Pure-R, single-pixel.

  • era5_to_monthly_r(): Unified reference implementation: hourly t2m + tp → monthly tas, tasmax, tasmin, pr. Pure-R, single-pixel.

  • era5_t2m_to_monthly(): Convert hourly 2-m temperature to monthly statistics (C++ backend).

  • era5_tp_to_monthly(): Convert hourly total precipitation to monthly total (C++ backend).

  • era5_to_monthly(): Convert ERA5-Land hourly t2m and tp to the four CHELSA-compatible monthly climate variables in a single call.

Examples

# Single pixel: 3 days of hourly data (72 hours) at ~285 K
set.seed(42)
hourly <- 285 + cumsum(rnorm(72, 0, 0.5))
result <- era5_t2m_to_monthly(hourly, n_days = 3L)
result$tas     # monthly mean temperature (K)
#> [1] 285.8759
result$tasmax  # monthly mean of daily maxima (K)
#> [1] 287.924
result$tasmin  # monthly mean of daily minima (K)
#> [1] 284.1525

# Single pixel: 3 days of hourly precipitation (72 hours)
set.seed(42)
hourly_tp <- pmax(0, rnorm(72, 0.0001, 0.00005))
era5_tp_to_monthly(hourly_tp)  # total in mm
#> [1] 7.458102

# Single pixel: 3 days of synthetic hourly data
n_days <- 3L
set.seed(42)
hourly_t2m <- 285 + 5 * sin(2 * pi * (seq(0, 71) - 4) / 24)
hourly_tp  <- pmax(0, rnorm(72, 0.0001, 0.00005))
result <- era5_to_monthly(hourly_t2m, hourly_tp, n_days)
result$tas     # monthly mean temperature (K)
#> [1] 285
result$tasmax  # monthly mean of daily maxima (K)
#> [1] 290
result$tasmin  # monthly mean of daily minima (K)
#> [1] 280
result$pr      # monthly precipitation (mm)
#> [1] 7.458102