Coverage for tests/test_statBug1697.py: 25%
47 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-29 02:27 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-29 02:27 -0700
1#
2# LSST Data Management System
3# Copyright 2008, 2009, 2010 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
23import unittest
25import numpy as np
27import lsst.utils.tests
28import lsst.afw.math as afwMath
29import lsst.afw.image as afwImage
32class WeightedStatsBugTestCase(unittest.TestCase):
34 def reportBadPixels(self, maskedImage, badPixelMask):
35 """Report the number of bad pixels in each plane of a masked image
37 Reports:
38 - the number of non-finite values in the image plane
39 - the number of bad pixels in the mask plane
40 - the number of non-finite values in the variance plane
41 """
42 arrayList = maskedImage.getArrays()
43 nBadImg = np.logical_not(np.isfinite(arrayList[0])).sum()
44 nBadMsk = np.sum(np.bitwise_and(arrayList[1], badPixelMask) > 0)
45 nBadVar = np.logical_not(np.isfinite(arrayList[2])).sum()
46 print(f"{nBadImg} bad image pixels, {nBadMsk} bad mask pixels, {nBadVar} bad variance pixels")
47 self.assertEqual(nBadImg, 0)
48 self.assertEqual(nBadMsk, 0)
49 self.assertEqual(nBadVar, 0)
51 def testWeightedStats(self):
52 """Test that bug from #1697 (weighted stats returning NaN) stays fixed."""
54 rand = afwMath.Random()
55 mu = 10000
57 afwImage.Mask.getPlaneBitMask("EDGE")
59 badPixelMask = afwImage.Mask.getPlaneBitMask("EDGE")
60 statsCtrl = afwMath.StatisticsControl()
61 statsCtrl.setNumSigmaClip(3.0)
62 statsCtrl.setNumIter(2)
63 statsCtrl.setAndMask(badPixelMask)
65 for weight in (300.0, 10.0, 1.0):
66 print(f"Testing with weight={weight:0.1f}")
67 maskedImageList = []
68 weightList = []
70 nx, ny = 256, 256
71 for i in range(3):
72 print("Processing ", i)
73 maskedImage = afwImage.MaskedImageF(nx, ny)
74 maskedImageList.append(maskedImage)
76 afwMath.randomPoissonImage(maskedImage.getImage(), rand, mu)
77 maskedImage.getVariance().set(mu)
78 weightList.append(weight)
80 self.reportBadPixels(maskedImage, badPixelMask)
82 print("Stack: ", end=' ')
83 coaddMaskedImage = afwMath.statisticsStack(
84 maskedImageList, afwMath.MEANCLIP, statsCtrl, weightList)
85 self.reportBadPixels(coaddMaskedImage, badPixelMask)
88class TestMemory(lsst.utils.tests.MemoryTestCase):
89 pass
92def setup_module(module):
93 lsst.utils.tests.init()
96if __name__ == "__main__": 96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true
97 lsst.utils.tests.init()
98 unittest.main()