23 todo: Consider tweaking pixel scale so the average scale is as specified, 24 rather than the scale at the center. 27 __all__ = [
"BaseSkyMapConfig",
"BaseSkyMap"]
33 from lsst.geom import SpherePoint, Angle, arcseconds, degrees
38 patchInnerDimensions = pexConfig.ListField(
39 doc=
"dimensions of inner region of patches (x,y pixels)",
44 patchBorder = pexConfig.Field(
45 doc=
"border between patch inner and outer bbox (pixels)",
49 tractOverlap = pexConfig.Field(
50 doc=
"minimum overlap between adjacent sky tracts, on the sky (deg)",
54 pixelScale = pexConfig.Field(
55 doc=
"nominal pixel scale (arcsec/pixel)",
59 projection = pexConfig.Field(
60 doc=
"one of the FITS WCS projection codes, such as:" 61 "- STG: stereographic projection" 62 "- MOL: Molleweide's projection" 63 "- 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. 81 config : `BaseSkyMapConfig` or None (optional) 82 The configuration for this SkyMap; if None use the default config. 86 BaseSkyMap is an abstract base class. Subclasses must do the following: 87 define ``__init__`` and have it construct the TractInfo objects and put 88 them in ``__tractInfoList__`` define ``__getstate__`` and ``__setstate__`` 89 to allow pickling (the butler saves sky maps using pickle); 90 see DodecaSkyMap for an example of how to do this. (Most of that code could 91 be moved into this base class, but that would make it harder to handle 92 older versions of pickle data.) define updateSha1 to add any 93 subclass-specific state to the hash. 95 All SkyMap subclasses must be conceptually immutable; they must always 96 refer to the same set of mathematical tracts and patches even if the in- 97 memory representation of those objects changes. 100 ConfigClass = BaseSkyMapConfig
109 pixelScale=
Angle(self.
config.pixelScale, arcseconds),
110 projection=self.
config.projection,
116 """Find the tract whose center is nearest the specified coord. 120 coord : `lsst.geom.SpherePoint` 121 ICRS sky coordinate to search for. 126 TractInfo of tract whose center is nearest the specified coord. 130 - If coord is equidistant between multiple sky tract centers then one 131 is arbitrarily chosen. 133 - The default implementation is not very efficient; subclasses may wish 137 If tracts do not cover the whole sky then the returned tract may not 140 distTractInfoList = []
141 for i, tractInfo
in enumerate(self):
142 angSep = coord.separation(tractInfo.getCtrCoord()).asDegrees()
144 distTractInfoList.append((angSep, i, tractInfo))
145 distTractInfoList.sort()
146 return distTractInfoList[0][2]
149 """Find tracts and patches that overlap a region. 153 coordList : `list` of `lsst.geom.SpherePoint` 154 List of ICRS sky coordinates to search for. 158 reList : `list` of (`TractInfo`, `list` of `PatchInfo`) 159 For tracts and patches that contain, or may contain, the specified 160 region. The list will be empty if there is no overlap. 165 This uses a naive algorithm that may find some tracts and patches 166 that do not overlap the region (especially if the region is not a 167 rectangle aligned along patch x, y). 170 for tractInfo
in self:
171 patchList = tractInfo.findPatchList(coordList)
173 retList.append((tractInfo, patchList))
177 """Find closest tract and patches that overlap coordinates. 181 coordList : `lsst.geom.SpherePoint` 182 List of ICRS sky coordinates to search for. 187 list of (TractInfo, list of PatchInfo) for tracts and patches 188 that contain, or may contain, the specified region. 189 The list will be empty if there is no overlap. 192 for coord
in coordList:
194 patchList = tractInfo.findPatchList(coordList)
195 if patchList
and not (tractInfo, patchList)
in retList:
196 retList.append((tractInfo, patchList))
213 return self.
getSha1() == other.getSha1()
214 except AttributeError:
215 return NotImplemented
218 return not (self == other)
221 """Return a SHA1 hash that uniquely identifies this SkyMap instance. 226 A 20-byte hash that uniquely identifies this SkyMap instance. 230 Subclasses should almost always override ``updateSha1`` instead of 231 this function to add subclass-specific state to the hash. 233 if self.
_sha1 is None:
234 sha1 = hashlib.sha1()
235 sha1.update(type(self).__name__.encode(
'utf-8'))
236 configPacked = struct.pack(
238 self.
config.patchInnerDimensions[0],
239 self.
config.patchInnerDimensions[1],
243 self.
config.projection.encode(
'ascii'),
246 sha1.update(configPacked)
248 self.
_sha1 = sha1.digest()
252 """Add subclass-specific state or configuration options to the SHA1. 256 sha1 : `hashlib.sha1` 257 A hashlib object on which `update` can be called to add 258 additional state to the hash. 262 This method is conceptually "protected" : it should be reimplemented by 263 all subclasses, but called only by the base class implementation of 266 raise NotImplementedError()
269 """Add SkyMap, Tract, and Patch Dimension entries to the given Gen3 275 The name of the skymap. 276 registry : `lsst.daf.butler.Registry` 277 The registry to add to. 281 for tractInfo
in self:
282 nx, ny = tractInfo.getNumPatches()
283 nxMax = max(nxMax, nx)
284 nyMax = max(nyMax, ny)
285 with registry.transaction():
286 registry.addDimensionEntry(
290 "tract_max": len(self),
291 "patch_nx_max": nxMax,
292 "patch_ny_max": nyMax}
294 for tractInfo
in self:
295 region = tractInfo.getOuterSkyPolygon()
298 {
"skymap": name,
"tract": tractInfo.getId(),
300 "ra": centroid.getRa().asDegrees(),
301 "dec": centroid.getDec().asDegrees()}
303 registry.addDimensionEntry(
"tract", entry)
305 for patchInfo
in tractInfo:
306 cellX, cellY = patchInfo.getIndex()
307 patchDataIdList.append(
308 {
"skymap": name,
"tract": tractInfo.getId(),
309 "patch": tractInfo.getSequentialPatchIndex(patchInfo),
310 "cell_x": cellX,
"cell_y": cellY,
311 "region": patchInfo.getOuterSkyPolygon(tractInfo.getWcs())}
313 registry.addDimensionEntryList(
"patch", patchDataIdList)
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)