| Type: | Package |
| Title: | Scalable and Flexible Derivation of Custom-Time Bioclimatic and Environmental Summary Variables |
| Version: | 0.4.1 |
| Maintainer: | Gonzalo E. Pinilla-Buitrago <gepinillab@gmail.com> |
| Description: | Provides an efficient tool for creating custom-time bioclimatic and derived environmental summary variables from user-supplied raster data for user-defined timeframes. The package overcomes computational bottlenecks by automatically switching between an in-memory framework using the 'terra' package to maximize speed for smaller datasets, and an on-disk tiling framework for rasters that exceed available RAM, leveraging 'exactextractr' and 'Rfast' to process data in chunks. The core functions, derive_bioclim() and derive_statistics(), offer a unified interface with flexibility for custom time periods beyond standard quarters and the use of fixed temporal indices, facilitating the creation of temporally-matched environmental variables for ecological and biogeographical modeling. Visit the package website https://gepinillab.github.io/fastbioclim/ to find tutorials in English and Spanish. |
| License: | GPL (≥ 3) |
| URL: | https://gepinillab.github.io/fastbioclim/ |
| BugReports: | https://github.com/gepinillab/fastbioclim/issues |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Depends: | R (≥ 4.1) |
| Imports: | exactextractr, future.apply, glue, progressr, purrr, qs2, Rfast, sf, terra (≥ 1.7-0) |
| Suggests: | mockery, testthat (≥ 3.0.0), withr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-03-09 21:35:32 UTC; Gonzalo |
| Author: | Gonzalo E. Pinilla-Buitrago
|
| Repository: | CRAN |
| Date/Publication: | 2026-03-10 09:40:26 UTC |
Tiled, Out-of-Core Time Series Aggregation (Internal)
Description
Tiled, Out-of-Core Time Series Aggregation (Internal)
Usage
aggregate_fast(
paths,
index,
output_names,
user_region,
tile_degrees,
output_dir,
verbose,
aggregation_type = "mean"
)
In-Memory Time Series Aggregation (Internal)
Description
In-Memory Time Series Aggregation (Internal)
Usage
aggregate_terra(
x,
index,
output_names,
output_dir,
gdal_opt,
overwrite,
verbose,
aggregation_type = "mean"
)
bio01_fast: Mean Temperature
Description
Calculates mean temperature across all temporal units (usually 12 months).
Usage
bio01_fast(tavg, cell)
Arguments
tavg |
A numeric **matrix** where **rows** represent spatial units (cells) and **columns** represent temporal units (e.g., 12 months). |
cell |
A numeric or character **vector** of original cell IDs. Its length must be exactly equal to the number of rows in 'tavg'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio01" (the calculated mean) and "cell" (the IDs).
bio01_terra: Mean Temperature
Description
Calculates mean temperature across all temporal units (layers).
Usage
bio01_terra(tavg)
Arguments
tavg |
A 'SpatRaster' object where each layer represents average temperature for a temporal unit (e.g., 12 months). |
Value
A single-layer 'SpatRaster' with the calculated mean temperature, named "bio01".
bio02_fast: Mean Diurnal Range
Description
Calculates the mean of the diurnal temperature ranges (tmax - tmin) across all temporal units.
Usage
bio02_fast(tmin, tmax, cell)
Arguments
tmin |
A numeric **matrix** of minimum temperatures. **Rows** represent spatial units (cells) and **columns** represent temporal units. Must have the exact same dimensions as 'tmax'. |
tmax |
A numeric **matrix** of maximum temperatures. **Rows** represent spatial units (cells) and **columns** represent temporal units. Must have the exact same dimensions as 'tmin'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tmin' and 'tmax'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio02" (mean diurnal range) and "cell".
bio02_terra: Mean Diurnal Range
Description
Calculates the mean of the diurnal temperature range (tmax - tmin) across all temporal units (layers).
Usage
bio02_terra(tmin, tmax)
Arguments
tmin |
A 'SpatRaster' object of minimum temperatures, where each layer is a temporal unit. Must have the same dimensions and number of layers as 'tmax'. |
tmax |
A 'SpatRaster' object of maximum temperatures, where each layer is a temporal unit. Must have the same dimensions and number of layers as 'tmin'. |
Value
A single-layer 'SpatRaster' with the mean diurnal range, named "bio02".
bio03_fast: Isothermality
Description
Calculates Isothermality representing the ratio of mean diurnal range to temperature range: (bio02 / bio07) * 100.
Usage
bio03_fast(bio02V, bio07V, cell)
Arguments
bio02V |
A numeric **vector** or **single-column matrix** of Bio02 values (Mean Diurnal Range). Length (or number of rows) must match 'bio07V' and 'cell'. |
bio07V |
A numeric **vector** or **single-column matrix** of Bio07 values (Temperature Range). Length (or number of rows) must match 'bio02V' and 'cell'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the length/rows of 'bio02V' and 'bio07V'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio03" and "cell".
bio03_terra: Isothermality
Description
Calculates Isothermality, defined as (bio02 / bio07) * 100.
Usage
bio03_terra(bio02, bio07)
Arguments
bio02 |
A single-layer 'SpatRaster' of Mean Diurnal Range (Bio02). |
bio07 |
A single-layer 'SpatRaster' of Temperature Range (Bio07). |
Value
A single-layer 'SpatRaster' with the calculated isothermality, named "bio03".
bio04_fast: Temperature Seasonality (Std Dev * 100)
Description
Calculates Temperature Seasonality, defined as the standard deviation of average temperatures across all temporal units (e.g., 12 months), multiplied by 100.
Usage
bio04_fast(tavg, cell)
Arguments
tavg |
A numeric **matrix** of average temperatures. **Rows** represent spatial units (cells) and **columns** represent temporal units. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tavg'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio04" (seasonality) and "cell".
bio04_terra: Temperature Seasonality (Std Dev * 100)
Description
Calculates the standard deviation of average temperatures across all layers, multiplied by 100.
Usage
bio04_terra(tavg)
Arguments
tavg |
A 'SpatRaster' object where each layer represents average temperature for a temporal unit. |
Value
A single-layer 'SpatRaster' with the temperature seasonality, named "bio04".
bio05_fast: Max Temperature of Warmest Unit
Description
Identifies the maximum temperature of the warmest temporal unit. If 'index_vector' is 'NULL', it calculates the row-wise maximum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio05_fast(tmax, cell, index_vector = NULL)
Arguments
tmax |
A numeric **matrix** of maximum temperatures. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tmax'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'tmax'. Values must be between 1 and 'ncol(tmax)'. This is typically used to extract the Tmax of the specific month identified as the warmest by another metric. |
Details
This function calculates bio05 following the standard definition used by WorldClim (Hijmans et al., 2005) and ANUCLIM 6.1 (Xu & Hutchinson, 2013), which is the single highest value from all maximum temperature layers (a "max of maxes"). It does not use mean temperature to first identify the warmest month.
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio05" (the maximum temperature) and "cell".
References
Hijmans, R.J., Cameron, S.E., Parra, J.L., Jones, P.G. and Jarvis, A. (2005). Very high resolution interpolated climate surfaces for global land areas. International Journal of Climatology, 25(15), 1965-1978.
O'Donnell, M. S., & Ignizio, D. A. (2012). Bioclimatic predictors for supporting ecological applications in the conterminous United States. U.S. Geological Survey Data Series 691.
Xu, T., & Hutchinson, M. F. (2013). New developments and applications in the ANUCLIM spatial climatic and bioclimatic modelling package. Environmental Modelling & Software, 40, 267-279.
bio05_terra: Max Temperature of Warmest Unit
Description
Identifies the maximum temperature of the warmest temporal unit (layer).
Usage
bio05_terra(tmax, warmest_unit = NULL)
Arguments
tmax |
A 'SpatRaster' object of maximum temperatures, where each layer is a temporal unit. |
warmest_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based) from which to extract the value. If 'NULL' (the default), the overall maximum across all layers is calculated. |
Details
This function calculates bio05 following the standard definition used by WorldClim (Hijmans et al., 2005) and ANUCLIM 6.1 (Xu & Hutchinson, 2013), which is the single highest value from all maximum temperature layers (a "max of maxes"). It does not use mean temperature to first identify the warmest month.
Value
A single-layer 'SpatRaster' with the maximum temperature, named "bio05".
References
Hijmans, R.J., Cameron, S.E., Parra, J.L., Jones, P.G. and Jarvis, A. (2005). Very high resolution interpolated climate surfaces for global land areas. International Journal of Climatology, 25(15), 1965-1978.
O'Donnell, M. S., & Ignizio, D. A. (2012). Bioclimatic predictors for supporting ecological applications in the conterminous United States. U.S. Geological Survey Data Series 691.
Xu, T., & Hutchinson, M. F. (2013). New developments and applications in the ANUCLIM spatial climatic and bioclimatic modelling package. Environmental Modelling & Software, 40, 267-279.
bio06_fast: Min Temperature of Coldest Unit
Description
Identifies the minimum temperature of the coldest temporal unit. If 'index_vector' is 'NULL', it calculates the row-wise minimum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio06_fast(tmin, cell, index_vector = NULL)
Arguments
tmin |
A numeric **matrix** of minimum temperatures. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tmin'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'tmin'. Values must be between 1 and 'ncol(tmin)'. This is typically used to extract the Tmin of the specific month identified as the coldest by another metric. |
Details
This function calculates bio06 following the standard definition used by WorldClim (Hijmans et al., 2005) and ANUCLIM 6.1 (Xu & Hutchinson, 2013), which is the single lowest value from all minimum temperature layers (a "min of mins"). It does not use mean temperature to first identify the coldest month.
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio06" (the minimum temperature) and "cell".
References
Hijmans, R.J., Cameron, S.E., Parra, J.L., Jones, P.G. and Jarvis, A. (2005). Very high resolution interpolated climate surfaces for global land areas. International Journal of Climatology, 25(15), 1965-1978.
O'Donnell, M. S., & Ignizio, D. A. (2012). Bioclimatic predictors for supporting ecological applications in the conterminous United States. U.S. Geological Survey Data Series 691.
Xu, T., & Hutchinson, M. F. (2013). New developments and applications in the ANUCLIM spatial climatic and bioclimatic modelling package. Environmental Modelling & Software, 40, 267-279.
bio06_terra: Min Temperature of Coldest Unit
Description
Identifies the minimum temperature of the coldest temporal unit (layer).
Usage
bio06_terra(tmin, coldest_unit = NULL)
Arguments
tmin |
A 'SpatRaster' object of minimum temperatures, where each layer is a temporal unit. |
coldest_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based) from which to extract the value. If 'NULL' (the default), the overall minimum across all layers is calculated. |
Details
This function calculates bio06 following the standard definition used by WorldClim (Hijmans et al., 2005; O'Donnell & Ignizio, 2012) and ANUCLIM 6.1 (Xu & Hutchinson, 2013), which is the single lowest value from all minimum temperature layers (a "min of mins"). It does not use mean temperature to first identify the coldest month.
Value
A single-layer 'SpatRaster' with the minimum temperature, named "bio06".
References
Hijmans, R.J., Cameron, S.E., Parra, J.L., Jones, P.G. and Jarvis, A. (2005). Very high resolution interpolated climate surfaces for global land areas. International Journal of Climatology, 25(15), 1965-1978.
O'Donnell, M. S., & Ignizio, D. A. (2012). Bioclimatic predictors for supporting ecological applications in the conterminous United States. U.S. Geological Survey Data Series 691.
Xu, T., & Hutchinson, M. F. (2013). New developments and applications in the ANUCLIM spatial climatic and bioclimatic modelling package. Environmental Modelling & Software, 40, 267-279.
bio07_fast: Temperature Range (bio05 - bio06)
Description
Calculates the Temperature Range, defined as the difference between the Maximum Temperature of the Warmest Unit (bio05) and the Minimum Temperature of the Coldest Unit (bio06).
Usage
bio07_fast(bio05V, bio06V, cell)
Arguments
bio05V |
A numeric **vector** or **single-column matrix** of Bio05 values. Length (or number of rows) must match 'bio06V' and 'cell'. |
bio06V |
A numeric **vector** or **single-column matrix** of Bio06 values. Length (or number of rows) must match 'bio05V' and 'cell'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the length/rows of 'bio05V' and 'bio06V'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio07" (annual range) and "cell".
bio07_terra: Temperature Range (bio05 - bio06)
Description
Calculates the difference between the Maximum Temperature of the Warmest Unit (bio05) and the Minimum Temperature of the Coldest Unit (bio06).
Usage
bio07_terra(bio05, bio06)
Arguments
bio05 |
A single-layer 'SpatRaster' of Bio05 values. |
bio06 |
A single-layer 'SpatRaster' of Bio06 values. |
Value
A single-layer 'SpatRaster' with the temperature annual range, named "bio07".
bio08_fast: Mean Temperature of Wettest Period
Description
Calculates the mean temperature of the specific rolling period identified as the wettest (highest precipitation).
Usage
bio08_fast(tperiod, pperiod_max_idx, period_length, cell)
Arguments
tperiod |
A numeric **matrix** of temperature values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods (typically 12). |
pperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the wettest period for each row. Its length must be exactly equal to the number of rows in 'tperiod'. |
period_length |
A single **integer** representing the number of units per period (e.g., 3 for months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio08" (mean temperature of wettest period) and "cell".
bio08_terra: Mean Temperature of Wettest Period
Description
Calculates the mean temperature of the specific rolling period identified as the wettest.
Usage
bio08_terra(tmp, wettest_period)
Arguments
tmp |
A 'SpatRaster' object where each layer represents the mean temperature for a rolling period. |
wettest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the wettest period. |
Value
A single-layer 'SpatRaster' containing the mean temperature of the wettest period, named "bio08".
bio09_fast: Mean Temperature of Driest Period
Description
Calculates the mean temperature of the specific rolling period identified as the driest (lowest precipitation).
Usage
bio09_fast(tperiod, pperiod_min_idx, period_length, cell)
Arguments
tperiod |
A numeric **matrix** of temperature values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
pperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the driest period for each row. Its length must be exactly equal to the number of rows in 'tperiod'. |
period_length |
A single **integer** representing the number of units per period. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio09" (mean temperature of driest period) and "cell".
bio09_terra: Mean Temperature of Driest Period
Description
Calculates the mean temperature of the specific rolling period identified as the driest.
Usage
bio09_terra(tmp, driest_period)
Arguments
tmp |
A 'SpatRaster' object where each layer represents the mean temperature for a rolling period. |
driest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the driest period. |
Value
A single-layer 'SpatRaster' containing the mean temperature of the driest period, named "bio09".
bio10_fast: Mean Temperature of Warmest Period
Description
Calculates the mean temperature of the specific rolling period identified as the warmest (highest temperature).
Usage
bio10_fast(tperiod, tperiod_max_idx, period_length, cell)
Arguments
tperiod |
A numeric **matrix** of temperature values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the warmest period for each row. Its length must be exactly equal to the number of rows in 'tperiod'. |
period_length |
A single **integer** representing the number of units per period. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio10" (mean temperature of warmest period) and "cell".
bio10_terra: Mean Temperature of Warmest Period
Description
Calculates the mean temperature of the specific rolling period identified as the warmest.
Usage
bio10_terra(tmp, warmest_period)
Arguments
tmp |
A 'SpatRaster' object where each layer represents the mean temperature for a rolling period. |
warmest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the warmest period. |
Value
A single-layer 'SpatRaster' containing the mean temperature of the warmest period, named "bio10".
bio11_fast: Mean Temperature of Coldest Period
Description
Calculates the mean temperature of the specific rolling period identified as the coldest (lowest temperature).
Usage
bio11_fast(tperiod, tperiod_min_idx, period_length, cell)
Arguments
tperiod |
A numeric **matrix** of temperature values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the coldest period for each row. Its length must be exactly equal to the number of rows in 'tperiod'. |
period_length |
A single **integer** representing the number of units per period. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'tperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio11" (mean temperature of coldest period) and "cell".
bio11_terra: Mean Temperature of Coldest Period
Description
Calculates the mean temperature of the specific rolling period identified as the coldest.
Usage
bio11_terra(tmp, coldest_period)
Arguments
tmp |
A 'SpatRaster' object where each layer represents the mean temperature for a rolling period. |
coldest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the coldest period. |
Value
A single-layer 'SpatRaster' containing the mean temperature of the coldest period, named "bio11".
bio12_fast: Total Precipitation
Description
Calculates the total precipitation (sum) across all temporal units (e.g., 12 months).
Usage
bio12_fast(prcp, cell)
Arguments
prcp |
A numeric **matrix** of precipitation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'prcp'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio12" (total precipitation) and "cell".
bio12_terra: Total Precipitation
Description
Calculates the total precipitation (sum) across all temporal units (layers).
Usage
bio12_terra(prcp)
Arguments
prcp |
A 'SpatRaster' object where each layer represents precipitation for a temporal unit. |
Value
A single-layer 'SpatRaster' with the total precipitation, named "bio12".
bio13_fast: Precipitation of Wettest Unit
Description
Identifies the precipitation of the wettest temporal unit (e.g., month). If 'index_vector' is 'NULL', it calculates the row-wise maximum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio13_fast(prcp, cell, index_vector = NULL)
Arguments
prcp |
A numeric **matrix** of precipitation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'prcp'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'prcp'. Values must be between 1 and 'ncol(prcp)'. This is typically used to extract the precipitation of the specific month identified as the wettest by another metric. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio13" (precipitation of wettest unit) and "cell".
bio13_terra: Precipitation of Wettest Unit
Description
Identifies the precipitation of the wettest temporal unit (layer).
Usage
bio13_terra(prcp, wettest_unit = NULL)
Arguments
prcp |
A 'SpatRaster' object where each layer represents precipitation for a temporal unit. |
wettest_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based) from which to extract the value. If 'NULL' (the default), the overall maximum across all layers is calculated. |
Value
A single-layer 'SpatRaster' with the precipitation of the wettest unit, named "bio13".
bio14_fast: Precipitation of Driest Unit
Description
Identifies the precipitation of the driest temporal unit (e.g., month). If 'index_vector' is 'NULL', it calculates the row-wise minimum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio14_fast(prcp, cell, index_vector = NULL)
Arguments
prcp |
A numeric **matrix** of precipitation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'prcp'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'prcp'. Values must be between 1 and 'ncol(prcp)'. This is typically used to extract the precipitation of the specific month identified as the driest by another metric. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio14" (precipitation of driest unit) and "cell".
bio14_terra: Precipitation of Driest Unit
Description
Identifies the precipitation of the driest temporal unit (layer).
Usage
bio14_terra(prcp, driest_unit = NULL)
Arguments
prcp |
A 'SpatRaster' object where each layer represents precipitation for a temporal unit. |
driest_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based) from which to extract the value. If 'NULL' (the default), the overall minimum across all layers is calculated. |
Value
A single-layer 'SpatRaster' with the precipitation of the driest unit, named "bio14".
bio15_fast: Precipitation Seasonality (CV)
Description
Calculates the Coefficient of Variation (CV) of precipitation. The formula used is: '(StandardDeviation / (Mean + 1)) * 100'. (The "+1" is added to the mean to avoid division by zero in completely arid areas).
Usage
bio15_fast(prcp, bio12V, n_units, cell)
Arguments
prcp |
A numeric **matrix** of precipitation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., 12 months). |
bio12V |
A numeric **vector** or **single-column matrix** of Total Annual Precipitation (Bio12). Its length (or number of rows) must be exactly equal to the number of rows in 'prcp'. |
n_units |
A single **integer** representing the number of temporal units (e.g., 12). This is used to calculate the mean precipitation from the total 'bio12V'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'prcp'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio15" (Precipitation Seasonality) and "cell".
bio15_terra: Precipitation Seasonality (CV)
Description
Calculates the Coefficient of Variation (CV) of precipitation across all layers.
Usage
bio15_terra(prcp)
Arguments
prcp |
A 'SpatRaster' object where each layer represents precipitation for a temporal unit. |
Value
A single-layer 'SpatRaster' with the precipitation seasonality, named "bio15".
Note
The formula adds 1 to the mean to avoid division by zero in arid areas.
bio16_fast: Precipitation of Wettest Period
Description
Calculates the total precipitation of the specific rolling period identified as the wettest (highest precipitation).
Usage
bio16_fast(pperiod, pperiod_max_idx, cell)
Arguments
pperiod |
A numeric **matrix** of precipitation sums for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
pperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the wettest period for each row. Its length must be exactly equal to the number of rows in 'pperiod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'pperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio16" (precipitation of wettest period) and "cell".
bio16_terra: Precipitation of Wettest Period
Description
Calculates the total precipitation of the specific rolling period identified as the wettest.
Usage
bio16_terra(wet, wettest_period)
Arguments
wet |
A 'SpatRaster' object where each layer is the precipitation sum for a rolling period. |
wettest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the wettest period. |
Value
A single-layer 'SpatRaster' with the precipitation of the wettest period, named "bio16".
bio17_fast: Precipitation of Driest Period
Description
Calculates the total precipitation of the specific rolling period identified as the driest (lowest precipitation).
Usage
bio17_fast(pperiod, pperiod_min_idx, cell)
Arguments
pperiod |
A numeric **matrix** of precipitation sums for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
pperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the driest period for each row. Its length must be exactly equal to the number of rows in 'pperiod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'pperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio17" (precipitation of driest period) and "cell".
bio17_terra: Precipitation of Driest Period
Description
Calculates the total precipitation of the specific rolling period identified as the driest.
Usage
bio17_terra(wet, driest_period)
Arguments
wet |
A 'SpatRaster' object where each layer is the precipitation sum for a rolling period. |
driest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the driest period. |
Value
A single-layer 'SpatRaster' with the precipitation of the driest period, named "bio17".
bio18_fast: Precipitation of Warmest Period
Description
Calculates the total precipitation of the specific rolling period identified as the warmest (highest temperature).
Usage
bio18_fast(pperiod, tperiod_max_idx, cell)
Arguments
pperiod |
A numeric **matrix** of precipitation sums for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the warmest period for each row. Its length must be exactly equal to the number of rows in 'pperiod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'pperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio18" (precipitation of warmest period) and "cell".
bio18_terra: Precipitation of Warmest Period
Description
Calculates the total precipitation of the specific rolling period identified as the warmest.
Usage
bio18_terra(wet, warmest_period)
Arguments
wet |
A 'SpatRaster' object where each layer is the precipitation sum for a rolling period. |
warmest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the warmest period. |
Value
A single-layer 'SpatRaster' with the precipitation of the warmest period, named "bio18".
bio19_fast: Precipitation of Coldest Period
Description
Calculates the total precipitation of the specific rolling period identified as the coldest (lowest temperature).
Usage
bio19_fast(pperiod, tperiod_min_idx, cell)
Arguments
pperiod |
A numeric **matrix** of precipitation sums for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the coldest period for each row. Its length must be exactly equal to the number of rows in 'pperiod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'pperiod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio19" (precipitation of coldest period) and "cell".
bio19_terra: Precipitation of Coldest Period
Description
Calculates the total precipitation of the specific rolling period identified as the coldest.
Usage
bio19_terra(wet, coldest_period)
Arguments
wet |
A 'SpatRaster' object where each layer is the precipitation sum for a rolling period. |
coldest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the coldest period. |
Value
A single-layer 'SpatRaster' with the precipitation of the coldest period, named "bio19".
bio20_fast: Mean Radiation
Description
Calculates mean solar radiation across all temporal units (usually 12 months).
Usage
bio20_fast(srad, cell)
Arguments
srad |
A numeric **matrix** where **rows** represent spatial units (cells) and **columns** represent temporal units (e.g., 12 months). |
cell |
A numeric or character **vector** of original cell IDs. Its length must be exactly equal to the number of rows in 'srad'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio20" (the calculated mean) and "cell" (the IDs).
bio20_terra: Mean Radiation
Description
Calculates mean solar radiation across all temporal units (layers).
Usage
bio20_terra(srad)
Arguments
srad |
A 'SpatRaster' object where each layer represents solar radiation for a temporal unit. |
Value
A single-layer 'SpatRaster' with the mean solar radiation, named "bio20".
#' @title bio21_fast: Highest Radiation Unit
Description
Identifies the highest solar radiation of the temporal unit with the highest value. If 'index_vector' is 'NULL', it calculates the row-wise maximum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio21_fast(srad, cell, index_vector = NULL)
Arguments
srad |
A numeric **matrix** of solar radiation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'srad'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'srad'. Values must be between 1 and 'ncol(srad)'. This is typically used to extract the solar radiation of a specific unit identified by another metric. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio21" (the maximum solar radiation) and "cell".
bio21_terra: Highest Moisture Unit
Description
Identifies the highest solar radiation of the unit with the highest value.
Usage
bio21_terra(srad, high_rad_unit = NULL)
Arguments
srad |
A 'SpatRaster' object where each layer represents solar radiation for a temporal unit. |
high_rad_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based). If 'NULL', the overall maximum across all layers is calculated. |
Value
A single-layer 'SpatRaster' with the maximum solar radiation, named "bio21".
bio22_fast: Lowest Radiation Unit
Description
Identifies the lowest solar radiation of the temporal unit with the lowest value. If 'index_vector' is 'NULL', it calculates the row-wise minimum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio22_fast(srad, cell, index_vector = NULL)
Arguments
srad |
A numeric **matrix** of solar radiation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'srad'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'srad'. Values must be between 1 and 'ncol(srad)'. This is typically used to extract the solar radiation of a specific unit identified by another metric. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio22" (the minimum solar radiation) and "cell".
bio22_terra: Lowest Radiation Unit
Description
Identifies the lowest solar radiation of the unit with the lowest value.
Usage
bio22_terra(srad, low_rad_unit = NULL)
Arguments
srad |
A 'SpatRaster' object where each layer represents solar radiation for a temporal unit. |
low_rad_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based). If 'NULL', the overall minimum across all layers is calculated. |
Value
A single-layer 'SpatRaster' with the minimum solar radiation, named "bio22".
bio23_fast: Radiation Seasonality (CV)
Description
Calculates the Coefficient of Variation (CV) of solar radiation. The formula used is: '(StandardDeviation / (Mean + 1)) * 100'. (The "+1" is added to the mean to avoid division by zero).
Usage
bio23_fast(srad, n_units, cell)
Arguments
srad |
A numeric **matrix** of solar radiation values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., 12 months). |
n_units |
A single **integer** representing the number of temporal units (e.g., 12). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'srad'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio23" (Solar Radiation Seasonality) and "cell".
bio23_terra: Radiation Seasonality (CV)
Description
Calculates the Coefficient of Variation (CV) of solar radiation across all layers.
Usage
bio23_terra(srad)
Arguments
srad |
A 'SpatRaster' object where each layer represents solar radiation for a temporal unit. |
Value
A single-layer 'SpatRaster' with the solar radiation seasonality, named "bio23".
bio24_fast: Radiation of Wettest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the wettest (highest precipitation).
Usage
bio24_fast(speriod, pperiod_max_idx, cell)
Arguments
speriod |
A numeric **matrix** of solar radiation values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
pperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the wettest period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio24" (mean solar radiation of wettest period) and "cell".
bio24_terra: Radiation of Wettest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the wettest.
Usage
bio24_terra(prad, wettest_period)
Arguments
prad |
A 'SpatRaster' object where each layer is the mean solar radiation for a rolling period. |
wettest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the wettest period. |
Value
A single-layer 'SpatRaster' with the solar radiation of the wettest period, named "bio24".
bio25_fast: Radiation of Driest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the driest (lowest precipitation).
Usage
bio25_fast(speriod, pperiod_min_idx, cell)
Arguments
speriod |
A numeric **matrix** of solar radiation values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
pperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the driest period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio25" (mean solar radiation of driest period) and "cell".
bio25_terra: Radiation of Driest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the driest.
Usage
bio25_terra(prad, driest_period)
Arguments
prad |
A 'SpatRaster' object where each layer is the mean solar radiation for a rolling period. |
driest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the driest period. |
Value
A single-layer 'SpatRaster' with the solar radiation of the driest period, named "bio25".
bio26_fast: Radiation of Warmest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the warmest (highest temperature).
Usage
bio26_fast(speriod, tperiod_max_idx, cell)
Arguments
speriod |
A numeric **matrix** of solar radiation values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the warmest period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio26" (mean solar radiation of warmest period) and "cell".
bio26_terra: Radiation of Warmest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the warmest.
Usage
bio26_terra(prad, warmest_period)
Arguments
prad |
A 'SpatRaster' object where each layer is the mean solar radiation for a rolling period. |
warmest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the warmest period. |
Value
A single-layer 'SpatRaster' with the solar radiation of the warmest period, named "bio26".
bio27_fast: Radiation of Coldest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the coldest (lowest temperature).
Usage
bio27_fast(speriod, tperiod_min_idx, cell)
Arguments
speriod |
A numeric **matrix** of solar radiation values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the coldest period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio27" (mean solar radiation of coldest period) and "cell".
bio27_terra: Radiation of Coldest Period
Description
Calculates the mean solar radiation of the specific rolling period identified as the coldest.
Usage
bio27_terra(prad, coldest_period)
Arguments
prad |
A 'SpatRaster' object where each layer is the mean solar radiation for a rolling period. |
coldest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the coldest period. |
Value
A single-layer 'SpatRaster' with the solar radiation of the coldest period, named "bio27".
bio28_fast: Mean Moisture
Description
Calculates mean moisture across all temporal units (usually 12 months).
Usage
bio28_fast(mois, cell)
Arguments
mois |
A numeric **matrix** where **rows** represent spatial units (cells) and **columns** represent temporal units (e.g., 12 months). |
cell |
A numeric or character **vector** of original cell IDs. Its length must be exactly equal to the number of rows in 'mois'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio28" (the calculated mean) and "cell" (the IDs).
bio28_terra: Mean Moisture
Description
Calculates mean moisture across all temporal units (layers).
Usage
bio28_terra(mois)
Arguments
mois |
A 'SpatRaster' object where each layer represents moisture for a temporal unit. |
Value
A single-layer 'SpatRaster' with the mean moisture, named "bio28".
bio29_fast: Highest Moisture Unit
Description
Identifies the highest moisture of the temporal unit with the highest value. If 'index_vector' is 'NULL', it calculates the row-wise maximum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio29_fast(mois, cell, index_vector = NULL)
Arguments
mois |
A numeric **matrix** of moisture values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'mois'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'mois'. Values must be between 1 and 'ncol(mois)'. This is typically used to extract the moisture of a specific unit identified by another metric. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio29" (the maximum moisture) and "cell".
bio29_terra: Highest Moisture Unit
Description
Identifies the highest moisture of the unit with the highest value.
Usage
bio29_terra(mois, high_mois_unit = NULL)
Arguments
mois |
A 'SpatRaster' object where each layer represents moisture for a temporal unit. |
high_mois_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based). If 'NULL', the overall maximum across all layers is calculated. |
Value
A single-layer 'SpatRaster' with the maximum moisture, named "bio29".
bio30_fast: Lowest Moisture Unit
Description
Identifies the lowest moisture of the temporal unit with the lowest value. If 'index_vector' is 'NULL', it calculates the row-wise minimum. If 'index_vector' is provided, it extracts the value from the specific column index for each row.
Usage
bio30_fast(mois, cell, index_vector = NULL)
Arguments
mois |
A numeric **matrix** of moisture values. **Rows** represent spatial units (cells) and **columns** represent temporal units (e.g., months). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'mois'. |
index_vector |
(Optional) An integer **vector** of column indices (1-based). If provided, its length must be exactly equal to the number of rows in 'mois'. Values must be between 1 and 'ncol(mois)'. This is typically used to extract the moisture of a specific unit identified by another metric. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio30" (the minimum moisture) and "cell".
bio30_terra: Lowest Moisture Unit
Description
Identifies the lowest moisture of the unit with the lowest value.
Usage
bio30_terra(mois, low_mois_unit = NULL)
Arguments
mois |
A 'SpatRaster' object where each layer represents moisture for a temporal unit. |
low_mois_unit |
(Optional) A single-layer 'SpatRaster' where cell values are integers indicating a static layer index (1-based). If 'NULL', the overall minimum across all layers is calculated. |
Value
A single-layer 'SpatRaster' with the minimum moisture, named "bio30".
bio31_fast: Moisture Seasonality (Std Dev * 100)
Description
Calculates Moisture Seasonality, defined as the standard deviation of moisture values across all temporal units (e.g., 12 months), multiplied by 100.
Usage
bio31_fast(mois, n_units, cell)
Arguments
mois |
A numeric **matrix** containing moisture values. **Rows** represent spatial units (cells) and **columns** represent temporal units. |
n_units |
A single **integer** representing the number of temporal units (e.g., 12). |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'mois'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio31" (Moisture Seasonality) and "cell".
bio31_terra: Moisture Seasonality (Std Dev * 100)
Description
Calculates the standard deviation of moisture across all layers, multiplied by 100.
Usage
bio31_terra(mois)
Arguments
mois |
A 'SpatRaster' object where each layer represents moisture for a temporal unit. |
Value
A single-layer 'SpatRaster' with the moisture seasonality, named "bio31".
bio32_fast: Mean Moisture of Most Moist Period
Description
Calculates the mean moisture of the specific rolling period identified as the most moist (highest moisture).
Usage
bio32_fast(speriod, speriod_max_idx, cell)
Arguments
speriod |
A numeric **matrix** of moisture values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
speriod_max_idx |
An integer **vector** indicating the column index (1-based) of the most moist period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio32" (mean moisture of most moist period) and "cell".
bio32_terra: Mean Moisture of Most Moist Period
Description
Calculates the mean moisture of the specific rolling period identified as the most moist.
Usage
bio32_terra(pmois, high_mois_period)
Arguments
pmois |
A 'SpatRaster' object where each layer is the mean moisture for a rolling period. |
high_mois_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the most moist period. |
Value
A single-layer 'SpatRaster' with the moisture of the most moist period, named "bio32".
bio33_fast: Mean Moisture of Least Moist Period
Description
Calculates the mean moisture of the specific rolling period identified as the least moist (lowest moisture).
Usage
bio33_fast(speriod, speriod_min_idx, cell)
Arguments
speriod |
A numeric **matrix** of moisture values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
speriod_min_idx |
An integer **vector** indicating the column index (1-based) of the least moist period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio33" (mean moisture of least moist period) and "cell".
bio33_terra: Mean Moisture of Least Moist Period
Description
Calculates the mean moisture of the specific rolling period identified as the least moist.
Usage
bio33_terra(pmois, low_mois_period)
Arguments
pmois |
A 'SpatRaster' object where each layer is the mean moisture for a rolling period. |
low_mois_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the least moist period. |
Value
A single-layer 'SpatRaster' with the moisture of the least moist period, named "bio33".
bio34_fast: Mean Moisture of Warmest Period
Description
Calculates the mean moisture of the specific rolling period identified as the warmest (highest temperature).
Usage
bio34_fast(speriod, tperiod_max_idx, cell)
Arguments
speriod |
A numeric **matrix** of moisture values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_max_idx |
An integer **vector** indicating the column index (1-based) of the warmest period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio34" (mean moisture of warmest period) and "cell".
bio34_terra: Mean Moisture of Warmest Period
Description
Calculates the mean moisture of the specific rolling period identified as the warmest.
Usage
bio34_terra(pmois, warmest_period)
Arguments
pmois |
A 'SpatRaster' object where each layer is the mean moisture for a rolling period. |
warmest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the warmest period. |
Value
A single-layer 'SpatRaster' with the moisture of the warmest period, named "bio34".
bio35_fast: Mean Moisture of Coldest Period
Description
Calculates the mean moisture of the specific rolling period identified as the coldest (lowest temperature).
Usage
bio35_fast(speriod, tperiod_min_idx, cell)
Arguments
speriod |
A numeric **matrix** of moisture values (means) for each rolling period. **Rows** represent spatial units (cells). **Columns** represent the rolling periods. |
tperiod_min_idx |
An integer **vector** indicating the column index (1-based) of the coldest period for each row. Its length must be exactly equal to the number of rows in 'speriod'. |
cell |
A vector of original cell IDs. Its length must be exactly equal to the number of rows in 'speriod'. |
Value
A **matrix** with dimensions 'c(N, 2)', where N is the number of input cells. The columns are named "bio35" (mean moisture of coldest period) and "cell".
bio35_terra: Mean Moisture of Coldest Period
Description
Calculates the mean moisture of the specific rolling period identified as the coldest.
Usage
bio35_terra(pmois, coldest_period)
Arguments
pmois |
A 'SpatRaster' object where each layer is the mean moisture for a rolling period. |
coldest_period |
A single-layer 'SpatRaster' where cell values are integers indicating the layer index (1-based) of the coldest period. |
Value
A single-layer 'SpatRaster' with the moisture of the coldest period, named "bio35".
Tiled, Out-of-Core Bioclimatic Variable Calculation
Description
Internal function to calculate bioclimatic variables for very large datasets by processing them in tiles. It reads data from file paths using 'exactextractr' and performs calculations with 'Rfast'.
Usage
bioclim_fast(
bios,
n_units,
tmin_path = NULL,
tmax_path = NULL,
prcp_path = NULL,
tavg_path = NULL,
srad_path = NULL,
mois_path = NULL,
period_length = 3,
circular = TRUE,
user_region = NULL,
tile_degrees = 5,
output_dir = tempdir(),
verbose = TRUE,
...
)
Arguments
bios |
Numeric vector of variables to compute. |
n_units |
Integer, number of layers per variable. |
period_length |
Integer, length of a calculation period. |
circular |
Logical, whether to wrap periods. |
user_region |
(Optional) An 'sf' or 'terra::SpatVector' object. If provided, the input raster 'x' is clipped and masked to this region before processing. The output raster's extent is the same of the 'user_region'. |
tile_degrees |
Numeric, size of processing tiles. |
output_dir |
Character, path for temporary files. |
verbose |
Logical, If 'TRUE', prints messages. |
... |
File paths for climate variables (e.g., 'tmin_path') and static indices (e.g., 'warmest_period_path'). |
Value
Character string: Path to the temporary directory containing intermediate '.qs2' files, to be used by an assembly function.
See Also
The user-facing wrapper function 'derive_bioclim()'.
In-Memory Bioclimatic Variable Calculation
Description
Internal function to calculate bioclimatic variables using 'terra' functions. It is designed for datasets that can fit into RAM.
Usage
bioclim_terra(
bios,
tmin = NULL,
tmax = NULL,
tavg = NULL,
prcp = NULL,
srad = NULL,
mois = NULL,
period_length = 3,
circular = TRUE,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
output_dir = tempdir(),
verbose = TRUE,
...
)
Arguments
bios |
Numeric vector of variables to compute. |
period_length |
Integer, length of a calculation period. |
circular |
Logical, whether to wrap periods. |
gdal_opt |
Character vector of GDAL options for writing. |
overwrite |
Logical, whether to overwrite existing files. |
output_dir |
Character, path to save final rasters. |
verbose |
Logical, If 'TRUE', prints messages. |
... |
'SpatRaster' objects for climate variables (e.g., 'tmin', 'tmax') and static indices (e.g., 'warmest_period'). |
Value
A 'terra::SpatRaster' object pointing to the newly created files.
See Also
The user-facing wrapper function 'derive_bioclim()'.
Print Bioclimatic Variable Names
Description
This function prints the names of bioclimatic variables based on the specified indices.
Usage
bionames(bios = 1:35)
Arguments
bios |
Numeric vector indicating the indices of bioclimatic variables to print. Default is 1:35, which prints all variable names. |
Value
None. Prints the names of the selected bioclimatic variables to the console.
Examples
bionames() # Print all bioclimatic variable names
bionames(c(1, 5, 12)) # Print names for variables 1, 5, and 12
Calculate Averages for SpatRasters
Description
Calculates temporal averages for a multi-layer SpatRaster. This function serves as a smart wrapper, automatically selecting between an in-memory ('terra') or out-of-core ('tiled') workflow based on data size.
Usage
calculate_average(
x,
index,
output_names = NULL,
output_dir = tempdir(),
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE
)
Arguments
x |
A 'terra::SpatRaster' object with multiple layers representing a time series. |
index |
A numeric or integer vector defining the grouping for aggregation. Its length must equal the number of layers in 'x'. For example, to average 360 monthly layers into 12 monthly means, 'index' would be 'rep(1:12, 30)'. |
output_names |
A character vector of names for the output layers. Its length must equal the number of unique groups in 'index'. If 'NULL', names like "avg_unit_1" are generated. |
output_dir |
The directory where the final averaged raster layers will be saved as GeoTIFF files. |
user_region |
(Optional) An 'sf' or 'terra::SpatVector' object. If provided, the input raster 'x' is clipped and masked to this region before processing. The output raster's extent is the same of the 'user_region'. |
method |
The processing method: "auto", "tiled", or "terra". |
tile_degrees |
(Tiled method only) The approximate size of processing tiles. |
gdal_opt |
(Optional) GDAL creation options for the output GeoTIFFs. |
overwrite |
Logical. If 'FALSE' (default), stops if output files exist. |
verbose |
Logical, If 'TRUE', prints messages. |
Value
A 'terra::SpatRaster' object pointing to the newly created files, with the following characteristics:
**Number of layers:** The number of layers will be equal to the number of unique values in the 'index' argument.
**Layer names:** Layer names are determined by the ‘output_names' argument. If 'NULL', they will be generated automatically (e.g., ’avg_unit_01', 'avg_unit_02', etc.).
**Extent:** If 'user_region' is provided, the extent of the output raster will be clipped to match that region. Otherwise, the extent will be the same as the input raster 'x'.
Examples
# The example raster "prcp.tif" is included in the package's `inst/extdata` directory.
# Load example data from Lesotho (Montlhy time series from 2016-01 to 2020-12)
raster_path <- system.file("extdata", "prcp.tif", package = "fastbioclim")
# Load the SpatRaster from the file
prcp_ts <- terra::rast(raster_path)
# The data has 60 layers (5 years of monthly data), so we create an
# index to group layers by month (1 to 12).
monthly_index <- rep(1:12, times = 5)
# Define a temporary directory for the output files
output_dir <- file.path(tempdir(), "monthly_prcp_avg")
# Run the calculate_average function
monthly_avg <- calculate_average(
x = prcp_ts,
index = monthly_index,
output_names = "prcp_avg",
output_dir = output_dir,
overwrite = TRUE,
verbose = FALSE
)
# Print the resulting SpatRaster summary
print(monthly_avg)
# Clean up the created files
unlink(output_dir, recursive = TRUE)
Calculate Rolling Temporal Averages for SpatRasters
Description
Calculates temporal summaries for each time unit over a moving window of cycles. This function is designed for time series where fundamental time **units** (e.g., months) are grouped into repeating **cycles** (e.g., years).
Usage
calculate_roll(
x,
window_size,
freq = 12,
step = 1,
fun = "mean",
name_template = "{prefix}_w{start_window}-{end_window}_u{idx_unit}",
output_prefix = "output",
output_dir = tempdir(),
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE
)
Arguments
x |
A 'terra::SpatRaster' object where each layer represents a time **unit**. |
window_size |
Integer. The size of the moving window, measured in the number of **cycles**. For example, if the data cycle is annual ('freq = 12'), a 'window_size' of 20 represents a 20-year window. |
freq |
Integer. The number of time **units** (layers) that constitute one complete **cycle**. Common examples: 12 for monthly units in a yearly cycle, or 24 for hourly units in a daily cycle. |
step |
Integer. The number of **cycles** to slide the window by for each iteration. Default is 1. |
fun |
Character. The name of the summary function (e.g., "mean"). Default is "mean". |
name_template |
A character string defining the template for output filenames, using 'glue' syntax. Default: '"{prefix}_w{start_window}-{end_window}_u{idx_unit}"'. Available placeholders are:
|
output_prefix |
A character string for output filenames. Default is "output". |
output_dir |
Directory to save the final GeoTIFF files. |
user_region |
(Optional) An 'sf' or 'terra::SpatVector' object. If provided, the input raster 'x' is clipped and masked to this region before processing. The output raster's extent is the same of the 'user_region'. |
method |
Processing method: "auto", "tiled", or "terra". |
tile_degrees |
(Tiled method only) Approximate size of processing tiles. |
gdal_opt |
(Optional) GDAL creation options for GeoTIFFs. |
overwrite |
Logical. If 'FALSE' (default), stops if output files exist. |
verbose |
Logical, If 'TRUE', prints messages. |
Value
A 'terra::SpatRaster' object pointing to the newly created files, with the following characteristics:
**Number of layers:** The number of layers is determined by the number of rolling windows processed (controlled by 'window_size' and 'step') multiplied by the cycle frequency ('freq').
**Layer names:** Layer names are constructed based on the ‘name_template' argument, incorporating the window range and unit index (e.g., ’output_w01-20_u01').
**Extent:** If 'user_region' is provided, the extent of the output raster will be clipped to match that region. Otherwise, the extent will be the same as the input raster 'x'.
Examples
# The example raster "prcp.tif" is included in the package's `inst/extdata` directory.
# Load example data from Lesotho (Montlhy time series from 2016-01 to 2020-12)
raster_path <- system.file("extdata", "prcp.tif", package = "fastbioclim")
# Load the SpatRaster from the file
prcp_ts <- terra::rast(raster_path)
# The data has 60 layers (5 years of monthly data).
# We want to calculate a 3-year rolling average on monthly data.
# Therefore, the window size is 3 (number of years)
# and the lenght of the cycle is 12 (number of months).
# We also want a moving window of one month, so the number of steps is 1.
n_years <- 3
n_months <- 12
n_steps <- 1
# Define a temporary directory for the output files
output_dir <- file.path(tempdir(), "roll_prcp_avg")
# Run the calculate_average function
roll_avg <- calculate_roll(
x = prcp_ts,
window_size = n_years,
freq = n_months,
step = n_steps,
fun = "mean",
output_prefix = "prcp_roll_avg",
output_dir = output_dir,
overwrite = TRUE,
verbose = FALSE
)
# Print the resulting SpatRaster summary of 36 layesr (n_year * n_months)
print(roll_avg)
# Clean up the created files
unlink(output_dir, recursive = TRUE)
Calculate Sums for SpatRasters
Description
Calculates temporal sums for a multi-layer SpatRaster. This function serves as a smart wrapper, automatically selecting between an in-memory ('terra') or out-of-core ('tiled') workflow based on data size.
Usage
calculate_sum(
x,
index,
output_names = NULL,
output_dir = tempdir(),
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE
)
Arguments
x |
A 'terra::SpatRaster' object with multiple layers representing a time series. |
index |
A numeric or integer vector defining the grouping for aggregation. Its length must equal the number of layers in 'x'. For example, to sum 365 daily layers into 12 monthly totals, 'index' would group the days by month. |
output_names |
A character vector of names for the output layers. Its length must equal the number of unique groups in 'index'. If 'NULL', names like "sum_unit_1" are generated. |
output_dir |
The directory where the final summed raster layers will be saved as GeoTIFF files. |
user_region |
(Optional) An 'sf' or 'terra::SpatVector' object. If provided, the input raster 'x' is clipped and masked to this region before processing. The output raster's extent is the same of the 'user_region'. |
method |
The processing method: "auto", "tiled", or "terra". |
tile_degrees |
(Tiled method only) The approximate size of processing tiles. |
gdal_opt |
(Optional) GDAL creation options for the output GeoTIFFs. |
overwrite |
Logical. If 'FALSE' (default), stops if output files exist. |
verbose |
Logical, If 'TRUE', prints messages. |
Value
A 'terra::SpatRaster' object pointing to the newly created files, with the following characteristics:
**Number of layers:** The number of layers will be equal to the number of unique values in the 'index' argument.
**Layer names:** Layer names are determined by the ‘output_names' argument. If 'NULL', they will be generated automatically (e.g., ’sum_unit_01', 'sum_unit_02', etc.).
**Extent:** If 'user_region' is provided, the extent of the output raster will be clipped to match that region. Otherwise, the extent will be the same as the input raster 'x'.
Examples
# The example raster "prcp.tif" is included in the package's `inst/extdata` directory.
# Load example data from Lesotho (Monthly time series from 2016-01 to 2020-12)
raster_path <- system.file("extdata", "prcp.tif", package = "fastbioclim")
# Load the SpatRaster from the file
prcp_ts <- terra::rast(raster_path)
# To calculate the total annual precipitation, we group the 60 monthly layers by year.
annual_index <- rep(2016:2020, each = 12)
# Define a temporary directory for the output files
output_dir <- file.path(tempdir(), "annual_prcp_sum")
# Run the calculate_sum function
annual_sum <- calculate_sum(
x = prcp_ts,
index = annual_index,
output_names = "prcp_sum",
output_dir = output_dir,
overwrite = TRUE,
verbose = FALSE
)
# Print the resulting SpatRaster summary (should have 5 layers)
print(annual_sum)
# Clean up the created files
unlink(output_dir, recursive = TRUE)
Standardize Environmental Variable Input Format
Description
Converts data frames, matrices, or vectors into a consistent matrix format with preserved column/row names for downstream processing.
Usage
check_evar(evar)
Arguments
evar |
Input environmental variable data. Can be: - data.frame: Converted to matrix - vector: Transposed to row matrix - matrix: Preserved with names checked |
Value
Matrix with column names preserved. If input was a vector, returns 1-row matrix with vector names as column names.
Validate Climate Input Rasters
Description
Performs rigorous checks on a set of climate raster files to ensure they are suitable for bioclimatic variable calculation.
Usage
check_rasters(..., verbose = TRUE, check_nas = TRUE)
Arguments
... |
Named arguments providing character vectors of file paths for each climate variable (e.g., 'tmin_files = c(...)', 'prcp_files = c(...)'). |
verbose |
Logical, If 'TRUE', prints messages. |
check_nas |
Logical. If 'TRUE' (the default), perform the potentially slow check for mismatched NA values. If 'FALSE', only check for geometry. |
Details
This function checks for two main sources of error: 1. **Geometric Inconsistency**: Ensures all input rasters share the exact same coordinate reference system (CRS), extent, and resolution. 2. **NA Mismatch**: Checks if the pattern of NA values is consistent across all layers of all provided climate variables. Mismatched NAs can lead to silent errors in calculations. This check can be time-consuming for very large rasters.
Value
A list containing a summary of the validation:
`is_valid` |
A single logical value: 'TRUE' if all checks pass, 'FALSE' otherwise. |
`geom_report` |
A message detailing the result of the geometry check. |
`na_report` |
A message detailing the result of the NA check. |
`mismatch_raster` |
If 'check_nas=TRUE' and mismatches are found, a 'SpatRaster' where non-zero values indicate pixels with inconsistent NAs. |
Calculate Sliding Periods for Temporal Analysis
Description
Defines sliding periods of a specified length for temporal calculations, handling wrap-around cases for circular data.
Usage
compute_periods(n_units, period_length, circular = TRUE)
Arguments
n_units |
Integer. The total number of temporal units (layers). |
period_length |
Integer. The number of consecutive units in each period. |
circular |
Logical. If TRUE, allows periods to wrap around. |
Value
List where each element contains 'period_length' consecutive unit indices.
Create an Inverse Cell ID Translation Function
Description
Generates a function to translate cell IDs from a source raster grid to a target raster grid, considering potential offsets and different dimensions. Handles cases where the target grid is a subset (e.g., cropped/masked) of the source grid.
Usage
define_translate(ncol_src, ncol_tgt, row_offset, col_offset)
Arguments
ncol_src |
Integer. Number of columns in the source raster. |
ncol_tgt |
Integer. Number of columns in the target raster. |
row_offset |
Integer. Row offset of the target grid's top-left corner relative to the source grid's top-left corner (0-based). |
col_offset |
Integer. Column offset of the target grid's top-left corner relative to the source grid's top-left corner (0-based). |
Value
A function that takes a vector of source cell IDs ('cell_src') and returns a vector of corresponding target cell IDs. Cells falling outside the target grid bounds will have 'NA_integer_' as their target ID.
Derive Comprehensive Bioclimatic Variables
Description
Calculates up to 35 bioclimatic variables from average monthly climate SpatRasters (or other temporal units). This function serves as a smart wrapper that automatically selects the most efficient processing workflow (in-memory vs. tiled) based on data size and user-defined region of interest.
Usage
derive_bioclim(
bios,
tmin = NULL,
tmax = NULL,
prcp = NULL,
tavg = NULL,
srad = NULL,
mois = NULL,
output_dir = tempdir(),
period_length = 3,
circular = TRUE,
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE,
...
)
Arguments
bios |
Numeric vector specifying which bioclimatic variables (1-35) to compute. |
tmin, tmax, prcp, tavg, srad, mois |
(Optional) 'terra::SpatRaster' objects containing the climate data for each temporal unit (e.g., 12 monthly layers). All provided rasters must have the same geometry and number of layers. |
output_dir |
The directory where the final bioclimatic variable rasters will be saved. The directory will be created if it does not exist. The default is temporal directory created by 'tempdir'. |
period_length |
Integer. The number of temporal units (e.g., months) that define a "period" for calculating summary variables like BIO8 (Mean Temp of Wettest Quarter). Defaults to 3, representing quarters for monthly data. |
circular |
Logical. If 'TRUE' (the default), period calculations will wrap around the beginning and end of the time series (e.g., for monthly data, Dec-Jan-Feb is considered a valid period). |
user_region |
(Optional) An 'sf' or 'terra::SpatVector' object defining the area of interest. If provided, all calculations will be clipped to this region. |
method |
The processing method. See Details for more information. |
tile_degrees |
(Tiled method only) The approximate size of processing tiles in degrees. Ignored if the 'terra' workflow is used. |
gdal_opt |
(Optional) A character vector of GDAL creation options for the output GeoTIFF files. Controls compression, threading, etc. |
overwrite |
(Optional) Logical. If 'FALSE' (the default), the function will stop immediately if any target output files already exist. |
verbose |
Logical, If 'TRUE', prints messages. |
... |
Additional arguments, primarily for passing static index rasters. See the "Static Indices" section for details. |
Details
This function unifies two processing backends. The 'method' argument controls which is used:
'"auto"': (Default) Intelligently chooses between "terra" and "tiled" based on estimated memory requirements.
'"terra"': Forces the fast, in-memory workflow. May fail on very large datasets.
'"tiled"': Forces the memory-safe, out-of-core workflow. Ideal for very large datasets. Requires that the input SpatRasters point to files on disk.
Period-based variables (e.g., BIO8, BIO10) are calculated using a moving window defined by 'period_length'.
Value
A 'terra::SpatRaster' object pointing to the newly created bioclimatic variable rasters, with the following characteristics:
**Number of layers:** The number of layers is equal to the number of unique variables requested in the 'bios' argument.
**Layer names:** Layer names are standardized (e.g., 'bio01', 'bio12') corresponding to the requested variable numbers.
**Extent:** If a 'user_region' is provided, the extent of the output raster will be clipped to match that region. Otherwise, the extent will be the same as the input rasters.
The returned object contains the following calculated variables:
- bio01
Mean Temperature
- bio02
Mean Diurnal Range
- bio03
Isothermality
- bio04
Temperature Seasonality
- bio05
Max Temperature of Warmest Unit
- bio06
Min Temperature of Coldest Unit
- bio07
Temperature Range
- bio08
Mean Temperature of Wettest Period
- bio09
Mean Temperature of Driest Period
- bio10
Mean Temperature of Warmest Period
- bio11
Mean Temperature of Coldest Period
- bio12
Precipitation Sum
- bio13
Precipitation of Wettest Unit
- bio14
Precipitation of Driest Unit
- bio15
Precipitation Seasonality
- bio16
Precipitation of Wettest Period
- bio17
Precipitation of Driest Period
- bio18
Precipitation of Warmest Period
- bio19
Precipitation of Coldest Period
- bio20
Mean Radiation
- bio21
Highest Radiation Unit
- bio22
Lowest Radiation Unit
- bio23
Radiation Seasonality
- bio24
Radiation of Wettest Period
- bio25
Radiation of Driest Period
- bio26
Radiation of Warmest Period
- bio27
Radiation of Coldest Period
- bio28*
Mean Moisture
- bio29*
Highest Moisture Unit
- bio30*
Lowest Moisture Unit
- bio31*
Moisture Seasonality
- bio32*
Mean Moisture of Most Moist Period
- bio33*
Mean Moisture of Least Moist Period
- bio34*
Mean Moisture of Warmest Period
- bio35*
Mean Moisture of Coldest Period
Static Indices
For advanced use cases, such as time-series analysis or defining specific seasons, you can provide pre-calculated index rasters to override the dynamic calculations. These are passed as named 'SpatRaster' objects via the '...' argument (e.g., 'warmest_period = my_warmest_idx_rast'). The wrapper function automatically handles passing them to the appropriate workflow.
When using the "tiled" workflow, these static index rasters **must** be file-backed (i.e., not held entirely in memory). Supported static indices include:
'warmest_unit', 'coldest_unit', 'wettest_unit', 'driest_unit'
'high_rad_unit', 'low_rad_unit', 'high_mois_unit', 'low_mois_unit'
'warmest_period', 'coldest_period', 'wettest_period', 'driest_period'
'high_mois_period', 'low_mois_period'
Note
*The original moisture variables proposed in the ANUCLIM manual are based on the Moisture Index (MI). However, this function allows users to calculate moisture-based bioclimatic variables using other units of moisture as inputs, offering greater flexibility in input data usage.
References
O’Donnell, M. S., & Ignizio, D. A. (2012). Bioclimatic predictors for supporting ecological applications in the conterminous United States. ANUCLIM 6.1 User Guide. Centre for Resource and Environmental Studies, The Australian National University.
Examples
# The example raster "prcp.tif" is included in the package's `inst/extdata` directory.
# Load example data from Lesotho (Montlhy time series from 2016-01 to 2020-12)
raster_path <- system.file("extdata", "prcp.tif", package = "fastbioclim")
# Load the SpatRaster from the file
prcp_ts <- terra::rast(raster_path)
# The data has 60 layers (5 years of monthly data), so we create an
# index to group layers by month (1 to 12).
monthly_index <- rep(1:12, times = 5)
# Define a temporary directory for the output files
output_dir <- file.path(tempdir(), "prcp_bios")
# Run the calculate_average function
monthly_avg <- calculate_average(
x = prcp_ts,
index = monthly_index,
output_names = "prcp_avg",
output_dir = output_dir,
overwrite = TRUE,
verbose = FALSE
)
# Once the monthly averaged is obtained, we can use it to obtain bioclimatic variables based
# just in precipitation (bios 12, 13, 14, 15, 16, 17).
prcp_bios <- derive_bioclim(
bios = 12:17,
prcp = monthly_avg,
output_dir = output_dir,
overwrite = TRUE,
verbose = FALSE
)
# Print the resulting SpatRaster summary with the four requested layers
print(prcp_bios)
# Clean up the created files
unlink(output_dir, recursive = TRUE)
Derive Custom Summary Statistics from Climate Variables
Description
Calculates a wide range of custom summary statistics for a primary climate variable, with options for interactions with a second variable. This function serves as a smart wrapper that automatically selects the most efficient processing workflow (in-memory vs. tiled).
Usage
derive_statistics(
variable,
stats = c("mean", "max", "min"),
inter_variable = NULL,
inter_stats = NULL,
output_prefix = "var",
suffix_inter_max = "inter_high",
suffix_inter_min = "inter_low",
output_dir = tempdir(),
period_length = 3,
period_stats = "mean",
circular = TRUE,
user_region = NULL,
method = c("auto", "tiled", "terra"),
tile_degrees = 5,
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE,
...
)
Arguments
variable |
A 'terra::SpatRaster' object for the primary variable. |
stats |
A character vector of statistics to compute for the primary variable. Supported: '"mean"', '"max"', '"min"', '"sum"', '"stdev"', '"cv_cli"', '"max_period"', '"min_period"'. |
inter_variable |
(Optional) A 'terra::SpatRaster' for an interactive variable. |
inter_stats |
(Optional) A character vector of interactive statistics to compute. Requires 'inter_variable'. Supported: '"max_inter"', '"min_inter"'. |
output_prefix |
A character string used as the prefix for all output file names (e.g., 'output_prefix = "wind"' results in "wind_mean.tif", "wind_max.tif"). |
suffix_inter_max |
Character. Suffix for the "max_inter" statistic name. Default: "inter_high". |
suffix_inter_min |
Character. Suffix for the "min_inter" statistic name. Default: "inter_low". |
output_dir |
The directory where the final summary rasters will be saved. |
period_length |
Integer. The number of temporal units (e.g., months) that define a "period". This is used for all period-based statistics, such as '"max_period"' and interactive statistics like '"max_inter"'. The same period length is applied to both the primary 'variable' and the 'inter_variable' when calculating these statistics. Default: 3. |
period_stats |
Character. The statistic ("mean" or "sum") to summarize data over each period. Default: "mean". |
circular |
Logical. If 'TRUE' (the default), period calculations wrap around. |
user_region |
(Optional) An 'sf' or 'terra::SpatVector' object. If provided, the input raster 'x' is clipped and masked to this region before processing. The output raster's extent is the same of the 'user_region'. |
method |
The processing method. See Details for more information. |
tile_degrees |
(Tiled method only) The approximate size of processing tiles. |
gdal_opt |
(Optional) A character vector of GDAL creation options for the output GeoTIFF files. |
overwrite |
(Optional) Logical. If 'FALSE' (the default), the function will stop if output files already exist. |
verbose |
Logical, If 'TRUE', prints messages. |
... |
Additional arguments, primarily for passing static index 'SpatRaster' objects. See the "Static Indices" section. |
Details
This function provides a flexible alternative to 'derive_bioclim()' for any multi-layer climate variable (e.g., wind speed, humidity). It unifies two processing backends, controlled by the 'method' argument:
'"auto"': (Default) Intelligently chooses between "terra" and "tiled".
'"terra"': Forces the fast, in-memory workflow.
'"tiled"': Forces the memory-safe, out-of-core workflow. Requires that all input SpatRasters point to files on disk.
Value
A 'terra::SpatRaster' object pointing to the newly created summary rasters, with the following characteristics:
**Number of layers:** The number of layers is equal to the total number of statistics requested in the 'stats' and 'inter_stats' arguments.
**Layer names:** Layer names are constructed by combining the ‘output_prefix' with the name of each statistic (e.g., ’prefix_mean', 'prefix_max'). For interactive statistics, the names are 'prefix_suffix_inter_high' and 'prefix_suffix_inter_low', where the suffixes are controlled by the 'suffix_inter_max' and 'suffix_inter_min' arguments.
**Extent:** If a 'user_region' is provided, the extent of the output raster will be clipped to match that region. Otherwise, the extent will be the same as the input 'variable' raster.
Static Indices
For advanced control, provide pre-calculated index rasters as named 'SpatRaster' objects via the '...' argument (e.g., 'max_unit = max_idx_rast'). Supported indices: 'max_unit', 'min_unit', 'max_period', 'min_period', 'max_interactive', 'min_interactive'.
Examples
# The example raster "prcp.tif" is included in the package's `inst/extdata` directory.
# Load example data from Lesotho (Montlhy time series from 2016-01 to 2020-12)
raster_path <- system.file("extdata", "prcp.tif", package = "fastbioclim")
# Load the SpatRaster from the file
prcp_ts <- terra::rast(raster_path)
# The data has 60 layers (5 years of monthly data), so we create an
# index to group layers by month (1 to 12).
monthly_index <- rep(1:12, times = 5)
# Define a temporary directory for the output files
output_dir <- file.path(tempdir(), "prcp_stats")
# Run the calculate_average function
monthly_avg <- calculate_average(
x = prcp_ts,
index = monthly_index,
output_names = "prcp_avg",
output_dir = output_dir,
overwrite = TRUE,
verbose = FALSE
)
# Once the monthly averaged is obtained, we can use it to derive statictics of precipitation
# Here we will obtain four summary statitics: mean, maximum, minimum, and standard deviation
prcp_stats <- derive_statistics(
variable = monthly_avg,
stats = c("mean", "max", "min", "stdev"),
prefix_variable = "prcp",
output_dir = output_dir,
overwrite = TRUE
)
# Print the resulting SpatRaster summary with the four requested layers
print(prcp_stats)
# Clean up the created files
unlink(output_dir, recursive = TRUE)
Create Moving Window Summaries of a SpatRaster
Description
This internal helper function calculates moving window summaries (periods) across the layers of a SpatRaster. It generates a new SpatRaster where each layer represents the sum of the layers from the original raster that fall within a specific window. The 'circular' argument controls whether the windows "wrap around" from the end of the time series to the beginning.
Usage
get_window(x, period, circular)
Arguments
x |
A 'terra::SpatRaster' object where each layer represents a temporal unit. |
period |
An integer specifying the size (number of layers) of the moving window. For monthly data ('nlyr(x) = 12'), a 'period' of 3 corresponds to a quarter. |
circular |
A logical. If 'TRUE', the window wraps from the last layer to the first. If 'FALSE', windows are only created where they fit completely within the original sequence of layers. |
Value
A 'terra::SpatRaster' object where each layer is the pixel-wise sum for a corresponding period.
If 'circular = TRUE', the output has the same number of layers as the input 'x'.
If 'circular = FALSE', the output has 'nlyr(x) - period + 1' layers.
Tiled, Out-of-Core Rolling Time Series Averaging (Internal)
Description
Tiled, Out-of-Core Rolling Time Series Averaging (Internal)
Usage
roll_fast(
paths,
window_size,
freq,
step,
fun,
output_names_list,
user_region,
tile_degrees,
output_dir,
verbose
)
In-Memory Rolling Time Series Averaging (Internal)
Description
In-Memory Rolling Time Series Averaging (Internal)
Usage
roll_terra(
x,
window_size,
freq,
step,
fun,
output_names_list,
output_dir,
gdal_opt,
overwrite,
verbose
)
Tiled, Out-of-Core Custom Variable Summarization
Description
Internal function to calculate custom summary statistics for very large datasets by processing them in tiles.
Usage
stats_fast(
variable_path,
n_units,
stats = c("mean", "max", "min"),
period_length = 3,
period_stats = "mean",
circular = TRUE,
inter_variable_path = NULL,
inter_stats = NULL,
max_unit_path = NULL,
min_unit_path = NULL,
max_period_path = NULL,
min_period_path = NULL,
max_interactive_path = NULL,
min_interactive_path = NULL,
output_prefix = "var",
suffix_inter_max = "inter_high",
suffix_inter_min = "inter_low",
user_region = NULL,
tile_degrees = 5,
output_dir = tempdir(),
write_raw_vars = FALSE,
verbose = TRUE,
...
)
Arguments
variable_path |
Path to primary variable rasters. |
n_units |
Integer, number of layers per variable. |
stats |
Character vector of stats to compute. |
output_prefix |
Character, prefix for output files. |
... |
Other arguments including inter_variable_path, period_length, circular, static index paths, etc. |
Value
Character string: Path to the temporary directory containing intermediate '.qs2' files.
See Also
The user-facing wrapper function 'derive_statistics()'.
In-Memory Custom Variable Summarization
Description
Internal function to calculate custom summary statistics using 'terra' functions. Designed for datasets that fit into RAM.
Usage
stats_terra(
variable,
stats = c("mean", "max", "min", "cv_cli", "max_period", "min_period"),
period_length = 3,
period_stats = "mean",
circular = TRUE,
inter_variable = NULL,
inter_stats = c("max_inter", "min_inter"),
max_unit = NULL,
min_unit = NULL,
max_period = NULL,
min_period = NULL,
max_interactive = NULL,
min_interactive = NULL,
output_prefix = "var",
suffix_inter_max = "inter_high",
suffix_inter_min = "inter_low",
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
output_dir = tempdir(),
verbose = TRUE,
...
)
Arguments
variable |
A SpatRaster for the primary variable. |
stats |
Character vector of stats to compute. |
output_prefix |
Character, prefix for output layer names. |
... |
Other arguments including inter_variable, period_length, circular, static index SpatRasters, etc. |
Value
A 'terra::SpatRaster' object containing the calculated summary layers.
See Also
The user-facing wrapper function 'derived_statistics()'.
Calculate Temporal Period Aggregates
Description
Computes aggregates (sums or mean) over defined temporal periods and identifies min/max periods.
Usage
var_periods(variable, periodos, n_units, period_length, stat)
Arguments
variable |
Matrix of temporal values (rows=pixels/cells, cols=units). |
periodos |
List of unit groupings (output from compute_periods). |
n_units |
Integer. Total number of temporal units. |
period_length |
Integer. Length of each period. |
stat |
Character. Either '"mean"' or '"sum"', specifying whether to calculate the average or total |
Value
Matrix with period sums ('num_periods' columns named "period_X"), "min_idx", and "max_idx" columns.
Export Bioclimatic Variables to GeoTIFF
Description
Assembles intermediate '.qs2' files into a full vector in memory, performs cell ID mapping if necessary, and writes final GeoTIFF rasters.
Usage
write_layers(
input_dir,
output_dir,
file_pattern = "bio",
gdal_opt = c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS"),
overwrite = FALSE,
verbose = TRUE
)
Arguments
input_dir |
Character string. Path to directory with intermediate '.qs2' files and 'template_info.qs2' |
output_dir |
Character string. Path for the final GeoTIFF files. |
file_pattern |
Character string. A prefix or base pattern to identify the groups of '.qs2' files. For example, if files are "bio01_1.qs2", "bio01_2.qs2", "bio02_1.qs2", etc., 'file_pattern' would be "bio". If files are "var_mean_1.qs2", "var_sum_1.qs2", etc., 'file_pattern' could be "var". The function will attempt to extract the full variable name (e.g., "bio01", "var_mean") from the filenames. Default is "bio". |
gdal_opt |
Character vector. GDAL creation options for the output GeoTIFF files. These options control compression, threading, and other advanced features. See the GDAL documentation for a full list of options for the GeoTIFF driver. The default is 'c("COMPRESS=DEFLATE", "PREDICTOR=3", "NUM_THREADS=ALL_CPUS")', which provides good, lossless compression. To disable compression, use 'NULL'. |
overwrite |
Logical. If 'TRUE', any existing GeoTIFF files in the 'output_dir' with the same name will be overwritten. If 'FALSE' (the default), the function will throw an error if it attempts to write to a file that already exists, which is a safety measure to prevent accidental data loss. |
verbose |
Logical, If 'TRUE', prints messages. |
Value
None. Writes GeoTIFF files to 'output_dir'.
Author(s)
Luis Osorio-Olvera, Gonzalo E. Pinilla-Buitrago