LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | List of all members
lsst.skymap.baseSkyMap.BaseSkyMap Class Reference
Inheritance diagram for lsst.skymap.baseSkyMap.BaseSkyMap:
lsst.skymap.cachingSkyMap.CachingSkyMap lsst.skymap.dodecaSkyMap.DodecaSkyMap lsst.skymap.equatSkyMap.EquatSkyMap lsst.skymap.discreteSkyMap.DiscreteSkyMap lsst.skymap.healpixSkyMap.HealpixSkyMap lsst.skymap.ringsSkyMap.RingsSkyMap

Public Member Functions

 __init__ (self, config=None)
 
 findTract (self, coord)
 
 findTractIdArray (self, ra, dec, degrees=False)
 
 findTractPatchList (self, coordList)
 
 findClosestTractPatchList (self, coordList)
 
 __getitem__ (self, ind)
 
 __iter__ (self)
 
 __len__ (self)
 
 __hash__ (self)
 
 __eq__ (self, other)
 
 __ne__ (self, other)
 
 logSkyMapInfo (self, log)
 
 getSha1 (self)
 
 updateSha1 (self, sha1)
 
 register (self, name, butler)
 

Public Attributes

 config
 
 SKYMAP_RUN_COLLECTION_NAME
 

Static Public Attributes

 ConfigClass = BaseSkyMapConfig
 
str SKYMAP_RUN_COLLECTION_NAME = "skymaps"
 
str SKYMAP_DATASET_TYPE_NAME = "skyMap"
 

Protected Attributes

 _tractInfoList
 
 _wcsFactory
 
 _sha1
 
 _tractBuilder
 

Detailed Description

A collection of overlapping Tracts that map part or all of the sky.

See TractInfo for more information.

Parameters
----------
config : `BaseSkyMapConfig` or `None` (optional)
    The configuration for this SkyMap; if None use the default config.

Notes
-----
BaseSkyMap is an abstract base class. Subclasses must do the following:
define ``__init__`` and have it construct the TractInfo objects and put
them in ``__tractInfoList__`` define ``__getstate__`` and ``__setstate__``
to allow pickling (the butler saves sky maps using pickle);
see DodecaSkyMap for an example of how to do this. (Most of that code could
be moved into this base class, but that would make it harder to handle
older versions of pickle data.) define updateSha1 to add any
subclass-specific state to the hash.

All SkyMap subclasses must be conceptually immutable; they must always
refer to the same set of mathematical tracts and patches even if the in-
memory representation of those objects changes.

Definition at line 130 of file baseSkyMap.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.skymap.baseSkyMap.BaseSkyMap.__init__ ( self,
config = None )

Reimplemented in lsst.skymap.discreteSkyMap.DiscreteSkyMap, lsst.skymap.healpixSkyMap.HealpixSkyMap, lsst.skymap.ringsSkyMap.RingsSkyMap, lsst.skymap.dodecaSkyMap.DodecaSkyMap, lsst.skymap.equatSkyMap.EquatSkyMap, and lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 158 of file baseSkyMap.py.

158 def __init__(self, config=None):
159 if config is None:
160 config = self.ConfigClass()
161 config.freeze() # just to be sure, e.g. for pickling
162 self.config = config
163 self._tractInfoList = []
164 self._wcsFactory = detail.WcsFactory(
165 pixelScale=Angle(self.config.pixelScale, arcseconds),
166 projection=self.config.projection,
167 rotation=Angle(self.config.rotation, degrees),
168 )
169 self._sha1 = None
170 self._tractBuilder = config.tractBuilder.apply()
171

Member Function Documentation

◆ __eq__()

lsst.skymap.baseSkyMap.BaseSkyMap.__eq__ ( self,
other )

Definition at line 311 of file baseSkyMap.py.

311 def __eq__(self, other):
312 try:
313 return self.getSha1() == other.getSha1()
314 except AttributeError:
315 return NotImplemented
316

◆ __getitem__()

lsst.skymap.baseSkyMap.BaseSkyMap.__getitem__ ( self,
ind )

Reimplemented in lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 299 of file baseSkyMap.py.

299 def __getitem__(self, ind):
300 return self._tractInfoList[ind]
301

◆ __hash__()

lsst.skymap.baseSkyMap.BaseSkyMap.__hash__ ( self)

Definition at line 308 of file baseSkyMap.py.

308 def __hash__(self):
309 return hash(self.getSha1())
310

◆ __iter__()

lsst.skymap.baseSkyMap.BaseSkyMap.__iter__ ( self)

Reimplemented in lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 302 of file baseSkyMap.py.

302 def __iter__(self):
303 return iter(self._tractInfoList)
304

◆ __len__()

lsst.skymap.baseSkyMap.BaseSkyMap.__len__ ( self)

Reimplemented in lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 305 of file baseSkyMap.py.

305 def __len__(self):
306 return len(self._tractInfoList)
307

◆ __ne__()

lsst.skymap.baseSkyMap.BaseSkyMap.__ne__ ( self,
other )

Definition at line 317 of file baseSkyMap.py.

317 def __ne__(self, other):
318 return not (self == other)
319

◆ findClosestTractPatchList()

lsst.skymap.baseSkyMap.BaseSkyMap.findClosestTractPatchList ( self,
coordList )
Find closest tract and patches that overlap coordinates.

Parameters
----------
coordList : `lsst.geom.SpherePoint`
    List of ICRS sky coordinates to search for.

Returns
-------
retList : `list`
    list of (TractInfo, list of PatchInfo) for tracts and patches
    that contain, or may contain, the specified region.
    The list will be empty if there is no overlap.

Definition at line 276 of file baseSkyMap.py.

276 def findClosestTractPatchList(self, coordList):
277 """Find closest tract and patches that overlap coordinates.
278
279 Parameters
280 ----------
281 coordList : `lsst.geom.SpherePoint`
282 List of ICRS sky coordinates to search for.
283
284 Returns
285 -------
286 retList : `list`
287 list of (TractInfo, list of PatchInfo) for tracts and patches
288 that contain, or may contain, the specified region.
289 The list will be empty if there is no overlap.
290 """
291 retList = []
292 for coord in coordList:
293 tractInfo = self.findTract(coord)
294 patchList = tractInfo.findPatchList(coordList)
295 if patchList and not (tractInfo, patchList) in retList:
296 retList.append((tractInfo, patchList))
297 return retList
298

◆ findTract()

lsst.skymap.baseSkyMap.BaseSkyMap.findTract ( self,
coord )
Find the tract whose center is nearest the specified coord.

Parameters
----------
coord : `lsst.geom.SpherePoint`
    ICRS sky coordinate to search for.

Returns
-------
result : `TractInfo`
    TractInfo of tract whose center is nearest the specified coord.

Notes
-----
- If coord is equidistant between multiple sky tract centers then one
  is arbitrarily chosen.

- The default implementation is not very efficient; subclasses may wish
  to override.

.. warning::

   If tracts do not cover the whole sky then the returned tract may not
   include the coord.

Reimplemented in lsst.skymap.dodecaSkyMap.DodecaSkyMap, lsst.skymap.healpixSkyMap.HealpixSkyMap, and lsst.skymap.ringsSkyMap.RingsSkyMap.

Definition at line 172 of file baseSkyMap.py.

172 def findTract(self, coord):
173 """Find the tract whose center is nearest the specified coord.
174
175 Parameters
176 ----------
177 coord : `lsst.geom.SpherePoint`
178 ICRS sky coordinate to search for.
179
180 Returns
181 -------
182 result : `TractInfo`
183 TractInfo of tract whose center is nearest the specified coord.
184
185 Notes
186 -----
187 - If coord is equidistant between multiple sky tract centers then one
188 is arbitrarily chosen.
189
190 - The default implementation is not very efficient; subclasses may wish
191 to override.
192
193 .. warning::
194
195 If tracts do not cover the whole sky then the returned tract may not
196 include the coord.
197 """
198 distTractInfoList = []
199 for i, tractInfo in enumerate(self):
200 angSep = coord.separation(tractInfo.getCtrCoord()).asDegrees()
201 # include index in order to disambiguate identical angSep values
202 distTractInfoList.append((angSep, i, tractInfo))
203 distTractInfoList.sort()
204 return distTractInfoList[0][2]
205

◆ findTractIdArray()

lsst.skymap.baseSkyMap.BaseSkyMap.findTractIdArray ( self,
ra,
dec,
degrees = False )
Find array of tract IDs with vectorized operations (where
supported).

If a given sky map does not support vectorized operations, then a loop
over findTract will be called.

Parameters
----------
ra : `numpy.ndarray`
    Array of Right Ascension.  Units are radians unless
    degrees=True.
dec : `numpy.ndarray`
    Array of Declination.  Units are radians unless
    degrees=True.
degrees : `bool`, optional
    Input ra, dec arrays are degrees if `True`.

Returns
-------
tractId : `numpy.ndarray`
    Array of tract IDs

Notes
-----
- If coord is equidistant between multiple sky tract centers then one
  is arbitrarily chosen.

.. warning::

   If tracts do not cover the whole sky then the returned tract may not
   include the given ra/dec.

Reimplemented in lsst.skymap.ringsSkyMap.RingsSkyMap.

Definition at line 206 of file baseSkyMap.py.

206 def findTractIdArray(self, ra, dec, degrees=False):
207 """Find array of tract IDs with vectorized operations (where
208 supported).
209
210 If a given sky map does not support vectorized operations, then a loop
211 over findTract will be called.
212
213 Parameters
214 ----------
215 ra : `numpy.ndarray`
216 Array of Right Ascension. Units are radians unless
217 degrees=True.
218 dec : `numpy.ndarray`
219 Array of Declination. Units are radians unless
220 degrees=True.
221 degrees : `bool`, optional
222 Input ra, dec arrays are degrees if `True`.
223
224 Returns
225 -------
226 tractId : `numpy.ndarray`
227 Array of tract IDs
228
229 Notes
230 -----
231 - If coord is equidistant between multiple sky tract centers then one
232 is arbitrarily chosen.
233
234 .. warning::
235
236 If tracts do not cover the whole sky then the returned tract may not
237 include the given ra/dec.
238 """
239 units = geom.degrees if degrees else geom.radians
240 coords = [geom.SpherePoint(r*units, d*units) for r, d in zip(np.atleast_1d(ra),
241 np.atleast_1d(dec))]
242
243 tractId = np.array([self.findTract(coord).getId() for coord in coords])
244
245 return tractId
246
Point in an unspecified spherical coordinate system.
Definition SpherePoint.h:57

◆ findTractPatchList()

lsst.skymap.baseSkyMap.BaseSkyMap.findTractPatchList ( self,
coordList )
Find tracts and patches that overlap a region.

Parameters
----------
coordList : `list` of `lsst.geom.SpherePoint`
    List of ICRS sky coordinates to search for.

Returns
-------
reList : `list` of (`TractInfo`, `list` of `PatchInfo`)
    For tracts and patches that contain, or may contain, the specified
    region. The list will be empty if there is no overlap.

Notes
-----
.. warning::

    This uses a naive algorithm that may find some tracts and patches
    that do not overlap the region (especially if the region is not a
    rectangle aligned along patch x, y).

Reimplemented in lsst.skymap.ringsSkyMap.RingsSkyMap.

Definition at line 247 of file baseSkyMap.py.

247 def findTractPatchList(self, coordList):
248 """Find tracts and patches that overlap a region.
249
250 Parameters
251 ----------
252 coordList : `list` of `lsst.geom.SpherePoint`
253 List of ICRS sky coordinates to search for.
254
255 Returns
256 -------
257 reList : `list` of (`TractInfo`, `list` of `PatchInfo`)
258 For tracts and patches that contain, or may contain, the specified
259 region. The list will be empty if there is no overlap.
260
261 Notes
262 -----
263 .. warning::
264
265 This uses a naive algorithm that may find some tracts and patches
266 that do not overlap the region (especially if the region is not a
267 rectangle aligned along patch x, y).
268 """
269 retList = []
270 for tractInfo in self:
271 patchList = tractInfo.findPatchList(coordList)
272 if patchList:
273 retList.append((tractInfo, patchList))
274 return retList
275

◆ getSha1()

lsst.skymap.baseSkyMap.BaseSkyMap.getSha1 ( self)
Return a SHA1 hash that uniquely identifies this SkyMap instance.

Returns
-------
sha1 : `bytes`
    A 20-byte hash that uniquely identifies this SkyMap instance.

Notes
-----
Subclasses should almost always override ``updateSha1`` instead of
this function to add subclass-specific state to the hash.

Definition at line 344 of file baseSkyMap.py.

344 def getSha1(self):
345 """Return a SHA1 hash that uniquely identifies this SkyMap instance.
346
347 Returns
348 -------
349 sha1 : `bytes`
350 A 20-byte hash that uniquely identifies this SkyMap instance.
351
352 Notes
353 -----
354 Subclasses should almost always override ``updateSha1`` instead of
355 this function to add subclass-specific state to the hash.
356 """
357 if self._sha1 is None:
358 sha1 = hashlib.sha1()
359 sha1.update(type(self).__name__.encode('utf-8'))
360 configPacked = self._tractBuilder.getPackedConfig(self.config)
361 sha1.update(configPacked)
362 self.updateSha1(sha1)
363 self._sha1 = sha1.digest()
364 return self._sha1
365

◆ logSkyMapInfo()

lsst.skymap.baseSkyMap.BaseSkyMap.logSkyMapInfo ( self,
log )
Write information about a sky map to supplied log

Parameters
----------
log : `logging.Logger`
    Log object that information about skymap will be written.

Definition at line 320 of file baseSkyMap.py.

320 def logSkyMapInfo(self, log):
321 """Write information about a sky map to supplied log
322
323 Parameters
324 ----------
325 log : `logging.Logger`
326 Log object that information about skymap will be written.
327 """
328 log.info("sky map has %s tracts" % (len(self),))
329 for tractInfo in self:
330 wcs = tractInfo.getWcs()
331 posBox = geom.Box2D(tractInfo.getBBox())
332 pixelPosList = (
333 posBox.getMin(),
334 geom.Point2D(posBox.getMaxX(), posBox.getMinY()),
335 posBox.getMax(),
336 geom.Point2D(posBox.getMinX(), posBox.getMaxY()),
337 )
338 skyPosList = [wcs.pixelToSky(pos).getPosition(geom.degrees) for pos in pixelPosList]
339 posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
340 log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches" %
341 (tractInfo.getId(), ", ".join(posStrList),
342 tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
343
A floating-point coordinate rectangle geometry.
Definition Box.h:413

◆ register()

lsst.skymap.baseSkyMap.BaseSkyMap.register ( self,
name,
butler )
Add skymap, tract, and patch Dimension entries to the given Gen3
Butler.

Parameters
----------
name : `str`
    The name of the skymap.
butler : `lsst.daf.butler.Butler`
    The butler to add to.

Raises
------
lsst.daf.butler.registry.ConflictingDefinitionError
    Raised if a different skymap exists with the same name.

Notes
-----
Registering the same skymap multiple times (with the exact same
definition) is safe, but inefficient; most of the work of computing
the rows to be inserted must be done first in order to check for
consistency between the new skymap and any existing one.

Re-registering a skymap with different tract and/or patch definitions
but the same summary information may not be detected as a conflict but
will never result in updating the skymap; there is intentionally no
way to modify a registered skymap (aside from manual administrative
operations on the database), as it is hard to guarantee that this can
be done without affecting reproducibility.

Definition at line 387 of file baseSkyMap.py.

387 def register(self, name, butler):
388 """Add skymap, tract, and patch Dimension entries to the given Gen3
389 Butler.
390
391 Parameters
392 ----------
393 name : `str`
394 The name of the skymap.
395 butler : `lsst.daf.butler.Butler`
396 The butler to add to.
397
398 Raises
399 ------
400 lsst.daf.butler.registry.ConflictingDefinitionError
401 Raised if a different skymap exists with the same name.
402
403 Notes
404 -----
405 Registering the same skymap multiple times (with the exact same
406 definition) is safe, but inefficient; most of the work of computing
407 the rows to be inserted must be done first in order to check for
408 consistency between the new skymap and any existing one.
409
410 Re-registering a skymap with different tract and/or patch definitions
411 but the same summary information may not be detected as a conflict but
412 will never result in updating the skymap; there is intentionally no
413 way to modify a registered skymap (aside from manual administrative
414 operations on the database), as it is hard to guarantee that this can
415 be done without affecting reproducibility.
416 """
417 numPatches = [tractInfo.getNumPatches() for tractInfo in self]
418 nxMax = max(nn[0] for nn in numPatches)
419 nyMax = max(nn[1] for nn in numPatches)
420
421 skyMapRecord = {
422 "skymap": name,
423 "hash": self.getSha1(),
424 "tract_max": len(self),
425 "patch_nx_max": nxMax,
426 "patch_ny_max": nyMax,
427 }
428 butler.registry.registerRun(self.SKYMAP_RUN_COLLECTION_NAME)
429 # Kind of crazy that we've got three different capitalizations of
430 # "skymap" here, but that's what the various conventions (or at least
431 # precedents) dictate.
432 from lsst.daf.butler import DatasetType
433 from lsst.daf.butler.registry import ConflictingDefinitionError
434 datasetType = DatasetType(
435 name=self.SKYMAP_DATASET_TYPE_NAME,
436 dimensions=["skymap"],
437 storageClass="SkyMap",
438 universe=butler.dimensions
439 )
440 butler.registry.registerDatasetType(datasetType)
441 with butler.transaction():
442 try:
443 inserted = butler.registry.syncDimensionData("skymap", skyMapRecord)
444 except ConflictingDefinitionError as err:
445 raise ConflictingDefinitionError(
446 f"SkyMap with hash {self.getSha1().hex()} is already registered with a different name."
447 ) from err
448 if inserted:
449 for tractInfo in self:
450 tractId = tractInfo.getId()
451 tractRegion = tractInfo.getOuterSkyPolygon()
452 tractWcs = tractInfo.getWcs()
453 tractRecord = dict(
454 skymap=name,
455 tract=tractId,
456 region=tractRegion,
457 )
458 butler.registry.insertDimensionData("tract", tractRecord)
459
460 patchRecords = []
461 for patchInfo in tractInfo:
462 xx, yy = patchInfo.getIndex()
463 patchRecords.append(
464 dict(
465 skymap=name,
466 tract=tractId,
467 patch=tractInfo.getSequentialPatchIndex(patchInfo),
468 cell_x=xx,
469 cell_y=yy,
470 region=patchInfo.getOuterSkyPolygon(tractWcs),
471 )
472 )
473 butler.registry.insertDimensionData("patch", *patchRecords)
474
475 butler.put(self, datasetType, {"skymap": name}, run=self.SKYMAP_RUN_COLLECTION_NAME)
int max

◆ updateSha1()

lsst.skymap.baseSkyMap.BaseSkyMap.updateSha1 ( self,
sha1 )
Add subclass-specific state or configuration options to the SHA1.

Parameters
----------
sha1 : `hashlib.sha1`
    A hashlib object on which `update` can be called to add
    additional state to the hash.

Notes
-----
This method is conceptually "protected" : it should be reimplemented by
all subclasses, but called only by the base class implementation of
`getSha1` .

Reimplemented in lsst.skymap.discreteSkyMap.DiscreteSkyMap, lsst.skymap.dodecaSkyMap.DodecaSkyMap, lsst.skymap.equatSkyMap.EquatSkyMap, lsst.skymap.healpixSkyMap.HealpixSkyMap, and lsst.skymap.ringsSkyMap.RingsSkyMap.

Definition at line 366 of file baseSkyMap.py.

366 def updateSha1(self, sha1):
367 """Add subclass-specific state or configuration options to the SHA1.
368
369 Parameters
370 ----------
371 sha1 : `hashlib.sha1`
372 A hashlib object on which `update` can be called to add
373 additional state to the hash.
374
375 Notes
376 -----
377 This method is conceptually "protected" : it should be reimplemented by
378 all subclasses, but called only by the base class implementation of
379 `getSha1` .
380 """
381 raise NotImplementedError()
382

Member Data Documentation

◆ _sha1

lsst.skymap.baseSkyMap.BaseSkyMap._sha1
protected

Definition at line 169 of file baseSkyMap.py.

◆ _tractBuilder

lsst.skymap.baseSkyMap.BaseSkyMap._tractBuilder
protected

Definition at line 170 of file baseSkyMap.py.

◆ _tractInfoList

lsst.skymap.baseSkyMap.BaseSkyMap._tractInfoList
protected

Definition at line 163 of file baseSkyMap.py.

◆ _wcsFactory

lsst.skymap.baseSkyMap.BaseSkyMap._wcsFactory
protected

Definition at line 164 of file baseSkyMap.py.

◆ config

lsst.skymap.baseSkyMap.BaseSkyMap.config

Definition at line 162 of file baseSkyMap.py.

◆ ConfigClass

lsst.skymap.baseSkyMap.BaseSkyMap.ConfigClass = BaseSkyMapConfig
static

Definition at line 156 of file baseSkyMap.py.

◆ SKYMAP_DATASET_TYPE_NAME

str lsst.skymap.baseSkyMap.BaseSkyMap.SKYMAP_DATASET_TYPE_NAME = "skyMap"
static

Definition at line 385 of file baseSkyMap.py.

◆ SKYMAP_RUN_COLLECTION_NAME [1/2]

str lsst.skymap.baseSkyMap.BaseSkyMap.SKYMAP_RUN_COLLECTION_NAME = "skymaps"
static

Definition at line 383 of file baseSkyMap.py.

◆ SKYMAP_RUN_COLLECTION_NAME [2/2]

lsst.skymap.baseSkyMap.BaseSkyMap.SKYMAP_RUN_COLLECTION_NAME

Definition at line 428 of file baseSkyMap.py.


The documentation for this class was generated from the following file: