24 - Consider tweaking pixel scale so the average scale is as specified, rather than the scale at the center 30 from lsst.geom import SpherePoint, Angle, arcseconds, degrees
33 __all__ = [
"BaseSkyMap"]
37 patchInnerDimensions = pexConfig.ListField(
38 doc=
"dimensions of inner region of patches (x,y pixels)",
43 patchBorder = pexConfig.Field(
44 doc=
"border between patch inner and outer bbox (pixels)",
48 tractOverlap = pexConfig.Field(
49 doc=
"minimum overlap between adjacent sky tracts, on the sky (deg)",
53 pixelScale = pexConfig.Field(
54 doc=
"nominal pixel scale (arcsec/pixel)",
58 projection = pexConfig.Field(
59 doc=
"""one of the FITS WCS projection codes, such as: 60 - STG: stereographic projection 61 - MOL: Molleweide's projection 62 - TAN: tangent-plane projection 67 rotation = pexConfig.Field(
68 doc=
"Rotation for WCS (deg)",
75 """A collection of overlapping Tracts that map part or all of the sky. 77 See TractInfo for more information. 79 BaseSkyMap is an abstract base class. Subclasses must do the following: 80 @li define __init__ and have it construct the TractInfo objects and put them in _tractInfoList 81 @li define __getstate__ and __setstate__ to allow pickling (the butler saves sky maps using pickle); 82 see DodecaSkyMap for an example of how to do this. (Most of that code could be moved 83 into this base class, but that would make it harder to handle older versions of pickle data.) 84 @li define updateSha1 to add any subclass-specific state to the hash. 86 All SkyMap subclasses must be conceptually immutable; they must always 87 refer to the same set of mathematical tracts and patches even if the in- 88 memory representation of those objects changes. 90 ConfigClass = BaseSkyMapConfig
93 """Construct a BaseSkyMap 95 @param[in] config: an instance of self.ConfigClass; if None the default config is used 103 pixelScale=
Angle(self.
config.pixelScale, arcseconds),
104 projection=self.
config.projection,
110 """Find the tract whose center is nearest the specified coord. 112 @param[in] coord: ICRS sky coordinate (lsst.afw.geom.SpherePoint) 113 @return TractInfo of tract whose center is nearest the specified coord 116 - if tracts do not cover the whole sky then the returned tract may not include the coord 119 - This routine will be more efficient if coord is ICRS. 120 - If coord is equidistant between multiple sky tract centers then one is arbitrarily chosen. 121 - The default implementation is not very efficient; subclasses may wish to override. 123 distTractInfoList = []
124 for i, tractInfo
in enumerate(self):
125 angSep = coord.separation(tractInfo.getCtrCoord()).asDegrees()
127 distTractInfoList.append((angSep, i, tractInfo))
128 distTractInfoList.sort()
129 return distTractInfoList[0][2]
132 """Find tracts and patches that overlap a region 134 @param[in] coordList: list of ICRS sky coordinates (lsst.afw.geom.SpherePoint) 135 @return list of (TractInfo, list of PatchInfo) for tracts and patches that contain, 136 or may contain, the specified region. The list will be empty if there is no overlap. 138 @warning this uses a naive algorithm that may find some tracts and patches that do not overlap 139 the region (especially if the region is not a rectangle aligned along patch x,y). 142 for tractInfo
in self:
143 patchList = tractInfo.findPatchList(coordList)
145 retList.append((tractInfo, patchList))
149 """Find closest tract and patches that overlap coordinates 151 @param[in] coordList: list of ICRS sky coordinates (lsst.afw.geom.SpherePoint) 152 @return list of (TractInfo, list of PatchInfo) for tracts and patches that contain, 153 or may contain, the specified region. The list will be empty if there is no overlap. 156 for coord
in coordList:
158 patchList = tractInfo.findPatchList(coordList)
159 if patchList
and not (tractInfo, patchList)
in retList:
160 retList.append((tractInfo, patchList))
177 return self.
getSha1() == other.getSha1()
178 except AttributeError:
179 return NotImplemented
182 return not (self == other)
185 """Return a SHA1 hash that uniquely identifies this SkyMap instance. 190 A 20-byte hash that uniquely identifies this SkyMap instance. 192 Subclasses should almost always override `updateSha1()` instead of 193 this function to add subclass-specific state to the hash. 195 if self.
_sha1 is None:
196 sha1 = hashlib.sha1()
197 sha1.update(type(self).__name__.encode(
'utf-8'))
198 configPacked = struct.pack(
200 self.
config.patchInnerDimensions[0],
201 self.
config.patchInnerDimensions[1],
205 self.
config.projection.encode(
'ascii'),
208 sha1.update(configPacked)
210 self.
_sha1 = sha1.digest()
214 """Add subclass-specific state or configuration options to the SHA1. 219 A hashlib object on which `update()` can be called to add 220 additional state to the hash. 222 This method is conceptually "protected": it should be reimplemented by 223 all subclasses, but called only by the base class implementation of 226 raise NotImplementedError()
229 """Add SkyMap, Tract, and Patch Dimension entries to the given Gen3 232 registry.addDimensionEntry(
"SkyMap", {
"skymap": name,
"hash": self.
getSha1()})
233 for tractInfo
in self:
234 region = tractInfo.getOuterSkyPolygon()
236 registry.addDimensionEntry(
238 {
"skymap": name,
"tract": tractInfo.getId(),
240 "ra": centroid.getRa().asDegrees(),
241 "dec": centroid.getDec().asDegrees()}
243 for patchInfo
in tractInfo:
244 cellX, cellY = patchInfo.getIndex()
245 registry.addDimensionEntry(
247 {
"skymap": name,
"tract": tractInfo.getId(),
248 "patch": tractInfo.getSequentialPatchIndex(patchInfo),
249 "cell_x": cellX,
"cell_y": cellY,
250 "region": patchInfo.getOuterSkyPolygon(tractInfo.getWcs())}
def updateSha1(self, sha1)
def findTractPatchList(self, coordList)
def findClosestTractPatchList(self, coordList)
def __getitem__(self, ind)
def findTract(self, coord)
def register(self, name, registry)
def __init__(self, config=None)