lsst.skymap  16.0-4-g13a27c5+22
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
24 from lsst.afw.geom import Box2D
25 
26 __all__ = ["PatchInfo", "makeSkyPolygonFromBBox"]
27 
28 
29 def makeSkyPolygonFromBBox(bbox, wcs):
30  """Make an on-sky polygon from a bbox and a SkyWcs
31 
32  Parameters
33  ----------
34  bbox : `lsst.afw.geom.Box2I` or `lsst.afw.geom.Box2D`
35  Bounding box of region, in pixel coordinates
36  wcs : `lsst.afw.geom.SkyWcs`
37  Celestial WCS
38 
39  Returns
40  -------
41  polygon : `lsst.sphgeom.ConvexPolygon`
42  On-sky region
43  """
44  pixelPoints = Box2D(bbox).getCorners()
45  skyPoints = wcs.pixelToSky(pixelPoints)
46  return ConvexPolygon.convexHull([sp.getVector() for sp in skyPoints])
47 
48 
49 class PatchInfo:
50  """Information about a patch within a tract of a sky map
51 
52  See TractInfo for more information.
53  """
54 
55  def __init__(self, index, innerBBox, outerBBox):
56  """Construct a PatchInfo
57 
58  @param[in] index: x,y index of patch (a pair of ints)
59  @param[in] innerBBox: inner bounding box (an afwGeom.Box2I)
60  @param[in] outerBBox: inner bounding box (an afwGeom.Box2I)
61  """
62  self._index = index
63  self._innerBBox = innerBBox
64  self._outerBBox = outerBBox
65  if not outerBBox.contains(innerBBox):
66  raise RuntimeError("outerBBox=%s does not contain innerBBox=%s" % (outerBBox, innerBBox))
67 
68  def getIndex(self):
69  """Return patch index: a tuple of (x, y)
70  """
71  return self._index
72 
73  def getInnerBBox(self):
74  """Get inner bounding box
75  """
76  return self._innerBBox
77 
78  def getOuterBBox(self):
79  """Get outer bounding box
80  """
81  return self._outerBBox
82 
83  def getInnerSkyPolygon(self, tractWcs):
84  """Get the inner on-sky region as an sphgeom.ConvexPolygon.
85  """
86  return makeSkyPolygonFromBBox(bbox=self.getInnerBBox(), wcs=tractWcs)
87 
88  def getOuterSkyPolygon(self, tractWcs):
89  """Get the outer on-sky region as a sphgeom.ConvexPolygon.
90  """
91  return makeSkyPolygonFromBBox(bbox=self.getOuterBBox(), wcs=tractWcs)
92 
93  def __eq__(self, rhs):
94  """Support ==
95  """
96  return (self.getIndex() == rhs.getIndex()) \
97  and (self.getInnerBBox() == rhs.getInnerBBox()) \
98  and (self.getOuterBBox() == rhs.getOuterBBox())
99 
100  def __ne__(self, rhs):
101  """Support !=
102  """
103  return not self.__eq__(rhs)
104 
105  def __str__(self):
106  """Return a brief string representation
107  """
108  return "PatchInfo(index=%s)" % (self.getIndex(),)
109 
110  def __repr__(self):
111  """Return a detailed string representation
112  """
113  return "PatchInfo(index=%s, innerBBox=%s, outerBBox=%s)" % \
114  (self.getIndex(), self.getInnerBBox(), self.getOuterBBox())
def makeSkyPolygonFromBBox(bbox, wcs)
Definition: patchInfo.py:29
def getInnerSkyPolygon(self, tractWcs)
Definition: patchInfo.py:83
def getOuterSkyPolygon(self, tractWcs)
Definition: patchInfo.py:88
def __init__(self, index, innerBBox, outerBBox)
Definition: patchInfo.py:55