Compute windspeed indicators from grouped data
Source:R/summarise_windspeed.R
summarise_windspeed.RdThe function computes windspeed (u2) indicators from grouped data. Expects windspeed in kilometers per hour (km/h). 1 m/s equals to 3.6 km/h.
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 high and low u2 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 l_u2_3, l_u2_5, h_u2_3 and h_u2_5 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 percentilel_eto_3Count of sequences of 3 days or more with windspeed bellow the climatological normall_eto_5Count of sequences of 5 days or more with windspeed bellow the climatological normalh_eto_3Count of sequences of 3 days or more with windspeed above the climatological normalh_eto_5Count of sequences of 5 days or more with windspeed above the climatological normal
Examples
# Compute monthly normals
normals <- windspeed_data |>
# 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) |>
summarise_normal(date_var = date, value_var = value, year_start = 1961, year_end = 1990) |>
dplyr::ungroup()
# Compute indicators
windspeed_data |>
# Create wave variables
dplyr::group_by(code_muni) |>
add_wave(
normals_df = normals,
threshold = 0,
threshold_cond = "lte",
size = 3,
var_name = "l_u2_3"
) |>
add_wave(
normals_df = normals,
threshold = 0,
threshold_cond = "lte",
size = 5,
var_name = "l_u2_5"
) |>
add_wave(
normals_df = normals,
threshold = 0,
threshold_cond = "gte",
size = 3,
var_name = "h_u2_3"
) |>
add_wave(
normals_df = normals,
threshold = 0,
threshold_cond = "gte",
size = 5,
var_name = "h_u2_5"
) |>
dplyr::ungroup() |>
# Identify month
dplyr::mutate(month = lubridate::month(date)) |>
# Group by id variable and month
dplyr::group_by(code_muni, month) |>
# Compute windspeed indicators
summarise_windspeed(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)