spharmgrid
Spherical harmonic tools for filtering, regridding, and kinematics in atmospheric science with Xarray, PyTorch, and JAX.
spharmgrid (spherical harmonic gridding) implements spherical harmonic filtering, regridding, differential operators, and atmospheric kinematics for global Xarray fields, PyTorch tensors, and JAX arrays. It computes relative vorticity, divergence, streamfunction, velocity potential, Helmholtz decomposition, and inverse wind transforms. The Xarray/NumPy API uses DUCC (ducc0) for spherical harmonic transforms; the optional PyTorch API uses torch-harmonics, and the optional JAX API uses S2FFT.
Supported grids are full rectangular Gauss–Legendre (GL) and Clenshaw–Curtis (CC) grids.
Install
Install with either pip, uv, or conda:
pip install spharmgrid
uv add spharmgrid
conda install -c conda-forge spharmgrid
Optional extras are:
spharmgrid[dask]— Dask-backed lazy execution;spharmgrid[cf]— optionalcf-xarraycoordinate discovery;spharmgrid[cli]— command-line NetCDF, Zarr, and GRIB I/O;spharmgrid[jax]— JAX arrays and S2FFT transforms;spharmgrid[torch]— PyTorch tensors and torch-harmonics transforms.
The spharmgrid.torch API can be installed with spharmgrid[torch]. See the
PyTorch API documentation
for installation instructions.
The spharmgrid.jax API requires JAX and S2FFT. See the
JAX API documentation
for supported GL and CC/MWSS dimensions, x64 and dtype requirements, and
examples. For CPU use, spharmgrid[jax] installs JAX and S2FFT. For GPU or
TPU use, install the appropriate JAX accelerator build first by following the
official JAX installation instructions,
then install spharmgrid[jax]; spharmgrid does not bundle or select CUDA or
TPU builds. The JAX API currently requires JAX x64 mode and float64 spatial
inputs; it does not enable x64 globally.
Install spharmgrid[cli,dask] to use the transforming CLI commands.
For a standalone command-line installation:
uv tool install "spharmgrid[cli,dask]"
For a project environment, install the CLI and Dask extras with either:
uv add "spharmgrid[cli,dask]"
pip install "spharmgrid[cli,dask]"
Quick start
Importing spharmgrid registers the .sg accessor on Xarray objects. This example applies a T6–42 spectral filter to a DataArray:
import xarray as xr
import spharmgrid
field = xr.open_dataarray("msl.nc")
filtered = field.sg.filter("T6-42")
See the Quick start for regridding, atmospheric wind diagnostics, direct-function equivalents, and further examples.
For differentiable PyTorch workflows, install spharmgrid[torch] and use
spharmgrid.torch:
import torch
import spharmgrid as sg
import spharmgrid.torch as sgt
grid = sg.gaussian_grid(64, 128)
field = torch.randn(grid.nlat, grid.nlon)
filtered = sgt.filter(field, grid=grid, truncation="T42")
See the PyTorch API documentation for tensor dimensions, reusable torch.nn modules, device/autograd behavior, and PyTorch bandwidth limits.
For differentiable JAX workflows, configure JAX x64 mode before creating
arrays and use spharmgrid.jax:
import jax
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
import spharmgrid as sg
import spharmgrid.jax as sgj
grid = sg.gaussian_grid(64, 127)
field = jnp.ones((grid.nlat, grid.nlon))
filtered = sgj.filter(field, grid=grid, truncation="T42")
The last two array dimensions are latitude and longitude.
Documentation
The optional CLI reads NetCDF, Zarr, and GRIB and writes NetCDF and Zarr. See the CLI documentation for installation and usage.
See the full documentation for grid requirements, coordinate handling, CF metadata, atmospheric kinematics, inverse transforms, zero-mode conventions, and command-line use.
Citation
If you use spharmgrid in research, please cite the software release DOI: 10.5281/zenodo.22559210. Citation metadata are also provided in CITATION.cff.
References
See the documentation References for the scientific literature and software cited by spharmgrid.
License
spharmgrid is distributed under the BSD 3-Clause License.
Metadata
Release files for spharmgrid 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spharmgrid-0.3.0.tar.gz | 279.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spharmgrid-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 338.8 kB
Release files / spharmgrid-0.3.0.tar.gz
| Download URL | spharmgrid-0.3.0.tar.gz |
|---|---|
| Size | 279.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b5e3c9646e3486578d15763d285b7d4079367ac3ca11d98c470abbb31e8593e
|
|
BLAKE2b-256 checksum How to use checksums |
8ff1f65f188167a4c8dc219b043929e2316960d1537ff7e1cb323d9201cb0cd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logRelease files / spharmgrid-0.3.0-py3-none-any.whl
| Download URL | spharmgrid-0.3.0-py3-none-any.whl |
|---|---|
| Size | 59.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
116095c6c4410892bd3c23354722a16a763c447c390a2704eecfbe7b651686c3
|
|
BLAKE2b-256 checksum How to use checksums |
d5ba7fb4a79129adb44df96ae99ed0e3930560edfa9cfa4ae7cbdff29267dcfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency log