LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.skymap.discreteSkyMap.DiscreteSkyMap Class Reference
Inheritance diagram for lsst.skymap.discreteSkyMap.DiscreteSkyMap:
lsst.skymap.cachingSkyMap.CachingSkyMap lsst.skymap.baseSkyMap.BaseSkyMap

Public Member Functions

def __init__ (self, config, version=0)
 
def generateTract (self, index)
 
def updateSha1 (self, sha1)
 
def __reduce__ (self)
 
def __iter__ (self)
 
def __len__ (self)
 
def __getitem__ (self, index)
 
def findTract (self, coord)
 
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 = DiscreteSkyMapConfig
 
string SKYMAP_RUN_COLLECTION_NAME = "skymaps"
 
string SKYMAP_DATASET_TYPE_NAME = "skyMap"
 

Detailed Description

Discrete sky map pixelization.

We put a square Tract at each of the nominated coordinates.

Parameters
----------
config : `lsst.skyMap.BaseSkyMapConfig`
    The configuration for this SkyMap; if None use the default config.
version : `int` or `tuple` of `int` (optional)
    Software version of this class, to retain compatibility with old
    instances.

Definition at line 50 of file discreteSkyMap.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.skymap.discreteSkyMap.DiscreteSkyMap.__init__ (   self,
  config,
  version = 0 
)

Definition at line 66 of file discreteSkyMap.py.

66  def __init__(self, config, version=0):
67  numTracts = len(config.radiusList)
68  super(DiscreteSkyMap, self).__init__(numTracts, config, version)
69 

Member Function Documentation

◆ __eq__()

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

Definition at line 212 of file baseSkyMap.py.

212  def __eq__(self, other):
213  try:
214  return self.getSha1() == other.getSha1()
215  except AttributeError:
216  return NotImplemented
217 

◆ __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 209 of file baseSkyMap.py.

209  def __hash__(self):
210  return hash(self.getSha1())
211 

◆ __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 218 of file baseSkyMap.py.

218  def __ne__(self, other):
219  return not (self == other)
220 

◆ __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 177 of file baseSkyMap.py.

177  def findClosestTractPatchList(self, coordList):
178  """Find closest tract and patches that overlap coordinates.
179 
180  Parameters
181  ----------
182  coordList : `lsst.geom.SpherePoint`
183  List of ICRS sky coordinates to search for.
184 
185  Returns
186  -------
187  retList : `list`
188  list of (TractInfo, list of PatchInfo) for tracts and patches
189  that contain, or may contain, the specified region.
190  The list will be empty if there is no overlap.
191  """
192  retList = []
193  for coord in coordList:
194  tractInfo = self.findTract(coord)
195  patchList = tractInfo.findPatchList(coordList)
196  if patchList and not (tractInfo, patchList) in retList:
197  retList.append((tractInfo, patchList))
198  return retList
199 

◆ findTract()

def lsst.skymap.baseSkyMap.BaseSkyMap.findTract (   self,
  coord 
)
inherited
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.ringsSkyMap.RingsSkyMap, lsst.skymap.healpixSkyMap.HealpixSkyMap, and lsst.skymap.dodecaSkyMap.DodecaSkyMap.

Definition at line 116 of file baseSkyMap.py.

116  def findTract(self, coord):
117  """Find the tract whose center is nearest the specified coord.
118 
119  Parameters
120  ----------
121  coord : `lsst.geom.SpherePoint`
122  ICRS sky coordinate to search for.
123 
124  Returns
125  -------
126  result : `TractInfo`
127  TractInfo of tract whose center is nearest the specified coord.
128 
129  Notes
130  -----
131  - If coord is equidistant between multiple sky tract centers then one
132  is arbitrarily chosen.
133 
134  - The default implementation is not very efficient; subclasses may wish
135  to override.
136 
137  **Warning:**
138  If tracts do not cover the whole sky then the returned tract may not
139  include the coord.
140  """
141  distTractInfoList = []
142  for i, tractInfo in enumerate(self):
143  angSep = coord.separation(tractInfo.getCtrCoord()).asDegrees()
144  # include index in order to disambiguate identical angSep values
145  distTractInfoList.append((angSep, i, tractInfo))
146  distTractInfoList.sort()
147  return distTractInfoList[0][2]
148 

◆ 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 149 of file baseSkyMap.py.

149  def findTractPatchList(self, coordList):
150  """Find tracts and patches that overlap a region.
151 
152  Parameters
153  ----------
154  coordList : `list` of `lsst.geom.SpherePoint`
155  List of ICRS sky coordinates to search for.
156 
157  Returns
158  -------
159  reList : `list` of (`TractInfo`, `list` of `PatchInfo`)
160  For tracts and patches that contain, or may contain, the specified
161  region. The list will be empty if there is no overlap.
162 
163  Notes
164  -----
165  **warning:**
166  This uses a naive algorithm that may find some tracts and patches
167  that do not overlap the region (especially if the region is not a
168  rectangle aligned along patch x, y).
169  """
170  retList = []
171  for tractInfo in self:
172  patchList = tractInfo.findPatchList(coordList)
173  if patchList:
174  retList.append((tractInfo, patchList))
175  return retList
176 

◆ generateTract()

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

Reimplemented from lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 70 of file discreteSkyMap.py.

70  def generateTract(self, index):
71  """Generate TractInfo for the specified tract index."""
72  center = geom.SpherePoint(self.config.raList[index], self.config.decList[index], geom.degrees)
73  radius = self.config.radiusList[index]
74  wcs = self._wcsFactory.makeWcs(crPixPos=geom.Point2D(0, 0), crValCoord=center)
75  return ExplicitTractInfo(index, self.config.patchInnerDimensions, self.config.patchBorder, center,
76  radius*geom.degrees, self.config.tractOverlap*geom.degrees, wcs)
77 
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
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 245 of file baseSkyMap.py.

245  def getSha1(self):
246  """Return a SHA1 hash that uniquely identifies this SkyMap instance.
247 
248  Returns
249  -------
250  sha1 : `bytes`
251  A 20-byte hash that uniquely identifies this SkyMap instance.
252 
253  Notes
254  -----
255  Subclasses should almost always override ``updateSha1`` instead of
256  this function to add subclass-specific state to the hash.
257  """
258  if self._sha1 is None:
259  sha1 = hashlib.sha1()
260  sha1.update(type(self).__name__.encode('utf-8'))
261  configPacked = struct.pack(
262  "<iiidd3sd",
263  self.config.patchInnerDimensions[0],
264  self.config.patchInnerDimensions[1],
265  self.config.patchBorder,
266  self.config.tractOverlap,
267  self.config.pixelScale,
268  self.config.projection.encode('ascii'),
269  self.config.rotation
270  )
271  sha1.update(configPacked)
272  self.updateSha1(sha1)
273  self._sha1 = sha1.digest()
274  return self._sha1
275 
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 221 of file baseSkyMap.py.

221  def logSkyMapInfo(self, log):
222  """Write information about a sky map to supplied log
223 
224  Parameters
225  ----------
226  log : `lsst.log.Log`
227  Log object that information about skymap will be written
228  """
229  log.info("sky map has %s tracts" % (len(self),))
230  for tractInfo in self:
231  wcs = tractInfo.getWcs()
232  posBox = geom.Box2D(tractInfo.getBBox())
233  pixelPosList = (
234  posBox.getMin(),
235  geom.Point2D(posBox.getMaxX(), posBox.getMinY()),
236  posBox.getMax(),
237  geom.Point2D(posBox.getMinX(), posBox.getMaxY()),
238  )
239  skyPosList = [wcs.pixelToSky(pos).getPosition(geom.degrees) for pos in pixelPosList]
240  posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
241  log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches" %
242  (tractInfo.getId(), ", ".join(posStrList),
243  tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
244 
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 297 of file baseSkyMap.py.

297  def register(self, name, butler):
298  """Add skymap, tract, and patch Dimension entries to the given Gen3
299  Butler.
300 
301  Parameters
302  ----------
303  name : `str`
304  The name of the skymap.
305  butler : `lsst.daf.butler.Butler`
306  The butler to add to.
307 
308  Raises
309  ------
310  lsst.daf.butler.registry.ConflictingDefinitionError
311  Raised if a different skymap exists with the same name.
312 
313  Notes
314  -----
315  Registering the same skymap multiple times (with the exact same
316  definition) is safe, but inefficient; most of the work of computing
317  the rows to be inserted must be done first in order to check for
318  consistency between the new skymap and any existing one.
319 
320  Re-registering a skymap with different tract and/or patch definitions
321  but the same summary information may not be detected as a conflict but
322  will never result in updating the skymap; there is intentionally no
323  way to modify a registered skymap (aside from manual administrative
324  operations on the database), as it is hard to guarantee that this can
325  be done without affecting reproducibility.
326  """
327  nxMax = 0
328  nyMax = 0
329  tractRecords = []
330  patchRecords = []
331  for tractInfo in self:
332  nx, ny = tractInfo.getNumPatches()
333  nxMax = max(nxMax, nx)
334  nyMax = max(nyMax, ny)
335  region = tractInfo.getOuterSkyPolygon()
336  centroid = SpherePoint(region.getCentroid())
337  tractRecords.append({
338  "skymap": name,
339  "tract": tractInfo.getId(),
340  "region": region,
341  "ra": centroid.getRa().asDegrees(),
342  "dec": centroid.getDec().asDegrees(),
343  })
344  for patchInfo in tractInfo:
345  cellX, cellY = patchInfo.getIndex()
346  patchRecords.append({
347  "skymap": name,
348  "tract": tractInfo.getId(),
349  "patch": tractInfo.getSequentialPatchIndex(patchInfo),
350  "cell_x": cellX,
351  "cell_y": cellY,
352  "region": patchInfo.getOuterSkyPolygon(tractInfo.getWcs()),
353  })
354  skyMapRecord = {
355  "skymap": name,
356  "hash": self.getSha1(),
357  "tract_max": len(self),
358  "patch_nx_max": nxMax,
359  "patch_ny_max": nyMax,
360  }
361  butler.registry.registerRun(self.SKYMAP_RUN_COLLECTION_NAME)
362  # Kind of crazy that we've got three different capitalizations of
363  # "skymap" here, but that's what the various conventions (or at least
364  # precedents) dictate.
365  from lsst.daf.butler import DatasetType
366  from lsst.daf.butler.registry import ConflictingDefinitionError
367  datasetType = DatasetType(
368  name=self.SKYMAP_DATASET_TYPE_NAME,
369  dimensions=["skymap"],
370  storageClass="SkyMap",
371  universe=butler.registry.dimensions
372  )
373  butler.registry.registerDatasetType(datasetType)
374  with butler.transaction():
375  try:
376  inserted = butler.registry.syncDimensionData("skymap", skyMapRecord)
377  except ConflictingDefinitionError as err:
378  raise ConflictingDefinitionError(
379  f"SkyMap with hash {self.getSha1().hex()} is already registered with a different name."
380  ) from err
381  if inserted:
382  butler.registry.insertDimensionData("tract", *tractRecords)
383  butler.registry.insertDimensionData("patch", *patchRecords)
384  butler.put(self, datasetType, {"skymap": name}, run=self.SKYMAP_RUN_COLLECTION_NAME)
int max
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35

◆ updateSha1()

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

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 78 of file discreteSkyMap.py.

78  def updateSha1(self, sha1):
79  """Add subclass-specific state or configuration options to the SHA1."""
80  fmt = "<{}d".format(len(self.config.radiusList))
81  sha1.update(struct.pack(fmt, *self.config.raList))
82  sha1.update(struct.pack(fmt, *self.config.decList))
83  sha1.update(struct.pack(fmt, *self.config.radiusList))
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

Member Data Documentation

◆ config

lsst.skymap.baseSkyMap.BaseSkyMap.config
inherited

Definition at line 107 of file baseSkyMap.py.

◆ ConfigClass

lsst.skymap.discreteSkyMap.DiscreteSkyMap.ConfigClass = DiscreteSkyMapConfig
static

Definition at line 63 of file discreteSkyMap.py.

◆ SKYMAP_DATASET_TYPE_NAME

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

Definition at line 295 of file baseSkyMap.py.

◆ SKYMAP_RUN_COLLECTION_NAME

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

Definition at line 293 of file baseSkyMap.py.


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