Compute minimum temperature indicators from grouped data
Source:R/summarise_temp_min.R
summarise_temp_min.RdThe function computes minimum temperature indicators from grouped data. Expects temperature in celsius degrees.
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 cold 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 cw3 and cw5 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 percentilecold_spells_3dCount of cold spells occurences, with 3 or more consecutive days with minimum temperature bellow the climatological normal value minus 5 celsius degreescold_spells_5dCount of cold spells occurences, with 5 or more consecutive days with minimum temperature bellow the climatological normal value minus 5 celsius degreescold_daysCount of cold days, when the minimum temperature is bellow the normal 10th percentilet_0Count of days with temperatures bellow or equal to 0 celsius degreest_5Count of days with temperatures bellow or equal to 5 celsius degreest_10Count of days with temperatures bellow or equal to 10 celsius degreest_15Count of days with temperatures bellow or equal to 15 celsius degreest_20Count of days with temperatures bellow or equal to 20 celsius degrees
Examples
# Compute monthly normals
normals <- temp_min_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 = 1961, year_end = 1990) |>
dplyr::ungroup()
# Compute indicators
temp_min_data |>
# Create wave variables
dplyr::group_by(code_muni) |>
add_wave(
normals_df = normals,
threshold = -5,
threshold_cond = "lte",
size = 3,
var_name = "cw3"
) |>
add_wave(
normals_df = normals,
threshold = -5,
threshold_cond = "lte",
size = 5,
var_name = "cw5"
) |>
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 minimum temperature indicators
summarise_temp_min(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)