Skip to main content
s2fft logo - schematic representation of a tiled sphere

S2FFT: differentiable and accelerated spherical transforms

Tests status Linting status Documentation status Codecov MIT License PyPI package arXiv All Contributors Open In Colab Linter

S2FFT is a Python package for computing Fourier transforms on the sphere and rotation group (Price & McEwen 2024) using JAX or PyTorch. It leverages autodiff to provide differentiable transforms, which are also deployable on hardware accelerators (e.g. GPUs and TPUs).

More specifically, S2FFT provides support for spin spherical harmonic and Wigner transforms (for both real and complex signals), with support for adjoint transformations where needed, and comes with different optimisations (precompute or not) that one may select depending on available resources and desired angular resolution $L$.

Algorithms ⚡

S2FFT leverages new algorithmic structures that can he highly parallelised and distributed, and so map very well onto the architecture of hardware accelerators (i.e. GPUs and TPUs). In particular, these algorithms are based on new Wigner-d recursions that are stable to high angular resolution $L$. The diagram below illustrates the recursions (for further details see Price & McEwen 2024).

Schematic of Wigner recursions

With this recursion to hand, the spherical harmonic coefficients of an isolatitudinally sampled map may be computed as a two step process. First, a 1D Fourier transform over longitude, for each latitudinal ring. Second, a projection onto the real polar-d functions. One may precompute and store all real polar-d functions for extreme acceleration, however this comes with an equally extreme memory overhead, which is infeasible at $L \sim 1024$. Alternatively, the real polar-d functions may calculated recursively, computing only a portion of the projection at a time, hence incurring negligible memory overhead at the cost of slightly slower execution. The diagram below illustrates the separable spherical harmonic transform (for further details see Price & McEwen 2024).

Schematic of forward and inverse spherical harmonic transforms

Sampling 🌍

The structure of the algorithms implemented in S2FFT can support any isolatitude sampling scheme. A number of sampling schemes are currently supported.

The equiangular sampling schemes of McEwen & Wiaux (2012), Driscoll & Healy (1995) and Gauss-Legendre (1986) are supported, which exhibit associated sampling theorems and so harmonic transforms can be computed to machine precision. Note that the McEwen & Wiaux sampling theorem reduces the Nyquist rate on the sphere by a factor of two compared to the Driscoll & Healy approach, halving the number of spherical samples required.

The popular HEALPix sampling scheme (Gorski et al. 2005) is also supported. The HEALPix sampling does not exhibit a sampling theorem and so the corresponding harmonic transforms do not achieve machine precision but exhibit some error. However, the HEALPix sampling provides pixels of equal areas, which has many practical advantages.

Visualization of spherical sampling schemes

[!NOTE] For algorithmic reasons JIT compilation of HEALPix transforms can become slow at high bandlimits, due to XLA unfolding of loops. After compilation, HEALPix transforms should execute with the efficiency outlined in the associated paper, therefore this additional time overhead need only be incurred once.

If running on a CPU, we provide (differentiable) JAX wrappers of the healpy transforms which can be used to sidestep the issue. This implementation can be selected by passing a method="jax_healpy" keyword argument to the s2fft.forward or s2fft.inverse functions - see example notebook.

If running on a GPU, a CUDA extension module is available which avoids the long compilation time. This implementation can be selected by passing a method="jax_cuda" keyword argument to the sfft.forward and s2fft.inverse functions. Currently we do not publish binary wheels with the CUDA extension support so you will need to build the package from source to use this functionality.

Installation 💻

The latest release of S2FFT published on PyPI can be installed by running

pip install s2fft

This will install S2FFT's dependencies including JAX if not already installed. As by default installing JAX from PyPI will use a CPU-only build, if you wish to install JAX with GPU or TPU support, you should first follow the relevant installation instructions in JAX's documentation and then install S2FFT as above.

Alternatively, the latest development version of S2FFT may be installed directly from GitHub by running

pip install git+https://github.com/astro-informatics/s2fft

CUDA extension support

To install the package with support for the CUDA extension module giving reduced compile times for running HEALPix transforms on the GPU, you will need to build from source on a system with CUDA (tested with version 12.3) and CMake (versions 3.19+) installed.

To install the latest development version from source in verbose mode run

pip install -v git+https://github.com/astro-informatics/s2fft

or to install a specific release tag in verbose mode run

pip install -v git+https://github.com/astro-informatics/s2fft@TAG

where TAG is the relevant version tag. The output should indicate if the CUDA install on your system is successfully detected.

Tests 🚦

A pytest test suite for the package is included in the tests directory. To install the test dependencies, clone the repository and install the package (in editable mode) with the extra test dependencies by running from the root of the repository

pip install -e ".[tests]"

To run the tests, run from the root of the repository

pytest

Documentation 📖

Documentation for the released version is available here. To install the documentation dependencies, clone the repository and install the package (in editable mode) with the extra documentation dependencies by running from the root of the repository

pip install -e ".[docs]"

To build the documentation, run from the root of the repository

cd docs
make html
open _build/html/index.html

Notebooks 📓

A series of tutorial notebooks are included in the notebooks directory and rendered in the documentation.

To install the dependencies required to run the notebooks locally, clone the repository and install the package (in editable mode) with the extra documentation and plotting dependencies by running from the root of the repository

pip install -e ".[docs,plotting]"

To run the notebooks in Jupyter Lab, run from the root of the repository

jupyter lab

Usage 🚀

To import and use S2FFT is as simple follows:

For a signal on the sphere

import s2fft

# Define sampled signal to transform and harmonic bandlimit
f = ...
L = ...
# Compute harmonic coefficients
flm = s2fft.forward(f, L, method="jax")
# Map back to pixel-space signal
f = s2fft.inverse(flm, L, method="jax")

For a signal on the rotation group

import s2fft

# Define sampled signal to transform and harmonic and azimuthal bandlimits
f = ...
L = ...
N = ...
# Compute Wigner coefficients
flmn = s2fft.wigner.forward(f, L, N, method="jax")
# Map back to pixel-space signal
f = fft.wigner.inverse_jax(flmn, L, N, method="jax")

For further details on usage see the documentation and associated notebooks.

We also provide PyTorch support for our transforms, as demonstrated in the Torch frontend tutorial notebook. This wraps the JAX implementations so JAX will need to be installed in addition to PyTorch.

SSHT & HEALPix wrappers 💡

S2FFT also provides JAX support for existing C/C++ packages, specifically HEALPix and SSHT. This works by wrapping Python bindings with custom JAX frontends. Note that this C/C++ to JAX interoperability is currently limited to CPU.

For example, one may call these alternate backends for the spherical harmonic transform by:

# Forward SSHT spherical harmonic transform
flm = s2fft.forward(f, L, sampling="mw", method="jax_ssht")

# Forward HEALPix spherical harmonic transform
flm = s2fft.forward(f, L, nside=nside, sampling="healpix", method="jax_healpy")

All of these JAX frontends supports out of the box reverse mode automatic differentiation, and under the hood is simply linking to the C/C++ packages you are familiar with. In this way S2fft enhances existing packages with gradient functionality for modern scientific computing or machine learning applications!

For further details on usage see the associated notebooks.

Benchmarks ⏱️

A suite of benchmark functions for both the on-the-fly and precompute versions of the spherical harmonic and Wigner transforms are available in the benchmarks directory, along with utilities for running the benchmarks and plotting the results.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Matt Price
Matt Price

💻 👀 🤔
Jason McEwen
Jason McEwen

💻 👀 🤔
Matt Graham
Matt Graham

💻 👀
sfmig
sfmig

💻 👀
Devaraj Gopinathan
Devaraj Gopinathan

💻
Francois Lanusse
Francois Lanusse

💻 🐛
Ikko Eltociear Ashimine
Ikko Eltociear Ashimine

📖
Kevin Mulder
Kevin Mulder

🐛
Philipp Misof
Philipp Misof

🐛 📖
Elis Roberts
Elis Roberts

🐛 📖
Wassim KABALAN
Wassim KABALAN

💻 👀 ⚠️
Mayeul d'Avezac
Mayeul d'Avezac

🚇
Will Graham
Will Graham

👀 💻 📖

We encourage contributions from any interested developers. A simple first addition could be adding support for more spherical sampling patterns!

Attribution 📚

Should this code be used in any way, we kindly request that the following article is referenced. A BibTeX entry for this reference may look like:

@article{price:s2fft,
   author      = "Matthew A. Price and Jason D. McEwen",
   title       = "Differentiable and accelerated spherical harmonic and Wigner transforms",
   journal     = "Journal of Computational Physics",
   year        = "2024",
   volume      = "510",
   pages       = "113109",
   eprint      = "arXiv:2311.14670",
   doi         = "10.1016/j.jcp.2024.113109"
}

You might also like to consider citing our related papers on which this code builds:

@article{mcewen:fssht,
    author      = "Jason D. McEwen and Yves Wiaux",
    title       = "A novel sampling theorem on the sphere",
    journal     = "IEEE Trans. Sig. Proc.",
    year        = "2011",
    volume      = "59",
    number      = "12",
    pages       = "5876--5887",
    eprint      = "arXiv:1110.6298",
    doi         = "10.1109/TSP.2011.2166394"
}
@article{mcewen:so3,
    author      = "Jason D. McEwen and Martin B{\"u}ttner and Boris ~Leistedt and Hiranya V. Peiris and Yves Wiaux",
    title       = "A novel sampling theorem on the rotation group",
    journal     = "IEEE Sig. Proc. Let.",
    year        = "2015",
    volume      = "22",
    number      = "12",
    pages       = "2425--2429",
    eprint      = "arXiv:1508.03101",
    doi         = "10.1109/LSP.2015.2490676"
}

License 📝

We provide this code under an MIT open-source licence with the hope that it will be of use to a wider community.

Copyright 2023 Matthew Price, Jason McEwen and contributors.

S2FFT is free software made available under the MIT License. For details see the LICENCE.txt file.

Metadata

Release files for s2fft 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 s2fft 1.4.0
File Size Uploaded
s2fft-1.4.0.tar.gz 22.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for s2fft 1.4.0
File
s2fft-1.4.0-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
s2fft-1.4.0-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
s2fft-1.4.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
s2fft-1.4.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
s2fft-1.4.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
s2fft-1.4.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 23.6 MB

Release files / s2fft-1.4.0.tar.gz

Download URL s2fft-1.4.0.tar.gz
Size 22.8 MB
Tags Source
SHA-256 checksum
How to use checksums
b84c0c2bb0c3dfabe3431360bf90224705554e92966ab87e92affc0fe8f956ba
BLAKE2b-256 checksum
How to use checksums
0260ac5914b6a5fce9df03d4c74eeeda9338c83eb3468fd856a08ea998b7656f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release files / s2fft-1.4.0-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL s2fft-1.4.0-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 138.6 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9ac7d4cee989d1e5d5724ec4bfd8259bade430c30bf916e5955548b541ba0b73
BLAKE2b-256 checksum
How to use checksums
2cb677f99f38bb0f09bf85f7b3667015941d003ecd880060955c1f6ea9edeef6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release files / s2fft-1.4.0-cp314-cp314t-macosx_11_0_arm64.whl

Download URL s2fft-1.4.0-cp314-cp314t-macosx_11_0_arm64.whl
Size 130.3 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
647edd6533035283e38567b8200937064e4e1fda3bad68f43c5c3259732816db
BLAKE2b-256 checksum
How to use checksums
531089793a12ecda9473651c4e8f395e9601fae02081e1f18e9b4af8c9035d85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release files / s2fft-1.4.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL s2fft-1.4.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 137.5 kB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
60ef04398dc4481232609a11d7ba4e0a9fbe3b311bbbab5a600f058dbaa7e61c
BLAKE2b-256 checksum
How to use checksums
bb747ec92e611283b1a559a0b2e535621985b66c6c48128207887a999448e472
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release files / s2fft-1.4.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL s2fft-1.4.0-cp312-abi3-macosx_11_0_arm64.whl
Size 129.4 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c5f984316b81fdfdcaffcfdcb2ba9bdf70b2c25d3ef23313f8123d360f566833
BLAKE2b-256 checksum
How to use checksums
0d1f39fc6e6f69a0c1f7de40f2defaa1ef80de33c66814b98506d850f18b0c18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release files / s2fft-1.4.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL s2fft-1.4.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 138.1 kB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
42a521700d4793f7ac8a2308233e561065567f03c98b91747c508f02ce4a2cd4
BLAKE2b-256 checksum
How to use checksums
9bbb0ca3beb35de790ac66a98c5ea1f8043125f9b331af1b0c519b1e62e0e342
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release files / s2fft-1.4.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL s2fft-1.4.0-cp311-cp311-macosx_11_0_arm64.whl
Size 129.8 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
739544caa6eb7cfa34700c1cc55634739601d8557819e88c7addce9fad93c7c5
BLAKE2b-256 checksum
How to use checksums
f9bc7175a55f8aa4c0e36fbe5c33b2d129309fe6025a0ad4a683e85c80cc45e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.4.0 This release

7 release files

1.3.0

34 release files

1.2.2

34 release files

1.2.0

35 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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