View source: R/bioclim_raster.R
| bioclim_raster | R Documentation |
Computes the 19 standard bioclimatic variables (BIO01-BIO19) from monthly climate raster data (SpatRaster objects with 12 layers, one per month) using terra's block-loop architecture for memory-efficient processing.
bioclim_raster(
tas,
tasmax,
tasmin,
pr,
filename = "",
n_blocks = NULL,
ncores = 1L,
overwrite = FALSE,
...
)
tas |
SpatRaster with 12 layers: monthly mean temperature. |
tasmax |
SpatRaster with 12 layers: monthly maximum temperature. |
tasmin |
SpatRaster with 12 layers: monthly minimum temperature. |
pr |
SpatRaster with 12 layers: monthly precipitation. |
filename |
Character string: output file path. Pass |
n_blocks |
Integer: target number of row blocks. If |
ncores |
Integer: number of CPU cores for within-block parallel
processing via OpenMP. Default is |
overwrite |
Logical: whether to overwrite an existing output file.
Default is |
... |
Additional arguments passed to |
This function follows terra's block-loop pattern: the input rasters are read
one horizontal block at a time (using terra::readStart(),
terra::readValues(), and terra::readStop()), keeping peak memory use
proportional to the block size rather than the full raster extent. Results
are written to the output raster block by block (using
terra::writeStart(), terra::writeValues(), and terra::writeStop()).
When ncores > 1, pixels within each block are processed in parallel using
OpenMP threads via bioclim_cpp(). Only one block is held in memory at a
time regardless of the number of threads.
A SpatRaster with 19 layers named bio01 through
bio19, sharing the spatial extent, resolution and CRS of tas.
bioclim() for single-pixel (vector) computation.
library(terra)
# Create small test rasters: 4 rows x 3 cols, 12 monthly layers
make_rast <- function(vals) {
r <- rast(nrows = 4, ncols = 3, nlyr = 12)
values(r) <- vals
r
}
n <- 4 * 3 # number of cells
tas <- make_rast(matrix(rep(1:12, each = n), nrow = n, ncol = 12))
tasmax <- make_rast(matrix(rep(2:13, each = n), nrow = n, ncol = 12))
tasmin <- make_rast(matrix(rep(0:11, each = n), nrow = n, ncol = 12))
pr <- make_rast(matrix(rep(1:12, each = n), nrow = n, ncol = 12))
# Compute all 19 bioclimatic variables in a single pass
result <- bioclim_raster(tas, tasmax, tasmin, pr)
nlyr(result) # 19
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.