From 790857fee77531b0b64b26ef98ff44b65b3528a6 Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Thu, 30 Nov 2023 21:59:35 +0000 Subject: [PATCH] move slow healpy import into functions that need it --- heracles/catalog/filters.py | 9 ++++++--- heracles/io.py | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/heracles/catalog/filters.py b/heracles/catalog/filters.py index 0036f53..26dcea2 100644 --- a/heracles/catalog/filters.py +++ b/heracles/catalog/filters.py @@ -20,7 +20,6 @@ import warnings -import healpy as hp import numpy as np @@ -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 @@ -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) diff --git a/heracles/io.py b/heracles/io.py index c661ff6..4aa15e9 100644 --- a/heracles/io.py +++ b/heracles/io.py @@ -28,7 +28,6 @@ from weakref import WeakValueDictionary import fitsio -import healpy as hp import numpy as np from .core import TocDict, toc_match @@ -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: @@ -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