Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 66 additions & 22 deletions examples/example.ipynb

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions heracles/healpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ def transform(self, data: NDArray[Any]) -> NDArray[Any]:

return alm

def set_for_map(self, m: NDArray[Any], spin: int) -> NDArray[Any]:
"""
Reads external data into the mapper's format.
"""
update_metadata(
m,
geometry="healpix",
kernel="healpix",
nside=self.__nside,
lmax=self.__lmax,
deconv=self.__deconv,
spin=spin,
)
return m

def resample(self, data: NDArray[Any]) -> NDArray[Any]:
"""
Change resolution of HEALPix map.
Expand Down
5 changes: 5 additions & 0 deletions heracles/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def map_values(
Add values to data.
"""

def set_for_map(self, m: NDArray[Any], spin: int) -> NDArray[Any]:
"""
Reads external data into the mapper's format.
"""

def transform(self, data: NDArray[Any]) -> NDArray[Any]:
"""
The spherical harmonic transform for this mapper.
Expand Down
14 changes: 5 additions & 9 deletions heracles/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from heracles.core import TocDict, toc_match
from heracles.progress import Progress, NoProgress
from heracles.healpy import HealpixMapper

if TYPE_CHECKING:
from collections.abc import Mapping, MutableMapping, Sequence
Expand Down Expand Up @@ -128,7 +129,6 @@ def _task_done():


def transform(
fields: Mapping[Any, Field],
data: Mapping[tuple[Any, Any], NDArray],
*,
out: MutableMapping[tuple[Any, Any], NDArray] | None = None,
Expand All @@ -151,15 +151,11 @@ def transform(
for (k, i), m in data.items():
current += 1
progress.update(current, total)

with progress.task(f"({k}, {i})"):
try:
field = fields[k]
except KeyError:
msg = f"unknown field name: {k}"
raise ValueError(msg) from None

out[k, i] = field.mapper_or_error.transform(m)
# create mapper
nside, lmax = m.dtype.metadata["nside"], m.dtype.metadata["lmax"]
mapper = HealpixMapper(nside=nside, lmax=lmax)
out[k, i] = mapper.transform(m)

# return the toc dict of alms
return out
Loading