Skip to content

Commit abae466

Browse files
authored
ENH(maps): allow setting lmax per map in transform_maps() (#52)
Make it possible to pass a mapping to the `lmax=` parameter of `transform_maps()` that contains individual `lmax` values for each map. Closes: #48
1 parent 9d7ca1a commit abae466

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

heracles/maps.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import typing as t
2323
import warnings
2424
from abc import ABCMeta, abstractmethod
25-
from collections.abc import Generator
25+
from collections.abc import Generator, Mapping
2626
from functools import partial, wraps
2727

2828
import healpy as hp
@@ -829,6 +829,7 @@ def map_catalogs(
829829
def transform_maps(
830830
maps: t.Mapping[tuple[t.Any, t.Any], MapData],
831831
*,
832+
lmax: t.Union[int, t.Mapping[t.Any, int], None] = None,
832833
out: t.MutableMapping[t.Any, t.Any] = None,
833834
progress: bool = False,
834835
**kwargs,
@@ -849,6 +850,10 @@ def transform_maps(
849850
# convert maps to alms, taking care of complex and spin-weighted maps
850851
for (k, i), m in maps.items():
851852
nside = hp.get_nside(m)
853+
if isinstance(lmax, Mapping):
854+
_lmax = lmax.get((k, i)) or lmax.get(k)
855+
else:
856+
_lmax = lmax
852857

853858
md = m.dtype.metadata or {}
854859
spin = md.get("spin", 0)
@@ -864,7 +869,7 @@ def transform_maps(
864869
msg = f"spin-{spin} maps not yet supported"
865870
raise NotImplementedError(msg)
866871

867-
alms = hp.map2alm(m, pol=pol, **kwargs)
872+
alms = hp.map2alm(m, lmax=_lmax, pol=pol, **kwargs)
868873

869874
if spin == 0:
870875
alms = {(k, i): alms}

tests/test_maps.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ def test_transform_maps(rng):
351351
assert alms["P_E", 1].dtype.metadata["nside"] == nside
352352
assert alms["P_B", 1].dtype.metadata["nside"] == nside
353353

354+
# explicit lmax per map
355+
maps = {("T", 0): t, ("P", 1): p}
356+
lmax = {"T": 10, "P": 20}
357+
alms = transform_maps(maps, lmax=lmax)
358+
359+
assert len(alms) == 3
360+
assert alms.keys() == {("T", 0), ("P_E", 1), ("P_B", 1)}
361+
assert alms["T", 0].size == (lmax["T"] + 1) * (lmax["T"] + 2) // 2
362+
assert alms["P_E", 1].size == (lmax["P"] + 1) * (lmax["P"] + 2) // 2
363+
assert alms["P_B", 1].size == (lmax["P"] + 1) * (lmax["P"] + 2) // 2
364+
354365

355366
def test_update_metadata():
356367
from heracles.maps import update_metadata

0 commit comments

Comments
 (0)