Coverage for tests/test_maskNans.py: 33%
47 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-18 02:35 -0700
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-18 02:35 -0700
1# This file is part of ip_isr.
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/>.
22import unittest
24import numpy as np
26import lsst.utils.tests
27import lsst.afw.image as afwImage
28from lsst.ip.isr import maskNans
30display = False
31if display: 31 ↛ 32line 31 didn't jump to line 32, because the condition on line 31 was never true
32 import lsst.afw.display as afwDisplay
33 afwDisplay.setDefaultMaskTransparency(75)
36class MaskNansTestCase(lsst.utils.tests.TestCase):
38 def setUp(self):
39 self.size = 100
40 self.freqImage = 34
41 self.freqMask = 12
42 self.freqVariance = 23
43 self.afterMask = 2
44 self.allowMask = 1
46 def check(self, ImageClass):
47 image = ImageClass(self.size, self.size)
48 x, y = np.indices((self.size, self.size))
49 image.getImage().getArray()[y, x] = np.where(x*y % self.freqImage, 0, np.nan)
50 image.getMask().getArray()[y, x] = np.where(x*y % self.freqMask, 0, self.allowMask)
51 image.getVariance().getArray()[y, x] = np.where(x*y % self.freqVariance, 0, np.nan)
53 if display:
54 afwDisplay.Display(frame=1).mtv(image.getImage(), title=self._testMethodName + ": Image")
55 afwDisplay.Display(frame=2).mtv(image.getVariance(), title=self._testMethodName + ": Variance")
56 afwDisplay.Display(frame=3).mtv(image.getMask(), title=self._testMethodName + ": Original mask")
58 isUnmasked = np.logical_not(image.getMask().getArray() & self.allowMask)
59 isNan = np.logical_or(np.isnan(image.getImage().getArray()),
60 np.isnan(image.getVariance().getArray()))
62 maskExpected = np.where(np.logical_and(isUnmasked, isNan), self.afterMask,
63 image.getMask().getArray())
64 numExpected = np.count_nonzero(maskExpected & self.afterMask)
66 numNans = maskNans(image, self.afterMask, self.allowMask)
68 if display:
69 afwDisplay.Display(frame=4).mtv(image.getMask(), title=self._testMethodName + ": UNC-ed mask")
71 self.assertEqual(numNans, numExpected)
72 self.assertMasksEqual(image.getMask(), maskExpected)
74 def testMaskImageF(self):
75 self.check(afwImage.MaskedImageF)
77 def testMaskImageD(self):
78 self.check(afwImage.MaskedImageD)
81class MemoryTester(lsst.utils.tests.MemoryTestCase):
82 pass
85def setup_module(module):
86 lsst.utils.tests.init()
89if __name__ == "__main__": 89 ↛ 90line 89 didn't jump to line 90, because the condition on line 89 was never true
90 lsst.utils.tests.init()
91 unittest.main()