R/bee_calc_baseline.R
BEE.calc.baseline.RdCalculate the daily baseline value using the mean or a quantile of a timeserie.
BEE.calc.baseline(
yourspatraster,
start_date = NULL,
end_date = NULL,
threshold,
quantile_value = NULL,
time_window = 5,
smooth_window = 10
): The SpatRaster that contains the values to be used to calculate the baseline (your reference time serie). Each layer must have a date and there must be no duplicates.
: The date to use as the first day of your reference period. It must be in the format YYYY-MM-DD. (Note that the provided dataset can cover a longer time period than the one you want to use as a reference.)
: The date to use as the first day of your reference period. It must be in the format YYYY-MM-DD.
: Specifies whether you want to use a percentile or the mean of the observed values as the threshold. The accepted arguments are "qt", to specify that you want to compute a percentile of the observed values in the reference timeframe, or "mean", if you want to use the mean of the observed values as threshold. If you want to use a fixed value as the threshold (e.g. biological optimum), you can skip this step and use BEE.id.extreme_day() directly.
: Indicates the desired percentile value. This must be between 0 and 1.
: Number of days on either side of day 'd' that are used to calculate the threshold value associated for day 'd'. For example, if "time_window = 5", the thershold value for 'd' day will be calculated using data from five days before day d, day d itself, and the five days after day d, from all years between "start_date" and "end_date".
: Number of days on either side of day 'd' that are used to calculate the mean value of the threshold assigned to the 'd' day. This allows your threshold value to be smoothed across days. For example, if "smooth_window" is set to 10 days, the final value on day 'd' will be the mean of the baseline/thershold values calculated for days: d - 10 to d + 10 (eleven values).
A SpatRaster with one day of the year per layer (366 layers) that has the same extent, pixel resolution and CRS as the provided SpatRaster. Each pixel contains the threshold value at which an extreme event is identified (the baseline value).
### Load the example dataset in R environement :
file_name <- system.file(file.path("extdata", "copernicus_data_celsius.tiff"),
package = "BioExtremeEvent")
copernicus_data_celsius <- terra::rast(file_name)
### **90th percentile threshold:** 90 % of the values observed at a given day
# accross all years of the reference time period are bellow the baseline
# value.
#### No smoothing: # 16s to run
baseline_qt90_smth_0 <- BEE.calc.baseline(yourspatraster = copernicus_data_celsius,
start_date = "2023-01-01",
end_date = "2025-12-31",
threshold = "qt",
quantile_value = 0.9,
time_window = 5,
smooth_window = 0)
#### Smoothing over 15 days: # 18s to run
baseline_qt90_smth_15 <- BEE.calc.baseline(yourspatraster = copernicus_data_celsius,
start_date = "2023-01-01",
end_date = "2025-12-31",
threshold = "qt",
quantile_value = 0.9,
time_window = 5,
smooth_window = 7) #7+1+7=15
###**Mean value threshold:**
baseline_mean <- BEE.calc.baseline(yourspatraster = copernicus_data_celsius,
start_date = "2023-01-01",
end_date = "2025-12-31",
threshold = "mean",
time_window = 5,
smooth_window = 7)
#if threshold = "mean", any quantile_value provided will be ignored.