LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lsst.skymap.tractInfo.TractInfo Class Reference
Inheritance diagram for lsst.skymap.tractInfo.TractInfo:
lsst.skymap.tractInfo.ExplicitTractInfo

Public Member Functions

def __init__
 
def findPatch
 
def findPatchList
 
def getBBox
 
def getCtrCoord
 
def getId
 
def getNumPatches
 
def getPatchBorder
 
def getPatchInfo
 
def getPatchInnerDimensions
 
def getTractOverlap
 
def getVertexList
 
def getWcs
 
def __str__
 
def __repr__
 
def __iter__
 
def __len__
 
def __getitem__
 

Private Member Functions

def _minimumBoundingBox
 
def _setupPatches
 
def _finalOrientation
 

Private Attributes

 _id
 
 _patchInnerDimensions
 
 _patchBorder
 
 _ctrCoord
 
 _vertexCoordList
 
 _tractOverlap
 
 _numPatches
 
 _wcs
 

Detailed Description

Information about a tract in a SkyMap sky pixelization

The tract is subdivided into rectangular patches. Each patch has the following properties:
- An inner region defined by an inner bounding. The inner regions of the patches exactly tile the tract,
  and all inner regions have the same dimensions. The tract is made larger as required to make this work.
- An outer region defined by an outer bounding box. The outer region extends beyond the inner region
  by patchBorder pixels in all directions, except there is no border at the edges of the tract.
  Thus patches overlap each other but never extend off the tract. If you do not want any overlap
  between adjacent patches then set patchBorder to 0.
- An index that consists of a pair of integers:
    0 <= x index < numPatches[0]
    0 <= y index < numPatches[1]
  Patch 0,0 is at the minimum corner of the tract bounding box.

Definition at line 30 of file tractInfo.py.

Constructor & Destructor Documentation

def lsst.skymap.tractInfo.TractInfo.__init__ (   self,
  id,
  patchInnerDimensions,
  patchBorder,
  ctrCoord,
  vertexCoordList,
  tractOverlap,
  wcs 
)
Construct a TractInfo

@param[in] id: tract ID
@param[in] patchInnerDimensions: dimensions of inner region of patches (x,y pixels)
@param[in] patchBorder: overlap between adjacent patches (in pixels, one int)
@param[in] ctrCoord: sky coordinate of center of inner region of tract, as an afwCoord.Coord;
    also used as the CRVAL for the WCS.
@param[in] vertexCoordList: list of sky coordinates (afwCoord.Coord)
    of vertices that define the boundaries of the inner region
@param[in] tractOverlap: minimum overlap between adjacent sky tracts; an afwGeom.Angle;
    this defines the minimum distance the tract extends beyond the inner region in all directions
@param[in,out] wcs: an afwImage.Wcs; the reference pixel will be shifted as required
    so that the lower left-hand pixel (index 0,0) has pixel position 0.0, 0.0

@warning
- It is not enforced that ctrCoord is the center of vertexCoordList, but SkyMap relies on it
- vertexCoordList will likely become a geom SphericalConvexPolygon someday.

Definition at line 45 of file tractInfo.py.

45 
46  def __init__(self, id, patchInnerDimensions, patchBorder, ctrCoord, vertexCoordList, tractOverlap, wcs):
47  """Construct a TractInfo
48 
49  @param[in] id: tract ID
50  @param[in] patchInnerDimensions: dimensions of inner region of patches (x,y pixels)
51  @param[in] patchBorder: overlap between adjacent patches (in pixels, one int)
52  @param[in] ctrCoord: sky coordinate of center of inner region of tract, as an afwCoord.Coord;
53  also used as the CRVAL for the WCS.
54  @param[in] vertexCoordList: list of sky coordinates (afwCoord.Coord)
55  of vertices that define the boundaries of the inner region
56  @param[in] tractOverlap: minimum overlap between adjacent sky tracts; an afwGeom.Angle;
57  this defines the minimum distance the tract extends beyond the inner region in all directions
58  @param[in,out] wcs: an afwImage.Wcs; the reference pixel will be shifted as required
59  so that the lower left-hand pixel (index 0,0) has pixel position 0.0, 0.0
60 
61  @warning
62  - It is not enforced that ctrCoord is the center of vertexCoordList, but SkyMap relies on it
63  - vertexCoordList will likely become a geom SphericalConvexPolygon someday.
64  """
65  self._id = id
66  try:
67  assert len(patchInnerDimensions) == 2
68  self._patchInnerDimensions = afwGeom.Extent2I(*(int(val) for val in patchInnerDimensions))
69  except:
70  raise TypeError("patchInnerDimensions=%s; must be two ints" % (patchInnerDimensions,))
71  self._patchBorder = int(patchBorder)
72  self._ctrCoord = ctrCoord
73  self._vertexCoordList = tuple(coord.clone() for coord in vertexCoordList)
74  self._tractOverlap = tractOverlap
75 
76  minBBox = self._minimumBoundingBox(wcs)
77  initialBBox, self._numPatches = self._setupPatches(minBBox, wcs)
78  self._bbox, self._wcs = self._finalOrientation(initialBBox, wcs)
79 

Member Function Documentation

def lsst.skymap.tractInfo.TractInfo.__getitem__ (   self,
  index 
)

Definition at line 302 of file tractInfo.py.

303  def __getitem__(self, index):
304  return self.getPatchInfo(index)
305 
def lsst.skymap.tractInfo.TractInfo.__iter__ (   self)

Definition at line 292 of file tractInfo.py.

293  def __iter__(self):
294  xNum, yNum = self.getNumPatches()
295  for y in range(yNum):
296  for x in range(xNum):
297  yield self.getPatchInfo((x,y))
def lsst.skymap.tractInfo.TractInfo.__len__ (   self)

Definition at line 298 of file tractInfo.py.

299  def __len__(self):
300  xNum, yNum = self.getNumPatches()
301  return xNum*yNum
def lsst.skymap.tractInfo.TractInfo.__repr__ (   self)

Definition at line 289 of file tractInfo.py.

290  def __repr__(self):
291  return "TractInfo(id=%s, ctrCoord=%s)" % (self._id, self._ctrCoord.getVector())
def lsst.skymap.tractInfo.TractInfo.__str__ (   self)

Definition at line 286 of file tractInfo.py.

287  def __str__(self):
288  return "TractInfo(id=%s)" % (self._id,)
def lsst.skymap.tractInfo.TractInfo._finalOrientation (   self,
  bbox,
  wcs 
)
private
Determine the final orientation

We offset everything so the lower-left corner is at 0,0
and compute the final Wcs.

@param bbox   Current bounding box
@param wcs    Current Wcs
@return revised bounding box, revised Wcs

Definition at line 134 of file tractInfo.py.

135  def _finalOrientation(self, bbox, wcs):
136  """Determine the final orientation
137 
138  We offset everything so the lower-left corner is at 0,0
139  and compute the final Wcs.
140 
141  @param bbox Current bounding box
142  @param wcs Current Wcs
143  @return revised bounding box, revised Wcs
144  """
145  finalBBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), bbox.getDimensions())
146  # shift the WCS by the same amount as the bbox; extra code is required
147  # because simply subtracting makes an Extent2I
148  pixPosOffset = afwGeom.Extent2D(finalBBox.getMinX() - bbox.getMinX(),
149  finalBBox.getMinY() - bbox.getMinY())
150  wcs.shiftReferencePixel(pixPosOffset)
151  return finalBBox, wcs
152 
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.skymap.tractInfo.TractInfo._minimumBoundingBox (   self,
  wcs 
)
private
Calculate the minimum bounding box for the tract, given the WCS

The bounding box is created in the frame of the supplied WCS,
so that it's OK if the coordinates are negative.

We compute the bounding box that holds all the vertices and the
desired overlap.

Definition at line 80 of file tractInfo.py.

80 
81  def _minimumBoundingBox(self, wcs):
82  """Calculate the minimum bounding box for the tract, given the WCS
83 
84  The bounding box is created in the frame of the supplied WCS,
85  so that it's OK if the coordinates are negative.
86 
87  We compute the bounding box that holds all the vertices and the
88  desired overlap.
89  """
90  minBBoxD = afwGeom.Box2D()
91  halfOverlap = self._tractOverlap / 2.0
92  for vertexCoord in self._vertexCoordList:
93  vertexDeg = vertexCoord.getPosition(afwGeom.degrees)
94  if self._tractOverlap == 0:
95  minBBoxD.include(wcs.skyToPixel(vertexCoord))
96  else:
97  numAngles = 24
98  angleIncr = afwGeom.Angle(360.0, afwGeom.degrees) / float(numAngles)
99  for i in range(numAngles):
100  offAngle = angleIncr * i
101  offCoord = vertexCoord.clone()
102  offCoord.offset(offAngle, halfOverlap)
103  pixPos = wcs.skyToPixel(offCoord)
104  minBBoxD.include(pixPos)
105  return minBBoxD
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.skymap.tractInfo.TractInfo._setupPatches (   self,
  minBBox,
  wcs 
)
private
Setup for patches of a particular size.

We grow the bounding box to hold an exact multiple of
the desired size (patchInnerDimensions), while keeping
the center roughly the same.  We return the final
bounding box, and the number of patches in each dimension
(as an Extent2I).

@param minBBox     Minimum bounding box for tract
@param wcs         Wcs object
@return final bounding box, number of patches

Definition at line 106 of file tractInfo.py.

107  def _setupPatches(self, minBBox, wcs):
108  """Setup for patches of a particular size.
109 
110  We grow the bounding box to hold an exact multiple of
111  the desired size (patchInnerDimensions), while keeping
112  the center roughly the same. We return the final
113  bounding box, and the number of patches in each dimension
114  (as an Extent2I).
115 
116  @param minBBox Minimum bounding box for tract
117  @param wcs Wcs object
118  @return final bounding box, number of patches
119  """
120  bbox = afwGeom.Box2I(minBBox)
121  bboxMin = bbox.getMin()
122  bboxDim = bbox.getDimensions()
123  numPatches = afwGeom.Extent2I(0, 0)
124  for i, innerDim in enumerate(self._patchInnerDimensions):
125  num = (bboxDim[i] + innerDim - 1) // innerDim # round up
126  deltaDim = (innerDim * num) - bboxDim[i]
127  if deltaDim > 0:
128  bboxDim[i] = innerDim * num
129  bboxMin[i] -= deltaDim // 2
130  numPatches[i] = num
131  bbox = afwGeom.Box2I(bboxMin, bboxDim)
132  return bbox, numPatches
133 
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.skymap.tractInfo.TractInfo.findPatch (   self,
  coord 
)
Find the patch containing the specified coord

@param[in] coord: sky coordinate (afwCoord.Coord)
@return PatchInfo of patch whose inner bbox contains the specified coord

@raise LookupError if coord is not in tract

@note This routine will be more efficient if coord is ICRS.

Definition at line 153 of file tractInfo.py.

154  def findPatch(self, coord):
155  """Find the patch containing the specified coord
156 
157  @param[in] coord: sky coordinate (afwCoord.Coord)
158  @return PatchInfo of patch whose inner bbox contains the specified coord
159 
160  @raise LookupError if coord is not in tract
161 
162  @note This routine will be more efficient if coord is ICRS.
163  """
164  pixelInd = afwGeom.Point2I(self.getWcs().skyToPixel(coord.toIcrs()))
165  if not self.getBBox().contains(pixelInd):
166  raise LookupError("coord %s is not in tract %s" % (coord, self.getId()))
167  patchInd = tuple(int(pixelInd[i]/self._patchInnerDimensions[i]) for i in range(2))
168  return self.getPatchInfo(patchInd)
def lsst.skymap.tractInfo.TractInfo.findPatchList (   self,
  coordList 
)
Find patches containing the specified list of coords

@param[in] coordList: list of sky coordinates (afwCoord.Coord)
@return list of PatchInfo for patches that contain, or may contain, the specified region.
    The list will be empty if there is no overlap.

@warning:
* This may give incorrect answers on regions that are larger than a tract
* This uses a naive algorithm that may find some patches that do not overlap the region
    (especially if the region is not a rectangle aligned along patch x,y).

Definition at line 169 of file tractInfo.py.

170  def findPatchList(self, coordList):
171  """Find patches containing the specified list of coords
172 
173  @param[in] coordList: list of sky coordinates (afwCoord.Coord)
174  @return list of PatchInfo for patches that contain, or may contain, the specified region.
175  The list will be empty if there is no overlap.
176 
177  @warning:
178  * This may give incorrect answers on regions that are larger than a tract
179  * This uses a naive algorithm that may find some patches that do not overlap the region
180  (especially if the region is not a rectangle aligned along patch x,y).
181  """
182  box2D = afwGeom.Box2D()
183  for coord in coordList:
184  try:
185  pixelPos = self.getWcs().skyToPixel(coord.toIcrs())
187  # the point is so far off the tract that its pixel position cannot be computed
188  continue
189  box2D.include(pixelPos)
190  bbox = afwGeom.Box2I(box2D)
191  bbox.grow(self.getPatchBorder())
192  bbox.clip(self.getBBox())
193  if bbox.isEmpty():
194  return ()
195 
196  llPatchInd = tuple(int(bbox.getMin()[i]/self._patchInnerDimensions[i]) for i in range(2))
197  urPatchInd = tuple(int(bbox.getMax()[i]/self._patchInnerDimensions[i]) for i in range(2))
198  return tuple(self.getPatchInfo((xInd, yInd))
199  for xInd in range(llPatchInd[0], urPatchInd[0]+1)
200  for yInd in range(llPatchInd[1], urPatchInd[1]+1))
An integer coordinate rectangle.
Definition: Box.h:53
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.skymap.tractInfo.TractInfo.getBBox (   self)
Get bounding box of tract (as an afwGeom.Box2I)

Definition at line 201 of file tractInfo.py.

202  def getBBox(self):
203  """Get bounding box of tract (as an afwGeom.Box2I)
204  """
205  return afwGeom.Box2I(self._bbox)
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.skymap.tractInfo.TractInfo.getCtrCoord (   self)
Get sky coordinate of center of tract (as an afwCoord.Coord)

Definition at line 206 of file tractInfo.py.

207  def getCtrCoord(self):
208  """Get sky coordinate of center of tract (as an afwCoord.Coord)
209  """
210  return self._ctrCoord
def lsst.skymap.tractInfo.TractInfo.getId (   self)
Get ID of tract

Definition at line 211 of file tractInfo.py.

212  def getId(self):
213  """Get ID of tract
214  """
215  return self._id
def lsst.skymap.tractInfo.TractInfo.getNumPatches (   self)
Get the number of patches in x, y

@return the number of patches in x, y

Definition at line 216 of file tractInfo.py.

217  def getNumPatches(self):
218  """Get the number of patches in x, y
219 
220  @return the number of patches in x, y
221  """
222  return self._numPatches
def lsst.skymap.tractInfo.TractInfo.getPatchBorder (   self)
Get batch border

@return patch border (pixels)

Definition at line 223 of file tractInfo.py.

224  def getPatchBorder(self):
225  """Get batch border
226 
227  @return patch border (pixels)
228  """
229  return self._patchBorder
def lsst.skymap.tractInfo.TractInfo.getPatchInfo (   self,
  index 
)
Return information for the specified patch

@param[in] index: index of patch, as a pair of ints
@return patch info, an instance of PatchInfo

@raise IndexError if index is out of range

Definition at line 230 of file tractInfo.py.

231  def getPatchInfo(self, index):
232  """Return information for the specified patch
233 
234  @param[in] index: index of patch, as a pair of ints
235  @return patch info, an instance of PatchInfo
236 
237  @raise IndexError if index is out of range
238  """
239  if (not 0 <= index[0] < self._numPatches[0]) \
240  or (not 0 <= index[1] < self._numPatches[1]):
241  raise IndexError("Patch index %s is not in range [0-%d, 0-%d]" % \
242  (index, self._numPatches[0]-1, self._numPatches[1]-1))
243  innerMin = afwGeom.Point2I(*[index[i] * self._patchInnerDimensions[i] for i in range(2)])
244  innerBBox = afwGeom.Box2I(innerMin, self._patchInnerDimensions)
245  if not self._bbox.contains(innerBBox):
246  raise RuntimeError(
247  "Bug: patch index %s valid but inner bbox=%s not contained in tract bbox=%s" % \
248  (index, innerBBox, self._bbox))
249  outerBBox = afwGeom.Box2I(innerBBox)
250  outerBBox.grow(self.getPatchBorder())
251  outerBBox.clip(self._bbox)
252  return PatchInfo(
253  index = index,
254  innerBBox = innerBBox,
255  outerBBox = outerBBox,
256  )
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.skymap.tractInfo.TractInfo.getPatchInnerDimensions (   self)
Get dimensions of inner region of the patches (all are the same)

@return dimensions of inner region of the patches (as an afwGeom Extent2I)

Definition at line 257 of file tractInfo.py.

258  def getPatchInnerDimensions(self):
259  """Get dimensions of inner region of the patches (all are the same)
260 
261  @return dimensions of inner region of the patches (as an afwGeom Extent2I)
262  """
263  return self._patchInnerDimensions
def lsst.skymap.tractInfo.TractInfo.getTractOverlap (   self)
Get minimum overlap of adjacent sky tracts

@return minimum overlap between adjacent sky tracts, as an afwGeom Angle

Definition at line 264 of file tractInfo.py.

265  def getTractOverlap(self):
266  """Get minimum overlap of adjacent sky tracts
267 
268  @return minimum overlap between adjacent sky tracts, as an afwGeom Angle
269  """
270  return self._tractOverlap
def lsst.skymap.tractInfo.TractInfo.getVertexList (   self)
Get list of sky coordinates of vertices that define the boundary of the inner region

@warning: this is not a deep copy
@warning vertexCoordList will likely become a geom SphericalConvexPolygon someday.

Definition at line 271 of file tractInfo.py.

272  def getVertexList(self):
273  """Get list of sky coordinates of vertices that define the boundary of the inner region
274 
275  @warning: this is not a deep copy
276  @warning vertexCoordList will likely become a geom SphericalConvexPolygon someday.
277  """
278  return self._vertexCoordList
def lsst.skymap.tractInfo.TractInfo.getWcs (   self)
Get WCS of tract

@warning: this is not a deep copy

Definition at line 279 of file tractInfo.py.

280  def getWcs(self):
281  """Get WCS of tract
282 
283  @warning: this is not a deep copy
284  """
285  return self._wcs

Member Data Documentation

lsst.skymap.tractInfo.TractInfo._ctrCoord
private

Definition at line 71 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._id
private

Definition at line 64 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._numPatches
private

Definition at line 76 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._patchBorder
private

Definition at line 70 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._patchInnerDimensions
private

Definition at line 67 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._tractOverlap
private

Definition at line 73 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._vertexCoordList
private

Definition at line 72 of file tractInfo.py.

lsst.skymap.tractInfo.TractInfo._wcs
private

Definition at line 77 of file tractInfo.py.


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