-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NullLinearityType to cameraGeom #71
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import absolute_import, division | ||
# | ||
# LSST Data Management System | ||
# Copyright 2016 LSST Corporation. | ||
# | ||
# This product includes software developed by the | ||
# LSST Project (http://www.lsst.org/). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the LSST License Statement and | ||
# the GNU General Public License along with this program. If not, | ||
# see <http://www.lsstcorp.org/LegalNotices/>. | ||
# | ||
import numpy as np | ||
|
||
from .geomLib import Box2I, Box2D | ||
|
||
__all__ = ["BoxGrid"] | ||
|
||
class BoxGrid(object): | ||
"""!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 (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) | ||
|
||
if isinstance(box, Box2I): | ||
stopDelta = 1 | ||
elif isinstance(box, Box2D): | ||
stopDelta = 0 | ||
else: | ||
raise RuntimeError("Unknown class %s of box %s" % (type(box), box)) | ||
self.boxClass = type(box) | ||
self.stopDelta = stopDelta | ||
|
||
minPoint = box.getMin() | ||
self.pointClass = type(minPoint) | ||
dtype = np.array(minPoint).dtype | ||
|
||
self._divList = [np.linspace(start=box.getMin()[i], | ||
stop=box.getMax()[i] + self.stopDelta, | ||
num=self._numColRow[i] + 1, | ||
endpoint=True, | ||
dtype=dtype) for i in range(2)] | ||
|
||
@property | ||
def numColRow(self): | ||
return self._numColRow | ||
|
||
def __getitem__(self, indXY): | ||
"""!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)]) | ||
return self.boxClass(beg, end) | ||
|
||
def __len__(self): | ||
return self.shape[0]*self.shape[1] | ||
|
||
def __iter__(self): | ||
"""!Return an iterator over all boxes, where column varies most quickly | ||
""" | ||
for row in xrange(self.numColRow[1]): | ||
for col in xrange(self.numColRow[0]): | ||
yield self[col, row] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import unittest | ||
|
||
import lsst.utils.tests | ||
import lsst.afw.geom as afwGeom | ||
from lsst.afw.geom.testUtils import BoxGrid | ||
|
||
class BoxGridTestCase(lsst.utils.tests.TestCase): | ||
"""!Unit tests for BoxGrid""" | ||
def test3By4(self): | ||
"""!Test a 3x4 box divided into a 3x2 grid, such that each sub-box is 1x2 | ||
""" | ||
for boxClass in (afwGeom.Box2I, afwGeom.Box2D): | ||
pointClass = type(boxClass().getMin()) | ||
extentClass = type(boxClass().getDimensions()) | ||
|
||
minPt = pointClass(-1, 3) | ||
extent = extentClass(3, 4) | ||
numColRow = (3, 2) | ||
outerBox = boxClass(minPt, extent) | ||
boxGrid = BoxGrid(box=outerBox, numColRow=numColRow) | ||
for box in boxGrid: | ||
self.assertEqual(box.getDimensions(), extentClass(1, 2)) | ||
for row in range(numColRow[1]): | ||
for col in range(numColRow[0]): | ||
box = boxGrid[col, row] | ||
predMin = outerBox.getMin() + extentClass(col*1, row*2) | ||
self.assertEqual(box.getMin(), predMin) | ||
|
||
def testIntUneven(self): | ||
"""!Test dividing an integer box into an uneven grid | ||
|
||
Divide a 5x4 box into 2x3 regions | ||
""" | ||
minPt = afwGeom.Point2I(0, 0) | ||
extent = afwGeom.Extent2I(5, 7) | ||
numColRow = (2, 3) | ||
outerBox = afwGeom.Box2I(minPt, extent) | ||
boxGrid = BoxGrid(box=outerBox, numColRow=numColRow) | ||
desColStarts = (0, 2) | ||
desWidths = (2, 3) | ||
desRowStarts = (0, 2, 4) | ||
desHeights = (2, 2, 3) | ||
for row in range(numColRow[1]): | ||
desRowStart = desRowStarts[row] | ||
desHeight = desHeights[row] | ||
for col in range(numColRow[0]): | ||
desColStart = desColStarts[col] | ||
desWidth = desWidths[col] | ||
box = boxGrid[col, row] | ||
self.assertEqual(tuple(box.getMin()), (desColStart, desRowStart)) | ||
self.assertEqual(tuple(box.getDimensions()), (desWidth, desHeight)) | ||
|
||
def suite(): | ||
"""!Returns a suite containing all the test cases in this module.""" | ||
lsst.utils.tests.init() | ||
|
||
suites = [] | ||
suites += unittest.makeSuite(BoxGridTestCase) | ||
suites += unittest.makeSuite(lsst.utils.tests.MemoryTestCase) | ||
return unittest.TestSuite(suites) | ||
|
||
def run(exit=False): | ||
"""!Run the tests""" | ||
lsst.utils.tests.run(suite(), exit) | ||
|
||
if __name__ == "__main__": | ||
run(True) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this present? Just rename
self._numColRow
asself.numColRow
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it read only. This class looks a bit like a numpy array, which you can reshape on the fly. I wanted to avoid anyone attempting that.