Coverage for tests/test_rowColumnStats.py : 21%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# # LSST Data Management System # Copyright 2008, 2009, 2010 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/>. #
# -*- python -*- Tests for statisticsStack row/column statistics
Run with: ./rowColumnStats.py or python >>> import rowColumnStats; rowColumnStats.run() """
# fill an image with a gradient self.n = 8 self.img = afwImage.ImageF(lsst.geom.Extent2I(self.n, self.n), 0)
# these are the known answers for comparison def nVector(n, v): return [v for i in range(n)] self.column = nVector(self.n, 0.0) self.row = nVector(self.n, 0.0) self.colPlus = nVector(self.n, 0.0) self.colMinus = nVector(self.n, 0.0) self.colMult = nVector(self.n, 0.0) self.colDiv = nVector(self.n, 0.0) self.rowPlus = nVector(self.n, 0.0) self.rowMinus = nVector(self.n, 0.0) self.rowMult = nVector(self.n, 0.0) self.rowDiv = nVector(self.n, 0.0)
# set the values in the image, and keep track of the stats to verify # things for y in range(self.n): for x in range(self.n): val = 1.0*x + 2.0*y self.img[x, y, afwImage.LOCAL] = val self.column[y] += val self.row[x] += val
for i in range(self.n): self.row[i] /= self.n self.column[i] /= self.n self.colPlus[i] = self.img[0, i, afwImage.LOCAL] + self.column[i]
# get stats on the columns and rows self.imgProjectCol = afwMath.statisticsStack( self.img, afwMath.MEAN, 'x') self.imgProjectRow = afwMath.statisticsStack( self.img, afwMath.MEAN, 'y')
del self.img del self.imgProjectCol del self.imgProjectRow
"""Test the column statistics """ for i in range(self.n): self.assertEqual(self.imgProjectCol[0, i, afwImage.LOCAL][0], self.column[i])
"""Test the row statistics """ for i in range(self.n): self.assertEqual(self.imgProjectRow[i, 0, afwImage.LOCAL][0], self.row[i])
""" Test operator overloading on columns """
columnSlice = afwImage.ImageSliceF(self.imgProjectCol.getImage())
imgAdd = self.img + columnSlice imgAdd2 = columnSlice + self.img imgSub = self.img - columnSlice imgMul = self.img * columnSlice imgMul2 = columnSlice * self.img imgDiv = self.img / columnSlice
for i in range(self.n): self.assertAlmostEqual(imgAdd[0, i, afwImage.LOCAL], self.img[0, i, afwImage.LOCAL] + columnSlice[0, i, afwImage.LOCAL]) self.assertAlmostEqual(imgAdd2[0, i, afwImage.LOCAL], imgAdd[0, i, afwImage.LOCAL]) self.assertAlmostEqual(imgSub[0, i, afwImage.LOCAL], self.img[0, i, afwImage.LOCAL] - columnSlice[0, i, afwImage.LOCAL]) self.assertAlmostEqual(imgMul[0, i, afwImage.LOCAL], self.img[0, i, afwImage.LOCAL] * columnSlice[0, i, afwImage.LOCAL]) self.assertAlmostEqual(imgMul2[0, i, afwImage.LOCAL], imgMul[0, i, afwImage.LOCAL]) self.assertAlmostEqual(imgDiv[0, i, afwImage.LOCAL], self.img[0, i, afwImage.LOCAL] / columnSlice[0, i, afwImage.LOCAL])
################################################################# # Test suite boiler plate #################################################################
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |