Coverage for tests/test_statBug1697.py: 25%
45 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-15 02:24 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-15 02:24 -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 nBadImg = np.logical_not(np.isfinite(maskedImage.image.array)).sum()
43 nBadMsk = np.sum(np.bitwise_and(maskedImage.mask.array, badPixelMask) > 0)
44 nBadVar = np.logical_not(np.isfinite(maskedImage.variance.array)).sum()
45 self.assertEqual(nBadImg, 0)
46 self.assertEqual(nBadMsk, 0)
47 self.assertEqual(nBadVar, 0)
49 def testWeightedStats(self):
50 """Test that bug from #1697 (weighted stats returning NaN) stays fixed."""
52 rand = afwMath.Random()
53 mu = 10000
55 afwImage.Mask.getPlaneBitMask("EDGE")
57 badPixelMask = afwImage.Mask.getPlaneBitMask("EDGE")
58 statsCtrl = afwMath.StatisticsControl()
59 statsCtrl.setNumSigmaClip(3.0)
60 statsCtrl.setNumIter(2)
61 statsCtrl.setAndMask(badPixelMask)
63 for weight in (300.0, 10.0, 1.0):
64 print(f"Testing with weight={weight:0.1f}")
65 maskedImageList = []
66 weightList = []
68 nx, ny = 256, 256
69 for i in range(3):
70 print("Processing ", i)
71 maskedImage = afwImage.MaskedImageF(nx, ny)
72 maskedImageList.append(maskedImage)
74 afwMath.randomPoissonImage(maskedImage.getImage(), rand, mu)
75 maskedImage.getVariance().set(mu)
76 weightList.append(weight)
78 self.reportBadPixels(maskedImage, badPixelMask)
80 print("Stack: ", end=' ')
81 coaddMaskedImage = afwMath.statisticsStack(
82 maskedImageList, afwMath.MEANCLIP, statsCtrl, weightList)
83 self.reportBadPixels(coaddMaskedImage, badPixelMask)
86class TestMemory(lsst.utils.tests.MemoryTestCase):
87 pass
90def setup_module(module):
91 lsst.utils.tests.init()
94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true
95 lsst.utils.tests.init()
96 unittest.main()