LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.skymap.healpixSkyMap.HealpixSkyMap Class Reference
Inheritance diagram for lsst.skymap.healpixSkyMap.HealpixSkyMap:
lsst.skymap.cachingSkyMap.CachingSkyMap lsst.skymap.baseSkyMap.BaseSkyMap

Public Member Functions

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

Public Attributes

 config
 

Static Public Attributes

 ConfigClass = HealpixSkyMapConfig
 
int numAngles = 4
 
string SKYMAP_RUN_COLLECTION_NAME = "skymaps"
 
string SKYMAP_DATASET_TYPE_NAME = "skyMap"
 

Detailed Description

HEALPix-based sky map pixelization.

We put a Tract at the position of each HEALPixel.


Parameters
----------
config : `lsst.skymap.BaseSkyMapConfig`
    The configuration for this SkyMap.
version : `int` or `tuple` of `int` (optional)
    Software version of this class, to retain compatibility with old
    instances.

Definition at line 86 of file healpixSkyMap.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.skymap.healpixSkyMap.HealpixSkyMap.__init__ (   self,
  config,
  version = 0 
)

Definition at line 104 of file healpixSkyMap.py.

104  def __init__(self, config, version=0):
105  self._nside = 1 << config.log2NSide
106  numTracts = healpy.nside2npix(self._nside)
107  super(HealpixSkyMap, self).__init__(numTracts, config, version)
108 

Member Function Documentation

◆ __eq__()

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

Definition at line 305 of file baseSkyMap.py.

305  def __eq__(self, other):
306  try:
307  return self.getSha1() == other.getSha1()
308  except AttributeError:
309  return NotImplemented
310 

◆ __getitem__()

def lsst.skymap.cachingSkyMap.CachingSkyMap.__getitem__ (   self,
  index 
)
inherited
Get the TractInfo for a particular index.

The tract is returned from a cache, if available, otherwise generated
on the fly.

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 80 of file cachingSkyMap.py.

80  def __getitem__(self, index):
81  """Get the TractInfo for a particular index.
82 
83  The tract is returned from a cache, if available, otherwise generated
84  on the fly.
85  """
86  if index < 0 or index > self._numTracts:
87  raise IndexError("Index out of range: %d vs %d" % (index, self._numTracts))
88  if self._tractCache[index] is not None:
89  return self._tractCache[index]
90  tract = self.generateTract(index)
91  self._tractCache[index] = tract
92  return tract
93 

◆ __hash__()

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

Definition at line 302 of file baseSkyMap.py.

302  def __hash__(self):
303  return hash(self.getSha1())
304 

◆ __iter__()

def lsst.skymap.cachingSkyMap.CachingSkyMap.__iter__ (   self)
inherited
Iterator over tracts.

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 71 of file cachingSkyMap.py.

71  def __iter__(self):
72  """Iterator over tracts."""
73  for i in range(self._numTracts):
74  yield self[i]
75 

◆ __len__()

def lsst.skymap.cachingSkyMap.CachingSkyMap.__len__ (   self)
inherited
Length is number of tracts.

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 76 of file cachingSkyMap.py.

76  def __len__(self):
77  """Length is number of tracts."""
78  return self._numTracts
79 

◆ __ne__()

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

Definition at line 311 of file baseSkyMap.py.

311  def __ne__(self, other):
312  return not (self == other)
313 

◆ __reduce__()

def lsst.skymap.cachingSkyMap.CachingSkyMap.__reduce__ (   self)
inherited
To support pickling.

Notes
-----
**Warning:** This method assumes that the constructor is be defined:
    __init__(self, config, version=defaultVersion)
The use of 'config' is effectively set by the registry mechanism.
If additional optional arguments are added, this method should be
overridden to correspond.

Definition at line 58 of file cachingSkyMap.py.

58  def __reduce__(self):
59  """To support pickling.
60 
61  Notes
62  -----
63  **Warning:** This method assumes that the constructor is be defined:
64  __init__(self, config, version=defaultVersion)
65  The use of 'config' is effectively set by the registry mechanism.
66  If additional optional arguments are added, this method should be
67  overridden to correspond.
68  """
69  return (self.__class__, (self.config, self._version))
70 

◆ findClosestTractPatchList()

def lsst.skymap.baseSkyMap.BaseSkyMap.findClosestTractPatchList (   self,
  coordList 
)
inherited
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 270 of file baseSkyMap.py.

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

◆ findTract()

def lsst.skymap.healpixSkyMap.HealpixSkyMap.findTract (   self,
  coord 
)
Find the tract whose inner region includes the coord.

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

Returns
-------
tractInfo : `TractInfo`
    Info for tract whose inner region includes the coord.

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 109 of file healpixSkyMap.py.

109  def findTract(self, coord):
110  """Find the tract whose inner region includes the coord.
111 
112  Parameters
113  ----------
114  coord : `lsst.geom.SpherePoint`
115  ICRS sky coordinate to search for.
116 
117  Returns
118  -------
119  tractInfo : `TractInfo`
120  Info for tract whose inner region includes the coord.
121  """
122  theta, phi = coordToAng(coord)
123  index = healpy.ang2pix(self._nside, theta, phi, nest=self.config.nest)
124  return self[index]
125 

◆ findTractIdArray()

def lsst.skymap.baseSkyMap.BaseSkyMap.findTractIdArray (   self,
  ra,
  dec,
  degrees = False 
)
inherited
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 : `np.ndarray`
    Array of Right Ascension.  Units are radians unless
    degrees=True.
dec : `np.ndarray`
    Array of Declination.  Units are radians unless
    degrees=True.
degrees : `bool`, optional
    Input ra, dec arrays are degrees if True.

Returns
-------
tractId : `np.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 203 of file baseSkyMap.py.

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

◆ findTractPatchList()

def lsst.skymap.baseSkyMap.BaseSkyMap.findTractPatchList (   self,
  coordList 
)
inherited
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 242 of file baseSkyMap.py.

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

◆ generateTract()

def lsst.skymap.healpixSkyMap.HealpixSkyMap.generateTract (   self,
  index 
)
Generate TractInfo for the specified tract index.

Reimplemented from lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 126 of file healpixSkyMap.py.

126  def generateTract(self, index):
127  """Generate TractInfo for the specified tract index."""
128  center = angToCoord(healpy.pix2ang(self._nside, index, nest=self.config.nest))
129  wcs = self._wcsFactory.makeWcs(crPixPos=geom.Point2D(0, 0), crValCoord=center)
130  return HealpixTractInfo(self._nside, index, self.config.nest, self._tractBuilder,
131  center, self.config.tractOverlap*geom.degrees,
132  wcs)
133 
std::shared_ptr< afw::geom::SkyWcs > makeWcs(SipForwardTransform const &sipForward, SipReverseTransform const &sipReverse, geom::SpherePoint const &skyOrigin)
Create a new TAN SIP Wcs from a pair of SIP transforms and the sky origin.

◆ getSha1()

def lsst.skymap.baseSkyMap.BaseSkyMap.getSha1 (   self)
inherited
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 338 of file baseSkyMap.py.

338  def getSha1(self):
339  """Return a SHA1 hash that uniquely identifies this SkyMap instance.
340 
341  Returns
342  -------
343  sha1 : `bytes`
344  A 20-byte hash that uniquely identifies this SkyMap instance.
345 
346  Notes
347  -----
348  Subclasses should almost always override ``updateSha1`` instead of
349  this function to add subclass-specific state to the hash.
350  """
351  if self._sha1 is None:
352  sha1 = hashlib.sha1()
353  sha1.update(type(self).__name__.encode('utf-8'))
354  configPacked = self._tractBuilder.getPackedConfig(self.config)
355  sha1.update(configPacked)
356  self.updateSha1(sha1)
357  self._sha1 = sha1.digest()
358  return self._sha1
359 
table::Key< int > type
Definition: Detector.cc:163

◆ logSkyMapInfo()

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

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

Definition at line 314 of file baseSkyMap.py.

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

◆ register()

def lsst.skymap.baseSkyMap.BaseSkyMap.register (   self,
  name,
  butler 
)
inherited
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 381 of file baseSkyMap.py.

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

◆ updateSha1()

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

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 134 of file healpixSkyMap.py.

134  def updateSha1(self, sha1):
135  """Add subclass-specific state or configuration options to the SHA1."""
136  sha1.update(struct.pack("<i?", self.config.log2NSide, self.config.nest))

Member Data Documentation

◆ config

lsst.skymap.baseSkyMap.BaseSkyMap.config
inherited

Definition at line 160 of file baseSkyMap.py.

◆ ConfigClass

lsst.skymap.healpixSkyMap.HealpixSkyMap.ConfigClass = HealpixSkyMapConfig
static

Definition at line 100 of file healpixSkyMap.py.

◆ numAngles

int lsst.skymap.healpixSkyMap.HealpixSkyMap.numAngles = 4
static

Definition at line 102 of file healpixSkyMap.py.

◆ SKYMAP_DATASET_TYPE_NAME

string lsst.skymap.baseSkyMap.BaseSkyMap.SKYMAP_DATASET_TYPE_NAME = "skyMap"
staticinherited

Definition at line 379 of file baseSkyMap.py.

◆ SKYMAP_RUN_COLLECTION_NAME

string lsst.skymap.baseSkyMap.BaseSkyMap.SKYMAP_RUN_COLLECTION_NAME = "skymaps"
staticinherited

Definition at line 377 of file baseSkyMap.py.


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