Skip to main content

No project description provided

Project description

XCDO

Test codecov PyPI - Version PyPI - Python Version Doc pre-commit

XCDO is a Python-based command-line tool built around Xarray. It provides a collection of operators for working with datasets such as NetCDF, GRIB, and Zarr, using a familiar CDO like interface. With the help of Python’s type annotations, creating new operators becomes effortless, making it easy to extend the tool with simple functions and build reusable, organised analysis workflows.

Installation

$ pip install xcdo

!!! Known issues - Only works with Python 3.12 and 3.13 on macOS. - Not well tested on Windows.


### Installing in a virtual environment You may want to install `xcdo` to an isolated virtual environment to avoid conflicts with other packages.

micromamba/mamba/conda

# Choose any of: micromamba, mamba, or conda
$ micromamba create -n xcdo python=3.13
$ micromamba activate xcdo
(xcdo)$ pip install xcdo

uv

$ uv venv --python 3.13 .venv
$ source .venv/bin/activate
(.venv)$ pip install xcdo

Usage

Generally, XCDO works much like CDO. For example:

$ xcdo -selvar,var1 indata.nc outdata.nc
$ xcdo -timemean -zonmean in.nc out.nc

You can find a list of all available operators here. or run xcdo --list on the command line.

$ xcdo --list

                            Available Operators
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Operator       Description                                   ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ cdo            Operator to run CDO commands                  │
│ showtimestamp  Show time stamp                               │
│ mermean        Meridional mean                               │
│ mermin         Meridional minimum                            │
│ mermax         Meridional maximum                            │
│ merstd         Meridional standard deviation                 │
│ mersum         Meridional sum                                

To get detailed information and the synopsis (or signature) about a specific operator, use:

$ xcdo --show <operator>
$ xcdo --show selvar
╭─ Synopsis ──────────────────────────────────────────────────╮
│                                                             │
│  xcdo -selvar,name input output                             │
│                                                             │
╰─────────────────────────────────────────────────────────────╯
╭─ Description ───────────────────────────────────────────────╮
│                                                             │
│  Select a data variable by name.                            │
│                                                             │
╰─────────────────────────────────────────────────────────────╯
                 Positional Arguments
┏━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ Parameter  Type  Required  Description          ┃
┡━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ name       TEXT  Required  Name of the variable │
└───────────┴──────┴──────────┴──────────────────────┘
╭─ Examples ──────────────────────────────────────────────────╮
│                                                             │
│  xcdo -selvar,tas infile.nc outfile.nc                      │
│  xcdo -selname,tas infile.nc outfile.nc                     │
│                                                             │
╰─────────────────────────────────────────────────────────────╯

User-defined operators

You can easily turn a regular Python function into your own XCDO operator. For example, here’s a small operator in a file named dump.py that simply prints a dataset to the terminal:

# dump.py
from xcdo import operator, DatasetIn

@operator()
def main(input: DatasetIn):
    print(input)

And this can be used as follows in xcdo:

$ xcdo -dump.py in.nc

You can see the signature and documentation of the custom operator by running:

$ xcdo --show dump.py

╭─ Synopsis ──────────────────────────────────────────────────╮
│                                                             │
│  xcdo -dump.py input                                        │
│                                                             │
╰─────────────────────────────────────────────────────────────╯

!!! Note Notice the .py extension on the custom operator? That’s because the operator name simply comes from the Python file’s name.

See Writing your own operators for more details.

Why XCDO?

  • Simple Python functions. If you know Python, you can create new operators instantly. This opens the door for real community-driven development.
  • Automatic help and documentation. XCDO automatically generates help and documentation for your operators, making it easy to share and reuse them.
  • CLI and Library. As these operators are Python functions, it can be called from Python scripts as well.
  • Custom operators. Drop a Python function into a file and call it like any other XCDO operator. This keeps your analysis workflows clean, modular, and easy to reuse.
  • Zarr support. Since XCDO builds on Xarray, it naturally supports modern formats like Zarr, which CDO doesn’t handle yet.
  • CDO integration. When you need the performance of CDO, you can call it directly with the “-cdo” operator and combine it with XCDO or custom operators in one chain.

With community support, XCDO can grow into a unified library of reusable and well-structured tools for climate and weather analysis.

Issues

Please report any issues here.

Contributing

Fork the repository and make your changes and submit a pull request.

Please contact me at prajeeshag@gmail.com for any questions or start a discussion on GitHub Discussions.

!!! warning "Under active development" XCDO is under active development. Although everything will work as expected, many features are not documented well yet.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xcdo-0.2.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xcdo-0.2.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file xcdo-0.2.0.tar.gz.

File metadata

  • Download URL: xcdo-0.2.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xcdo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d48b1607816531ffbf2ecd719e6c18bbcfc025c76cb181bc7860288307372d3d
MD5 28503114662c5ca5f8ba5b91ec1f6bc0
BLAKE2b-256 8abdcb0dc45cab7befdd9089fc5b470fe61279b5392bde265e143572a9d0e965

See more details on using hashes here.

Provenance

The following attestation bundles were made for xcdo-0.2.0.tar.gz:

Publisher: publish.yml on prajeeshag/xcdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xcdo-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: xcdo-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xcdo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 934f66401c48c8bb2a4b7dcb39e9a89499f3e414dfb8f508c560441fd158c35b
MD5 0ec926dc7e9824c595e9e9ef5aea4957
BLAKE2b-256 e463dddeacf8a249747f923e9cd7c67fe0f71b699b07ec5e6749aa80bb0c7191

See more details on using hashes here.

Provenance

The following attestation bundles were made for xcdo-0.2.0-py3-none-any.whl:

Publisher: publish.yml on prajeeshag/xcdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page