s2fft
S2FFT: Differentiable and accelerated spherical transforms
Science Score: 59.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org, sciencedirect.com, springer.com -
✓Committers with academic emails
2 of 12 committers (16.7%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.9%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
S2FFT: Differentiable and accelerated spherical transforms
Basic Info
- Host: GitHub
- Owner: astro-informatics
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://astro-informatics.github.io/s2fft
- Size: 67.5 MB
Statistics
- Stars: 202
- Watchers: 10
- Forks: 13
- Open Issues: 48
- Releases: 9
Topics
Metadata Files
README.md
# S2FFT: differentiable and accelerated spherical transforms
[](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml)
[](https://github.com/astro-informatics/s2fft/actions/workflows/linting.yml)
[](https://github.com/astro-informatics/s2fft/actions/workflows/docs.yml)
[](https://codecov.io/gh/astro-informatics/s2fft)
[](https://opensource.org/licenses/MIT)
[](https://badge.fury.io/py/s2fft)
[](https://arxiv.org/abs/2311.14670)

[](https://colab.research.google.com/github/astro-informatics/s2fft/blob/main/notebooks/spherical_harmonic_transform.ipynb)
[](https://github.com/astral-sh/ruff)
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).
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).
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.
[!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
healpytransforms which can be used to sidestep the issue. This implementation can be selected by passing amethod="jax_healpy"keyword argument to thes2fft.forwardors2fft.inversefunctions - 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 thesfft.forwardands2fft.inversefunctions. 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
bash
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
bash
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
bash
pip install -v git+https://github.com/astro-informatics/s2fft
or to install a specific release tag in verbose mode run
bash
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
bash
pip install -e ".[tests]"
To run the tests, run from the root of the repository
bash
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
bash
pip install -e ".[docs]"
To build the documentation, run from the root of the repository
bash
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
bash
pip install -e ".[docs,plotting]"
To run the notebooks in Jupyter Lab, run from the root of the repository
bash
jupyter lab
Usage
To import and use S2FFT is as simple follows:
For a signal on the sphere
```python 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
```python 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:
``` python
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): <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable -->
Matt Price |
Jason McEwen |
Matt Graham |
sfmig |
Devaraj Gopinathan |
Francois Lanusse |
Ikko Eltociear Ashimine |
Kevin Mulder |
Philipp Misof |
Elis Roberts |
Wassim KABALAN |
Mayeul d'Avezac |
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.
The file lib/include/kernel_helpers.h is adapted from
code in a tutorial on extending JAX by
Dan Foreman-Mackey and licensed under a MIT license.
The file lib/include/kernel_nanobind_helpers.h
is adapted from code
by the JAX authors
and licensed under a Apache-2.0 license.
Owner
- Name: AstroInfo Team @ UCL
- Login: astro-informatics
- Kind: organization
- Location: United Kingdom
- Website: http://www.jasonmcewen.org/
- Repositories: 29
- Profile: https://github.com/astro-informatics
GitHub Events
Total
- Create event: 47
- Release event: 4
- Issues event: 51
- Watch event: 62
- Delete event: 39
- Member event: 1
- Issue comment event: 102
- Push event: 310
- Pull request review event: 54
- Pull request review comment event: 38
- Pull request event: 85
- Fork event: 4
Last Year
- Create event: 47
- Release event: 4
- Issues event: 51
- Watch event: 62
- Delete event: 39
- Member event: 1
- Issue comment event: 102
- Push event: 310
- Pull request review event: 54
- Pull request review comment event: 38
- Pull request event: 85
- Fork event: 4
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| CosmoMatt | m****e@h****k | 413 |
| Jason McEwen | j****n@g****m | 182 |
| Matt Graham | m****m@g****m | 154 |
| Wassim KABALAN | w****v@g****m | 38 |
| Devaraj Gopinathan | d****n@u****k | 36 |
| allcontributors[bot] | 4****] | 25 |
| dependabot[bot] | 4****] | 6 |
| EiffL | f****l@g****m | 4 |
| Philipp Misof | m****f@c****e | 2 |
| Ikko Eltociear Ashimine | e****r@g****m | 1 |
| Elis Roberts | e****s@i****m | 1 |
| CosmoMatt | m****e@k****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 138
- Total pull requests: 146
- Average time to close issues: 3 months
- Average time to close pull requests: 12 days
- Total issue authors: 13
- Total pull request authors: 11
- Average comments per issue: 1.08
- Average comments per pull request: 1.37
- Merged pull requests: 125
- Bot issues: 0
- Bot pull requests: 26
Past Year
- Issues: 50
- Pull requests: 87
- Average time to close issues: about 1 month
- Average time to close pull requests: 12 days
- Issue authors: 9
- Pull request authors: 10
- Average comments per issue: 1.16
- Average comments per pull request: 1.17
- Merged pull requests: 69
- Bot issues: 0
- Bot pull requests: 23
Top Authors
Issue Authors
- jasonmcewen (66)
- matt-graham (42)
- CosmoMatt (11)
- PhilippMisofCH (5)
- Magwos (4)
- ASKabalan (3)
- lgrcia (2)
- sijil-jose (2)
- mariogeiger (1)
- mreineck (1)
- ntessore (1)
- MEH04 (1)
- ElisR (1)
- yangjinhui11 (1)
Pull Request Authors
- matt-graham (71)
- CosmoMatt (41)
- jasonmcewen (25)
- dependabot[bot] (18)
- allcontributors[bot] (13)
- ASKabalan (4)
- ElisR (2)
- PhilippMisofCH (2)
- ntessore (1)
- eltociear (1)
- kmulderdas (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 455 last-month
- Total dependent packages: 2
- Total dependent repositories: 0
- Total versions: 8
- Total maintainers: 3
pypi.org: s2fft
Differentiable and accelerated spherical transforms with JAX
- Documentation: https://s2fft.readthedocs.io/
- License: MIT License Copyright (c) 2022 Authors & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 1.3.0
published 10 months ago
Rankings
Maintainers (3)
Dependencies
- JamesIves/github-pages-deploy-action 4.1.5 composite
- actions/checkout v2.3.1 composite
- actions/setup-python v2 composite
- actions/checkout v2.3.1 composite
- actions/setup-python v2 composite
- colorlog *
- ipykernel *
- ipywidgets *
- jax >=0.3.13
- numpy >=1.20
- pyssht *
- pyvista *
- pyyaml *
- trame *
- ipython ==7.16.1
- jupyter ==1.0.0
- nbsphinx-link ==1.3.0
- pydata-sphinx-theme ==0.12.0
- sphinx ==4.2.0
- sphinx-copybutton *
- sphinx-git ==11.0.0
- sphinx-tabs ==3.2.0
- sphinx_rtd_theme *
- sphinx_toolbox ==2.15.0
- sphinxcontrib-bibtex ==2.4.1
- sphinxcontrib-texfigure ==0.1.3
- sphinxemoji *
- codecov * test
- healpy * test
- jaxlib * test
- pytest * test
- pytest-cov * test
- so3 * test
- ipykernel *
- ipywidgets *
- pyvista *
- trame *