LSSTApplications  20.0.0
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.skymap.ringsSkyMap.RingsSkyMap Class Reference
Inheritance diagram for lsst.skymap.ringsSkyMap.RingsSkyMap:
lsst.skymap.cachingSkyMap.CachingSkyMap lsst.skymap.baseSkyMap.BaseSkyMap

Public Member Functions

def __init__ (self, config, version=1)
 
def getRingIndices (self, index)
 
def generateTract (self, index)
 
def findTract (self, coord)
 
def findAllTracts (self, coord)
 
def findTractPatchList (self, coordList)
 
def updateSha1 (self, sha1)
 
def __reduce__ (self)
 
def __iter__ (self)
 
def __len__ (self)
 
def __getitem__ (self, index)
 
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, registry)
 

Public Attributes

 config
 

Static Public Attributes

 ConfigClass
 

Detailed Description

Rings sky map pixelization.

We divide the sphere into N rings of Declination, plus the two polar
caps, which sets the size of the individual tracts.  The rings are
divided in RA into an integral number of tracts of this size; this
division is made at the Declination closest to zero so as to ensure
full overlap.

Rings are numbered in the rings from south to north. The south pole cap is
``tract=0``, then the tract at ``raStart`` in the southernmost ring is
``tract=1``. Numbering continues (in the positive RA direction) around that
ring and then continues in the same fashion with the next ring north, and
so on until all reaching the north pole cap, which is
``tract=len(skymap) - 1``.

However, ``version=0`` had a bug in the numbering of the tracts: the first
and last tracts in the first (southernmost) ring were identical, and the
first tract in the last (northernmost) ring was missing. When using
``version=0``, these tracts remain missing in order to preserve the
numbering scheme.

Parameters
----------
config : `lsst.skymap.RingsSkyMapConfig`
    The configuration for this SkyMap.
version : `int`, optional
    Software version of this class, to retain compatibility with old
    verisons. ``version=0`` covers the period from first implementation
    until DM-14809, at which point bugs were identified in the numbering
    of tracts (affecting only tracts at RA=0). ``version=1`` uses the
    post-DM-14809 tract numbering.

Definition at line 41 of file ringsSkyMap.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.skymap.ringsSkyMap.RingsSkyMap.__init__ (   self,
  config,
  version = 1 
)

Definition at line 77 of file ringsSkyMap.py.

77  def __init__(self, config, version=1):
78  assert version in (0, 1), "Unrecognised version: %s" % (version,)
79  # We count rings from south to north
80  # Note: pole caps together count for one additional ring when calculating the ring size
81  self._ringSize = math.pi / (config.numRings + 1) # Size of a ring in Declination (radians)
82  self._ringNums = [] # Number of tracts for each ring
83  for i in range(config.numRings):
84  startDec = self._ringSize*(i + 0.5) - 0.5*math.pi
85  stopDec = startDec + self._ringSize
86  dec = min(math.fabs(startDec), math.fabs(stopDec)) # Declination for determining division in RA
87  self._ringNums.append(int(2*math.pi*math.cos(dec)/self._ringSize) + 1)
88  numTracts = sum(self._ringNums) + 2
89  super(RingsSkyMap, self).__init__(numTracts, config, version)
90  self._raStart = self.config.raStart*geom.degrees
91 

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 

◆ findAllTracts()

def lsst.skymap.ringsSkyMap.RingsSkyMap.findAllTracts (   self,
  coord 
)
Find all tracts which include the specified coord.

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

Returns
-------
tractList : `list` of `TractInfo`
    The tracts which include the specified coord.

Definition at line 204 of file ringsSkyMap.py.

204  def findAllTracts(self, coord):
205  """Find all tracts which include the specified coord.
206 
207  Parameters
208  ----------
209  coord : `lsst.geom.SpherePoint`
210  ICRS sky coordinate to search for.
211 
212  Returns
213  -------
214  tractList : `list` of `TractInfo`
215  The tracts which include the specified coord.
216  """
217  ringNum = self._decToRingNum(coord.getLatitude())
218 
219  tractList = list()
220  # ringNum denotes the closest ring to the specified coord
221  # I will check adjacent rings which may include the specified coord
222  for r in [ringNum - 1, ringNum, ringNum + 1]:
223  if r < 0 or r >= self.config.numRings:
224  # Poles will be checked explicitly outside this loop
225  continue
226  tractNum = self._raToTractNum(coord.getLongitude(), r)
227  # Adjacent tracts will also be checked.
228  for t in [tractNum - 1, tractNum, tractNum + 1]:
229  # Wrap over raStart
230  if t < 0:
231  t = t + self._ringNums[r]
232  elif t > self._ringNums[r] - 1:
233  t = t - self._ringNums[r]
234 
235  extra = 0
236  if self._version == 0 and t == 0 and r != 0:
237  # Account for off-by-one error in getRingIndices
238  # Note that this means that tract 1 gets duplicated.
239  extra = 1
240 
241  index = sum(self._ringNums[:r + extra], t + 1) # Allow 1 for south pole
242  tract = self[index]
243  if tract.contains(coord):
244  tractList.append(tract)
245 
246  # Always check tracts at poles
247  # Southern cap is 0, Northern cap is the last entry in self
248  for entry in [0, len(self)-1]:
249  tract = self[entry]
250  if tract.contains(coord):
251  tractList.append(tract)
252 
253  return tractList
254 

◆ 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.ringsSkyMap.RingsSkyMap.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 from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 186 of file ringsSkyMap.py.

186  def findTract(self, coord):
187  ringNum = self._decToRingNum(coord.getLatitude())
188  if ringNum == -1:
189  # Southern cap
190  return self[0]
191  if ringNum == self.config.numRings:
192  # Northern cap
193  return self[self._numTracts - 1]
194  tractNum = self._raToTractNum(coord.getLongitude(), ringNum)
195 
196  if self._version == 0 and tractNum == 0 and ringNum != 0:
197  # Account for off-by-one error in getRingIndices
198  # Note that this means that tract 1 gets duplicated.
199  ringNum += 1
200 
201  index = sum(self._ringNums[:ringNum], tractNum + 1) # Allow 1 for south pole
202  return self[index]
203 

◆ findTractPatchList()

def lsst.skymap.ringsSkyMap.RingsSkyMap.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 from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 255 of file ringsSkyMap.py.

255  def findTractPatchList(self, coordList):
256  retList = []
257  for coord in coordList:
258  for tractInfo in self.findAllTracts(coord):
259  patchList = tractInfo.findPatchList(coordList)
260  if patchList and not (tractInfo, patchList) in retList:
261  retList.append((tractInfo, patchList))
262  return retList
263 

◆ generateTract()

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

Reimplemented from lsst.skymap.cachingSkyMap.CachingSkyMap.

Definition at line 123 of file ringsSkyMap.py.

123  def generateTract(self, index):
124  """Generate TractInfo for the specified tract index."""
125  ringNum, tractNum = self.getRingIndices(index)
126  if ringNum == -1: # South polar cap
127  ra, dec = 0, -0.5*math.pi
128  elif ringNum == self.config.numRings: # North polar cap
129  ra, dec = 0, 0.5*math.pi
130  else:
131  dec = self._ringSize*(ringNum + 1) - 0.5*math.pi
132  ra = ((2*math.pi*tractNum/self._ringNums[ringNum])*geom.radians
133  + self._raStart).wrap().asRadians()
134 
135  center = geom.SpherePoint(ra, dec, geom.radians)
136  wcs = self._wcsFactory.makeWcs(crPixPos=geom.Point2D(0, 0), crValCoord=center)
137  return ExplicitTractInfo(index, self.config.patchInnerDimensions, self.config.patchBorder, center,
138  0.5*self._ringSize*geom.radians, self.config.tractOverlap*geom.degrees,
139  wcs)
140 

◆ getRingIndices()

def lsst.skymap.ringsSkyMap.RingsSkyMap.getRingIndices (   self,
  index 
)
Calculate ring indices given a numerical index of a tract.

The ring indices are the ring number and the tract number within
the ring.

The ring number is -1 for the south polar cap and increases to the
north.  The north polar cap has ring number = numRings.  The tract
number is zero for either of the polar caps.

Definition at line 92 of file ringsSkyMap.py.

92  def getRingIndices(self, index):
93  """Calculate ring indices given a numerical index of a tract.
94 
95  The ring indices are the ring number and the tract number within
96  the ring.
97 
98  The ring number is -1 for the south polar cap and increases to the
99  north. The north polar cap has ring number = numRings. The tract
100  number is zero for either of the polar caps.
101  """
102  if index == 0: # South polar cap
103  return -1, 0
104  if index == self._numTracts - 1: # North polar cap
105  return self.config.numRings, 0
106  if index < 0 or index >= self._numTracts:
107  raise IndexError("Tract index %d is out of range [0, %d]" % (index, len(self) - 1))
108  ring = 0 # Ring number
109  tractNum = index - 1 # Tract number within ring
110  if self._version == 0:
111  # Maintain the off-by-one bug in version=0 (DM-14809).
112  # This means that the first tract in the first ring is duplicated
113  # and the first tract in the last ring is missing.
114  while ring < self.config.numRings and tractNum > self._ringNums[ring]:
115  tractNum -= self._ringNums[ring]
116  ring += 1
117  else:
118  while ring < self.config.numRings and tractNum >= self._ringNums[ring]:
119  tractNum -= self._ringNums[ring]
120  ring += 1
121  return ring, tractNum
122 

◆ 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 

◆ 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 

◆ register()

def lsst.skymap.baseSkyMap.BaseSkyMap.register (   self,
  name,
  registry 
)
inherited
Add SkyMap, Tract, and Patch Dimension entries to the given Gen3
Butler Registry.

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

Definition at line 293 of file baseSkyMap.py.

293  def register(self, name, registry):
294  """Add SkyMap, Tract, and Patch Dimension entries to the given Gen3
295  Butler Registry.
296 
297  Parameters
298  ----------
299  name : `str`
300  The name of the skymap.
301  registry : `lsst.daf.butler.Registry`
302  The registry to add to.
303  """
304  nxMax = 0
305  nyMax = 0
306  records = {
307  "skymap": [],
308  "tract": [],
309  "patch": [],
310  }
311  for tractInfo in self:
312  nx, ny = tractInfo.getNumPatches()
313  nxMax = max(nxMax, nx)
314  nyMax = max(nyMax, ny)
315  region = tractInfo.getOuterSkyPolygon()
316  centroid = SpherePoint(region.getCentroid())
317  records["tract"].append({
318  "skymap": name,
319  "tract": tractInfo.getId(),
320  "region": region,
321  "ra": centroid.getRa().asDegrees(),
322  "dec": centroid.getDec().asDegrees(),
323  })
324  for patchInfo in tractInfo:
325  cellX, cellY = patchInfo.getIndex()
326  records["patch"].append({
327  "skymap": name,
328  "tract": tractInfo.getId(),
329  "patch": tractInfo.getSequentialPatchIndex(patchInfo),
330  "cell_x": cellX,
331  "cell_y": cellY,
332  "region": patchInfo.getOuterSkyPolygon(tractInfo.getWcs()),
333  })
334  records["skymap"].append({
335  "skymap": name,
336  "hash": self.getSha1(),
337  "tract_max": len(self),
338  "patch_nx_max": nxMax,
339  "patch_ny_max": nyMax,
340  })
341  with registry.transaction():
342  for dimension, recordsForDimension in records.items():
343  registry.insertDimensionData(dimension, *recordsForDimension)

◆ updateSha1()

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

Reimplemented from lsst.skymap.baseSkyMap.BaseSkyMap.

Definition at line 264 of file ringsSkyMap.py.

264  def updateSha1(self, sha1):
265  """Add subclass-specific state or configuration options to the SHA1."""
266  sha1.update(struct.pack("<id", self.config.numRings, self.config.raStart))

Member Data Documentation

◆ config

lsst.skymap.baseSkyMap.BaseSkyMap.config
inherited

Definition at line 107 of file baseSkyMap.py.

◆ ConfigClass

lsst.skymap.ringsSkyMap.RingsSkyMap.ConfigClass
static

Definition at line 74 of file ringsSkyMap.py.


The documentation for this class was generated from the following file:
lsst::afw::table::SpherePoint
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35
ast::append
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
max
int max
Definition: BoundedField.cc:104
lsst::meas::astrom::makeWcs
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.
Definition: SipTransform.cc:148
list
daf::base::PropertyList * list
Definition: fits.cc:913
lsst.gdb.ip.diffim.printers.register
def register(obj)
Definition: printers.py:20
min
int min
Definition: BoundedField.cc:103
type
table::Key< int > type
Definition: Detector.cc:163
lsst::geom::Point< double, 2 >
lsst::geom::SpherePoint
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
lsst::geom::Box2D
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
pex.config.wrap.wrap
def wrap(ctrl)
Definition: wrap.py:302