23 __all__ = [
"PatchInfo"]
28 from lsst.geom import Extent2I, Point2I, Box2I
29 from .detail
import makeSkyPolygonFromBBox, Index2D
30 from .cellInfo
import CellInfo
34 """Information about a patch within a tract of a sky map.
36 If cellInnerDimensions and cellBorder are set then the patch
37 will be gridded with cells.
39 See `TractInfo` for more information.
43 index : `lsst.skymap.Index2D`
44 x,y index of patch (a pair of ints)
45 innerBBox : `lsst.geom.Box2I`
47 outerBBox : `lsst.geom.Box2I`
49 sequentialIndex : `int`
50 Patch sequential index
51 tractWcs : `lsst.afw.geom.SkyWcs`
53 cellInnerDimensions : `Iterable` [`int`, `int`] or `lsst.geom.Extent2I`, optional
54 Inner dimensions of each cell (x,y pixels).
55 cellBorder : `int`, optional
56 Cell border size (pixels).
57 numCellsPerPatchInner : `int`, optional
58 Number of cells per inner patch region.
59 numCellsInPatchBorder : `int`, optional
60 Number of cells in the patch border.
63 def __init__(self, index, innerBBox, outerBBox, sequentialIndex,
65 cellInnerDimensions=(0, 0), cellBorder=0,
66 numCellsPerPatchInner=0, numCellsInPatchBorder=0):
71 self.
_wcs_wcs = tractWcs
72 if not outerBBox.contains(innerBBox):
73 raise RuntimeError(
"outerBBox=%s does not contain innerBBox=%s" % (outerBBox, innerBBox))
74 if not isinstance(cellInnerDimensions, (Iterable, Extent2I)):
75 raise ValueError(
"Input cellInnerDimensions is not an iterable.")
76 if len(cellInnerDimensions) != 2:
77 raise ValueError(
"Input cellInnerDimensions does not have two values.")
81 if numCellsPerPatchInner == 0:
85 self.
_numCells_numCells =
Index2D(x=numCellsPerPatchInner + 2*numCellsInPatchBorder,
86 y=numCellsPerPatchInner + 2*numCellsInPatchBorder)
89 """Return patch index: a tuple of (x, y)
93 result : `lsst.skymap.Index2D`
98 index = property(getIndex)
101 """Return patch sequential index.
106 Sequential patch index.
110 sequential_index = property(getSequentialIndex)
113 """Return the associated tract wcs
117 wcs : `lsst.afw.geom.SkyWcs`
122 wcs = property(getWcs)
125 """Get inner bounding box.
129 bbox : `lsst.geom.Box2I`
130 The inner bounding Box.
134 inner_bbox = property(getInnerBBox)
137 """Get outer bounding box.
141 bbox : `lsst.geom.Box2I`
142 The outer bounding Box.
146 outer_bbox = property(getOuterBBox)
149 """Get the inner on-sky region.
153 tractWcs : `lsst.afw.image.SkyWcs`, optional
154 WCS for the associated tract.
158 result : `lsst.sphgeom.ConvexPolygon`
159 The inner sky region.
161 _tractWcs = tractWcs
if tractWcs
is not None else self.
_wcs_wcs
169 """Get the outer on-sky region.
173 tractWcs : `lsst.afw.image.SkyWcs`, optional
174 WCS for the associated tract.
178 result : `lsst.sphgeom.ConvexPolygon`
179 The outer sky region.
181 _tractWcs = tractWcs
if tractWcs
is not None else self.
_wcs_wcs
189 """Get the number of cells in x, y.
191 May return (0, 0) if no cells are defined.
195 result : `lsst.skymap.Index2D`
196 The number of cells in x, y.
200 num_cells = property(getNumCells)
205 cell_border = property(getCellBorder)
208 """Return information for the specified cell.
212 index : `lsst.skymap.Index2D` or `int`
213 Index of cell, as `Index2D`, or `Iterable` [`int`, `int`];
214 or a sequential index as returned by getSequentialCellIndex;
215 negative values are not supported.
219 result : `lsst.skymap.CellInfo`
220 The cell info for that index.
225 If index is out of range.
228 raise IndexError(
"Patch does not contain cells.")
229 if isinstance(index, Index2D):
232 if isinstance(index, numbers.Number):
236 if (
not 0 <= _index.x < self.
_numCells_numCells.x) \
237 or (
not 0 <= _index.y < self.
_numCells_numCells.y):
238 raise IndexError(
"Cell index %s is not in range [0-%d, 0-%d]" %
245 + patchInnerBBox.getBegin()[i]
249 outerBBox =
Box2I(innerBBox)
257 tractWcs=self.
_wcs_wcs
261 """Get dimensions of inner region of the cells (all are the same)
265 cell_inner_dimensions = property(getCellInnerDimensions)
268 """Return a single integer that uniquely identifies
269 the given cell within this patch.
273 cellInfo : `lsst.skymap.CellInfo`
277 sequentialIndex : `int`
282 If index is out of range.
284 index = cellInfo.getIndex()
288 """Return a single integer that uniquely identifies
289 the given cell within this patch.
293 index : `lsst.skymap.Index2D`
297 sequentialIndex : `int`
302 If index is out of range.
304 if isinstance(index, Index2D):
309 return nx*_index.y + _index.x
312 """Convert a sequential index into an index pair.
316 sequentialIndex : `int`
320 x, y : `lsst.skymap.Index2D`
325 If index is out of range.
328 raise IndexError(
"Patch does not contain cells.")
331 x = sequentialIndex % nx
332 y = sequentialIndex // nx
337 for y
in range(yNum):
338 for x
in range(xNum):
349 return (self.
getIndexgetIndex() == rhs.getIndex()) \
350 and (self.
getInnerBBoxgetInnerBBox() == rhs.getInnerBBox()) \
351 and (self.
getOuterBBoxgetOuterBBox() == rhs.getOuterBBox()) \
352 and (self.
getNumCellsgetNumCells() == rhs.getNumCells()) \
353 and (self.
getCellBordergetCellBorder() == rhs.getCellBorder())
356 return not self.
__eq____eq__(rhs)
359 return "PatchInfo(index=%s)" % (self.
getIndexgetIndex(),)
363 return (
"PatchInfo(index=%s, innerBBox=%s, outerBBox=%s, cellInnerDimensions=%s, "
364 "cellBorder=%s, numCellsPerPatchInner=%s)") % \
369 return "PatchInfo(index=%s, innerBBox=%s, outerBBox=%s)" % \
An integer coordinate rectangle.
def getOuterSkyPolygon(self, tractWcs=None)
def getCellInnerDimensions(self)
def getCellInfo(self, index)
def __init__(self, index, innerBBox, outerBBox, sequentialIndex, tractWcs, cellInnerDimensions=(0, 0), cellBorder=0, numCellsPerPatchInner=0, numCellsInPatchBorder=0)
def outer_sky_polygon(self)
def getSequentialCellIndex(self, cellInfo)
def getCellIndexPair(self, sequentialIndex)
def getSequentialCellIndexFromPair(self, index)
def inner_sky_polygon(self)
def getInnerSkyPolygon(self, tractWcs=None)
def getSequentialIndex(self)
def __getitem__(self, index)
Extent< int, 2 > Extent2I
def makeSkyPolygonFromBBox(bbox, wcs)