Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH(catalog,io): move slow healpy import into functions #67

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
9 changes: 6 additions & 3 deletions heracles/catalog/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import warnings

import healpy as hp
import numpy as np


Expand Down Expand Up @@ -65,8 +64,10 @@ class FootprintFilter:

def __init__(self, footprint, lon, lat):
"""Filter using the given footprint map and position columns."""
from healpy import get_nside

self._footprint = footprint
self._nside = hp.get_nside(footprint)
self._nside = get_nside(footprint)
self._lonlat = (lon, lat)

@property
Expand All @@ -87,7 +88,9 @@ def __repr__(self):
def __call__(self, page):
"""filter catalog page"""

from healpy import ang2pix

lon, lat = self._lonlat
ipix = hp.ang2pix(self._nside, page[lon], page[lat], lonlat=True)
ipix = ang2pix(self._nside, page[lon], page[lat], lonlat=True)
exclude = np.where(self._footprint[ipix] == 0)[0]
page.delete(exclude)
6 changes: 5 additions & 1 deletion heracles/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from weakref import WeakValueDictionary

import fitsio
import healpy as hp
import numpy as np

from .core import TocDict, toc_match
Expand Down Expand Up @@ -76,6 +75,8 @@ def _read_metadata(hdu):
def _write_map(fits, ext, m, *, names=None):
"""write HEALPix map to FITS table"""

import healpy as hp

# prepare column data and names
cols = list(np.atleast_2d(m))
if names is None:
Expand Down Expand Up @@ -199,6 +200,9 @@ def _read_twopoint(fits, ext):

def read_vmap(filename, nside=None, field=0):
"""read visibility map from a HEALPix map file"""

import healpy as hp

vmap = hp.read_map(filename, field=field, dtype=float)

# set unseen pixels to zero
Expand Down
Loading