Skip to main content

Xarray Extension for working with spherical harmonic data

DOI Build PyPI version Documentation Status

This extension adds functionality to work with Spherical Harmonics to Xarray.

Features and functionality

  • Gravity functionals: (convert from Stokes coefficients to various gravity functionals, such as equivalent water heights, geoid changes, etc.)
  • Filter (e.g. Gaussian or anisotropic filter applied in the spectral domain)
  • The use of Xarray-like operations allow for applying functionality to multi-dimensional datasets
  • A spectral sea level equation solver

Getting started

The tutorials in the documentation provide Jupyter Notebooks with examples of how to make use of the module. The notebooks can also be found on the github repository.

The functionality of shxarray becomes available when importing the module together with Xarray:

import shxarray
import xarray as xr

after which the shxarray accessor becomes available for use, e.g.:

nmax=20
nmin=2
dazeros=xr.DataArray.sh.ones(nmax=nmax,nmin=nmin)

Installation

You can install this package from PyPi using:

pip install shxarray

Backends

Shxarray comes with a default shlib backend written in C++ and Cython. In addition, a very fast 'shtns' backend can be used when SHTns is installed. The backends can be specified in enabled routines as the options: engine='shlib' or engine='shtns'.

Development Installation

If you want to help in the development of this package, it's best to clone the repository to allow for modifications and pull requests. The extension makes use of Cython generated code to speed up spherical harmonic synthesis and analysis.

  1. Create your own virtual environment with venv or Anaconda (Optional but recommended, when a user installation is desired)
  2. Clone this repository git clone https://github.com/ITC-Water-Resources/shxarray.git
  3. Change to the repository directory cd shaxarray
  4. Set the environment variable export USE_CYTHON=1 (Optional and only in the case Cython code is being developed or needs to be regenerated)
  5. Install using pip pip install . or use pip install -e . for an editable install

Cython build tip on an editable install

From the repository root directory, regenerating the shared library running

python ./setup.py build_ext

will be much faster than using

pip install -e .

This will build the shared library in for example ./build/lib.linux-x86_64-cpython-3xx/shxarray/shlib.cpython-3xx-x86_64-linux-gnu.so. To make sure changes are picked up in your editable install you should create a symbolic link in the Python part of the library e.g. :

cd src/shxarray/
ln -sf ../../build/lib.linux-x86_64-cpython-311/shxarray/shlib.cpython-311-x86_64-linux-gnu.so

Numpy version issues

The provided c++ files are cythonized against numpy > 2. When building against older numpy versions (<2), the cpp files are re-cythonized upon install, this requires a working cython installation.

Contributing

This repository is under development and contributions and feedback is welcome.

Contributors

Metadata

Release files for shxarray 1.4.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 shxarray 1.4.0
File Size Uploaded Provenance Actions
shxarray-1.4.0.tar.gz 25.1 MB With provenance Details for shxarray-1.4.0.tar.gz

Release files / shxarray-1.4.0.tar.gz

Download URL shxarray-1.4.0.tar.gz
Size 25.1 MB
Tags Source
SHA-256 checksum
How to use checksums
74c9d71b5f6f4d6cea5c0f3084dc261b2524f06a91655c26538416e3a7607795
BLAKE2b-256 checksum
How to use checksums
01c2638b39c7f408abfb96c9226c4f26de055a3d212f59f29a308c09259a0041
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 8, 2025.

Transparency log

Security for shxarray 1.4.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.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for shxarray-1.4.0.tar.gz

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 Jul 8, 2025.

Transparency log

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