Compute precipitation indicators from grouped data
Source:R/summarise_precipitation.R
summarise_precipitation.RdThe function computes precipitation indicators from grouped data. Expects precipitation in millimeters (mm).
Arguments
- .x
grouped data, created with
dplyr::group_by()- value_var
name of the variable with temperature values.
- normals_df
normals data, created with
summarise_normal()
Details
The rain spells indicators are computed based on climatological normals, created with the summarise_normal() function and passed with the normals_df argument. Keys to join the normals data must be present (like id, year, and month) and use the same names.
The variables rs3 and rs5 must be present in the dataset. Those variables can be computed with the add_wave() function. Plase follow this function example for the correct arguments.
The following indicators are computed for each group.
countCount of data pointsnormal_meanClimatological normal mean, fromnormals_dfargumentnormal_p10Climatological 10th percentile, fromnormals_dfargumentnormal_p90Climatological 90th percentile, fromnormals_dfargumentmeanAveragemedianMediansdStandard deviationseStandard errormaxMaximum valueminMinimum valuep1010th percentilep2525th percentilep7575th percentilep9090th percentilers3Count of rain spells occurences, with 3 or more consecutive days with rain above the climatological normal average valuers5Count of rain spells occurences, with 5 or more consecutive days with rain above the climatological normal average valuep_1Count of days with precipitation above 1mmp_5Count of days with precipitation above 5mmp_10Count of days with precipitation above 10mmp_50Count of days with precipitation above 50mmp_100Count of days with precipitation above 100mmd_3Count of sequences of 3 days or more without precipitationd_5Count of sequences of 5 days or more without precipitationd_10Count of sequences of 10 days or more without precipitationd_15Count of sequences of 15 days or more without precipitationd_20Count of sequences of 20 days or more without precipitationd_25Count of sequences of 25 days or more without precipitation
Examples
# Compute monthly normals
normals <- precipitation_data |>
# Identify month
dplyr::mutate(month = lubridate::month(date)) |>
# Group by id variable and month
dplyr::group_by(code_muni, month) |>
summarise_normal(date_var = date, value_var = value, year_start = 1981, year_end = 2010) |>
dplyr::ungroup()
# Compute indicators
precipitation_data |>
dplyr::filter(date >= as.Date("2011-01-01")) |>
# Create wave variables
dplyr::group_by(code_muni) |>
add_wave(
normals_df = normals,
threshold = 0,
threshold_cond = "gte",
size = 3,
var_name = "rs3"
) |>
add_wave(
normals_df = normals,
threshold = 0,
threshold_cond = "gte",
size = 5,
var_name = "rs5"
) |>
dplyr::ungroup() |>
# Identify year
dplyr::mutate(year = lubridate::year(date)) |>
# Identify month
dplyr::mutate(month = lubridate::month(date)) |>
# Group by id variable, year and month
dplyr::group_by(code_muni, year, month) |>
# Compute precipitation indicators
summarise_precipitation(value_var = value, normals_df = normals) |>
# Ungroup
dplyr::ungroup()
#> Error in purrr::map(.x = res, .f = iden): ℹ In index: 1.
#> Caused by error in `nseq::trle_cond()`:
#> ! unused argument (pos = TRUE)