Skip to content

Commit

Permalink
Fixup: improve geom testUtils as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
r-owen committed Jun 7, 2016
1 parent ad8f75f commit dfb1965
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions python/lsst/afw/geom/testUtils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, division
#
# LSST Data Management System
# Copyright 2015 LSST Corporation.
# Copyright 2016 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand All @@ -20,38 +20,37 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
"""Utilities that should be imported into the lsst.afw.coord namespace when lsst.afw.coord is used
In the case of the assert functions, importing them makes them available in lsst.utils.tests.TestCase
"""
import numpy as np

from .geomLib import Box2I, Box2D

__all__ = ["BoxGrid"]

class BoxGrid(object):
"""!Divide a box into nx x ny smaller boxes
"""!Divide a box into nx by ny sub-boxes that tile the region
"""
def __init__(self, box, numColRow):
"""!Construct a BoxGrid
The sub-boxes will be of the same type as `box` and will exactly tile `box`;
they will also all be the same size, to the extent possible (some variation
is inevitable for integer boxes that cannot be evenly divided.
@param[in] box box (an lsst.afw.geom.Box2I or Box2D);
the boxes in the grid will be of the same type
@param[in] numColRow number of columns and rows
@param[in] numColRow number of columns and rows (a pair of ints)
"""
if len(numColRow) != 2:
raise RuntimeError("numColRow=%r; must be a sequence of two integers" % (numColRow,))
self._numColRow = tuple(int(val) for val in numColRow)

boxClass = type(box)
if boxClass == Box2I:
if isinstance(box, Box2I):
stopDelta = 1
elif boxClass == Box2D:
elif isinstance(box, Box2D):
stopDelta = 0
else:
raise RuntimeError("Unknown box class %s of box %s" % (boxClass, box))
self.boxClass = boxClass
raise RuntimeError("Unknown class %s of box %s" % (type(box), box))
self.boxClass = type(box)
self.stopDelta = stopDelta

minPoint = box.getMin()
Expand All @@ -69,10 +68,10 @@ def numColRow(self):
return self._numColRow

def __getitem__(self, indXY):
"""!Return the box at the specified x,y index
"""!Return the box at the specified x,y index (a pair of ints)
"""
beg = self.pointClass(*[self._divList[i][indXY[i]] for i in range(2)])
end = self.pointClass(*[self._divList[i][indXY[i]+1]-self.stopDelta for i in range(2)])
end = self.pointClass(*[self._divList[i][indXY[i] + 1] - self.stopDelta for i in range(2)])
return self.boxClass(beg, end)

def __len__(self):
Expand Down

0 comments on commit dfb1965

Please sign in to comment.