Welcome to pycdo
| Package | |
| Coverage | |
| Meta |
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.
Release files for pycdo 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycdo-0.2.1.tar.gz | 33.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycdo-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 299.0 kB
Release files / pycdo-0.2.1.tar.gz
| Download URL | pycdo-0.2.1.tar.gz |
|---|---|
| Size | 33.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e828d767279501e7bb6ee63b76d094fe1bd052e4fb96102ed7b9e42be088df9
|
|
BLAKE2b-256 checksum How to use checksums |
f812bf06f472a0117e4a37904def9c78820089e45baa21d859bbade62175f8ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.2 cpython/3.12.3 HTTPX/0.28.1
|
Release files / pycdo-0.2.1-py3-none-any.whl
| Download URL | pycdo-0.2.1-py3-none-any.whl |
|---|---|
| Size | 266.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80a7585850b90abb578133506a6ae8ff371cc301ed00bd80bce15a0cef90ef3a
|
|
BLAKE2b-256 checksum How to use checksums |
dd9821f194fb5bdaf8818f0862edf4a2ea005864a3ee55357b20c25a47c49621
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.2 cpython/3.12.3 HTTPX/0.28.1
|