| Title: | Unified Climate Indices for Temperature, Precipitation, and Drought |
|---|---|
| Description: | Compute the standard suite of climate indices from daily weather observations. Provides the canonical 'ETCCDI' 27 (Expert Team on Climate Change Detection and Indices), the 'ET-SCI' heatwave and cold-wave families plus the Excess Heat Factor of Nairn and Fawcett (2013), and agroclimatic, drought, and human-comfort families. Drought indices ('SPI', 'SPEI') accept a choice of distribution (gamma or Pearson III for SPI; log-logistic or generalised extreme value for SPEI). Reference evapotranspiration is available via Hargreaves and the FAO-56 Penman-Monteith method (Allen et al. 1998). Percentile-based indices support the Zhang (2005) in-base bootstrap. Daily inputs are numeric vectors plus a 'Date' vector; outputs are tidy data frames. Optional gridded support via 'terra' applies any index over a 'SpatRaster' and reads 'netCDF' input. No external API calls; pairs with data packages such as 'readnoaa'. References: Alexander et al. (2006) <doi:10.1029/2005JD006290>; Zhang et al. (2011) <doi:10.1002/wcc.147>; Zhang et al. (2005) <doi:10.1175/JCLI3366.1>. |
| Authors: | Charles Coverdale [aut, cre] |
| Maintainer: | Charles Coverdale <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-30 15:07:07 UTC |
| Source: | https://github.com/charlescoverdale/climatekit |
Compute a daily climatekit index function for every cell in a
SpatRaster x whose layers represent successive days, and return
the per-period results as a SpatRaster. The supplied function fun
must accept a numeric vector and a Date vector and return a data
frame with period and value columns (the standard climatekit
shape).
ck_apply_grid(x, fun, dates, ...)ck_apply_grid(x, fun, dates, ...)
x |
A SpatRaster. Layers correspond one-to-one with |
fun |
A |
dates |
Date vector of length |
... |
Additional named arguments forwarded to |
All cells must share the same dates. Cells that are entirely NA
are returned as NA. Run-time scales linearly with the number of
cells; for very large grids consider sub-setting first.
A SpatRaster with one layer per output period (layer names are the period labels).
if (requireNamespace("terra", quietly = TRUE)) { dates <- seq(as.Date("2024-01-01"), as.Date("2024-12-31"), by = "day") n <- length(dates) # Tiny 2x2 SpatRaster of synthetic daily Tmax r <- terra::rast(nrows = 2, ncols = 2, nlyrs = n, xmin = 0, xmax = 2, ymin = 0, ymax = 2) set.seed(1) for (i in seq_len(n)) { terra::values(r[[i]]) <- rnorm(4, 15, 5) } txx_r <- ck_apply_grid(r, ck_txx, dates = dates, period = "annual") terra::nlyr(txx_r) }if (requireNamespace("terra", quietly = TRUE)) { dates <- seq(as.Date("2024-01-01"), as.Date("2024-12-31"), by = "day") n <- length(dates) # Tiny 2x2 SpatRaster of synthetic daily Tmax r <- terra::rast(nrows = 2, ncols = 2, nlyrs = n, xmin = 0, xmax = 2, ymin = 0, ymax = 2) set.seed(1) for (i in seq_len(n)) { terra::values(r[[i]]) <- rnorm(4, 15, 5) } txx_r <- ck_apply_grid(r, ck_txx, dates = dates, period = "annual") terra::nlyr(txx_r) }
Returns a data frame listing every index that climatekit can compute,
along with its category, unit, and a short description.
ck_available()ck_available()
A data frame with columns index, category, unit, and
description.
ck_available()ck_available()
The Branas index combines temperature and precipitation during the growing season to estimate disease pressure (especially downy mildew) in vineyards. It is the sum of (monthly mean temperature) times (monthly precipitation total) over the five months of the growing season: April-August in the Northern Hemisphere; October-February in the Southern Hemisphere. The Southern Hemisphere season spans two calendar years and is reported under the year in which it starts.
ck_branas(precip, tavg, dates, lat = 50)ck_branas(precip, tavg, dates, lat = 50)
precip |
Numeric vector of daily precipitation (mm). |
tavg |
Numeric vector of daily mean temperatures (degrees C). |
dates |
Date vector of the same length as |
lat |
Numeric. Latitude in decimal degrees, used to select the hemisphere convention. Default 50 (Northern Hemisphere). |
A data frame with columns period, value, index, and unit.
Branas, J., Bernon, G., & Levadoux, L. (1946). Elements de viticulture generale.
dates <- seq(as.Date("2024-04-01"), as.Date("2024-08-31"), by = "day") set.seed(42) tavg <- rnorm(length(dates), mean = 12, sd = 3) precip <- rgamma(length(dates), shape = 0.5, rate = 0.2) ck_branas(precip, tavg, dates)dates <- seq(as.Date("2024-04-01"), as.Date("2024-08-31"), by = "day") set.seed(42) tavg <- rnorm(length(dates), mean = 12, sd = 3) precip <- rgamma(length(dates), shape = 0.5, rate = 0.2) ck_branas(precip, tavg, dates)
Filter the comprehensive climatekit index catalogue (see
ck_catalogue()) by sector, applicable standard (ETCCDI / ET-SCI /
agroclimatic / comfort / drought / energy), or a free-text search
across the function name, full name, and ETCCDI code.
ck_browse(sector = NULL, standard = NULL, search = NULL)ck_browse(sector = NULL, standard = NULL, search = NULL)
sector |
Character (length 1) or |
standard |
Character (length 1) or |
search |
Character (length 1) or |
The catalogue, filtered to matching rows. Same column structure
as ck_catalogue().
ck_browse(standard = "ETCCDI") ck_browse(sector = "agriculture") ck_browse(search = "heat")ck_browse(standard = "ETCCDI") ck_browse(sector = "agriculture") ck_browse(search = "heat")
Returns the complete catalogue of climate indices implemented by
climatekit, with one row per ck_* function and columns covering
the canonical short code (where applicable), the full name, the
index family, the relevant sector, the unit, the source standard,
and the principal citation key.
ck_catalogue()ck_catalogue()
Use ck_browse() to filter by sector or standard.
A data frame with columns ck_function, code, name,
category, sector, unit, standard, and citation_key.
tab <- ck_catalogue() head(tab) # Tally indices by standard: table(tab$standard)tab <- ck_catalogue() head(tab) # Tally indices by standard: table(tab$standard)
A generic dispatcher that calls the appropriate ck_* function based on
a string index name. Useful for programmatic workflows where the index
is selected at runtime.
ck_compute(data, index, ...)ck_compute(data, index, ...)
data |
A named list or data frame containing the required input
vectors. Column names should match function argument names (e.g.
|
index |
Character. Name of the index to compute (e.g.
|
... |
Additional arguments passed to the underlying function (e.g.
|
A data frame as returned by the underlying ck_* function.
d <- data.frame( dates = as.Date("2024-01-01") + 0:9, tmin = c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) ) ck_compute(d, "frost_days")d <- data.frame( dates = as.Date("2024-01-01") + 0:9, tmin = c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) ) ck_compute(d, "frost_days")
Convert between Celsius, Fahrenheit, and Kelvin.
ck_convert_temp(x, from, to)ck_convert_temp(x, from, to)
x |
Numeric vector of temperatures. |
from |
Character. Source unit: |
to |
Character. Target unit: |
Numeric vector of converted temperatures.
ck_convert_temp(c(0, 100), from = "C", to = "F") ck_convert_temp(32, from = "F", to = "C")ck_convert_temp(c(0, 100), from = "C", to = "F") ck_convert_temp(32, from = "F", to = "C")
Sum of (Tavg - base) for all days where daily average temperature is
above the base temperature (default 18 degrees C).
ck_cooling_degree_days(tavg, dates, base = 18, period = "annual")ck_cooling_degree_days(tavg, dates, base = 18, period = "annual")
tavg |
Numeric vector of daily average temperatures (degrees C). |
dates |
Date vector of the same length as |
base |
Numeric. Base temperature in degrees C (default 18). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-07-01") + 0:9 tavg <- c(25, 30, 22, 20, 28, 19, 32, 17, 35, 27) ck_cooling_degree_days(tavg, dates)dates <- as.Date("2024-07-01") + 0:9 tavg <- c(25, 30, 22, 20, 28, 19, 32, 17, 35, 27) ck_cooling_degree_days(tavg, dates)
ETCCDI canonical index CSDI. Annual count of days in spans of at least
six consecutive days where daily Tmin falls below the 10th percentile of
the calendar-day distribution from a reference period (default 1961 to
1990). Cold-side counterpart to ck_wsdi().
ck_csdi(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 6L)ck_csdi(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 6L)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 6, the ETCCDI standard). |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_csdi(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_csdi(tmin, dates))
ET-SCI cold-wave family index. mode = "excess" (default) returns
the peak (threshold - Tmin) across cold-wave days, expressed as a
positive magnitude. mode = "absolute" returns the minimum raw
Tmin across cold-wave days (the coldest event-day value). Returns
NA for years with no cold waves.
ck_cwa( tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )ck_cwa( tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
mode |
One of |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwa(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwa(tmin, dates))
ET-SCI cold-wave family index. Length in days of the longest
cold-wave event in each year (see ck_cwn() for the cold-wave
definition).
ck_cwd(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)ck_cwd(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
Note: the same letters CWD also denote the ETCCDI Consecutive Wet
Days precipitation index, which is unrelated and is implemented in
ck_wet_days(). These are two different indices that share an
acronym in the climate-extremes literature.
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwd(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwd(tmin, dates))
ET-SCI cold-wave family index. Annual total number of days inside any
cold-wave event (see ck_cwn() for the cold-wave definition).
ck_cwf(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)ck_cwf(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwf(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwf(tmin, dates))
ET-SCI cold-wave family index. mode = "excess" (default) returns
the mean of (threshold - Tmin) across cold-wave days, expressed as
a positive magnitude. mode = "absolute" returns the mean raw
Tmin across cold-wave days. Returns NA for years with no cold
waves.
ck_cwm( tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )ck_cwm( tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
mode |
One of |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwm(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwm(tmin, dates))
ET-SCI cold-wave family index. Annual count of distinct cold-wave events, where a cold wave is a span of at least three consecutive days with daily Tmin below the 10th percentile of the calendar-day distribution from a reference period (default 1961 to 1990).
ck_cwn(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)ck_cwn(tmin, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwn(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_cwn(tmin, dates))
Mean daily temperature range (Tmax - Tmin) per period.
ck_diurnal_range(tmin, tmax, dates, period = "annual")ck_diurnal_range(tmin, tmax, dates, period = "annual")
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tmin <- c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) tmax <- c(5, 10, 6, 12, 4, 8, 9, 3, 7, 6) ck_diurnal_range(tmin, tmax, dates)dates <- as.Date("2024-01-01") + 0:9 tmin <- c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) tmax <- c(5, 10, 6, 12, 4, 8, 9, 3, 7, 6) ck_diurnal_range(tmin, tmax, dates)
Maximum number of consecutive days with precipitation below a threshold.
ck_dry_days(precip, dates, threshold = 1, period = "annual")ck_dry_days(precip, dates, threshold = 1, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
threshold |
Numeric. Dry day threshold in mm (default 1). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 0, 5, 0, 0, 0, 2, 0, 0, 0) ck_dry_days(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 0, 5, 0, 0, 0, 2, 0, 0, 0) ck_dry_days(precip, dates)
Annual summary of the daily Excess Heat Factor heatwave intensity metric. EHF combines a 3-day mean daily temperature anomaly above the 95th percentile of the reference period with an acclimatisation term (3-day mean minus previous 30-day mean). Positive EHF days indicate heatwave conditions; larger values indicate more severe or less-acclimatised events. This is the operational heatwave metric used by the Australian Bureau of Meteorology.
ck_ehf( tmax, tmin, dates, ref_start = 1961L, ref_end = 1990L, stat = c("max", "n_positive", "sum_positive") )ck_ehf( tmax, tmin, dates, ref_start = 1961L, ref_end = 1990L, stat = c("max", "n_positive", "sum_positive") )
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
stat |
One of |
Three annual summaries are exposed via the stat argument:
"max" (default): peak EHF in the year. Strongest
single-day intensity.
"n_positive": count of days with EHF > 0. A
frequency-of-heatwave-conditions measure.
"sum_positive": sum of EHF on days with EHF > 0.
A severity-weighted total.
A data frame with columns period, value, index, and unit.
Nairn, J. R., & Fawcett, R. J. B. (2013). Defining heatwaves: heatwave defined as a heat-impact event servicing all community and business sectors in Australia. CAWCR Technical Report No. 060.
Perkins, S. E., & Alexander, L. V. (2013). On the measurement of heatwaves. Journal of Climate, 26(13), 4500-4517. doi:10.1175/JCLI-D-12-00383.1.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") s <- 2 * pi * as.integer(format(dates, "%j")) / 365 tmax <- 20 + 10 * sin(s) + rnorm(length(dates)) tmin <- 10 + 8 * sin(s) + rnorm(length(dates)) tail(ck_ehf(tmax, tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") s <- 2 * pi * as.integer(format(dates, "%j")) / 365 tmax <- 20 + 10 * sin(s) + rnorm(length(dates)) tmin <- 10 + 8 * sin(s) + rnorm(length(dates)) tail(ck_ehf(tmax, tmin, dates))
Returns the 27 canonical Expert Team on Climate Change Detection and
Indices (ETCCDI) indices as documented by Alexander et al. (2006) and
Zhang et al. (2011), with each row showing the canonical short code,
full name, input variable, unit, definition, and the corresponding
climatekit function (or NA where the index is not yet
implemented).
ck_etccdi_27()ck_etccdi_27()
Use this table to audit coverage, locate the ck_* function for a
given ETCCDI code, or filter to indices that climatekit currently
implements: subset(ck_etccdi_27(), !is.na(ck_function)).
A data frame with one row per canonical ETCCDI index and
columns code, name, variable, unit, definition,
ck_function, and status.
Alexander, L. V. et al. (2006). Global observed changes in daily climate extremes of temperature and precipitation. Journal of Geophysical Research: Atmospheres, 111(D5). doi:10.1029/2005JD006290.
Zhang, X. et al. (2011). Indices for monitoring changes in extremes based on daily temperature and precipitation data. Wiley Interdisciplinary Reviews: Climate Change, 2(6), 851-870. doi:10.1002/wcc.147.
tab <- ck_etccdi_27() head(tab) # Indices currently implemented in climatekit: subset(tab, !is.na(ck_function))[, c("code", "ck_function")] # Coverage: table(tab$status)tab <- ck_etccdi_27() head(tab) # Indices currently implemented in climatekit: subset(tab, !is.na(ck_function))[, c("code", "ck_function")] # Coverage: table(tab$status)
A simplified fire danger proxy based on temperature, humidity, wind speed, and recent precipitation. This is NOT the Canadian Forest Fire Weather Index (Van Wagner 1987); for the full FWI system, use the cffdrs package.
ck_fire_danger(tavg, humidity, wind_speed, precip)ck_fire_danger(tavg, humidity, wind_speed, precip)
tavg |
Numeric vector of temperatures (degrees C). |
humidity |
Numeric vector of relative humidity (percent, 0-100). |
wind_speed |
Numeric vector of wind speeds (km/h). |
precip |
Numeric vector of daily precipitation (mm). |
A data frame with columns value, index, and unit.
ck_fire_danger( tavg = c(30, 25, 35), humidity = c(20, 40, 15), wind_speed = c(25, 10, 30), precip = c(0, 5, 0) )ck_fire_danger( tavg = c(30, 25, 35), humidity = c(20, 40, 15), wind_speed = c(25, 10, 30), precip = c(0, 5, 0) )
Day of year of the first autumn frost (Tmin < 0 degrees C) in each
year. Hemisphere is selected by lat: in the Northern Hemisphere
(lat >= 0) the search starts at July 1 (DOY 183); in the Southern
Hemisphere it starts at March 1 (DOY 60), matching the autumn entry
for each.
ck_first_frost(tmin, dates, lat = 50)ck_first_frost(tmin, dates, lat = 50)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
lat |
Numeric. Latitude in decimal degrees, used to select the hemisphere convention. Default 50 (Northern Hemisphere). |
A data frame with columns period, value (day of year),
date (the frost date), index, and unit.
dates <- seq(as.Date("2024-07-01"), as.Date("2024-12-31"), by = "day") set.seed(42) tmin <- 15 - seq_along(dates) * 0.15 + rnorm(length(dates), sd = 3) ck_first_frost(tmin, dates)dates <- seq(as.Date("2024-07-01"), as.Date("2024-12-31"), by = "day") set.seed(42) tmin <- 15 - seq_along(dates) * 0.15 + rnorm(length(dates), sd = 3) ck_first_frost(tmin, dates)
Convenience wrapper that delegates to terra::rast(). Reads the
file at path and returns a SpatRaster, optionally restricted to a
single variable. terra and ncdf4 must be installed (both are listed
in Suggests:).
ck_from_netcdf(path, var = NULL)ck_from_netcdf(path, var = NULL)
path |
Character. Path to a netCDF file. |
var |
Character or |
A SpatRaster (one layer per time step in the netCDF file).
## Not run: r <- ck_from_netcdf("tas_day.nc", var = "tas") terra::nlyr(r) # number of daily layers ## End(Not run)## Not run: r <- ck_from_netcdf("tas_day.nc", var = "tas") terra::nlyr(r) # number of daily layers ## End(Not run)
Count the number of days where minimum temperature is below 0 degrees C.
ck_frost_days(tmin, dates, period = "annual")ck_frost_days(tmin, dates, period = "annual")
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tmin <- c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) ck_frost_days(tmin, dates)dates <- as.Date("2024-01-01") + 0:9 tmin <- c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) ck_frost_days(tmin, dates)
Sum of (Tavg - base) for all days where daily average temperature is
above the base temperature (default 10 degrees C).
ck_growing_degree_days(tavg, dates, base = 10, period = "annual")ck_growing_degree_days(tavg, dates, base = 10, period = "annual")
tavg |
Numeric vector of daily average temperatures (degrees C). |
dates |
Date vector of the same length as |
base |
Numeric. Base temperature in degrees C (default 10). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-07-01") + 0:9 tavg <- c(15, 20, 8, 12, 25, 9, 30, 11, 22, 18) ck_growing_degree_days(tavg, dates)dates <- as.Date("2024-07-01") + 0:9 tavg <- c(15, 20, 8, 12, 25, 9, 30, 11, 22, 18) ck_growing_degree_days(tavg, dates)
Compute the growing season length following the ETCCDI definition: the number of days between the first occurrence of at least 6 consecutive days with daily mean temperature above 5 degrees C and the first span of 6 consecutive days with Tmean below 5 degrees C after July 1 (Northern Hemisphere) or January 1 (Southern Hemisphere). Calculated per year.
ck_growing_season(tavg, dates, lat = 50)ck_growing_season(tavg, dates, lat = 50)
tavg |
Numeric vector of daily mean temperatures (degrees C). |
dates |
Date vector of the same length as |
lat |
Numeric. Latitude in decimal degrees (used to determine hemisphere for end-of-season rule). Default 50 (Northern Hemisphere). |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:364 set.seed(42) tavg <- sin(seq(0, 2 * pi, length.out = 365)) * 15 + 5 ck_growing_season(tavg, dates)dates <- as.Date("2024-01-01") + 0:364 set.seed(42) tavg <- sin(seq(0, 2 * pi, length.out = 365)) * 15 + 5 ck_growing_season(tavg, dates)
Compute the heat index (apparent temperature) using the Rothfusz regression equation used by the US National Weather Service.
ck_heat_index(tavg, humidity)ck_heat_index(tavg, humidity)
tavg |
Numeric vector of temperatures (degrees C). |
humidity |
Numeric vector of relative humidity (percent, 0-100). |
A data frame with columns value, index, and unit.
Rothfusz, L. P. (1990). The heat index equation. NWS Technical Attachment SR 90-23.
ck_heat_index(tavg = c(30, 35, 40), humidity = c(60, 70, 50))ck_heat_index(tavg = c(30, 35, 40), humidity = c(60, 70, 50))
Sum of (base - Tavg) for all days where daily average temperature is
below the base temperature (default 18 degrees C).
ck_heating_degree_days(tavg, dates, base = 18, period = "annual")ck_heating_degree_days(tavg, dates, base = 18, period = "annual")
tavg |
Numeric vector of daily average temperatures (degrees C). |
dates |
Date vector of the same length as |
base |
Numeric. Base temperature in degrees C (default 18). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tavg <- c(5, 10, 15, 20, 8, 12, 18, 3, 25, 7) ck_heating_degree_days(tavg, dates)dates <- as.Date("2024-01-01") + 0:9 tavg <- c(5, 10, 15, 20, 8, 12, 18, 3, 25, 7) ck_heating_degree_days(tavg, dates)
Count of days with precipitation at or above a threshold (default 10 mm).
ck_heavy_precip(precip, dates, threshold = 10, period = "annual")ck_heavy_precip(precip, dates, threshold = 10, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
threshold |
Numeric. Threshold in mm (default 10). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 12, 0, 15, 2, 0, 11, 4, 0) ck_heavy_precip(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 12, 0, 15, 2, 0, 11, 4, 0) ck_heavy_precip(precip, dates)
The Huglin index is used in viticulture to characterise the thermal potential of a region for grape growing. It is computed over the growing season (April 1 to September 30 in the Northern Hemisphere; October 1 to March 31 in the Southern Hemisphere).
ck_huglin(tmin, tmax, dates, lat)ck_huglin(tmin, tmax, dates, lat)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
lat |
Numeric. Latitude in decimal degrees (used to determine hemisphere and day-length coefficient). |
A data frame with columns period, value, index, and unit.
Huglin, P. (1978). Nouveau mode d'evaluation des possibilites heliothermiques d'un milieu viticole. Comptes Rendus de l'Academie d'Agriculture de France, 64, 1117-1126.
dates <- seq(as.Date("2024-04-01"), as.Date("2024-09-30"), by = "day") set.seed(42) tmin <- rnorm(length(dates), mean = 12, sd = 3) tmax <- tmin + runif(length(dates), 8, 15) ck_huglin(tmin, tmax, dates, lat = 45)dates <- seq(as.Date("2024-04-01"), as.Date("2024-09-30"), by = "day") set.seed(42) tmin <- rnorm(length(dates), mean = 12, sd = 3) tmax <- tmin + runif(length(dates), 8, 15) ck_huglin(tmin, tmax, dates, lat = 45)
Compute the Canadian humidex from temperature and dewpoint.
ck_humidex(tavg, dewpoint)ck_humidex(tavg, dewpoint)
tavg |
Numeric vector of temperatures (degrees C). |
dewpoint |
Numeric vector of dewpoint temperatures (degrees C). |
A data frame with columns value, index, and unit.
Masterson, J., & Richardson, F. A. (1979). Humidex: A method of quantifying human discomfort due to excessive heat and humidity. Environment Canada.
ck_humidex(tavg = c(30, 35), dewpoint = c(20, 25))ck_humidex(tavg = c(30, 35), dewpoint = c(20, 25))
ET-SCI heatwave family index. Reports the peak magnitude of daily
Tmax across all heatwave days in the year. mode = "excess"
(default) gives the maximum of (Tmax - threshold). mode = "absolute" gives the maximum raw Tmax across heatwave days
(matching Perkins-Alexander 2013). Returns NA for years with
no heatwaves.
ck_hwa( tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )ck_hwa( tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
mode |
One of |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwa(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwa(tmax, dates))
ET-SCI heatwave family index. Length in days of the longest heatwave
event in each year (see ck_hwn() for the heatwave definition).
ck_hwd(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)ck_hwd(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwd(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwd(tmax, dates))
ET-SCI heatwave family index. Annual total number of days inside any
heatwave event (see ck_hwn() for the heatwave definition).
ck_hwf(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)ck_hwf(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwf(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwf(tmax, dates))
ET-SCI heatwave family index. Reports the mean magnitude of daily
Tmax across all heatwave days in the year. mode = "excess"
(default) gives the mean of (Tmax - threshold), matching the
ET-SCI / climpact convention. mode = "absolute" gives the mean
raw Tmax across heatwave days, matching Perkins-Alexander (2013).
Returns NA for years with no heatwaves.
ck_hwm( tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )ck_hwm( tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L, mode = c("excess", "absolute") )
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
mode |
One of |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwm(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwm(tmax, dates))
ET-SCI heatwave family index. Annual count of distinct heatwave events, where a heatwave is a span of at least three consecutive days with daily Tmax above the 90th percentile of the calendar-day distribution from a reference period (default 1961 to 1990).
ck_hwn(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)ck_hwn(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 3L)
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 3, the ET-SCI standard). |
Single-threshold definition (TX-only). For the dual-threshold
Perkins-Alexander variant (TX and TN both above 90th percentile) see
climpact.
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwn(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_hwn(tmax, dates))
Count the number of days where maximum temperature is below 0 degrees C.
ck_ice_days(tmax, dates, period = "annual")ck_ice_days(tmax, dates, period = "annual")
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tmax <- c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) ck_ice_days(tmax, dates)dates <- as.Date("2024-01-01") + 0:9 tmax <- c(-2, 3, -1, 5, -3, 0, 2, -4, 1, -1) ck_ice_days(tmax, dates)
Day of year of the last spring frost (Tmin < 0 degrees C) in each
year. Hemisphere is selected by lat: in the Northern Hemisphere
the search runs up to July 1 (DOY 183); in the Southern Hemisphere
up to October 1 (DOY 274), matching the spring boundary for each.
ck_last_frost(tmin, dates, lat = 50)ck_last_frost(tmin, dates, lat = 50)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
lat |
Numeric. Latitude in decimal degrees, used to select the hemisphere convention. Default 50 (Northern Hemisphere). |
A data frame with columns period, value (day of year),
date (the frost date), index, and unit.
dates <- seq(as.Date("2024-01-01"), as.Date("2024-06-30"), by = "day") set.seed(42) tmin <- -10 + seq_along(dates) * 0.12 + rnorm(length(dates), sd = 3) ck_last_frost(tmin, dates)dates <- seq(as.Date("2024-01-01"), as.Date("2024-06-30"), by = "day") set.seed(42) tmin <- -10 + seq_along(dates) * 0.12 + rnorm(length(dates), sd = 3) ck_last_frost(tmin, dates)
Maximum precipitation recorded in a single day per period.
ck_max_1day_precip(precip, dates, period = "annual")ck_max_1day_precip(precip, dates, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 22, 0, 15, 25, 0, 11, 4, 30) ck_max_1day_precip(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 22, 0, 15, 25, 0, 11, 4, 30) ck_max_1day_precip(precip, dates)
Maximum precipitation total over any 5 consecutive days per period.
ck_max_5day_precip(precip, dates, period = "annual")ck_max_5day_precip(precip, dates, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 22, 0, 15, 25, 0, 11, 4, 30) ck_max_5day_precip(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 22, 0, 15, 25, 0, 11, 4, 30) ck_max_5day_precip(precip, dates)
Returns metadata (unit, category, description, reference) for a named climate index.
ck_metadata(index)ck_metadata(index)
index |
Character string. The index name (e.g. |
A list with elements index, category, unit, description,
and reference.
ck_metadata("frost_days")ck_metadata("frost_days")
Estimate daily PET using the Hargreaves-Samani equation, which requires only daily temperature extremes and latitude.
ck_pet(tmin, tmax, lat, dates)ck_pet(tmin, tmax, lat, dates)
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
lat |
Numeric. Latitude in decimal degrees. |
dates |
Date vector of the same length as |
A data frame with columns date, value, index, and unit.
Hargreaves, G. H., & Samani, Z. A. (1985). Reference crop evapotranspiration from temperature. Applied Engineering in Agriculture, 1(2), 96-99.
dates <- as.Date("2024-07-01") + 0:9 tmin <- c(15, 16, 14, 17, 15, 13, 16, 14, 15, 16) tmax <- c(30, 32, 28, 33, 31, 27, 34, 29, 30, 32) ck_pet(tmin, tmax, lat = 45, dates = dates)dates <- as.Date("2024-07-01") + 0:9 tmin <- c(15, 16, 14, 17, 15, 13, 16, 14, 15, 16) tmax <- c(30, 32, 28, 33, 31, 27, 34, 29, 30, 32) ck_pet(tmin, tmax, lat = 45, dates = dates)
Compute reference evapotranspiration ETo using the FAO-56 Penman-Monteith equation (Allen et al. 1998), the international standard for ETo estimation. Required inputs are daily Tmin and Tmax; optional inputs (humidity, wind speed, incoming solar radiation, elevation) increase accuracy. Where humidity, wind, or solar radiation are missing, FAO-56 fallback estimators are used.
ck_pet_pm( tmin, tmax, lat, dates, elev = 0, wind = 2, rh_min = NULL, rh_max = NULL, rs = NULL, albedo = 0.23, krs = 0.16 )ck_pet_pm( tmin, tmax, lat, dates, elev = 0, wind = 2, rh_min = NULL, rh_max = NULL, rs = NULL, albedo = 0.23, krs = 0.16 )
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
tmax |
Numeric vector of daily maximum temperatures (degrees C),
same length as |
lat |
Numeric. Latitude in decimal degrees. |
dates |
Date vector of the same length as |
elev |
Numeric. Elevation above sea level in metres (default 0). |
wind |
Numeric vector or single value. 2-m wind speed (m/s).
Default |
rh_min, rh_max
|
Optional numeric vectors of daily minimum and
maximum relative humidity in percent. Both must be supplied
together; otherwise vapour pressure falls back to |
rs |
Optional numeric vector of daily incoming solar
radiation (MJ m^-2 day^-1). If |
albedo |
Numeric. Surface albedo (default 0.23). |
krs |
Numeric. Hargreaves-Samani coefficient for the Rs fallback (default 0.16 for inland sites; 0.19 for coastal). |
Inputs and units:
tmin, tmax: daily minimum and maximum temperature (degrees C).
lat: latitude in decimal degrees, used for the
extraterrestrial-radiation calculation.
elev: elevation above sea level in metres (default 0).
wind: 2-metre wind speed (m/s). Default 2 m/s (the
FAO-56 fallback value when wind data are unavailable).
rh_min, rh_max: minimum and maximum daily relative
humidity (\
pressure is estimated as e0(tmin) (FAO-56 Eq. 48).
rs: daily incoming solar radiation (MJ m^-2 day^-1).
If NULL, estimated by Hargreaves-Samani: Rs = krs * Ra * sqrt(Tmax - Tmin) with krs = 0.16 for inland sites.
albedo: surface albedo (default 0.23, the FAO grass
reference).
A data frame with columns date, value, index
("pet_pm"), and unit.
Allen, R. G., Pereira, L. S., Raes, D., & Smith, M. (1998). Crop evapotranspiration: guidelines for computing crop water requirements. FAO Irrigation and Drainage Paper 56.
dates <- as.Date("2024-07-01") + 0:9 tmin <- c(15, 16, 14, 17, 15, 13, 16, 14, 15, 16) tmax <- c(30, 32, 28, 33, 31, 27, 34, 29, 30, 32) ck_pet_pm(tmin, tmax, lat = 45, dates = dates)dates <- as.Date("2024-07-01") + 0:9 tmin <- c(15, 16, 14, 17, 15, 13, 16, 14, 15, 16) tmax <- c(30, 32, 28, 33, 31, 27, 34, 29, 30, 32) ck_pet_pm(tmin, tmax, lat = 45, dates = dates)
Mean precipitation on wet days (days with precipitation >= 1 mm). Also known as the Simple Daily Intensity Index.
ck_precip_intensity(precip, dates, period = "annual")ck_precip_intensity(precip, dates, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 12, 0, 15, 2, 0, 11, 4, 0) ck_precip_intensity(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 12, 0, 15, 2, 0, 11, 4, 0) ck_precip_intensity(precip, dates)
ETCCDI canonical index R95p. Annual total precipitation on days where daily precipitation exceeds the 95th percentile of wet-day precipitation in a reference period (default 1961 to 1990). A wet day is one with precipitation at or above 1 mm. The threshold is a single value derived from all wet days in the reference period (not calendar-day specific).
ck_r95p(precip, dates, ref_start = 1961L, ref_end = 1990L, period = "annual")ck_r95p(precip, dates, ref_start = 1961L, ref_end = 1990L, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") precip <- pmax(rgamma(length(dates), shape = 0.4, scale = 8) - 1, 0) tail(ck_r95p(precip, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") precip <- pmax(rgamma(length(dates), shape = 0.4, scale = 8) - 1, 0) tail(ck_r95p(precip, dates))
ETCCDI canonical index R99p. Annual total precipitation on days where
daily precipitation exceeds the 99th percentile of wet-day precipitation
in a reference period (default 1961 to 1990). Same convention as
ck_r95p().
ck_r99p(precip, dates, ref_start = 1961L, ref_end = 1990L, period = "annual")ck_r99p(precip, dates, ref_start = 1961L, ref_end = 1990L, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") precip <- pmax(rgamma(length(dates), shape = 0.4, scale = 8) - 1, 0) tail(ck_r99p(precip, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") precip <- pmax(rgamma(length(dates), shape = 0.4, scale = 8) - 1, 0) tail(ck_r99p(precip, dates))
Compute the SPEI by fitting a log-logistic distribution to the monthly climatic water balance (precipitation minus potential evapotranspiration) accumulated over a rolling window.
ck_spei(precip, pet, dates, scale = 3, distribution = c("log-logistic", "gev"))ck_spei(precip, pet, dates, scale = 3, distribution = c("log-logistic", "gev"))
precip |
Numeric vector of daily precipitation (mm). |
pet |
Numeric vector of daily potential evapotranspiration (mm). |
dates |
Date vector of the same length as |
scale |
Integer. Accumulation period in months (default 3). |
distribution |
Character. Either |
A data frame with columns period, value, index, and unit.
Vicente-Serrano, S. M., Begueria, S., & Lopez-Moreno, J. I. (2010). A multiscalar drought index sensitive to global warming: the Standardized Precipitation Evapotranspiration Index. Journal of Climate, 23(7), 1696-1718.
dates <- seq(as.Date("2020-01-01"), as.Date("2023-12-31"), by = "day") set.seed(42) precip <- rgamma(length(dates), shape = 0.5, rate = 0.1) pet <- rep(3, length(dates)) ck_spei(precip, pet, dates, scale = 3)dates <- seq(as.Date("2020-01-01"), as.Date("2023-12-31"), by = "day") set.seed(42) precip <- rgamma(length(dates), shape = 0.5, rate = 0.1) pet <- rep(3, length(dates)) ck_spei(precip, pet, dates, scale = 3)
Compute the SPI by fitting a parametric distribution to rolling monthly precipitation accumulations and transforming to standard normal deviates. Two distributions are supported: the two-parameter gamma (default; WMO-1090 standard) and the three-parameter Pearson III. The Pearson III tail is heavier and is preferred in arid regions where the wet-day distribution is highly skewed (Stagge et al. 2015).
ck_spi(precip, dates, scale = 3, distribution = c("gamma", "pearsonIII"))ck_spi(precip, dates, scale = 3, distribution = c("gamma", "pearsonIII"))
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
scale |
Integer. Accumulation period in months (default 3). |
distribution |
Character. Either |
A data frame with columns period, value, index, and unit.
McKee, T. B., Doesken, N. J., & Kleist, J. (1993). The relationship of drought frequency and duration to time scales.
Stagge, J. H., Tallaksen, L. M., Gudmundsson, L., Van Loon, A. F., & Stahl, K. (2015). Candidate distributions for climatological drought indices (SPI and SPEI). International Journal of Climatology, 35(13), 4027-4040. doi:10.1002/joc.4267.
dates <- seq(as.Date("2020-01-01"), as.Date("2023-12-31"), by = "day") set.seed(42) precip <- rgamma(length(dates), shape = 0.5, rate = 0.1) ck_spi(precip, dates, scale = 3)dates <- seq(as.Date("2020-01-01"), as.Date("2023-12-31"), by = "day") set.seed(42) precip <- rgamma(length(dates), shape = 0.5, rate = 0.1) ck_spi(precip, dates, scale = 3)
Count the number of days where maximum temperature exceeds 25 degrees C.
ck_summer_days(tmax, dates, period = "annual")ck_summer_days(tmax, dates, period = "annual")
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-07-01") + 0:9 tmax <- c(22, 26, 28, 24, 30, 25, 27, 23, 31, 29) ck_summer_days(tmax, dates)dates <- as.Date("2024-07-01") + 0:9 tmax <- c(22, 26, 28, 24, 30, 25, 27, 23, 31, 29) ck_summer_days(tmax, dates)
ETCCDI canonical index TN10p. Percentage of days where daily Tmin
falls below the 10th percentile of the calendar-day distribution
from a reference period (default 1961 to 1990). Computation follows
the same convention as ck_tx10p() and supports the same
bootstrap argument.
ck_tn10p( tmin, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )ck_tn10p( tmin, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
period |
Character. Aggregation period: |
bootstrap |
Logical. If |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tn10p(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tn10p(tmin, dates))
ETCCDI canonical index TN90p. Percentage of days where daily Tmin
exceeds the 90th percentile of the calendar-day distribution from a
reference period (default 1961 to 1990). Computation follows the
same convention as ck_tx10p() and supports the same bootstrap
argument.
ck_tn90p( tmin, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )ck_tn90p( tmin, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
period |
Character. Aggregation period: |
bootstrap |
Logical. If |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tn90p(tmin, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmin <- 5 + 8 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tn90p(tmin, dates))
ETCCDI canonical index TNn. The minimum value of daily minimum temperature (Tmin) within each reporting period (coldest night).
ck_tnn(tmin, dates, period = "annual")ck_tnn(tmin, dates, period = "annual")
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tmin <- c(-2, 3, -1, 5, -8, 0, 2, -12, 1, -1) ck_tnn(tmin, dates)dates <- as.Date("2024-01-01") + 0:9 tmin <- c(-2, 3, -1, 5, -8, 0, 2, -12, 1, -1) ck_tnn(tmin, dates)
ETCCDI canonical index TNx. The maximum value of daily minimum temperature (Tmin) within each reporting period (warmest night).
ck_tnx(tmin, dates, period = "annual")ck_tnx(tmin, dates, period = "annual")
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-07-01") + 0:9 tmin <- c(15, 18, 22, 19, 14, 21, 23, 17, 20, 19) ck_tnx(tmin, dates)dates <- as.Date("2024-07-01") + 0:9 tmin <- c(15, 18, 22, 19, 14, 21, 23, 17, 20, 19) ck_tnx(tmin, dates)
Annual or monthly total precipitation in wet days, where a wet day is
a day with precipitation at or above wet_day_threshold mm (default
1 mm, the ETCCDI standard). This is the canonical ETCCDI 'PRCPTOT'
definition (Alexander et al. 2006; Zhang et al. 2011).
ck_total_precip(precip, dates, period = "annual", wet_day_threshold = 1)ck_total_precip(precip, dates, period = "annual", wet_day_threshold = 1)
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
wet_day_threshold |
Numeric (mm). Days with precipitation strictly below this threshold are excluded from the sum. Default 1. |
Sub-threshold trace amounts are excluded. Pass
wet_day_threshold = 0 to recover the previous behaviour of
summing all daily values.
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 3, 0, 8, 2, 0, 1, 4, 0) ck_total_precip(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 3, 0, 8, 2, 0, 1, 4, 0) ck_total_precip(precip, dates)
Count the number of days where minimum temperature exceeds 20 degrees C.
ck_tropical_nights(tmin, dates, period = "annual")ck_tropical_nights(tmin, dates, period = "annual")
tmin |
Numeric vector of daily minimum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-07-01") + 0:9 tmin <- c(18, 21, 22, 19, 25, 20, 23, 17, 24, 21) ck_tropical_nights(tmin, dates)dates <- as.Date("2024-07-01") + 0:9 tmin <- c(18, 21, 22, 19, 25, 20, 23, 17, 24, 21) ck_tropical_nights(tmin, dates)
ETCCDI canonical index TX10p. Percentage of days where daily Tmax falls below the 10th percentile of the calendar-day distribution from a reference period (default 1961 to 1990). The threshold is computed using a 5-day window centred on each calendar day, pooled across the reference period.
ck_tx10p( tmax, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )ck_tx10p( tmax, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
period |
Character. Aggregation period: |
bootstrap |
Logical. If |
Set bootstrap = TRUE to apply the Zhang et al. (2005) in-base
leave-one-out bootstrap, which removes the self-inclusion bias for
years inside the reference period. The bootstrap is computationally
expensive (roughly N^2 percentile fits for an N-year reference)
but is the canonical climdex.pcic / climpact behaviour and is
required for climate-change attribution work that spans the base.
A data frame with columns period, value, index, and unit.
Zhang, X., Hegerl, G. C., Zwiers, F. W., & Kenyon, J. (2005). Avoiding inhomogeneity in percentile-based indices of temperature extremes. Journal of Climate, 18(11), 1641-1651. doi:10.1175/JCLI3366.1.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tx10p(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tx10p(tmax, dates))
ETCCDI canonical index TX90p. Percentage of days where daily Tmax
exceeds the 90th percentile of the calendar-day distribution from a
reference period (default 1961 to 1990). Computation follows the
same convention as ck_tx10p() and supports the same bootstrap
argument.
ck_tx90p( tmax, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )ck_tx90p( tmax, dates, ref_start = 1961L, ref_end = 1990L, period = "annual", bootstrap = FALSE )
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
period |
Character. Aggregation period: |
bootstrap |
Logical. If |
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tx90p(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_tx90p(tmax, dates))
ETCCDI canonical index TXn. The minimum value of daily maximum temperature (Tmax) within each reporting period (coldest day).
ck_txn(tmax, dates, period = "annual")ck_txn(tmax, dates, period = "annual")
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tmax <- c(5, 10, -3, 12, 4, 8, 22, -8, 7, 6) ck_txn(tmax, dates)dates <- as.Date("2024-01-01") + 0:9 tmax <- c(5, 10, -3, 12, 4, 8, 22, -8, 7, 6) ck_txn(tmax, dates)
ETCCDI canonical index TXx. The maximum value of daily maximum temperature (Tmax) within each reporting period.
ck_txx(tmax, dates, period = "annual")ck_txx(tmax, dates, period = "annual")
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 tmax <- c(5, 10, 18, 12, 4, 8, 22, 3, 7, 6) ck_txx(tmax, dates)dates <- as.Date("2024-01-01") + 0:9 tmax <- c(5, 10, 18, 12, 4, 8, 22, 3, 7, 6) ck_txx(tmax, dates)
Count of days with precipitation at or above a threshold (default 20 mm).
ck_very_heavy_precip(precip, dates, threshold = 20, period = "annual")ck_very_heavy_precip(precip, dates, threshold = 20, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
threshold |
Numeric. Threshold in mm (default 20). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 22, 0, 15, 25, 0, 11, 4, 30) ck_very_heavy_precip(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(0, 5, 22, 0, 15, 25, 0, 11, 4, 30) ck_very_heavy_precip(precip, dates)
Count the number of days in warm spells, where a warm spell is defined
as at least six consecutive days with Tmax above the threshold
quantile of the full input series. This is a quick approximation
driven by a single series-wide quantile, and does not require a
reference period.
ck_warm_spell(tmax, dates, threshold = 0.9, period = "annual")ck_warm_spell(tmax, dates, threshold = 0.9, period = "annual")
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
threshold |
Numeric. Quantile threshold (default 0.9, i.e. 90th percentile). |
period |
Character. Aggregation period: |
For the canonical ETCCDI WSDI definition (1961-1990 calendar-day base,
six-day spell rule), use ck_wsdi().
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:364 set.seed(42) tmax <- rnorm(365, mean = 20, sd = 5) ck_warm_spell(tmax, dates)dates <- as.Date("2024-01-01") + 0:364 set.seed(42) tmax <- rnorm(365, mean = 20, sd = 5) ck_warm_spell(tmax, dates)
Maximum number of consecutive days with precipitation at or above a threshold.
ck_wet_days(precip, dates, threshold = 1, period = "annual")ck_wet_days(precip, dates, threshold = 1, period = "annual")
precip |
Numeric vector of daily precipitation (mm). |
dates |
Date vector of the same length as |
threshold |
Numeric. Wet day threshold in mm (default 1). |
period |
Character. Aggregation period: |
A data frame with columns period, value, index, and unit.
dates <- as.Date("2024-01-01") + 0:9 precip <- c(5, 3, 0, 2, 8, 1, 0, 0, 4, 6) ck_wet_days(precip, dates)dates <- as.Date("2024-01-01") + 0:9 precip <- c(5, 3, 0, 2, 8, 1, 0, 0, 4, 6) ck_wet_days(precip, dates)
Compute wind chill using the North American Wind Chill Index formula (Environment Canada / US NWS). Valid for temperatures at or below 10 degrees C and wind speeds above 4.8 km/h.
ck_wind_chill(tavg, wind_speed)ck_wind_chill(tavg, wind_speed)
tavg |
Numeric vector of temperatures (degrees C). |
wind_speed |
Numeric vector of wind speeds (km/h). |
A data frame with columns value, index, and unit.
ck_wind_chill(tavg = c(-5, -10, 0), wind_speed = c(20, 30, 15))ck_wind_chill(tavg = c(-5, -10, 0), wind_speed = c(20, 30, 15))
The Winkler index (also called growing degree days for viticulture) accumulates daily mean temperature above 10 degrees C during the growing season (April-October in NH, October-April in SH).
ck_winkler(tavg, dates)ck_winkler(tavg, dates)
tavg |
Numeric vector of daily average temperatures (degrees C). |
dates |
Date vector of the same length as |
A data frame with columns period, value, index, and unit.
Amerine, M. A., & Winkler, A. J. (1944). Composition and quality of musts and wines of California grapes.
dates <- seq(as.Date("2024-04-01"), as.Date("2024-10-31"), by = "day") set.seed(42) tavg <- rnorm(length(dates), mean = 18, sd = 4) ck_winkler(tavg, dates)dates <- seq(as.Date("2024-04-01"), as.Date("2024-10-31"), by = "day") set.seed(42) tavg <- rnorm(length(dates), mean = 18, sd = 4) ck_winkler(tavg, dates)
ETCCDI canonical index WSDI. Annual count of days in spans of at least six consecutive days where daily Tmax exceeds the 90th percentile of the calendar-day distribution from a reference period (default 1961 to 1990). The threshold is computed using a 5-day window centred on each calendar day, pooled across the reference period.
ck_wsdi(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 6L)ck_wsdi(tmax, dates, ref_start = 1961L, ref_end = 1990L, min_spell = 6L)
tmax |
Numeric vector of daily maximum temperatures (degrees C). |
dates |
Date vector of the same length as |
ref_start, ref_end
|
Integer. Reference period boundary years (inclusive). Defaults to 1961 and 1990. |
min_spell |
Integer. Minimum spell length in days (default 6, the ETCCDI standard). |
Days inside qualifying spells are counted into the year they fall in; a spell that crosses a year boundary contributes to both years proportionally. Annual aggregation only.
A data frame with columns period, value, index, and unit.
set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_wsdi(tmax, dates))set.seed(1) dates <- seq(as.Date("1961-01-01"), as.Date("1991-12-31"), by = "day") tmax <- 15 + 10 * sin(2 * pi * as.integer(format(dates, "%j")) / 365) + rnorm(length(dates)) tail(ck_wsdi(tmax, dates))
Removes any cached reference data stored by climatekit.
clear_cache()clear_cache()
Invisibly returns TRUE if cache was cleared, FALSE if no cache
existed.
op <- options(climatekit.cache_dir = tempdir()) clear_cache() options(op)op <- options(climatekit.cache_dir = tempdir()) clear_cache() options(op)