1 from builtins
import zip
2 from builtins
import object
33 except Exception
as e:
35 """An object which blows up when we try to read it"""
38 raise RuntimeError(
"Was unable to import healpy: %s" % e)
41 from lsst.pex.config
import Field
42 from lsst.afw.coord
import IcrsCoord
43 import lsst.afw.geom
as afwGeom
44 from .cachingSkyMap
import CachingSkyMap
45 from .tractInfo
import TractInfo
49 """Convert healpy's ang to an afw Coord
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 IcrsCoord(float(thetaphi[1])*afwGeom.radians, float(thetaphi[0] - 0.5*numpy.pi)*afwGeom.radians)
59 """Convert an afw Coord 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.
91 ConfigClass = HealpixSkyMapConfig
98 @param[in] config: an instance of self.ConfigClass; if None the default config is used
99 @param[in] version: software version of this class, to retain compatibility with old instances
101 self.
_nside = 1 << config.log2NSide
102 numTracts = healpy.nside2npix(self.
_nside)
103 super(HealpixSkyMap, self).
__init__(numTracts, config, version)
106 """Find the tract whose inner region includes the coord."""
108 index = healpy.ang2pix(self.
_nside, theta, phi, nest=self.config.nest)
112 """Get the TractInfo for a particular index"""
113 center =
angToCoord(healpy.pix2ang(self.
_nside, index, nest=self.config.nest))
114 wcs = self._wcsFactory.makeWcs(crPixPos=afwGeom.Point2D(0, 0), crValCoord=center)
116 self.config.patchBorder, center, self.config.tractOverlap*afwGeom.degrees,