rx5day: Calculate Rx5day Index

View source: R/rIACI.R

rx5dayR Documentation

Calculate Rx5day Index

Description

Calculates the maximum consecutive 5-day precipitation amount.

Usage

rx5day(ci, freq = c("monthly", "annual"), center_mean_on_last_day = FALSE)

Arguments

ci

List. Climate input object created by climate_input.

freq

Character. Frequency of calculation, either "monthly" or "annual".

center_mean_on_last_day

Logical. Whether to center the mean on the last day (default is FALSE).

Value

Data frame with dates and calculated Rx5day values.

Examples


# 1. Generate a daily date sequence from 1960-01-01 to 2020-12-31
dates <- seq.Date(
  from = as.Date("1960-01-01"),
  to   = as.Date("2020-12-31"),
  by   = "day"
)

# 2. Create random weather data for each date
n <- length(dates)
tmax <- runif(n, min = 5, max = 40)
tmin <- runif(n, min = -10,  max = 5)
# Example: use a Poisson distribution to simulate precipitation
prec <- rpois(n, lambda = 2)
# Random wind speeds, e.g., 0 to 10 m/s
wind <- runif(n, min = 0, max = 10)

# 3. Construct the climate_input object
ci <- climate_input(
  tmax  = tmax,
  tmin  = tmin,
  prec  = prec,
  wind  = wind,
  dates = dates
)
# Then:
# 4. Calculate monthly Rx5day index
rx5day_values <- rx5day(ci, freq = "monthly")


rIACI documentation built on April 12, 2025, 9:16 a.m.