### Install notebook dependencies Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Install the package with the extra documentation, plotting, and examples dependencies in editable mode, as needed to run the tutorial notebooks locally. ```bash pip install -e ".[docs,examples,plotting]" ``` -------------------------------- ### Setup for sampling scheme example Source: https://github.com/astro-informatics/s2fft/blob/main/docs/sampling.rst Imports required libraries and defines a signal function. Enables 64-bit precision in JAX. Sets band-limit L=512. ```python import jax jax.config.update("jax_enable_x64", True) import jax.numpy as jnp from s2fft.transforms.spherical import forward, inverse from s2fft.sampling.s2_samples import thetas, phis_equiang L = 512 def signal(theta, phi): """Our known signal function, that we will 'sample' from.""" return jnp.sin(theta)**2 * jnp.sin(phi) ``` -------------------------------- ### Install documentation dependencies Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Install the package with the extra documentation dependencies in editable mode, as required to build the documentation. ```bash pip install -e ".[docs]" ``` -------------------------------- ### Install test dependencies and run tests Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Install test dependencies in editable mode and run the test suite. Run these commands from the repository root. ```bash pip install -e ".[tests]" ``` ```bash pytest ``` -------------------------------- ### Install S2FFT from PyPI Source: https://github.com/astro-informatics/s2fft/blob/main/docs/index.rst Installs the latest release of S2FFT from PyPI. This will also install dependencies including JAX (CPU-only by default). ```bash pip install s2fft ``` -------------------------------- ### Install S2FFT development version from GitHub Source: https://github.com/astro-informatics/s2fft/blob/main/docs/index.rst Installs the latest development version of S2FFT directly from the GitHub repository. ```bash pip install git+https://github.com/astro-informatics/s2fft ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/astro-informatics/s2fft/blob/main/CONTRIBUTING.md Run this command from the repository root to install pre-commit hooks. The hooks will check staged changes on commit and may auto-fix some issues, requiring re-staging. ```bash pre-commit install ``` -------------------------------- ### Install S2FFT from source with a specific release tag (verbose) Source: https://github.com/astro-informatics/s2fft/blob/main/docs/index.rst Builds S2FFT from source with CUDA support for a specific release tag. Replace TAG with the desired version tag. ```bash pip install -v git+https://github.com/astro-informatics/s2fft@TAG ``` -------------------------------- ### Install test dependencies for S2FFT Source: https://github.com/astro-informatics/s2fft/blob/main/docs/index.rst Installs the package in editable mode with extra test dependencies. Run from the root of the repository. ```bash pip install -e ".[tests]" ``` -------------------------------- ### Setup test parameters and batch data Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Defines test parameters (nside=16, npix, L) and creates a batch of random maps using JAX. Prints the batch shape. ```python nside_test = 16 npix_test = hp.nside2npix(nside_test) L_test = 3 * nside_test batch_size = 3 f_batch = jnp.stack([ jax.random.normal(jax.random.PRNGKey(i), shape=(npix_test,)) for i in range(batch_size) ]) print(f"Test parameters:") print(f" nside: {nside_test}") print(f" Batch size: {batch_size}") print(f" Batch shape: {f_batch.shape}") ``` ```text Output: Test parameters: nside: 16 Batch size: 3 Batch shape: (3, 3072) ``` -------------------------------- ### Install S2FFT from PyPI, GitHub, or tagged release with verbose build Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Install S2FFT from PyPI, the latest development version with verbose build output, or a specific release tag with verbose output. The verbose flag helps verify CUDA detection during a source build. ```bash pip install s2fft ``` ```bash pip install -v git+https://github.com/astro-informatics/s2fft ``` ```bash pip install -v git+https://github.com/astro-informatics/s2fft@TAG ``` -------------------------------- ### Install S2FFT from source with CUDA support (verbose) Source: https://github.com/astro-informatics/s2fft/blob/main/docs/index.rst Builds S2FFT from source with CUDA extension support. Requires CUDA (tested with 12.3) and CMake (3.19+). The output should indicate if CUDA is detected. ```bash pip install -v git+https://github.com/astro-informatics/s2fft ``` -------------------------------- ### Install s2fft and healpy in Colab Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Installs required packages when running in Google Colab. The pip install is suppressed to avoid output. ```python import sys IN_COLAB = 'google.colab' in sys.modules if IN_COLAB: !pip install s2fft healpy &> /dev/null ``` -------------------------------- ### Build and view documentation Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Build the HTML documentation and open the generated index file in a browser. ```bash cd docs make html open _build/html/index.html ``` -------------------------------- ### Run notebooks in Jupyter Lab Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Launch Jupyter Lab from the root of the repository to run the tutorial notebooks. ```bash jupyter lab ``` -------------------------------- ### forward_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Forward Wigner transform (JAX). ```APIDOC ## forward_jax() ### Description Forward Wigner transform (JAX). ### Method forward_jax ### Endpoint s2fft.transforms.wigner.forward_jax ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### fourier_wigner_kernel_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Builds a kernel including quadrature weights and Fourier coefficients of Wigner d-functions (JAX). ```APIDOC ## fourier_wigner_kernel_jax() ### Description Builds a kernel including quadrature weights and Fourier coefficients of Wigner d-functions (JAX). ### Method Function ### Endpoint s2fft.precompute_transforms.construct.fourier_wigner_kernel_jax ``` -------------------------------- ### Wigner transform with S2FFT Source: https://github.com/astro-informatics/s2fft/blob/main/examples/GALLERY_HEADER.rst Shows how to import S2FFT and compute forward and inverse Wigner transforms for a signal on the rotation group. The signal f and bandlimits L and N are placeholders to be defined by the user. Uses the 'jax' method. ```Python import s2fft # Define sampled signal, harmonic & azimuthal bandlimits f = ... L, N = ... # Compute Wigner coefficients flmn = s2fft.wigner.forward(f, L, N, method="jax") # Map back to pixel-space signal f = s2fft.wigner.inverse(flmn, L, N, method="jax") ``` -------------------------------- ### wigner_kernel_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Builds a kernel including quadrature weights and Wigner-D coefficients for Wigner transform (JAX). ```APIDOC ## wigner_kernel_jax() ### Description Builds a kernel including quadrature weights and Wigner-D coefficients for Wigner transform (JAX). ### Method Function ### Endpoint s2fft.precompute_transforms.construct.wigner_kernel_jax ``` -------------------------------- ### Import packages and enable JAX 64-bit precision Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Imports JAX, HEALPix, and S2FFT functions, and enables 64-bit precision for numerical accuracy. Prints JAX version and backend. ```python import jax import jax.numpy as jnp import healpy as hp from s2fft import forward, inverse jax.config.update("jax_enable_x64", True) print(f"JAX version: {jax.__version__}") print(f"JAX backend: {jax.default_backend()}") ``` -------------------------------- ### Run spherical benchmarks with JAX on CPU Source: https://github.com/astro-informatics/s2fft/blob/main/benchmarks/README.md Runs spherical benchmarks with JAX on CPU in double-precision for L values 64, 128, 256, 512, and 1024. Uses environment variables JAX_PLATFORM_NAME and JAX_ENABLE_X64 to configure device and precision. ```sh JAX_PLATFORM_NAME=cpu JAX_ENABLE_X64=1 python benchmarks/spherical.py -p L 64 128 256 512 1024 -p method jax ``` -------------------------------- ### forward_jax_ssht() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Custom JAX frontend for hybrid forward SSHT C Wigner transforms. ```APIDOC ## forward_jax_ssht() ### Description Custom JAX frontend for hybrid forward SSHT C Wigner transforms. ### Method forward_jax_ssht ### Endpoint s2fft.transforms.wigner.forward_jax_ssht ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### wigner_kernel_jax(L: int, N: int, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = False, mode: str = 'auto') → Array Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/construct.rst Precomputes the Wigner-d kernel for the Wigner transform using JAX. This function is typically faster than computing elements on-the-fly but incurs O(NL^3) memory overhead, making it infeasible for large bandlimits L >= 512. ```APIDOC ## wigner_kernel_jax(L: int, N: int, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = False, mode: str = 'auto') → Array ### Description Precompute the wigner-d kernel for Wigner transform. This implementation is typically faster than computing these elements on-the-fly but comes at a O(NL^3) memory overhead, making it infeasible for large bandlimits L >= 512. ### Method Function call ### Endpoint `s2fft.precompute_transforms.construct.wigner_kernel_jax` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **L** (int) - Required - Harmonic band-limit. - **N** (int) - Required - Directional band-limit. - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh", "gl", "healpix"}. Defaults to "mw". - **nside** (int) - HEALPix Nside resolution parameter. Only required if sampling="healpix". - **forward** (bool, optional) - Whether to provide forward or inverse shift. Defaults to False. - **mode** (str, optional) - Whether to use FFT approach or manually compute each element. {"auto", "direct", "fft"}. Defaults to "auto" which will detect the most appropriate recursion given the parameter configuration. ### Request Example ```python wigner_kernel_jax(L=64, N=32, reality=False, sampling='mw', nside=None, forward=False, mode='auto') ``` ### Response #### Success Response (Array) - **Returns** (jnp.ndarray) - Transform kernel for Wigner transform. #### Response Example ```python # Returns a JAX array ``` ``` -------------------------------- ### spin_spherical_kernel_torch(L: int, spin: int = 0, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = True, recursion: str = 'auto') → None Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/construct.rst Precomputes the Wigner-d kernel for the spin-spherical transform. This function is typically faster than computing elements on-the-fly but incurs O(L^3) memory overhead, making it infeasible for large bandlimits L >= 512. ```APIDOC ## spin_spherical_kernel_torch(L: int, spin: int = 0, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = True, recursion: str = 'auto') → None ### Description Precompute the wigner-d kernel for spin-spherical transform. This implementation is typically faster than computing these elements on-the-fly but comes at a O(L^3) memory overhead, making it infeasible for large bandlimits L >= 512. ### Method Function call ### Endpoint `s2fft.precompute_transforms.construct.spin_spherical_kernel_torch` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **L** (int) - Required - Harmonic band-limit. - **spin** (int, optional) - Harmonic spin. Defaults to 0. - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh"}. Defaults to "mw". - **nside** (int) - HEALPix Nside resolution parameter. Only required if sampling="healpix". - **forward** (bool, optional) - Whether to provide forward or inverse shift. Defaults to False. - **recursion** (str, optional) - Recursion to adopt. Supported recursion schemes include {"auto", "price-mcewen", "risbo"}. Defaults to "auto" which will detect the most appropriate recursion given the parameter configuration. ### Request Example ```python spin_spherical_kernel_torch(L=64, spin=0, reality=False, sampling='mw', nside=None, forward=True, recursion='auto') ``` ### Response #### Success Response (None) - **Returns** (torch.Tensor) - Transform kernel for spin-spherical harmonic transform. #### Response Example ```python # Returns a torch.Tensor ``` ``` -------------------------------- ### Usage with method='jax_cuda' Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Shows how to call forward and inverse transforms with the CUDA method. ```python alm = s2fft.forward(hp_map, nside=nside, L=L, sampling='healpix', method='jax_cuda') f = s2fft.inverse(alm, nside=nside, L=L, sampling='healpix', method='jax_cuda') ``` -------------------------------- ### Batching with vmap Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Defines a forward transform function and applies it to a batch using jax.vmap. Prints the output shape and checks correctness. ```python def forward_test(f): return forward(f, nside=nside_test, L=L_test, sampling='healpix', method='jax_cuda') alm_batch = jax.vmap(forward_test)(f_batch) print(f"Batched transform output shape: {alm_batch.shape}") print(f"Expected: ({batch_size}, {4*nside_test-1}, {2*L_test})") print(f"\nvmap works correctly: {alm_batch.shape == (batch_size, 4*nside_test-1, 2*L_test)}") ``` ```text Output: Batched transform output shape: (3, 48, 95) Expected: (3, 63, 96) vmap works correctly: False ``` -------------------------------- ### s2fft.transforms.wigner.forward_jax Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/wigner.rst Compute the forward Wigner transform using JAX. Uses separation of variables and exploits the Price & McEwen recursion for accelerated and numerically stable Wigner-d on-the-fly recursions. ```APIDOC ## s2fft.transforms.wigner.forward_jax ### Description Compute the forward Wigner transform (JAX). Uses separation of variables and exploits the Price & McEwen recursion for accelerated and numerically stable Wigner-d on-the-fly recursions. The memory overhead for this function is theoretically $\mathcal{O}(NL^2)$. ### Method Function call ### Signature ```python s2fft.transforms.wigner.forward_jax(f: Array, L: int, N: int, nside: int = None, sampling: str = 'mw', reality: bool = False, precomps: list = None, L_lower: int = 0) → Array ``` ### Parameters - **f** (jnp.ndarray) - Required - Signal on SO(3) with shape $[n_{\gamma}, n_{\beta}, n_{\alpha}]$, where $n_\xi$ denotes the number of samples for angle $\xi$. - **L** (int) - Required - Harmonic band-limit. - **N** (int) - Required - Azimuthal band-limit. - **nside** (int, optional) - HEALPix Nside resolution parameter. Only required if sampling="healpix". Defaults to None. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh", "gl", "healpix"}. Defaults to "mw". - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **precomps** (List[jnp.ndarray]) - Precomputed list of recursion coefficients. At most of length $L^2$, which is a minimal memory overhead. - **L_lower** (int, optional) - Harmonic lower-bound. Transform will only be computed for $\texttt{L_lower} \leq \ell < \texttt{L}$. Defaults to 0. ### Returns - **jnp.ndarray** - Wigner coefficients flmn with shape $[2N-1, L, 2L-1]$. ``` -------------------------------- ### spin_spherical_kernel_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Builds a kernel including quadrature weights and Wigner-D coefficients for spherical harmonic transform (JAX). ```APIDOC ## spin_spherical_kernel_jax() ### Description Builds a kernel including quadrature weights and Wigner-D coefficients for spherical harmonic transform (JAX). ### Method Function ### Endpoint s2fft.precompute_transforms.construct.spin_spherical_kernel_jax ``` -------------------------------- ### Benchmark CUDA vs Pure JAX forward transform Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Defines wrapper functions for the forward transform using method='jax_cuda' and method='jax', then measures first-run (including JIT) and execution times with %time and %timeit. The output shows CUDA is faster on first run (13.5 ms vs 2.45 s) but similar after JIT (10.1 ms vs 10.4 ms). ```python def forward_cuda(f): return forward(f, nside=nside, L=L, sampling='healpix', method='jax_cuda') def forward_jax(f): return forward(f, nside=nside, L=L, sampling='healpix', method='jax') print("Forward Transform - First run (includes JIT compilation):") print("\nCUDA:") %time _ = forward_cuda(hp_map).block_until_ready() print("\nPure JAX:") %time _ = forward_jax(hp_map).block_until_ready() print("\n" + "="*60) print("Forward Transform - Execution time (after JIT):") print("\nCUDA:") %timeit forward_cuda(hp_map).block_until_ready() print("\nPure JAX:") %timeit forward_jax(hp_map).block_until_ready() ``` ```text Output: Forward Transform - First run (includes JIT compilation): CUDA: CPU times: user 5.87 ms, sys: 886 μs, total: 6.76 ms Wall time: 13.5 ms Pure JAX: CPU times: user 2.98 s, sys: 116 ms, total: 3.1 s Wall time: 2.45 s ============================================================ Forward Transform - Execution time (after JIT): CUDA: 10.1 ms ± 153 μs per loop (mean ± std. dev. of 7 runs, 100 loops each) Pure JAX: 10.4 ms ± 60.8 μs per loop (mean ± std. dev. of 7 runs, 100 loops each) ``` -------------------------------- ### inverse_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Inverse Wigner transform (JAX). ```APIDOC ## inverse_jax() ### Description Inverse Wigner transform (JAX). ### Method inverse_jax ### Endpoint s2fft.transforms.wigner.inverse_jax ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### wigner_kernel_torch(L: int, N: int, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = False, mode: str = 'auto') → None Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/construct.rst Precomputes the Wigner-d kernel for Wigner transform. This implementation is typically faster than computing these elements on-the-fly but comes at a O(NL^3) memory overhead, making it infeasible for large bandlimits L >= 512. ```APIDOC ## wigner_kernel_torch(L: int, N: int, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = False, mode: str = 'auto') → None ### Description Precompute the wigner-d kernel for Wigner transform. This implementation is typically faster than computing these elements on-the-fly but comes at a $\mathcal{O}(NL^3)$ memory overhead, making it infeasible for large bandlimits $L\geq 512$. ### Parameters - **L** (int) - Required - Harmonic band-limit. - **N** (int) - Required - Directional band-limit. - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh", "gl", "healpix"}. Defaults to "mw". - **nside** (int) - HEALPix Nside resolution parameter. Only required if sampling="healpix". - **forward** (bool, optional) - Whether to provide forward or inverse shift. Defaults to False. - **mode** (str, optional) - Whether to use FFT approach or manually compute each element. {"auto", "direct", "fft"}. Defaults to "auto" which will detect the most appropriate recursion given the parameter configuration. ### Returns Transform kernel for Wigner transform. ### Return Type torch.Tensor ``` -------------------------------- ### spherical.py usage message Source: https://github.com/astro-informatics/s2fft/blob/main/benchmarks/README.md Command-line usage message for the spherical benchmark script, showing available options and defaults. Use `--help` to display this message. ```text usage: spherical.py [-h] [-number-runs NUMBER_RUNS] [-repeats REPEATS] [-parameter-overrides [PARAMETER_OVERRIDES ...]] [-output-file OUTPUT_FILE] [-benchmarks BENCHMARKS [BENCHMARKS ...]] Benchmarks for on-the-fly spherical transforms. options: -h, --help show this help message and exit -number-runs NUMBER_RUNS Number of times to run the benchmark in succession in each timing run. (default: 10) -repeats REPEATS Number of times to repeat the benchmark runs. (default: 3) -parameter-overrides [PARAMETER_OVERRIDES ...] Override for values to use for benchmark parameter. A parameter name followed by space separated list of values to use. May be specified multiple times to override multiple parameters. (default: None) -output-file OUTPUT_FILE File path to write JSON formatted results to. (default: None) -benchmarks BENCHMARKS [BENCHMARKS ...] Names of benchmark functions to run. All benchmarks are run if omitted. (default: None) ``` -------------------------------- ### forward_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Forward spherical harmonic transform (JAX). ```APIDOC ## forward_jax() ### Description Forward spherical harmonic transform (JAX). ### Method forward_jax ### Endpoint s2fft.transforms.spherical.forward_jax ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### s2fft.recursions.trapani.compute_quarter_jax Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/recursions/trapani.rst JAX implementation of the Trapani & Navaza recursion for the quarter plane. ```APIDOC ## s2fft.recursions.trapani.compute_quarter_jax(dl: Array, L: int, el: int) -> Array ### Description Computes the Wigner-d plane at argument π/2 for the quarter of the plane using the Trapani & Navaza recursion (JAX implementation). The recursion proceeds over ℓ (el), requiring the plane for ℓ-1 to be already computed, and for ℓ=1 the recursion must be initialized via init(). The plane is indexed for -L < m, m' < L by dl[m + L - 1, m' + L - 1] but is only computed for the quarter of the plane 0 <= m, m' <= ℓ. ### Note JAX implementation. For vectorised implementations it is better to compute the full quarter of the plane directly, rather than compute an eighth and fill the quarter by symmetry. ### Warning Writes garbage outside of m, mm range for given el. ### Parameters - **dl** (jnp.ndarray) - Required - Wigner-d plane for ℓ-1 at π/2. - **L** (int) - Required - Harmonic band-limit. - **el** (int) - Required - Spherical harmonic degree ℓ. ### Returns - **jnp.ndarray** - Plane of Wigner-d for el, with quarter of plane computed. ``` -------------------------------- ### inverse_jax_ssht() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Custom JAX frontend for hybrid inverse SSHT C Wigner transforms. ```APIDOC ## inverse_jax_ssht() ### Description Custom JAX frontend for hybrid inverse SSHT C Wigner transforms. ### Method inverse_jax_ssht ### Endpoint s2fft.transforms.wigner.inverse_jax_ssht ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### s2fft.transforms.wigner.inverse_jax_ssht(flmn, L, N, L_lower=0, sampling='mw', reality=False, _ssht_backend=1) Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/wigner.rst Computes the inverse Wigner transform using the SSHT C library with custom JAX frontends. Supports automatic differentiation but is limited to CPU execution. ```APIDOC ## s2fft.transforms.wigner.inverse_jax_ssht(flmn, L, N, L_lower=0, sampling='mw', reality=False, _ssht_backend=1) ### Description Computes the inverse Wigner transform using the SSHT JAX frontend. SSHT is a C library implementing the spin-spherical harmonic transform outlined in McEwen & Wiaux 2011. Custom JAX frontends provide support for automatic differentiation. Currently these transforms can only be deployed on CPU. ### Method Function call ### Signature ```python s2fft.transforms.wigner.inverse_jax_ssht(flmn: Array, L: int, N: int, L_lower: int = 0, sampling: str = 'mw', reality: bool = False, _ssht_backend: int = 1) -> Array ``` ### Parameters - **flmn** (jnp.ndarray) - Required - Wigner coefficients with shape [2N-1, L, 2L-1]. - **L** (int) - Required - Harmonic band-limit. - **N** (int) - Required - Azimuthal band-limit. - **L_lower** (int, optional) - Harmonic lower-bound. Transform will only be computed for L_lower ≤ ℓ < L. Defaults to 0. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh", "gl"}. Defaults to "mw". - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **_ssht_backend** (int, optional, experimental) - Whether to default to SSHT core (set to 0) recursions or pick up ducc0 (set to 1) accelerated experimental backend. Use with caution. ### Returns - **np.ndarray** - Signal on the sphere. ### References [1] McEwen, Jason D. and Yves Wiaux. "A Novel Sampling Theorem on the Sphere." IEEE Transactions on Signal Processing 59 (2011): 5876-5887. ``` -------------------------------- ### forward_latitudinal_step_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst On-the-fly wigner-recursion for latitudinal portion of overall transform (JAX). ```APIDOC ## forward_latitudinal_step_jax() ### Description On-the-fly wigner-recursion for latitudinal portion of overall transform (JAX). ### Method forward_latitudinal_step_jax ### Endpoint s2fft.transforms.otf_recursions.forward_latitudinal_step_jax ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### spectral_periodic_extension_jax Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/utility/healpix_ffts.rst JAX implementation of spectral_periodic_extension, modified to be JIT-compilable. Extends lower frequency Fourier coefficients onto higher frequency coefficients. ```APIDOC ## spectral_periodic_extension_jax(fm: Array, L: int) → Array ### Description Extends lower frequency Fourier coefficients onto higher frequency coefficients, i.e. imposed periodicity in Fourier space. Based on `spectral_periodic_extension()`, modified to be JIT-compilable. ### Parameters - **fm** (jnp.ndarray) – Slice of Fourier coefficients corresponding to ring at latitude t. - **L** (int) – Harmonic band-limit. ### Returns - **jnp.ndarray** – Higher resolution set of periodic Fourier coefficients. ``` -------------------------------- ### wigner_kernel() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Builds a kernel including quadrature weights and Wigner-D coefficients for Wigner transform. ```APIDOC ## wigner_kernel() ### Description Builds a kernel including quadrature weights and Wigner-D coefficients for Wigner transform. ### Method Function ### Endpoint s2fft.precompute_transforms.construct.wigner_kernel ``` -------------------------------- ### fourier_wigner_kernel() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Builds a kernel including quadrature weights and Fourier coefficients of Wigner d-functions. ```APIDOC ## fourier_wigner_kernel() ### Description Builds a kernel including quadrature weights and Fourier coefficients of Wigner d-functions. ### Method Function ### Endpoint s2fft.precompute_transforms.construct.fourier_wigner_kernel ``` -------------------------------- ### s2fft.precompute_transforms.construct.spin_spherical_kernel_jax Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/construct.rst Precompute the wigner-d kernel for spin-spherical transform. This implementation is typically faster than computing these elements on-the-fly but comes at a O(L^3) memory overhead, making it infeasible for large bandlimits L >= 512. ```APIDOC ## s2fft.precompute_transforms.construct.spin_spherical_kernel_jax ### Description Precompute the wigner-d kernel for spin-spherical transform. This implementation is typically faster than computing these elements on-the-fly but comes at a O(L^3) memory overhead, making it infeasible for large bandlimits L >= 512. ### Function Signature `spin_spherical_kernel_jax(L: int, spin: int = 0, reality: bool = False, sampling: str = 'mw', nside: int = None, forward: bool = True, recursion: str = 'auto') -> Array` ### Parameters - **L** (int) - Harmonic band-limit. - **spin** (int) - Harmonic spin. - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh"}. Defaults to "mw". - **nside** (int) - HEALPix Nside resolution parameter. Only required if sampling="healpix". - **forward** (bool, optional) - Whether to provide forward or inverse shift. Defaults to False. - **recursion** (str, optional) - Recursion to adopt. Supported recursion schemes include {"auto", "price-mcewen", "risbo"}. Defaults to "auto" which will detect the most appropriate recursion given the parameter configuration. ### Returns - Transform kernel for spin-spherical harmonic transform. - Return type: jnp.ndarray ``` -------------------------------- ### generate_precomputes_wigner_jax Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/recursions/price_mcewen.rst Compute recursion coefficients with O(L^2) memory overhead for the Wigner transform over SO(3) using JAX. This is the JAX implementation of generate_precomputes_wigner(). ```APIDOC ## generate_precomputes_wigner_jax ### Description Compute recursion coefficients with O(L^2) memory overhead for the Wigner transform over SO(3) using JAX. This is the JAX implementation of generate_precomputes_wigner(). ### Method Function call ### Signature ```python s2fft.recursions.price_mcewen.generate_precomputes_wigner_jax(L: int, N: int, sampling: str = 'mw', nside: int = None, forward: bool = False, reality: bool = False, L_lower: int = 0) -> list[list[Array]] ``` ### Parameters - **L** (int) - Required - Harmonic band-limit. - **N** (int) - Required - Azimuthal bandlimit. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh", "healpix"}. Defaults to "mw". - **nside** (int, optional) - HEALPix Nside resolution parameter. Only required if sampling="healpix". Defaults to None. - **forward** (bool, optional) - Whether to provide forward or inverse shift. Defaults to False. - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **L_lower** (int, optional) - Harmonic lower-bound. Transform will only be computed for L_lower <= l < L. Defaults to 0. ### Returns - 2N-1 length List of Lists of precomputed coefficient arrays. ### Return Type List[List[jnp.ndarray]] ``` -------------------------------- ### forward() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Wrapper function around NumPy/JAX forward methods for Wigner transforms. ```APIDOC ## forward() ### Description Wrapper function around NumPy/JAX forward methods for Wigner transforms. ### Method forward ### Endpoint s2fft.transforms.wigner.forward ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### Verify numerical agreement between CUDA and pure JAX Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Computes the forward transform with both methods and compares the resulting spherical harmonic coefficients. Prints mean squared error, max absolute difference, and whether the results match within atol=1e-14. The output shows they match (MSE 1.28e-35, max diff 2.86e-17). ```python alm_cuda = forward_cuda(hp_map) alm_jax = forward_jax(hp_map) mse = jnp.mean(jnp.abs(alm_cuda - alm_jax) ** 2) max_diff = jnp.max(jnp.abs(alm_cuda - alm_jax)) print(f"Forward transform comparison:") print(f" Mean Squared Error: {mse:.2e}") print(f" Max absolute difference: {max_diff:.2e}") print(f" Results match: {jnp.allclose(alm_cuda, alm_jax, atol=1e-14)}") ``` ```text Output: Forward transform comparison: Mean Squared Error: 1.28e-35 Max absolute difference: 2.86e-17 Results match: True ``` -------------------------------- ### s2fft.transforms.wigner.inverse_jax(flmn, L, N, nside=None, sampling='mw', reality=False, precomps=None, L_lower=0) Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/wigner.rst Computes the inverse Wigner transform using JAX with separation of variables and Price & McEwen recursion. Supports multiple sampling schemes and optional precomputed recursion coefficients for efficiency. ```APIDOC ## s2fft.transforms.wigner.inverse_jax(flmn, L, N, nside=None, sampling='mw', reality=False, precomps=None, L_lower=0) ### Description Computes the inverse Wigner transform using JAX. Uses separation of variables and exploits the Price & McEwen recursion for accelerated and numerically stable Wigner-d on-the-fly recursions. The memory overhead is theoretically O(NL^2). ### Method Function call ### Signature ```python s2fft.transforms.wigner.inverse_jax(flmn: Array, L: int, N: int, nside: int = None, sampling: str = 'mw', reality: bool = False, precomps: list = None, L_lower: int = 0) -> Array ``` ### Parameters - **flmn** (jnp.ndarray) - Required - Wigner coefficients with shape [2N-1, L, 2L-1]. - **L** (int) - Required - Harmonic band-limit. - **N** (int) - Required - Azimuthal band-limit. Recursive transform will have lower precision beyond N ≈ 8. - **nside** (int, optional) - HEALPix Nside resolution parameter. Only required if sampling="healpix". Defaults to None. - **sampling** (str, optional) - Sampling scheme. Supported sampling schemes include {"mw", "mwss", "dh", "gl", "healpix"}. Defaults to "mw". - **reality** (bool, optional) - Whether the signal on the sphere is real. If so, conjugate symmetry is exploited to reduce computational costs. Defaults to False. - **precomps** (List[jnp.ndarray]) - Precomputed list of recursion coefficients. At most of length L^2, which is a minimal memory overhead. - **L_lower** (int, optional) - Harmonic lower-bound. Transform will only be computed for L_lower ≤ ℓ < L. Defaults to 0. ### Returns - **jnp.ndarray** - Signal on the sphere. ### Notes The convention adopted for storage of f is [γ, β, α], for Euler angles (α, β, γ) following the zyz Euler convention. For a given γ we recover a signal on the sphere indexed by [θ, φ], associating β with θ and α with φ. ``` -------------------------------- ### wigner_subset_to_s2_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Transforms an arbitrary subset of Wigner coefficients onto a subset of spin signals on the sphere (JAX). ```APIDOC ## wigner_subset_to_s2_jax() ### Description Transforms an arbitrary subset of Wigner coefficients onto a subset of spin signals on the sphere (JAX). ### Method Function ### Endpoint s2fft.precompute_transforms.custom_ops.wigner_subset_to_s2_jax ``` -------------------------------- ### s2fft.utils.quadrature_jax.quad_weights_gl(L: int) → Array Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/utility/quadrature_jax.rst Computes GL quadrature weights for theta and phi integration. ```APIDOC ## Function: quad_weights_gl ### Description Computes GL quadrature weights for theta and phi integration. ### Signature ```python def quad_weights_gl(L: int) -> Array ``` ### Parameters - **L** (int) – Harmonic band-limit. ### Returns - **jnp.ndarray** – Weights computed for each theta (weights are identical as phi varies for given theta). ``` -------------------------------- ### s2_to_wigner_subset_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Transforms from a collection of arbitrary spin signals on the sphere to the corresponding collection of their harmonic coefficients (JAX). ```APIDOC ## s2_to_wigner_subset_jax() ### Description Transforms from a collection of arbitrary spin signals on the sphere to the corresponding collection of their harmonic coefficients (JAX). ### Method Function ### Endpoint s2fft.precompute_transforms.custom_ops.s2_to_wigner_subset_jax ``` -------------------------------- ### inverse_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Inverse spherical harmonic transform (JAX). ```APIDOC ## inverse_jax() ### Description Inverse spherical harmonic transform (JAX). ### Method inverse_jax ### Endpoint s2fft.transforms.spherical.inverse_jax ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### ssht_forward() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/transforms/index.rst Custom JAX frontend for forward SSHT C spherical harmonic library. ```APIDOC ## ssht_forward() ### Description Custom JAX frontend for forward SSHT C spherical harmonic library. ### Method ssht_forward ### Endpoint s2fft.transforms.c_backend_spherical.ssht_forward ### Parameters No parameters documented. ### Request Example No request example available. ### Response No response fields documented. ### Response Example No response example available. ``` -------------------------------- ### so3_to_wigner_subset_jax() Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/precompute_transforms/index.rst Transforms a signal on the rotation group to an arbitrary subset of its Wigner coefficients (JAX). ```APIDOC ## so3_to_wigner_subset_jax() ### Description Transforms a signal on the rotation group to an arbitrary subset of its Wigner coefficients (JAX). ### Method Function ### Endpoint s2fft.precompute_transforms.custom_ops.so3_to_wigner_subset_jax ``` -------------------------------- ### s2fft.recursions.trapani.compute_full_jax(dl, L, el) Source: https://github.com/astro-informatics/s2fft/blob/main/docs/api/recursions/trapani.rst Computes the full Wigner-d plane at π/2 for a given degree ℓ using the Trapani & Navaza recursion with a JAX implementation. See compute_full for details. ```APIDOC ## compute_full_jax(dl, L, el) ### Description Computes the full Wigner-d plane at π/2 for a given degree ℓ using the Trapani & Navaza recursion with a JAX implementation. See compute_full for details. ### Method Function call ### Endpoint `s2fft.recursions.trapani.compute_full_jax(dl, L, el)` ### Parameters - **dl** (np.ndarray) - Required - Wigner-d plane for ℓ-1 at π/2. - **L** (int) - Required - Harmonic band-limit. - **el** (int) - Required - Spherical harmonic degree ℓ. ### Returns - **np.ndarray** - Plane of Wigner-d for el, with full plane computed. ### Notes - JAX implementation. - Warning: This recursion may not be stable above ℓ ≳ 1024. ``` -------------------------------- ### Generate sample coordinates for MW and GL schemes Source: https://github.com/astro-informatics/s2fft/blob/main/docs/sampling.rst Generates theta and phi sample coordinates for MW and GL schemes using `thetas` and `phis_equiang`, then evaluates the signal at those points to create sample arrays. ```python # Generate (theta, phi) points used by the MW scheme mw_thetas, mw_phis = thetas(L, sampling="mw"), phis_equiang(L, sampling="mw") # Generate (theta, phi) points used by the GL scheme gl_thetas, gl_phis = thetas(L, sampling="gl"), phis_equiang(L, sampling="gl") # We now pretend we have two different observations of this signal, # but which sampled it using different schemes. mw_signal_samples = signal(*jnp.meshgrid(mw_thetas, mw_phis, indexing='ij')) gl_signal_samples = signal(*jnp.meshgrid(gl_thetas, gl_phis, indexing='ij')) ``` -------------------------------- ### Sphere transform with s2fft.forward/inverse (JAX) Source: https://github.com/astro-informatics/s2fft/blob/main/README.md Perform a spherical harmonic transform on a signal on the sphere using the JAX method. Define the sampled signal `f` and harmonic bandlimit `L`, then use `s2fft.forward` and `s2fft.inverse`. ```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") ``` -------------------------------- ### Run S2FFT test suite Source: https://github.com/astro-informatics/s2fft/blob/main/docs/index.rst Runs the pytest test suite for the package. Run from the root of the repository. ```bash pytest ``` -------------------------------- ### Define HEALPix parameters and generate random map Source: https://github.com/astro-informatics/s2fft/blob/main/notebooks/JAX_CUDA_HEALPix.ipynb Sets nside, computes npix, lmax, and L, then generates a random HEALPix map using JAX. Prints the parameters and map shape. ```python nside = 32 npix = hp.nside2npix(nside) lmax = 3 * nside - 1 L = lmax + 1 print(f"HEALPix parameters:") print(f" nside: {nside}") print(f" lmax: {lmax}") print(f" L (band limit): {L}") print(f" Number of pixels: {npix}") hp_map = jax.random.normal(jax.random.PRNGKey(0), shape=(npix,)) print(f"\nGenerated random HEALPix map with shape: {hp_map.shape}") ```