🧰 Utilities

Climate indexes

StochasticWeatherGenerators.VCX3Function
VCX3(df; y_col, nb = 3)

Yearly Max of nb = 3 days sliding mean for y for every year. By default, y_col is the first column not with a Date type

using DataFrames, Dates, RollingFunctions
time_range = Date(1956):Day(1):Date(2019,12,31)
df = DataFrame(:DATE => time_range, :Temperature => 20 .+ 5*randn(length(time_range)))
VCX3(df)
source
VCX3(y, idxs; nb = 3)

Yearly Max of nb = 3 days sliding mean for y. Here idxs can be a vector of vector (or range) corresponds to the index of every year.

using DataFrames, Dates, RollingFunctions
time_range = Date(1956):Day(1):Date(2019,12,31)
year_range = unique(year.(time_range))
df = DataFrame(:DATE => time_range, :Temperature => 20 .+ 5*randn(length(time_range)))
idx_year = [findall(x-> year.(x) == m, df[:, :DATE]) for m in year_range]
VCX3(df.Temperature, idx_year)
source
StochasticWeatherGenerators.monthly_aggFunction
monthly_agg(y::AbstractArray, idxs)
using DataFrames, Dates
time_range = Date(1956):Day(1):Date(2019,12,31)
year_range = unique(year.(time_range))
df = DataFrame(:DATE => time_range, :Temperature => 20 .+ 5*randn(length(time_range)))
monthly_agg(df, :Temperature) 
monthly_agg(df, :Temperature, mean) 
# or
idx_year = [findall(x-> year.(x) == m, df[:, :DATE]) for m in year_range]
idx_month = [findall(x-> month.(x) == m, df[:, :DATE]) for m in 1:12]
idx_all = [intersect(yea, mon) for yea in idx_year, mon in idx_month]
monthly_agg(df.Temperature, idx_all)
source
StochasticWeatherGenerators.corTailFunction
corTail(x::AbstractMatrix, q = 0.95)

Compute the (symmetric averaged) tail index matrix M of a vector x, i.e. M[i, j] = (ℙ(x[:,j] > Fxⱼ(q) ∣ x[:,i] > Fxᵢ(q)) + ℙ(x[:,i] > Fxᵢ(q) ∣ x[:,j] > Fxⱼ(q)))/2 where Fx(q) is the CDF of x. Note it uses the same convention as cor function i.e. observations in rows and features in column.

source

Generic utilities

Map utilities

StochasticWeatherGenerators.dms_to_ddFunction
dms_to_dd(l)

Convert l in Degrees:Minutes:Seconds to Decimal Degrees. Inputs are strings of the form

  • LAT : Latitude in degrees:minutes:seconds (+: North, -: South)
  • LON : Longitude in degrees:minutes:seconds (+: East, -: West)
source
StochasticWeatherGenerators.haversineFunction
haversine(lat1, long1, lat2, long2, r = 6372.8)

Compute the haversine distance between two points on a sphere of radius r, where the points are given by the latitude/longitude pairs lat1/long1 and lat2/long2 (in degrees). From this JuMP.jl tutorial.

source