🧰 Utilities
Climate indexes
StochasticWeatherGenerators.VCX3 — FunctionVCX3(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)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)StochasticWeatherGenerators.monthly_agg — Functionmonthly_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)StochasticWeatherGenerators.corTail — FunctioncorTail(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.
StochasticWeatherGenerators.longuest_spell — Functionlonguest_spell(y::AbstractArray; value=0)Compute the length of the longuest consecutive sequence of value in y
StochasticWeatherGenerators.pmf_spell — Functionpmf_spell(y::AbstractVector, value)Return the distribution of spells (consecutive sequence of with the same value) length of value in y
Generic utilities
StochasticWeatherGenerators.my_color — Functionmy_color(k, K)Convenience for plot colors pattern and hidden states to blue for k=1 (∼wetter) and orange for k=K (∼driest)
Map utilities
StochasticWeatherGenerators.dms_to_dd — Functiondms_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)
StochasticWeatherGenerators.haversine — Functionhaversine(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.
StochasticWeatherGenerators.LLA — TypeLLA{T<:Real}Coordinate structure inspired by Geodesy.jl
StochasticWeatherGenerators.distance_x_to_y — Functiondistance_x_to_y(station_x, station_y)Distance in km between two stations. Does not take into account altitude. station must have a field LAT and LON in Decimal Degree.