23 __all__ = [
'HealpixSkyMapConfig',
'HealpixSkyMap']
34 except Exception
as e:
36 """An object which blows up when we try to read it"""
39 raise RuntimeError(
"Was unable to import healpy: %s" % e)
42 from lsst.pex.config
import Field
44 from .cachingSkyMap
import CachingSkyMap
45 from .tractInfo
import TractInfo
49 """Convert healpy's ang to an lsst.geom.SpherePoint
51 The ang is provided as a single object, thetaphi, so the output
52 of healpy functions can be directed to this function without
53 additional translation.
55 return geom.SpherePoint(float(thetaphi[1]), float(thetaphi[0] - 0.5*numpy.pi), geom.radians)
59 """Convert an lsst.geom.SpherePoint to a healpy ang (theta, phi)
61 The Healpix convention is that 0 <= theta <= pi, 0 <= phi < 2pi.
63 return (coord.getLatitude().asRadians() + 0.5*numpy.pi, coord.getLongitude().asRadians())
67 """Tract for the HealpixSkyMap"""
69 def __init__(self, nSide, ident, nest, patchInnerDimensions, patchBorder, ctrCoord, tractOverlap, wcs):
70 """Set vertices from nside, ident, nest"""
71 theta, phi = healpy.vec2ang(numpy.transpose(healpy.boundaries(nSide, ident, nest=nest)))
72 vertexList = [
angToCoord(thetaphi)
for thetaphi
in zip(theta, phi)]
73 super(HealpixTractInfo, self).
__init__(ident, patchInnerDimensions, patchBorder, ctrCoord,
74 vertexList, tractOverlap, wcs)
78 """Configuration for the HealpixSkyMap"""
79 log2NSide = Field(dtype=int, default=0, doc=
"Number of sides, expressed in powers of 2")
80 nest = Field(dtype=bool, default=
False, doc=
"Use NEST ordering instead of RING?")
87 """HEALPix-based sky map pixelization.
89 We put a Tract at the position of each HEALPixel.
94 config : `lsst.skymap.BaseSkyMapConfig`
95 The configuration for this SkyMap.
96 version : `int` or `tuple` of `int` (optional)
97 Software version of this class, to retain compatibility with old
100 ConfigClass = HealpixSkyMapConfig
105 self.
_nside = 1 << config.log2NSide
106 numTracts = healpy.nside2npix(self.
_nside)
107 super(HealpixSkyMap, self).
__init__(numTracts, config, version)
110 """Find the tract whose inner region includes the coord.
114 coord : `lsst.geom.SpherePoint`
115 ICRS sky coordinate to search for.
119 tractInfo : `TractInfo`
120 Info for tract whose inner region includes the coord.
123 index = healpy.ang2pix(self.
_nside, theta, phi, nest=self.
config.nest)
127 """Generate TractInfo for the specified tract index."""
131 self.
config.patchBorder, center, self.
config.tractOverlap*geom.degrees,
135 """Add subclass-specific state or configuration options to the SHA1."""
136 sha1.update(struct.pack(
"<i?", self.
config.log2NSide, self.
config.nest))