Thresholds

ClimateStats.cal_anomaly_quantileFunction
cal_anomaly_quantile(
    A::AbstractArray{T<:Real},
    dates;
    parallel,
    use_mov,
    na_rm,
    method,
    p1,
    p2,
    fun,
    probs,
    options...
) -> Any

Calculate the anomaly of a 3D array of temperature data.

Arguments

  • A : the 3D array of temperature data
  • dates : an array of dates corresponding to the temperature data
  • parallel : whether to use parallel processing (default true)
  • use_mov : whether to use a moving window to calculate the threshold (default true)
  • method : the method to use for calculating the threshold, one of ["full", "season", "base", "pTRS"] (default "full")
  • probs : default [0.5]
  • p1 : the start year for the reference period (default 1981)
  • p2 : the end year for the reference period (default 2010)
  • fun : the function used to calculate the anomaly (default _exceed)

Returns

An array of the same shape as A containing the temperature anomaly.

References

  1. Vogel, M. M., Zscheischler, J., Fischer, E. M., & Seneviratne, S. I. (2020). Development of Future Heatwaves for Different Hazard Thresholds. Journal of Geophysical Research: Atmospheres, 125(9). https://doi.org/10.1029/2019JD032070
source
ClimateStats.cal_anomaly_climFunction
cal_anomaly_clim(
    A::AbstractArray{T<:Real},
    dates;
    parallel,
    use_mov,
    method,
    p1,
    p2,
    fun_clim,
    fun_anom
) -> Any

Calculate the anomaly of an array relative to its climatology.

Arguments

  • A::AbstractArray{T}: The input array to calculate the anomaly of.

  • dates: The dates corresponding to the input array.

  • parallel::Bool=true: Whether to use parallel processing.

  • use_mov=true: Whether to use a moving window to calculate the climatology.

  • method="full": The method to use for calculating the climatology. Can be "base", "season", or "full".

  • p1=1981: The start year for the period to use for calculating the climatology.

  • p2=2010: The end year for the period to use for calculating the climatology.

  • fun_clim=nanmean: The function to use for calculating the climatology.

  • fun_anom=_exceed: The function to use for calculating the anomaly.

Returns

  • anom: The anomaly of the input array relative to its climatology.

Example

using Ipaper

# Generate some sample data
A = rand(365, 10)
dates = Date(2000, 1, 1):Day(1):Date(2000, 12, 31)

# Calculate the anomaly relative to the climatology
anom = cal_anomaly_clim(A, dates; method="base")
source
ClimateStats.cal_thresholdFunction
cal_threshold(
    A::AbstractArray{T<:Real},
    dates;
    parallel,
    use_mov,
    na_rm,
    method,
    p1,
    p2,
    probs,
    options...
) -> Any

Calculate the threshold value for a given dataset A and dates. The threshold value is calculated based on the specified method.

Arguments

  • A::AbstractArray{T}: The input data array.

  • dates: The dates corresponding to the input data array.

  • parallel::Bool=true: Whether to use parallel computation.

  • use_mov::Bool=true: Whether to use moving window.

  • na_rm::Bool=true: Whether to remove missing values.

  • method::String="full": Possible values are "base", "season", and "full".

  • p1::Int=1981: The start year for the reference period.

  • p2::Int=2010: The end year for the reference period.

  • probs::Vector{Float64}=[0.5]: The probability levels to use for calculating the threshold value.

  • options...: Additional options to pass to the underlying functions.

Returns

For different methods:

  • full: Array with the dimension of (dims..., ntime, nprob)
  • base: Array with the dimension of (dims..., 366, nprob)
  • season: Array with the dimension of (dims..., nyear)

Examples

dates = Date(2010, 1):Day(1):Date(2020, 12, 31);
ntime = length(dates)
data = rand(10, ntime);
cal_threshold(data, dates; p1=2010, p2=2015, method="full")
source
ClimateStats.cal_mTRS_baseFunction
cal_mTRS_base(
    arr::AbstractArray{T<:Real, N},
    dates;
    dims,
    use_quantile,
    fun!,
    probs,
    dtype,
    p1,
    p2,
    kw...
) -> AbstractArray{T} where T<:Real

Moving Threshold for Heatwaves Definition

Arguments

  • arr : time should be in the last dimension.

  • type: The matching type of the moving doys, "md" (default) or "doy".

Return

  • TRS: in the dimension of [nlat, nlon, ndoy, nprob]

References

  1. Vogel, M. M., Zscheischler, J., Fischer, E. M., & Seneviratne, S. I. (2020). Development of Future Heatwaves for Different Hazard Thresholds. Journal of Geophysical Research: Atmospheres, 125(9). https://doi.org/10.1029/2019JD032070
source
ClimateStats.cal_mTRS_fullFunction
cal_mTRS_full(
    arr::AbstractArray{T<:Real, N},
    dates;
    dims,
    width,
    verbose,
    use_quantile,
    fun!,
    use_mov,
    probs,
    kw...
) -> Any

Moving Threshold for Heatwaves Definition

Arguments

  • use_mov: Boolean (default true).
    • if true, 31*15 values will be used to calculate threshold for each grid;
    • if false, the input arr is smoothed first, then only 15 values will be used to calculate threshold.

!!! 必须是完整的年份,不然会出错

References

  1. Vogel, M. M., Zscheischler, J., Fischer, E. M., & Seneviratne, S. I. (2020). Development of Future Heatwaves for Different Hazard Thresholds. Journal of Geophysical Research: Atmospheres, 125(9). https://doi.org/10.1029/2019JD032070
source
ClimateStats.cal_climatology_baseFunction
cal_climatology_base(
    A::AbstractArray{T<:Real},
    dates;
    fun!,
    kw...
) -> AbstractArray{T} where T<:Real

Calculate the climatology of a dataset A based on the dates.

The climatology is the long-term average of a variable over a specific period of time. This function calculates the climatology of the input dataset A based on the dates dates. The calculation is performed by applying a function fun! to a moving window of the data.

Arguments:

  • A : :AbstractArray{T}: the input dataset, where T is a subtype of Real.
  • dates : the dates associated with the input dataset, as a vector of Date objects.
  • fun! : the function to apply to the moving window of the data. It should take an input array and return a scalar.
  • use_quantile: default false, a boolean indicating whether to use a quantile-based filter to remove outliers.
  • p1, p2 : the references period

Returns:

  • a matrix of the same size as A, containing the climatology values.

Example:

using Dates
using Statistics
# using NaNStatistics

A = rand(365, 10) |> transpose # simulate a year of daily data for 10 variables
dates = Date(2022, 1, 1):Day(1):Date(2022, 12, 31)
clim = cal_climatology_base(A, dates; p1=2022, p2=2022)
source
ClimateStats.cal_mTRS_base!Function
cal_mTRS_base!(
    Q::AbstractArray{T<:Real},
    arr::AbstractArray{T<:Real, N},
    mmdd;
    dims,
    fun,
    probs,
    parallel,
    halfwin,
    use_mov,
    ignore...
) -> AbstractArray{T} where T<:Real
source
ClimateStats.cal_mTRS_base3!Function
cal_mTRS_base3!(
    Q::AbstractArray,
    data::AbstractArray{T<:Real, 3},
    mmdd;
    dims,
    probs,
    parallel,
    halfwin,
    use_mov,
    method_q,
    na_rm,
    ignore...
) -> AbstractArray
source
ClimateStats.cal_yearly_TairFunction

Calculate yearly air temperature.

Description

we use the fixed thresholds and add the seasonal warming signal. Thus, thresholds are defined as a fixed baseline (such as for the fixed threshold) plus seasonally moving mean warming of the corresponding future climate based on the 31-year moving mean of the warmest three months.

Details

This function calculates the yearly air temperature based on the input temperature data and dates. If only_summer is true, it only calculates the temperature for summer months. The function applies the calculation along the specified dimensions.

Arguments

  • A::AbstractArray{T,N}: input array of temperature data.
  • dates: array of dates corresponding to the temperature data.
  • dims=N: dimensions to apply the function along.
  • only_summer=false: if true, only calculate temperature for summer months.

Returns

  • T_year: array of yearly temperature data.
source