Skip to main content

Maintenance PyTest Coverage Status PyPI Conda Documentation DOI

smmregrid

A compact python regridder using sparse matrix multiplication

The regridder uses CDO as a backend for weights computation, and then uses efficiently sparse matrix multiplication with dask to provide xarray lazy output. It supports all grids supported by CDO.

Please note that this tool is not thought as "another interpolation tool", but rather a method to apply pre-computed weights within the python environment. The speedup against CDO is estimated to be about ~1.5 to ~5 times, slightly lower if then files are written to the disk. 2D and 3D data are supported on all the grids supported by CDO, and special treatment can be assigned to vertical coordinates with changing mask (e.g. ocean 3D datasets). It works smoothly on both xarray.Dataset and xarray.DataArray. Attributes are kept and target grids can be both file on disk or CDO-compliant grids (e.g. r180x90, F128, etc).

The tool works for python versions >=3.10 and requires CDO >= 2.6.2. It is safer to run it through conda/mamba.

Linux

The simplest way is to install smmregrid from conda-forge, which brings in all the binary dependencies (including CDO and eccodes):

mamba create -n smmregrid -c conda-forge smmregrid
mamba activate smmregrid

Or, installing from PyPI:

mamba create -n smmregrid "python>=3.10" cdo eccodes numba
mamba activate smmregrid
pip install smmregrid

Alternatively, you can clone the repo and use the environment file available

git clone https://github.com/jhardenberg/smmregrid.git
cd smmregrid
mamba env create -f environment.yml
mamba activate smmregrid

macOS

Recent CDO versions are not available from conda-forge for macOS, so CDO must be installed with Homebrew, while the python environment is still managed with conda/mamba:

brew install cdo
mamba create -n smmregrid -c conda-forge smmregrid

The conda-forge package of smmregrid does not include CDO on macOS. Similarly, if you install from PyPI:

brew install cdo
mamba create -n smmregrid "python>=3.10" eccodes numba
mamba activate smmregrid
pip install smmregrid

or, from the cloned repo, use the dedicated environment file (which does not include CDO):

brew install cdo
mamba env create -f environment-macos.yml
mamba activate smmregrid

Which CDO is used

smmregrid looks for the CDO executable in this order:

  1. the cdo argument of Regridder / CdoGenerate, if provided;
  2. the CDO environment variable (the same used by python-cdo);
  3. cdo in the PATH.

On macOS, make sure that no cdo from conda-forge is installed in your environment (e.g. pulled in by another package), since it would shadow the Homebrew one in the PATH. If you cannot avoid it, point smmregrid to the Homebrew CDO explicitly:

export CDO=$(brew --prefix)/bin/cdo

The CDO version is checked at runtime, and an error is raised if it is older than the minimum supported. You can check which version is used with python -c "import smmregrid; print(smmregrid.cdo_version())".

As a disclaimer, this repository represents a modification of the regridding routines developed in climtas by Scott Wales, which already implements efficiently this idea and has no other significant dependencies.

Cautionary notes:

  • It does not work correctly if the Xarray.Dataset includes fields with time-varying missing points
  • It works only with interpolation methods/grids supported by CDO
  • It does not support ESMF weigths.

Metadata

Release files for smmregrid 0.3.0

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

Source distribution (sdist)

Source distribution for smmregrid 0.3.0
File Size Uploaded Provenance Actions
smmregrid-0.3.0.tar.gz 42.3 kB Without provenance Details for smmregrid-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 86.9 kB

Release files / smmregrid-0.3.0.tar.gz

Download URL smmregrid-0.3.0.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
de48aeab49f472f4d5f636bd9dcc9aa14ee25819115eeeea8ec7804475ad4ba1
BLAKE2b-256 checksum
How to use checksums
6fe3a3949014ae50e91707eb52c4674aa59256225b3287cc1b160535a2c1c6c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / smmregrid-0.3.0-py3-none-any.whl

Download URL smmregrid-0.3.0-py3-none-any.whl
Size 44.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e088289bc939811d3f52b5ee74fb096099b29b15380f63cec73e98917d2e2a26
BLAKE2b-256 checksum
How to use checksums
1874179782afca684cb51c45b91ebfc7c47926568dd1c954b696a337294c68c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for smmregrid 0.3.0

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.

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