Temperature & Other variables
So far only a seasonal AR(1)
model is coded, i.e., AR(1) with periodic coefficients. It can be used for Temperature but also for some other "simple" variables.
For a showcase on how to use these on a multivariate example, see the AppliMultivariate SWG: Application to crop model tutorial.
StochasticWeatherGenerators.fit_AR1
— Functionfit_AR1(df_full::DataFrame, var, 𝐃𝐞𝐠, K = length(unique(df_full.z)), T = length(unique(n2t)))
fit_AR1(y::AbstractArray, z::AbstractArray, n2t, 𝐃𝐞𝐠, K = length(unique(z |> skipmissing)), T = length(unique(n2t)))
Fit a Seasonal AR(1) model of period T
and with K
hidden states for the variable X
of the DataFrame df_full
. The hidden states must be given in a the column z
of i.e. df_full.z
. The correspondance between day of the year t
and index in the time series n
must be given in the column n2t
i.e. df_full.n2t
.
$X_{n+1} = \mu(t_n, z_n) + \phi(t_n, z_n) X_n + \sigma(t_n, z_n)\xi$
with $\xi \sim \mathcal{N}(0,1)$.
StochasticWeatherGenerators.cov_ar1
— Functioncov_ar1(dfs::AbstractArray{<:DataFrame}, ar1s, var, K = length(unique(dfs[1].z)))
Fit the covariance matrix of the residual ϵ
of several AR(1) models ar1s
. One matrix is fitted per hidden state. The hidden state z
must be given in df.z
. Note that we consider constant in time the covariance matrices.
Temperature
There is a simple model to generate correlated $T_{\mathrm{max}}$ and $T_{\mathrm{max}}$.
StochasticWeatherGenerators.fit_TN
— Functionfit_TN(df_full::DataFrame, 𝐃𝐞𝐠, T; kwargs...)
Fit the variable TN
(daily minimum temperature). In fact it fits the difference ΔT = TX - TN
to ensure a positive difference between TX
and TN
StochasticWeatherGenerators.rand_cond
— Functionrand_cond(ϵ, z, θ_uni, θ_cor, n2t, T)
Generate a random variable conditionally to another one assuming a Gaussian copula dependance with correlation ρₜ(t / T, θ_cor)
(depending on the day of the year). ϵ
is assumed Normal(0,1)
.
StochasticWeatherGenerators.cor_groupby
— Functioncor_groupby(df::DataFrame, var1, var2, T::Integer; θ0 = [0, 0.0, 0.0])
Compute and fit the cor
between two var
with a smooth function for each z
.
StochasticWeatherGenerators.cor_groupbyTXTN
— Functioncor_groupbyTXTN(df::DataFrame, T::Integer; θ0 = [0, 0.0, 0.0])
Compute and fit the cor
between :TX
and :TX-:TN
with a smooth function for each z
.
- Add
AR(p>1)
models. - Add state-of-the-art temperature models, e.g. with good extremes.
Others
For positive variables, one can truncate when generating the AR(1)
model, but it is not a convincing modeling approach (but it kind of works when in a hurry).
- Add a true truncated AR model.
- Add more appropriate and domain specific models
- Other multivariate models: (Sparks et al., 2018; Flecher et al., 2010)
References
- Flecher, C.; Naveau, P.; Allard, D. and Brisson, N. (2010). A Stochastic Daily Weather Generator for Skewed Data. Water Resources Research 46.
- Sparks, N. J.; Hardwick, S. R.; Schmid, M. and Toumi, R. (2018). IMAGE: A Multivariate Multi-Site Stochastic Weather Generator for European Weather and Climate. Stochastic Environmental Research and Risk Assessment 32, 771–784.