Skip to content

Commit 4ef9c67

Browse files
authored
Merge pull request #170 from astro-informatics/mmg/healpix-fft-tests
Tests for consistency of HEALPix FFT and IFFT implementations
2 parents 01f0b9a + 4fe1afc commit 4ef9c67

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/test_healpix_ffts.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import numpy as np
2+
import healpy as hp
3+
import pytest
4+
from jax import config
5+
from s2fft.sampling import s2_samples as samples
6+
from s2fft.utils.healpix_ffts import (
7+
healpix_fft_jax,
8+
healpix_fft_numpy,
9+
healpix_ifft_jax,
10+
healpix_ifft_numpy,
11+
)
12+
13+
14+
config.update("jax_enable_x64", True)
15+
16+
17+
nside_to_test = [4, 5]
18+
reality_to_test = [False, True]
19+
20+
21+
@pytest.mark.parametrize("nside", nside_to_test)
22+
@pytest.mark.parametrize("reality", reality_to_test)
23+
def test_healpix_fft_jax_numpy_consistency(flm_generator, nside, reality):
24+
L = 2 * nside
25+
# Generate a random bandlimited signal
26+
flm = flm_generator(L=L, reality=reality)
27+
flm_hp = samples.flm_2d_to_hp(flm, L)
28+
f = hp.sphtfunc.alm2map(flm_hp, nside, lmax=L - 1)
29+
# Test consistency
30+
assert np.allclose(
31+
healpix_fft_numpy(f, L, nside, reality), healpix_fft_jax(f, L, nside, reality)
32+
)
33+
34+
35+
@pytest.mark.parametrize("nside", nside_to_test)
36+
@pytest.mark.parametrize("reality", reality_to_test)
37+
def test_healpix_ifft_jax_numpy_consistency(flm_generator, nside, reality):
38+
L = 2 * nside
39+
# Generate a random bandlimited signal
40+
flm = flm_generator(L=L, reality=reality)
41+
flm_hp = samples.flm_2d_to_hp(flm, L)
42+
f = hp.sphtfunc.alm2map(flm_hp, nside, lmax=L - 1)
43+
ftm = healpix_fft_numpy(f, L, nside, reality)
44+
ftm_copy = np.copy(ftm)
45+
# Test consistency
46+
assert np.allclose(
47+
healpix_ifft_numpy(ftm, L, nside, reality),
48+
healpix_ifft_jax(ftm_copy, L, nside, reality),
49+
)

0 commit comments

Comments
 (0)