Generates the mean of the values over a certain percentile threshold for the portion of the Raster* that intersects a polygon
get_perc_risk_index(b, p, perc_val = 75, mod = "gt")
RasterLayer/Brick/Stack containing the historical observations or a proxy (typically a reanalysis).
SpatialPolygons* object
is the percentile value used as a threshold
defines if the values considered for the mean are above (gt) or below (lt) the threshold
The function returns a numeric value (for each layer in b
),
corresponding to the mean of the values of b
above/below a given
percentile of the historical observations.
if (FALSE) {
# Read RISICO test data
r_risico <- readRDS(system.file("extdata", "RISICO_raster.rds",
package = "caliver"))
# Set missing crs
raster::crs(r_risico) <- "+proj=longlat +datum=WGS84 +no_defs"
# Define dummy polygon, as sf simple feature
shape <- sf::st_bbox(c(xmin = 7, xmax = 18, ymax = 40, ymin = 18),
crs = sf::st_crs(4326))
get_perc_risk_index(b = r_risico, p = shape, perc_val = 75, mod = "gt")
}