Wavelet transform (Numpy)#
[ ]:
# Install s2wav
!pip install s2wav &> /dev/null
Lets start by importing some packages which we’ll be using in this notebook
[3]:
import s2wav # Wavelet transforms on the sphere and rotation group
import s2fft # Spherical harmonic and Wigner transforms
import numpy as np
Now we’ll define the constraints of the problem and generated some random data just for this example
[4]:
L = 16 # Spherical harmonic bandlimit
N = 3 # Azimuthal (directional) bandlimit
sampling = "mw" # Sampling scheme
# Generate a random bandlimited signal to work with
rng = np.random.default_rng(12346161)
flm = s2fft.utils.signal_generator.generate_flm(rng, L)
f = s2fft.inverse(flm, L)
We can calculate the wavelet and scaling coefficients by running
[5]:
wavelet_coeffs, scaling_coeffs = s2wav.analysis_base(f, L, N)
when an exact sampling theorem is chosen we can recover the original signal to machine precision by running
[6]:
f_check = s2wav.synthesis_base(wavelet_coeffs, scaling_coeffs, L, N)
Lets double check that we actually got machine precision!
[8]:
print(f"Mean absolute error = {np.nanmean(np.abs(f_check - f))}")
Mean absolute error = 2.056856753687673e-14