Tidyextreme: A Tidy Toolbox for Climate Extreme Indices

Marcio Baldissera Cure

2026-02-01

Introduction

The tidyextreme package provides a streamlined, tidyverse-compliant toolkit for calculating essential climate extreme indices as defined by the Expert Team on Climate Change Detection and Indices (ETCCDI). Designed for seamless integration into modern data analysis workflows, it allows researchers to compute key metrics—such as maximum 1-day precipitation (Rx1day), consecutive dry days (CDD), warm spell duration (WSDI), and monthly temperature extremes (TXx, TNn)—directly from daily or hourly data using a consistent calculate_*() syntax. By returning tidy data frames and leveraging dplyr and ggplot2 compatibility, tidyextreme simplifies the entire process of extreme event analysis, from data preparation to visualization, making climate research more efficient and reproducible.

Installation

# Option 1: Using devtools

devtools::install_github("Mauritia-flexuosa/tidyextreme")

# Option 2: Using remotes

remotes::install_github("Mauritia-flexuosa/tidyextreme")

# Or from CRAN (when available)
#install.packages("tidyextreme") # Not yet on CRAN

1. Data Preparation

Creating Synthetic Climate Data

Let’s create 10 years of realistic daily climate data:

set.seed(123)
library(tibble)
library(lubridate)

# Create 10 years of daily data (2000-2009)
n_years <- 10
n_days <- n_years * 365

climate_data <- tibble::tibble(
  date = seq(as.Date("2000-01-01"), by = "day", length.out = n_days),
  
  # Precipitation: seasonal pattern with extreme events
  prcp = pmax(0, rgamma(n_days, shape = 1.2, rate = 0.4) + 
               sin(yday(date) * 2 * pi / 365) * 5),
  
  # Maximum temperature: seasonal with warming trend
  tmax = 20 + 10 * sin(yday(date) * 2 * pi / 365 - pi/2) + 
         rnorm(n_days, 0, 3) + 
         (year(date) - 2000) * 0.1,
  
  # Minimum temperature: seasonal
  tmin = 10 + 8 * sin(yday(date) * 2 * pi / 365 - pi/2) + 
         rnorm(n_days, 0, 2)
)

# Add extreme events
climate_data$prcp[100] <- 150
climate_data$tmax[500:505] <- 42
climate_data$tmin[800:803] <- -8

head(climate_data)
## # A tibble: 6 × 4
##   date        prcp  tmax   tmin
##   <date>     <dbl> <dbl>  <dbl>
## 1 2000-01-01 0.860 11.3   2.25 
## 2 2000-01-02 5.30   5.77  1.95 
## 3 2000-01-03 5.77   9.80  3.13 
## 4 2000-01-04 7.52   9.06  0.351
## 5 2000-01-05 3.28  11.3   5.38 
## 6 2000-01-06 9.03  10.5  -1.27

2. Precipitation Indices

2.1 Maximum 1-day Precipitation (Rx1day)

Calculates the annual maximum 1-day precipitation amount, following ETCCDI definition Rx1day.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

min_valid_years: Minimum years with valid data (default: 1)

Returns: A data.frame with columns: year, Rx1day

library(tidyextreme)

rx1day_result <- calculate_Rx1day(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(rx1day_result)
## # A tibble: 6 × 2
##    year Rx1day
##   <dbl>  <dbl>
## 1  2000  150  
## 2  2001   20.4
## 3  2002   21.2
## 4  2003   21.3
## 5  2004   18.4
## 6  2005   20.0

2.2 Maximum Consecutive 5-day Precipitation (Rx5day)

Calculates the annual maximum precipitation amount accumulated over 5 consecutive days, following ETCCDI definition Rx5day.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

Returns: A data.frame with columns: year, Rx5day

rx5day_result <- calculate_Rx5day(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(rx5day_result)
## # A tibble: 6 × 2
##    year Rx5day
##   <dbl>  <dbl>
## 1  2000  185. 
## 2  2001   57.8
## 3  2002   53.1
## 4  2003   63.7
## 5  2004   53.7
## 6  2005   52.2

2.3 Number of Heavy Precipitation Days (R10mm)

Counts the number of days per year when precipitation >= 10 mm, following ETCCDI definition R10mm.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string) (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

threshold: Precipitation threshold in mm (default: 10)

Returns: A data.frame with columns: year, R10mm

r10mm_result <- calculate_R10mm(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(r10mm_result)
## # A tibble: 6 × 2
##    year R10mm
##   <dbl> <int>
## 1  2000    17
## 2  2001    22
## 3  2002    18
## 4  2003    27
## 5  2004    21
## 6  2005    18

2.4 Number of Very Heavy Precipitation Days (R20mm)

Counts the number of days per year when precipitation >= 20 mm, following ETCCDI definition R20mm.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

threshold: Precipitation threshold in mm (default: 20)

Returns: A data.frame with columns: year, R20mm

r20mm_result <- calculate_R20mm(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(r20mm_result)
## # A tibble: 6 × 2
##    year R20mm
##   <dbl> <int>
## 1  2000     1
## 2  2001     1
## 3  2002     1
## 4  2003     2
## 5  2004     0
## 6  2005     0

2.5 Number of Days with Precipitation >= 1mm (R1mm)

Counts the number of days per year when precipitation >= 1 mm, representing wet days.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

threshold: Precipitation threshold in mm (default: 1)

Returns: A data.frame with columns: year, R1mm

r1mm_result <- calculate_R1mm(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(r1mm_result)
## # A tibble: 6 × 2
##    year  R1mm
##   <dbl> <int>
## 1  2000   234
## 2  2001   232
## 3  2002   223
## 4  2003   221
## 5  2004   236
## 6  2005   235

2.6 Consecutive Dry Days (CDD)

Calculates statistics for dry spells (consecutive days with precipitation < 1 mm), following ETCCDI definition CDD.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

dry_threshold: Threshold for dry day in mm (default: 1)

Returns: A data.frame with columns: year, CDD_max, CDD_mean, CDD_median, n_dry_spells

cdd_result <- calculate_CDD(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(cdd_result)
## # A tibble: 6 × 5
##    year CDD_max CDD_mean CDD_median n_dry_spells
##   <dbl>   <int>    <dbl>      <dbl>        <int>
## 1  2000      22     3.77          2           35
## 2  2001      18     3.91          2           34
## 3  2002      21     4.73          3           30
## 4  2003      36     4.97          3           29
## 5  2004      23     3.71          2           35
## 6  2005      13     3.94          3           33

2.7 Consecutive Wet Days (CWD)

Calculates statistics for wet spells (consecutive days with precipitation >= 1 mm), following ETCCDI definition CWD.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

wet_threshold: Threshold for wet day in mm (default: 1)

Returns: A data.frame with columns: year, CWD_max, CWD_mean, CWD_median, n_wet_spells

cwd_result <- calculate_CWD(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(cwd_result)
## # A tibble: 6 × 5
##    year CWD_max CWD_mean CWD_median n_wet_spells
##   <dbl>   <int>    <dbl>      <dbl>        <int>
## 1  2000     172     6.69          1           35
## 2  2001     164     6.63          2           35
## 3  2002     177     7.43          1           30
## 4  2003     171     7.37          1           30
## 5  2004     177     6.74          1           35
## 6  2005     179     6.91          1           34

2.8 Simple Daily Intensity Index (SDII)

Calculates the mean precipitation amount on wet days (>= 1 mm), following ETCCDI definition SDII.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

wet_threshold: Threshold for wet day in mm (default: 1)

Returns: A data.frame with columns: year, SDII, wet_days, total_prcp

sdii_result <- calculate_SDII(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(sdii_result)
## # A tibble: 6 × 4
##    year  SDII wet_days total_prcp
##   <dbl> <dbl>    <int>      <dbl>
## 1  2000  5.92      234      1398.
## 2  2001  5.88      232      1376.
## 3  2002  5.70      223      1285.
## 4  2003  6.15      221      1376.
## 5  2004  5.58      236      1329.
## 6  2005  5.54      235      1312.

2.9 Annual Precipitation Statistics

Calculates comprehensive annual precipitation statistics including total precipitation, number of wet days, mean daily precipitation, and maximum daily precipitation.

Parameters:

df: Data frame with precipitation data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

prcp_col: Name of precipitation column (daily data) (string)

precip_col: Name of precipitation column (hourly data) (string)

wet_threshold: Threshold for wet day in mm (default: 1)

Returns: A data.frame with columns: year, PRCP_total, PRCP_days, PRCP_mean, PRCP_max

prcpstats_result <- calculate_PRCPstats(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  prcp_col = "prcp"
)

head(prcpstats_result)
## # A tibble: 6 × 5
##    year PRCP_total PRCP_days PRCP_mean PRCP_max
##   <dbl>      <dbl>     <int>     <dbl>    <dbl>
## 1  2000      1398.       234      3.82    150  
## 2  2001      1376.       232      3.77     20.4
## 3  2002      1285.       223      3.52     21.2
## 4  2003      1376.       221      3.77     21.3
## 5  2004      1329.       236      3.63     18.4
## 6  2005      1312.       235      3.59     20.0

3. Temperature Indices

3.1 Number of Summer Days (TX > 25 °C)

Counts the number of days per year when daily maximum temperature exceeds 25°C, following ETCCDI definition SU25.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

threshold: Temperature threshold in  °C (default: 25)

Returns: A tibble with columns: year, TX25

tx25_result <- calculate_TX25(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax"
)

head(tx25_result)
## # A tibble: 6 × 2
##    year  TX25
##   <dbl> <int>
## 1  2000   115
## 2  2001   119
## 3  2002   122
## 4  2003   118
## 5  2004   117
## 6  2005   122

3.2 Number of Tropical Nights (TN > 20 °C)

Counts the number of days per year when daily minimum temperature exceeds 20 °C, following ETCCDI definition TR20.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmin_col: Name of minimum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

threshold: Temperature threshold in  °C (default: 20)

Returns: A tibble with columns: year, TR20

tr20_result <- calculate_TR20(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmin_col = "tmin"
)

head(tr20_result)
## # A tibble: 6 × 2
##    year  TR20
##   <dbl> <int>
## 1  2000     6
## 2  2001     4
## 3  2002    10
## 4  2003    15
## 5  2004     8
## 6  2005    10

3.3 Monthly Maximum Value of Daily Maximum Temperature (TXx)

Calculates the highest daily maximum temperature for each month, following ETCCDI definition TXx.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

min_days: Minimum days per month for valid calculation (default: 20)

Returns: A tibble with columns: year, month, TXx

txx_result <- calculate_TXx(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax"
)

head(txx_result)
## # A tibble: 6 × 3
##    year month   TXx
##   <dbl> <dbl> <dbl>
## 1  2000     1  14.4
## 2  2000     2  19.6
## 3  2000     3  22.7
## 4  2000     4  27.2
## 5  2000     5  33.8
## 6  2000     6  36.2

3.4 Monthly Minimum Value of Daily Minimum Temperature (TNn)

Calculates the lowest daily minimum temperature for each month, following ETCCDI definition TNn.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmin_col: Name of minimum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

min_days: Minimum days per month for valid calculation (default: 20)

Returns: A tibble with columns: year, month, TNn

tnn_result <- calculate_TNn(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmin_col = "tmin"
)

head(tnn_result)
## # A tibble: 6 × 3
##    year month   TNn
##   <dbl> <dbl> <dbl>
## 1  2000     1 -1.27
## 2  2000     2 -4.54
## 3  2000     3  4.55
## 4  2000     4  8.25
## 5  2000     5 11.7 
## 6  2000     6 13.6

3.5 Number of Days with Temperature >= 30 °C (TX30)

Counts the number of days per year when daily temperature is greater than or equal to 30 °C.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

Returns: A tibble with columns: year, TX30

tx30_result <- calculate_TX30(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax"
)

head(tx30_result)
## # A tibble: 6 × 2
##    year  TX30
##   <dbl> <int>
## 1  2000    38
## 2  2001    39
## 3  2002    43
## 4  2003    37
## 5  2004    34
## 6  2005    50

3.6 Number of Days with Temperature >= 35 °C (TX35)

Counts the number of days per year when daily temperature is greater than or equal to 35 °C.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

Returns: A tibble with columns: year, TX35

tx35_result <- calculate_TX35(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax"
)

head(tx35_result)
## # A tibble: 6 × 2
##    year  TX35
##   <dbl> <int>
## 1  2000     2
## 2  2001     8
## 3  2002     2
## 4  2003     3
## 5  2004     4
## 6  2005     3

3.7 Number of Days with Temperature < 0 °C (TN0)

Counts the number of days per year when daily temperature is less than 0 °C.

Parameters:

df: Data frame with climate data

frequency Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmin_col: Name of minimum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

Returns: A tibble with columns: year, TN0

tn0_result <- calculate_TN0(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmin_col = "tmin"
)

head(tn0_result)
## # A tibble: 6 × 2
##    year   TN0
##   <dbl> <int>
## 1  2000     9
## 2  2001     9
## 3  2002    13
## 4  2003     8
## 5  2004     6
## 6  2005     7

3.8 Diurnal Temperature Range (DTR)

Calculates the mean and standard deviation of daily temperature range (difference between maximum and minimum temperature) per year.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

tmin_col: Name of minimum temperature column (daily data) (string)

temp_col: Name of temperature column (hourly data)

Returns: A tibble with columns: year, DTR_mean, DTR_sd, n_days

dtr_result <- calculate_DTR(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax",
  tmin_col = "tmin"
)

head(dtr_result)
## # A tibble: 6 × 4
##    year DTR_mean DTR_sd n_days
##   <dbl>    <dbl>  <dbl>  <int>
## 1  2000    10.2    3.68    366
## 2  2001    10.5    4.23    365
## 3  2002    10.4    4.16    365
## 4  2003     9.96   3.67    365
## 5  2004    10.0    3.67    366
## 6  2005    10.4    3.78    365

3.9 90th Percentile of Daily Temperature (TX90p)

Calculates the 90th percentile of daily temperature per year, used as threshold for extreme warm days.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

Returns: A tibble with columns: year, TX90p

tx90p_result <- calculate_TX90p(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax"
)

head(tx90p_result)
## # A tibble: 6 × 2
##    year TX90p
##   <dbl> <dbl>
## 1  2000  30.1
## 2  2001  30.0
## 3  2002  30.6
## 4  2003  30.0
## 5  2004  29.8
## 6  2005  30.9

3.10 10th Percentile of Daily Temperature (TN10p)

Calculates the 10th percentile of daily temperature per year, used as threshold for extreme cold nights.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmin_col: Name of minimum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

Returns: A tibble with columns: year, TN10p

tn10p_result <- calculate_TN10p(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmin_col = "tmin"
)

head(tn10p_result)
## # A tibble: 6 × 2
##    year TN10p
##   <dbl> <dbl>
## 1  2000  2.24
## 2  2001  1.72
## 3  2002  2.17
## 4  2003  2.22
## 5  2004  2.34
## 6  2005  2.38

3.11 Warm Spell Duration Index (WSDI)

Calculates the number of days with at least 6 consecutive days where temperature exceeds the 90th percentile, following ETCCDI definition WSDI.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col: Name of maximum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

window_days: Window size for percentile calculation (default: 30)

min_consecutive: Minimum consecutive days for warm spell (default: 6)

Returns: A tibble with columns: year, WSDI, n_spells, mean_spell_length

wsdi_result <- calculate_WSDI(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax",
  window_days = 30,
  min_consecutive = 6
)

head(wsdi_result)
## # A tibble: 0 × 4
## # ℹ 4 variables: year <dbl>, WSDI <int>, n_spells <int>,
## #   mean_spell_length <dbl>

3.12 Cold Spell Duration Index (CSDI)

Calculates the number of days with at least 6 consecutive days where temperature is below the 10th percentile, following ETCCDI definition CSDI.

Parameters:

df: Data frame with climate data

frequency: Temporal frequency "daily" or "hourly" (string)

time_col: Name of the time column (string). For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmin_col: Name of minimum temperature column (daily data) (string)

temp_col: Name of temperature column (for single temp or hourly) (string)

window_days: Window size for percentile calculation (default: 30)

min_consecutive: Minimum consecutive days for cold spell (default: 6)

Returns: A tibble with columns: year, CSDI, n_spells, mean_spell_length

csdi_result <- calculate_CSDI(
  df = climate_data,
  frequency = "daily",
  time_col = "date",
  tmin_col = "tmin",
  window_days = 30,
  min_consecutive = 6
)

head(csdi_result)
## # A tibble: 0 × 4
## # ℹ 4 variables: year <dbl>, CSDI <int>, n_spells <int>,
## #   mean_spell_length <dbl>

4. Visualizing Results

Let’s visualize some of the calculated indices to see trends over time:

library(ggplot2)
library(tidyr)
library(dplyr)
# Prepare data for visualization
precip_data <- rx1day_result |>
  left_join(r10mm_result, by = "year") |>
  left_join(sdii_result |> select(year, SDII), by = "year")

# Convert to long format for plotting
precip_long <- precip_data |>
  pivot_longer(cols = -year, names_to = "index", values_to = "value")

# Plot precipitation indices
ggplot(precip_long, aes(x = year, y = value, color = index)) +
  geom_line(size = 1) +
  geom_point(size = 2) +
  facet_wrap(~index, scales = "free_y", ncol = 1) +
  labs(title = "Precipitation Indices Over Time",
       x = "Year",
       y = "Value") +
  theme_minimal() +
  theme(legend.position = "none")

5. Summary

The tidyextreme package provides a comprehensive set of functions for calculating climate extreme indices. All functions follow ETCCDI definitions and return tidy data frames for easy analysis and visualization.

This vignette demonstrates the basic usage of all functions in the tidyextreme package. For more detailed information about each function, run in R.

Feedback, Issues, and Support

The tidyextreme package is under active development. Feedback and contributions are welcome!

Thank you for using tidyextreme!

6. References

All indices in the tidyextreme package follow the definitions from the Expert Team on Climate Change Detection and Indices (ETCCDI).

For more information about the ETCCDI and the official definitions of these indices, please refer to:

ETCCDI Official Website: https://etccdi.pacificclimate.org/

Climate Change Indices: Definitions and methods available at https://etccdi.pacificclimate.org/list_27_indices.shtml

Key References:

Zhang, X., Alexander, L., Hegerl, G.C., Jones, P., Tank, A.K., Peterson, T.C., Trewin, B., and Zwiers, F.W. (2011). Indices for monitoring changes in extremes based on daily temperature and precipitation data. WIREs Climate Change, 2(6), 851-870. https://doi.org/10.1002/wcc.147

Klein Tank, A.M.G., Zwiers, F.W., and Zhang, X. (2009). Guidelines on Analysis of extremes in a changing climate in support of informed decisions for adaptation. World Meteorological Organization, WMO-TD No. 1500, 56 pp.

The R package climdex.pcic which also implements ETCCDI indices: https://cran.r-project.org/package=climdex.pcic (not available anymore on CRAN)

## tidyextreme version: 1.0.0