Apply a threshold-based mask to climate data based on value ranges.
Description
Apply a threshold-based mask to climate data based on value ranges.
c4h_index(
data,
return_mask = FALSE,
lower_threshold = NULL,
upper_threshold = NULL,
closed = TRUE
)Arguments
data: s2dv_cube object with the climate data to be masked, usually read usingc4h_load.return_mask: Boolean. If TRUE (default), return original values where the condition is fulfilled and NA otherwise. If FALSE, return 1 where the condition is met and 0 otherwise.lower_threshold: Numeric. Optional lower threshold of the mask. All cells below that value will be masked out.upper_threshold: Numeric. Optional upper threshold of the mask. All cells above that value will be masked out.closed: Boolean. If TRUE (default), use closed intervals including the threshold values. If FALSE, intervals are open.
Returns
An s2dv_cube with the values masked or the mask (depending on return_mask).
Examples
# Read reanalysis data
obs_path <- system.file("extdata", "reanalysis", package = "clim4health")
obs <- c4h_load(obs_path,
variable = "t2m",
year = 2010,
month = 1,
ext = "nc")
c4h_plot(obs)
# Compute index, temperature higher than 290K
index <- c4h_index(obs, lower_threshold = 290)
c4h_plot(index)
# Return mask, temperature higher than 290K
mask <- c4h_index(obs, return_mask = TRUE, lower_threshold = 290)
c4h_plot(mask)