-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lsst.afw.image.testUtils.makeRampImage and a unit test
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
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,62 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
|
||
import lsst.utils.tests | ||
import lsst.afw.geom as afwGeom | ||
import lsst.afw.image as afwImage | ||
from lsst.afw.image.testUtils import makeRampImage | ||
|
||
class MakeRampImageTestCase(lsst.utils.tests.TestCase): | ||
"""!Unit tests for makeRampImage""" | ||
def testUnitInterval(self): | ||
"""!Test small ramp images with unit interval for known values | ||
""" | ||
for imageClass in (afwImage.ImageU, afwImage.ImageF, afwImage.ImageD): | ||
dim = afwGeom.Extent2I(7, 9) | ||
box = afwGeom.Box2I(afwGeom.Point2I(-1, 3), dim) | ||
numPix = dim[0]*dim[1] | ||
for start in (-5, 0, 4): | ||
if imageClass == afwImage.ImageU and start < 0: | ||
continue | ||
predStop = start + numPix - 1 # for integer steps | ||
for stop in (None, predStop): | ||
rampImage = makeRampImage(bbox=box, start=start, stop=predStop, imageClass=imageClass) | ||
predArr = np.arange(start, predStop+1) | ||
self.assertEqual(len(predArr), numPix) | ||
predArr.shape = (dim[1], dim[0]) | ||
self.assertImagesNearlyEqual(rampImage, predArr) | ||
|
||
def testNonUnitIntervals(self): | ||
"""!Test a small ramp image with non-integer increments | ||
""" | ||
for imageClass in (afwImage.ImageU, afwImage.ImageF, afwImage.ImageD): | ||
dim = afwGeom.Extent2I(7, 9) | ||
box = afwGeom.Box2I(afwGeom.Point2I(-1, 3), dim) | ||
numPix = dim[0]*dim[1] | ||
for start in (-5.1, 0, 4.3): | ||
if imageClass == afwImage.ImageU and start < 0: | ||
continue | ||
for stop in (7, 1001.5, 5.4): | ||
rampImage = makeRampImage(bbox=box, start=start, stop=stop, imageClass=imageClass) | ||
dtype = rampImage.getArray().dtype | ||
predArr = np.linspace(start, stop, num=numPix, endpoint=True, dtype=dtype) | ||
predArr.shape = (dim[1], dim[0]) | ||
self.assertImagesNearlyEqual(rampImage, predArr) | ||
|
||
|
||
def suite(): | ||
"""!Returns a suite containing all the test cases in this module.""" | ||
lsst.utils.tests.init() | ||
|
||
suites = [] | ||
suites += unittest.makeSuite(MakeRampImageTestCase) | ||
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) |