Skip to main content

Python wrapper of the Climate Data Operators

Project description

Welcome to pycdo

Package Latest PyPI Version Supported Python Versions
Coverage Codecov test coverage
Meta Code of Conduct

pycdo is a wrapper for the Climate Data Operators (CDO). It allows chaining CDO operators using method chaining and handles options and temporary files for you.

Get started

You can install this package into your preferred Python environment using pip:

pip install pycdo

Example

from pycdo import cdo, cdo_options, cdo_cache, geopotential

The ymonmean operator computes monthly annual cycle. The pycdo function is cdo_ymonmean()

cdo(geopotential).ymonmean()
CDO operation.
cdo -ymonmean [ /home/user1/Documents/python/pycdo/src/pycdo/data/geopotential.nc ] {output}

The output just prints the command with a place holder output. Use .execute() to actually run the command. If no output file is specified, then the result is saved in a tempfile.

cdo(geopotential).ymonmean().execute()
'/tmp/tmpio8g3urm'

Operators can be chained. Lets select just the Southern Hemisphere first.

(
    cdo(geopotential)
    .sellonlatbox(0, 360, -90, 0)
    .ymonmean()
    .execute()
)
'/tmp/tmpnojlbike'

We can save operations to execute later or as input for other operations

sh_geopotential = (
    cdo(geopotential)
    .sellonlatbox(0, 360, -90, 0)
    .sellevel(300)
    .ymonmean()
) 

cdo(sh_geopotential).ymonmean().execute()
'/tmp/tmpfj30dnfe'

Temporary files are deleted when the variables holding them are garbage collected to prevent blowing up disk space when iterating over the same code.

For long-running operations, you can set up a cache.

cdo_cache.set("data/pycdo")
<pycdo.cdo_cache.CdoCache at 0x708498224710>

This turns off the automatic deletion and returns existing files instead of re-runing CDO operators.

import time
# First run. 
start = time.time()
sh_geopotential.execute()
time.time() - start
0.060179710388183594
# Second run just returns the existing file
start = time.time()
sh_geopotential.execute()
time.time() - start
0.0006704330444335938

You can set global options that will apply to all operations.

cdo_options.set("-Z")  # Compress result
sh_geopotential
CDO operation.
cdo -Z -ymonmean [ -sellevel,300 [ -sellonlatbox,0,360,-90,0 [ /home/user1/Documents/python/pycdo/src/pycdo/data/geopotential.nc ] ] ] {output}
import shutil
shutil.rmtree("data/pycdo")

Copyright

  • Copyright © 2025 Elio Campitelli.
  • Free software distributed under the MIT License.

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

pycdo-0.2.1.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

pycdo-0.2.1-py3-none-any.whl (266.0 kB view details)

Uploaded Python 3

File details

Details for the file pycdo-0.2.1.tar.gz.

File metadata

  • Download URL: pycdo-0.2.1.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.12.3 HTTPX/0.28.1

File hashes

Hashes for pycdo-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3e828d767279501e7bb6ee63b76d094fe1bd052e4fb96102ed7b9e42be088df9
MD5 a903437d856173ffd55442795d688834
BLAKE2b-256 f812bf06f472a0117e4a37904def9c78820089e45baa21d859bbade62175f8ae

See more details on using hashes here.

File details

Details for the file pycdo-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pycdo-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 266.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.12.3 HTTPX/0.28.1

File hashes

Hashes for pycdo-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80a7585850b90abb578133506a6ae8ff371cc301ed00bd80bce15a0cef90ef3a
MD5 7d77a538f16c6d21d9f0def373a917c0
BLAKE2b-256 dd9821f194fb5bdaf8818f0862edf4a2ea005864a3ee55357b20c25a47c49621

See more details on using hashes here.

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