lsst.skymap  15.0-5-gb31927c
patchInfo.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 from lsst.sphgeom import ConvexPolygon, UnitVector3d
24 from lsst.afw.geom import Point2D
25 
26 __all__ = ["PatchInfo"]
27 
28 
29 class PatchInfo:
30  """Information about a patch within a tract of a sky map
31 
32  See TractInfo for more information.
33  """
34 
35  def __init__(self, index, innerBBox, outerBBox):
36  """Construct a PatchInfo
37 
38  @param[in] index: x,y index of patch (a pair of ints)
39  @param[in] innerBBox: inner bounding box (an afwGeom.Box2I)
40  @param[in] outerBBox: inner bounding box (an afwGeom.Box2I)
41  """
42  self._index = index
43  self._innerBBox = innerBBox
44  self._outerBBox = outerBBox
45  if not outerBBox.contains(innerBBox):
46  raise RuntimeError("outerBBox=%s does not contain innerBBox=%s" % (outerBBox, innerBBox))
47 
48  def getIndex(self):
49  """Return patch index: a tuple of (x, y)
50  """
51  return self._index
52 
53  def getInnerBBox(self):
54  """Get inner bounding box
55  """
56  return self._innerBBox
57 
58  def getOuterBBox(self):
59  """Get outer bounding box
60  """
61  return self._outerBBox
62 
63  def getPolygon(self, tractWcs):
64  """Return a patch out bbox as a sphgeom.ConvexPolygon.
65  """
66  bbox = self.getOuterBBox()
67  corners = [Point2D(c) for c in bbox.getCorners()]
68  vertices = tractWcs.pixelToSky(corners)
69  points = [UnitVector3d(*sp.getVector()) for sp in vertices]
70  return ConvexPolygon(points)
71 
72  def __eq__(self, rhs):
73  """Support ==
74  """
75  return (self.getIndex() == rhs.getIndex()) \
76  and (self.getInnerBBox() == rhs.getInnerBBox()) \
77  and (self.getOuterBBox() == rhs.getOuterBBox())
78 
79  def __ne__(self, rhs):
80  """Support !=
81  """
82  return not self.__eq__(rhs)
83 
84  def __str__(self):
85  """Return a brief string representation
86  """
87  return "PatchInfo(index=%s)" % (self.getIndex(),)
88 
89  def __repr__(self):
90  """Return a detailed string representation
91  """
92  return "PatchInfo(index=%s, innerBBox=%s, outerBBox=%s)" % \
93  (self.getIndex(), self.getInnerBBox(), self.getOuterBBox())
def getPolygon(self, tractWcs)
Definition: patchInfo.py:63
def __init__(self, index, innerBBox, outerBBox)
Definition: patchInfo.py:35