View source: R/habitat_suitability.R
| habitat_suitability | R Documentation |
Evaluates the standardized multivariate-normal density of Jimenez et
al. (2022, Eq. 2) at every cell of an environmental
SpatRaster, returning a one-layer raster of
suitability values in (0, 1] (or, optionally, log-suitability
in (-\infty, 0]).
habitat_suitability(
param,
env,
output = "",
overwrite = FALSE,
return_log = FALSE,
threads = RcppParallel::defaultNumThreads(),
wopt = list()
)
param |
Named list with components
The Cholesky factor of |
env |
A multi-layer |
output |
Character. File path for the output GeoTIFF. The empty
string |
overwrite |
Logical. If |
return_log |
Logical. If |
threads |
Integer. Number of parallel threads handed to the
inner C++ kernel. Default
|
wopt |
List. Additional write options forwarded to
|
Memory is bounded by the largest block selected by terra's memory
manager: continental-scale rasters are processed without ever
materialising the full grid in R. The per-cell computation is run by
niche_suitability_cpp, an RcppParallel kernel
that takes raw pointers into terra's column-major buffer.
The function follows the streaming I/O pattern from xsdm-devel's recipe 03:
terra::readStart on env, paired with an
on.exit(terra::readStop);
terra::writeStart on the output, paired with an
on.exit(terra::writeStop);
for each block i: read each variable's tile via
terra::readValues(..., mat = TRUE), pack into a flat
column-major numeric vector (n_tile x p), mask
NA cells, compact, call
niche_suitability_cpp, scatter the result back, and
terra::writeValues.
A one-layer SpatRaster named "suitability" (or
"log_suitability" when return_log = TRUE). Returned
invisibly when output is non-empty.
niche_suitability_cpp,
predict.xnicher.
## Hand-built (mu, Sigma):
r1 <- terra::rast(nrows = 10, ncols = 10)
r2 <- terra::rast(nrows = 10, ncols = 10)
terra::values(r1) <- rnorm(100)
terra::values(r2) <- rnorm(100)
ex <- c(r1, r2)
names(ex) <- c("bio1", "bio12")
habitat_suitability(
param = list(mu = c(0, 0), Sigma = diag(2)),
env = ex
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.