Spherical harmonic transform#

This tutorial demonstrates how to use S2FFT to compute spherical harmonic transforms.

Open in Google Colab

If you are working on this notebook in Google Colab; you will need to have Google Colab install cartopy, s2fft and pyssht, as well as fetch the data we’ll be using. You can do this by adding a cell to the top of the notebook with the following content:

!pip install cartopy s2fft pyssht &> /dev/null
!mkdir data/
!wget https://github.com/astro-informatics/s2fft/raw/main/examples/data/Gaia_EDR3_flux.npy -P data/ &> /dev/null

and then running that cell.

In this example we will adopt the sampling scheme of McEwen & Wiaux (2012). First let’s load an input signal that is sampled on the sphere with this sampling scheme.

import jax

jax.config.update("jax_enable_x64", True)

import cartopy.crs as ccrs
import numpy as np
from matplotlib import pyplot as plt

import s2fft

sampling = "mw"
f = np.load("data/Gaia_EDR3_flux.npy")
L = f.shape[0]

Let’s look at the input signal:

plt.figure(figsize=(10, 5))
ax = plt.axes(projection=ccrs.Mollweide())
im = ax.imshow(f, transform=ccrs.PlateCarree(), cmap="magma")
plt.axis("off")
plt.show()
spherical harmonic transform

Computing the forward spherical harmonic transform#

Let’s now run the JAX function to compute the spherical harmonic transform of this map.

flm = s2fft.forward_jax(f, L)

Computing the inverse spherical harmonic transform#

Let’s run the JAX function to compute the inverse spherical harmonic transform to get back to the input map.

f_recov = s2fft.inverse_jax(flm, L)

Computing the error#

Let’s check the associated error, which should be close to machine precision for the sampling scheme used.

print(f"Mean absolute error = {np.nanmean(np.abs(f_recov - f))}")
Mean absolute error = 1.7115446183082752e-14

Total running time of the script: (1 minutes 3.803 seconds)

Gallery generated by Sphinx-Gallery