Skip to main content

xeofs logo

Versions PyPI Conda
Build & Testing Build codecov
Code Quality Black Ruff
Documentation Docs
Citation JOSS Zenodo
Licensing License
User Engagement Downloads

Overview

xeofs is a specialized Python package designed for dimensionality reduction in climate science, aimed at extracting meaningful patterns from large datasets. It provides eigenmethods such as Principal Component Analysis (EOF analysis) and several related variants. Seamlessly integrated with xarray and Dask, xeofs enables efficient handling and scalable computation of large, multi-dimensional datasets.

  • Multi-Dimensional: Designed for xarray objects, it applies dimensionality reduction to multi-dimensional data while maintaining data labels.
  • Dask-Integrated: Supports large datasets via Dask xarray objects
  • Extensive Methods: Offers various dimensionality reduction techniques
  • Adaptable Output: Provides output corresponding to the type of input, whether single or list of xr.DataArray or xr.Dataset
  • Missing Values: Handles NaN values within the data
  • Bootstrapping: Comes with a user-friendly interface for model evaluation using bootstrapping
  • Efficient: Ensures computational efficiency, particularly with large datasets through randomized SVD
  • Modular: Allows users to implement and incorporate new dimensionality reduction methods

Installation

To install the package, use either of the following commands:

conda install -c conda-forge xeofs

or

pip install xeofs

Quickstart

In order to get started with xeofs, follow these simple steps:

Import the package

>>> import xarray as xr  # for example data only
>>> import xeofs as xe

Load example data

>>> t2m = xr.tutorial.open_dataset("air_temperature")
>>> t2m_west = t2m.isel(lon=slice(None, 20))
>>> t2m_east = t2m.isel(lon=slice(21, None))

EOF analysis Initiate and fit the EOF/PCA model to the data

>>> eof = xe.single.EOF(n_modes=10)
>>> eof.fit(t2m, dim="time")  # doctest: +ELLIPSIS
<xeofs.single.eof.EOF object at ...>

Now, you can access the model's EOF components and PC scores:

>>> comps = eof.components()  # EOFs (spatial patterns)
>>> scores = eof.scores()  # PCs (temporal patterns)

Varimax-rotated EOF analysis Initiate and fit an EOFRotator class to the model to obtain a varimax-rotated EOF analysis

>>> rotator = xe.single.EOFRotator(n_modes=3)
>>> rotator.fit(eof) # doctest: +ELLIPSIS
<xeofs.single.eof_rotator.EOFRotator object at ...>

>>> rot_comps = rotator.components()  # Rotated EOFs (spatial patterns)
>>> rot_scores = rotator.scores()  # Rotated PCs (temporal patterns)

Maximum Covariance Analysis (MCA)

>>> mca = xe.cross.MCA(n_modes=10)
>>> mca.fit(t2m_west, t2m_east, dim="time")  # doctest: +ELLIPSIS
<xeofs.cross.mca.MCA object at ...>

>>> comps1, comps2 = mca.components()  # Singular vectors (spatial patterns)
>>> scores1, scores2 = mca.scores()  # Expansion coefficients (temporal patterns)

Varimax-rotated MCA

>>> rotator = xe.cross.MCARotator(n_modes=10)
>>> rotator.fit(mca)  # doctest: +ELLIPSIS
<xeofs.cross.mca_rotator.MCARotator object at ...>

>>> rot_comps = rotator.components()  # Rotated singular vectors (spatial patterns)
>>> rot_scores = rotator.scores()  # Rotated expansion coefficients (temporal patterns)

To further explore the capabilities of xeofs, check out the available documentation and examples. For a full list of currently available methods, see the Reference API.

Documentation

For a more comprehensive overview and usage examples, visit the documentation.

Contributing

Contributions are highly welcomed and appreciated. If you're interested in improving xeofs or fixing issues, please read our Contributing Guide.

For local development, install Pixi and run these commands from your clone:

pixi install --locked
pixi run test
pixi run -e lint lint
pixi run -e docs docs

Pixi installs an editable copy of xeofs and uses the committed pixi.lock. Installing released packages with pip or Conda is unchanged.

License

This project is licensed under the terms of the MIT license.

Contact

For questions or support, please open a Github issue.

Credits

  • Randomized PCA: scikit-learn
  • EOF analysis: Python package eofs by Andrew Dawson
  • MCA: Python package xMCA by Yefee
  • CCA: Python package CCA-Zoo by James Chapman
  • ROCK-PCA: Matlab implementation by Diego Bueso
  • Sparse PCA: Based on Ristretto library by Benjamin Erichson

How to cite?

When using xeofs, kindly remember to cite the original references of the methods employed in your work. Additionally, if xeofs is proving useful in your research, we'd appreciate if you could acknowledge its use with the following citation:

@article{rieger_xeofs_2024,
author = {Rieger, Niclas and Levang, Samuel J.},
doi = {10.21105/joss.06060},
journal = {Journal of Open Source Software},
month = jan,
number = {93},
pages = {6060},
title = {{xeofs: Comprehensive EOF analysis in Python with xarray}},
url = {https://joss.theoj.org/papers/10.21105/joss.06060},
volume = {9},
year = {2024}
}

Contributors

Contributors

Metadata

Release files for xeofs 3.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xeofs 3.0.6
File Size Uploaded Provenance Actions
xeofs-3.0.6.tar.gz 8.2 MB Without provenance Details for xeofs-3.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xeofs 3.0.6
File Interpreter ABI Platform Actions
xeofs-3.0.6-py3-none-any.whl Python 3 none any Details for xeofs-3.0.6-py3-none-any.whl

Total release size: 8.4 MB

Release files / xeofs-3.0.6.tar.gz

Download URL xeofs-3.0.6.tar.gz
Size 8.2 MB
Tags Source
SHA-256 checksum
How to use checksums
397844fac117d1910bab4004d3d174d2a5f3ce5f4873ec90ef399af609bc3a00
BLAKE2b-256 checksum
How to use checksums
d7a1bd52df72e9e1df0cce271db6ccdc0a5ea3254a33fa830e202e4a4e706d3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / xeofs-3.0.6-py3-none-any.whl

Download URL xeofs-3.0.6-py3-none-any.whl
Size 134.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a710c1f945615af7a09450d8f402fda22b0bbc2735035cf4b8933226283d8e8a
BLAKE2b-256 checksum
How to use checksums
95ee6e1c83c4990d1287bdb567c5b5e9bb95864fce07f80d0eccc46d2c321582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for xeofs 3.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page