Skip to content

Commit

Permalink
Made single-mode alm roundtrip unit test work with general lmax (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurea authored Aug 18, 2023
1 parent d3f36d1 commit cd84cf2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions pixell/curvedsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@ def __init__(self, lmax=None, mmax=None, nalm=None, stride=1, layout="triangular
mstart = layout
self.lmax = lmax
self.mmax = mmax
self.stride= stride
self.stride= int(stride)
self.nelem = int(np.max(mstart) + (lmax+1)*stride)
if nalm is not None:
assert self.nelem == nalm, "lmax must be explicitly specified when lmax != mmax"
self.mstart= mstart.astype(np.uint64)
def lm2ind(self, l, m):
return self.mstart[m]+l*self.stride
return (self.mstart[m].astype(int, copy=False)+l*self.stride).astype(int, copy=False)
def get_map(self):
"""Return the explicit [nelem,{l,m}] mapping this alm_info represents."""
raise NotImplementedError
Expand Down
42 changes: 21 additions & 21 deletions pixell/tests/test_pixell.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,20 @@ def test_prepare_alm_mmax(self):
self.assertEqual(ainfo_out.nelem, ainfo_in.nelem)

def test_alm2map_roundtrip(self):

# Test curvedsky's alm2map/map2alm.
lmax = 3
lmax = 30
ainfo = curvedsky.alm_info(lmax)

nrings = lmax + 1
nrings = lmax + 2
nphi = 2 * lmax + 1
shape, wcs = enmap.fullsky_geometry(shape=(nrings,nphi))

# Test different input shapes and dtypes.
# Case 1a: 1d double precision.
spin = 0
alm = np.zeros((ainfo.nelem), dtype=np.complex128)
alm[4] = 1. + 1.j
i = ainfo.lm2ind(lmax,lmax)
alm[i] = 1. + 1.j

omap = enmap.zeros(shape, wcs, np.float64)
curvedsky.alm2map(alm, omap, spin=spin)
Expand All @@ -535,7 +535,7 @@ def test_alm2map_roundtrip(self):
# Case 1b: 1d single precision.
spin = 0
alm = np.zeros((ainfo.nelem), dtype=np.complex64)
alm[4] = 1. + 1.j
alm[i] = 1. + 1.j

omap = enmap.zeros(shape, wcs, np.float32)
curvedsky.alm2map(alm, omap, spin=spin)
Expand All @@ -546,8 +546,8 @@ def test_alm2map_roundtrip(self):
spin = 1
nspin = 2
alm = np.zeros((nspin, ainfo.nelem), dtype=np.complex128)
alm[0,4] = 1. + 1.j
alm[1,4] = 2. - 2.j
alm[0,i] = 1. + 1.j
alm[1,i] = 2. - 2.j

omap = enmap.zeros((nspin,)+shape, wcs, np.float64)
curvedsky.alm2map(alm, omap, spin=spin)
Expand All @@ -558,8 +558,8 @@ def test_alm2map_roundtrip(self):
spin = 1
nspin = 2
alm = np.zeros((nspin, ainfo.nelem), dtype=np.complex64)
alm[0,4] = 1. + 1.j
alm[1,4] = 2. - 2.j
alm[0,i] = 1. + 1.j
alm[1,i] = 2. - 2.j

omap = enmap.zeros((nspin,)+shape, wcs, np.float32)
curvedsky.alm2map(alm, omap, spin=spin)
Expand All @@ -571,12 +571,12 @@ def test_alm2map_roundtrip(self):
nspin = 2
ntrans = 3
alm = np.zeros((ntrans, nspin, ainfo.nelem), dtype=np.complex128)
alm[0,0,4] = 1. + 1.j
alm[0,1,4] = 2. - 2.j
alm[1,0,4] = 3. + 3.j
alm[1,1,4] = 4. - 4.j
alm[2,0,4] = 5. + 5.j
alm[2,1,4] = 6. - 6.j
alm[0,0,i] = 1. + 1.j
alm[0,1,i] = 2. - 2.j
alm[1,0,i] = 3. + 3.j
alm[1,1,i] = 4. - 4.j
alm[2,0,i] = 5. + 5.j
alm[2,1,i] = 6. - 6.j

omap = enmap.zeros((ntrans,nspin)+shape, wcs, np.float64)
curvedsky.alm2map(alm, omap, spin=spin)
Expand All @@ -588,12 +588,12 @@ def test_alm2map_roundtrip(self):
nspin = 2
ntrans = 3
alm = np.zeros((ntrans, nspin, ainfo.nelem), dtype=np.complex64)
alm[0,0,4] = 1. + 1.j
alm[0,1,4] = 2. - 2.j
alm[1,0,4] = 3. + 3.j
alm[1,1,4] = 4. - 4.j
alm[2,0,4] = 5. + 5.j
alm[2,1,4] = 6. - 6.j
alm[0,0,i] = 1. + 1.j
alm[0,1,i] = 2. - 2.j
alm[1,0,i] = 3. + 3.j
alm[1,1,i] = 4. - 4.j
alm[2,0,i] = 5. + 5.j
alm[2,1,i] = 6. - 6.j

omap = enmap.zeros((ntrans,nspin)+shape, wcs, np.float32)
curvedsky.alm2map(alm, omap, spin=spin)
Expand Down

0 comments on commit cd84cf2

Please sign in to comment.