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)
44 from .cachingSkyMap
import CachingSkyMap
45 from .tractInfo
import TractInfo
47 __all__ = [
'HealpixSkyMapConfig',
'HealpixSkyMap']
51 """Convert healpy's ang to an afw Coord 53 The ang is provided as a single object, thetaphi, so the output 54 of healpy functions can be directed to this function without 55 additional translation. 57 return IcrsCoord(float(thetaphi[1])*afwGeom.radians, float(thetaphi[0] - 0.5*numpy.pi)*afwGeom.radians)
61 """Convert an afw Coord to a healpy ang (theta, phi) 63 The Healpix convention is that 0 <= theta <= pi, 0 <= phi < 2pi. 65 return (coord.getLatitude().asRadians() + 0.5*numpy.pi, coord.getLongitude().asRadians())
69 """Tract for the HealpixSkyMap""" 71 def __init__(self, nSide, ident, nest, patchInnerDimensions, patchBorder, ctrCoord, tractOverlap, wcs):
72 """Set vertices from nside, ident, nest""" 73 theta, phi = healpy.vec2ang(numpy.transpose(healpy.boundaries(nSide, ident, nest=nest)))
74 vertexList = [
angToCoord(thetaphi)
for thetaphi
in zip(theta, phi)]
75 super(HealpixTractInfo, self).
__init__(ident, patchInnerDimensions, patchBorder, ctrCoord,
76 vertexList, tractOverlap, wcs)
80 """Configuration for the HealpixSkyMap""" 81 log2NSide = Field(dtype=int, default=0, doc=
"Number of sides, expressed in powers of 2")
82 nest = Field(dtype=bool, default=
False, doc=
"Use NEST ordering instead of RING?")
89 """HEALPix-based sky map pixelization. 91 We put a Tract at the position of each HEALPixel. 93 ConfigClass = HealpixSkyMapConfig
100 @param[in] config: an instance of self.ConfigClass; if None the default config is used 101 @param[in] version: software version of this class, to retain compatibility with old instances 103 self.
_nside = 1 << config.log2NSide
104 numTracts = healpy.nside2npix(self.
_nside)
105 super(HealpixSkyMap, self).
__init__(numTracts, config, version)
108 """Find the tract whose inner region includes the coord.""" 110 index = healpy.ang2pix(self.
_nside, theta, phi, nest=self.
config.nest)
114 """Get the TractInfo for a particular index""" 116 wcs = self.
_wcsFactory.makeWcs(crPixPos=afwGeom.Point2D(0, 0), crValCoord=center)
118 self.
config.patchBorder, center, self.
config.tractOverlap*afwGeom.degrees,
122 """Add subclass-specific state or configuration options to the SHA1.""" 123 sha1.update(struct.pack(
"<i?", self.
config.log2NSide, self.
config.nest))
def __getattr__(self, name, e=e)
def updateSha1(self, sha1)
def __init__(self, config, version=0)
def __init__(self, nSide, ident, nest, patchInnerDimensions, patchBorder, ctrCoord, tractOverlap, wcs)
def findTract(self, coord)
def generateTract(self, index)