eof

eof(data, /, neof=5, axis_time=- 2, axis_space=- 1, weights=None, percent=False, normalize=False)[source]

Calculate the first N EOFs using the scipy algorithm for Hermetian matrices on the covariance matrix.

Parameters
  • data (array-like) – Data of arbitrary shape.

  • neof (int, optional) – Number of eigenvalues we want.

  • axis_time (int, optional) – Axis used as the ‘record’ or ‘time’ dimension.

  • axis_space (int or list of int, optional) – Axis or axes used as ‘space’ dimension.

  • weights (array-like, optional) – Area or mass weights; must be broadcastable on multiplication with data weights. Will be normalized prior to application.

  • percent (bool, optional) – Whether to return raw eigenvalue(s) or the percentage of total variance explained by eigenvalue(s). Default is False.

  • normalize (bool, optional) – Whether to normalize the data by its standard deviation at every point prior to obtaining the EOFs.

Returns

  • pcs (array-like) – The standardized principal components. The axis_space dimensions are reduced to length 1.

  • projs (array-like) – Projections of the standardized principal components onto the original data. The axis_time dimension is reduced to length 1.

  • evals – If percent is Flase, these are the eigenvalues. Otherwise, this is the percentage of total variance explained by the corresponding eigenvector. The axis_time and axis_space dimensions are reduced to length 1.

  • nstars – The approximate degrees of freedom as determined by the [Wil11] autocorrelation critereon. This can be used to compute the approximate 95% error bounds for the eigenvalues using the [NBCM82] critereon of \(\lambda \sqrt{2 / N^*}\). The axis_time and axis_space dimensions are reduced to length 1.

Examples

>>> import numpy as np
>>> import xarray as xr
>>> import climopy as climo
>>> state = np.random.RandomState(51423)
>>> data = xr.DataArray(
...     state.rand(10, 6, 100, 40, 20),
...     dims=('member', 'run', 'time', 'lev', 'lat'),
...     coords={
...         'member': np.arange(1, 11),
...         'run': np.arange(1, 7),
...         'time': np.arange(100.0),
...         'lev': np.linspace(0.0, 1000.0, 40),
...         'lat': np.linspace(-90.0, 90.0, 20),
...     }
... )
>>> pcs, projs, evals, nstars = climo.eof(data, axis_time=2, axis_space=(3, 4))
>>> pcs.sizes
Frozen({'eof': 5, 'member': 10, 'run': 6, 'time': 100, 'lev': 1, 'lat': 1})
>>> projs.sizes
Frozen({'eof': 5, 'member': 10, 'run': 6, 'time': 1, 'lev': 40, 'lat': 20})
>>> pcs.head(time=1, run=1, member=1).T
<xarray.DataArray (lat: 1, lev: 1, time: 1, run: 1, member: 1, eof: 5)>
array([[[[[[-0.13679781,  1.08751657,  2.52901891,  0.00737416,
             0.55085823]]]]]])
Coordinates:
  * member   (member) int64 1
  * run      (run) int64 1
  * time     (time) float64 0.0
  * eof      (eof) int64 1 2 3 4 5
Dimensions without coordinates: lat, lev
>>> projs.head(lat=1, lev=1, run=1, member=1).T
<xarray.DataArray (lat: 1, lev: 1, time: 1, run: 1, member: 1, eof: 5)>
array([[[[[[-0.02304145, -0.01572039,  0.02761249, -0.06884522,
             0.04163672]]]]]])
Coordinates:
  * member   (member) int64 1
  * run      (run) int64 1
  * lev      (lev) float64 0.0
  * lat      (lat) float64 -90.0
  * eof      (eof) int64 1 2 3 4 5
Dimensions without coordinates: time

References

NBCM82

Gerald R. North, Thomas L. Bell, Robert F. Cahalan, and Fanthune J. Moeng. Sampling Errors in the Estimation of Empirical Orthogonal Functions. Monthly Weather Review, 110(7):699–706, July 1982. doi:10.1175/1520-0493(1982)110<0699:SEITEO>2.0.CO;2.

Wil11

Daniel S. Wilks. Statistical Methods in the Atmospheric Sciences. Academic Press, Amsterdam ; Boston, 3 edition edition, June 2011. ISBN 978-0-12-385022-5.