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_AR1Function
fit_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)$.

source
StochasticWeatherGenerators.cov_ar1Function
cov_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.

source

Temperature

There is a simple model to generate correlated $T_{\mathrm{max}}$ and $T_{\mathrm{max}}$.

StochasticWeatherGenerators.fit_TNFunction
fit_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

source
StochasticWeatherGenerators.rand_condFunction
rand_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).

source
Todo
  • 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).

Todo

References