End-to-end pipeline that reads ERA5-Land hourly GRIB/NetCDF files, aggregates them to CHELSA-compatible monthly climate variables, and computes the 19 standard bioclimatic variables (BIO01–BIO19).
Usage
era5_bioclim(
t2m_files,
tp_files,
year,
output = tempdir(),
to_celsius = TRUE,
variables = 1:19,
ncores = 1L,
save_monthly = FALSE
)Arguments
- t2m_files
Character vector of 12 file paths to monthly ERA5-Land hourly 2-m temperature files (one per calendar month, January–December). Each file may be GRIB or NetCDF.
- tp_files
Character vector of 12 file paths to monthly ERA5-Land hourly total precipitation files (same order as
t2m_files).- year
Integer: the calendar year (used to determine days per month).
- output
Character path to an output directory for GeoTIFF files. Defaults to a temporary directory.
- to_celsius
Logical: convert temperatures to Celsius? Default
TRUEfor WorldClim-convention bioclimatic variables.- variables
Integer vector of bioclimatic variables to compute (1–19). Default
1:19(all).- ncores
Integer: OpenMP threads for aggregation. Default
1L.- save_monthly
Logical: write intermediate monthly GeoTIFFs? Default
FALSE.
Value
A terra::SpatRaster with one layer per bioclimatic variable.
Details
The pipeline proceeds in three stages:
Monthly aggregation: For each of the 12 calendar months, hourly
t2mis aggregated totas,tasmax, andtasmin; hourlytpis summed topr.Stack: The 12 monthly layers are assembled into
terra::SpatRasterobjects with 12 bands each.Bioclim:
bioclim_rastercomputes BIO01–BIO19.
Examples
if (FALSE) { # \dontrun{
# Paths to ERA5-Land GRIB files on the HPC cluster
t2m_files <- sprintf("era5land_t2m_hourly_2020_%02d.grib", 1:12)
tp_files <- sprintf("era5land_tp_hourly_2020_%02d.grib", 1:12)
bio <- era5_bioclim(t2m_files, tp_files, year = 2020L, ncores = 4L)
terra::plot(bio[[1]]) # BIO01
} # }