pyesmda.approximate_covariance_matrix_from_ensembles#

pyesmda.approximate_covariance_matrix_from_ensembles(ensemble_1: ndarray[tuple[Any, ...], dtype[float64]], ensemble_2: ndarray[tuple[Any, ...], dtype[float64]]) ndarray[tuple[Any, ...], dtype[float64]][source]#

Approximate the covariance matrix between two ensembles in the EnKF way.

The covariance matrice \(C_{m1m2}\) is approximated from the ensemble in the standard way of EnKF [Evensen, 2007, Aanonsen et al., 2009]:

\[C_{p1p2} = \frac{1}{N_{e} - 1} \sum_{j=1}^{N_{e}}\left(m1_{j} - \overline{m1}\right)\left(m2_{j} - \overline{m2} \right)^{T}\]
Parameters:
  • ensemble_1 (NDArrayFloat) – First ensemble of realization with diemnsions (\(N_{m1}, N_{e}\)).

  • ensemble_2 (NDArrayFloat) – Second ensemble of realization with diemnsions (\(N_{m2}, N_{e}\)).

Returns:

The two ensembles approximated covariance matrix.

Return type:

NDArrayFloat

Examples

>>> X = np.array([[-2.4, -0.3,  0.7],
...               [ 0.2,  1.1, -1.5]])
>>> Y = np.array([[ 0.4, -0.4, -0.9],
...               [ 1. , -0.1, -0.4],
...               [-0. , -0.5,  1.1],
...               [-1.8, -1.1,  0.3]])
>>> approximate_covariance_matrix_from_ensembles(X.T, Y.T)
array([[-1.035     , -1.15833333,  0.66      ,  1.56333333],
       [ 0.465     ,  0.36166667, -1.08      , -1.09666667]])

Verify against numpy.cov

>>> np.cov(X, rowvar=True, ddof=1)
array([[ 2.50333333, -0.99666667],
       [-0.99666667,  1.74333333]])
>>> approximate_covariance_matrix_from_ensembles(X.T, X.T)
array([[ 2.50333333, -0.99666667],
       [-0.99666667,  1.74333333]])
Raises:

ValueError – _description_