Coverage for tests/test_rowColumnStats.py: 24%
66 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 02:49 -0700
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 02:49 -0700
1# This file is part of afw.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""
23Tests for statisticsStack row/column statistics
25Run with:
26 python test_rowColumnStats.py
27or
28 pytest test_rowColumnStats.py
29"""
30import unittest
32import lsst.geom
33import lsst.afw.image as afwImage
34import lsst.afw.math as afwMath
35import lsst.utils.tests
38class RowColumnStatisticsTestCase(unittest.TestCase):
40 def setUp(self):
42 # fill an image with a gradient
43 self.n = 8
44 self.img = afwImage.ImageF(lsst.geom.Extent2I(self.n, self.n), 0)
46 # these are the known answers for comparison
47 def nVector(n, v):
48 return [v for i in range(n)]
49 self.column = nVector(self.n, 0.0)
50 self.row = nVector(self.n, 0.0)
51 self.colPlus = nVector(self.n, 0.0)
52 self.colMinus = nVector(self.n, 0.0)
53 self.colMult = nVector(self.n, 0.0)
54 self.colDiv = nVector(self.n, 0.0)
55 self.rowPlus = nVector(self.n, 0.0)
56 self.rowMinus = nVector(self.n, 0.0)
57 self.rowMult = nVector(self.n, 0.0)
58 self.rowDiv = nVector(self.n, 0.0)
60 # set the values in the image, and keep track of the stats to verify
61 # things
62 for y in range(self.n):
63 for x in range(self.n):
64 val = 1.0*x + 2.0*y
65 self.img[x, y, afwImage.LOCAL] = val
66 self.column[y] += val
67 self.row[x] += val
69 for i in range(self.n):
70 self.row[i] /= self.n
71 self.column[i] /= self.n
72 self.colPlus[i] = self.img[0, i, afwImage.LOCAL] + self.column[i]
74 # get stats on the columns and rows
75 self.imgProjectCol = afwMath.statisticsStack(
76 self.img, afwMath.MEAN, 'x')
77 self.imgProjectRow = afwMath.statisticsStack(
78 self.img, afwMath.MEAN, 'y')
80 def tearDown(self):
81 del self.img
82 del self.imgProjectCol
83 del self.imgProjectRow
85 def testColumnStats(self):
86 """Test the column statistics """
87 for i in range(self.n):
88 self.assertEqual(self.imgProjectCol[0, i, afwImage.LOCAL][0], self.column[i])
90 def testRowStats(self):
91 """Test the row statistics """
92 for i in range(self.n):
93 self.assertEqual(self.imgProjectRow[i, 0, afwImage.LOCAL][0], self.row[i])
95 def testColumnOperators(self):
96 """ Test operator overloading on columns """
98 columnSlice = afwImage.ImageSliceF(self.imgProjectCol.getImage())
100 imgAdd = self.img + columnSlice
101 imgAdd2 = columnSlice + self.img
102 imgSub = self.img - columnSlice
103 imgMul = self.img * columnSlice
104 imgMul2 = columnSlice * self.img
105 imgDiv = self.img / columnSlice
107 for i in range(self.n):
108 self.assertAlmostEqual(imgAdd[0, i, afwImage.LOCAL],
109 self.img[0, i, afwImage.LOCAL] + columnSlice[0, i, afwImage.LOCAL])
110 self.assertAlmostEqual(imgAdd2[0, i, afwImage.LOCAL],
111 imgAdd[0, i, afwImage.LOCAL])
112 self.assertAlmostEqual(imgSub[0, i, afwImage.LOCAL],
113 self.img[0, i, afwImage.LOCAL] - columnSlice[0, i, afwImage.LOCAL])
114 self.assertAlmostEqual(imgMul[0, i, afwImage.LOCAL],
115 self.img[0, i, afwImage.LOCAL] * columnSlice[0, i, afwImage.LOCAL])
116 self.assertAlmostEqual(imgMul2[0, i, afwImage.LOCAL], imgMul[0, i, afwImage.LOCAL])
117 self.assertAlmostEqual(imgDiv[0, i, afwImage.LOCAL],
118 self.img[0, i, afwImage.LOCAL] / columnSlice[0, i, afwImage.LOCAL])
121#################################################################
122# Test suite boiler plate
123#################################################################
124class TestMemory(lsst.utils.tests.MemoryTestCase):
125 pass
128def setup_module(module):
129 lsst.utils.tests.init()
132if __name__ == "__main__": 132 ↛ 133line 132 didn't jump to line 133, because the condition on line 132 was never true
133 lsst.utils.tests.init()
134 unittest.main()