Coverage for tests/test_defect.py: 21%
72 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-28 02:29 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-28 02:29 -0800
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.geom
28import lsst.afw.image as afwImage
29import lsst.ip.isr as ipIsr
31display = False # set to True to display images
32if display: 32 ↛ 33line 32 didn't jump to line 33, because the condition on line 32 was never true
33 import lsst.afw.display as afwDisplay
34 afwDisplay.setDefaultMaskTransparency(75)
37class DefectTestCases(lsst.utils.tests.TestCase):
39 def setUp(self):
40 self.setVal = 10.
42 def tearDown(self):
43 del self.setVal
45 def testDefectBase(self):
46 """Test DefectBases"""
48 defectList = ipIsr.Defects()
49 ccdImage = afwImage.MaskedImageF(250, 225)
50 ccdImage.set(self.setVal, 0, self.setVal)
51 #
52 # Insert some defects into the Ccd
53 #
54 for x0, y0, x1, y1 in [
55 (34, 0, 35, 80),
56 (34, 81, 34, 100),
57 (180, 100, 182, 130),
58 ]:
59 bbox = lsst.geom.Box2I(lsst.geom.Point2I(x0, y0), lsst.geom.Point2I(x1, y1))
60 defectList.append(bbox)
61 bad = ccdImage.Factory(ccdImage, bbox, afwImage.LOCAL)
62 bad.set(100)
64 defectList.maskPixels(ccdImage, maskName="BAD")
65 mask = ccdImage.getMask()
66 bitMask = mask.getPlaneBitMask('BAD')
67 for d in defectList:
68 bad = mask.Factory(mask, d.getBBox(), afwImage.LOCAL)
69 self.assertTrue((bad.getArray() & bitMask == bitMask).all())
71 if display:
72 disp = afwDisplay.Display()
73 disp.mtv(ccdImage.getImage(), title=self._testMethodName + ": Defects")
74 for d in defectList:
75 afwDisplay.utils.drawBBox(d.getBBox(), ctype=afwDisplay.CYAN, borderWidth=.5)
76 disp.incrDefaultFrame()
78 ipIsr.interpolateDefectList(ccdImage, defectList, 2.)
79 im = ccdImage.getImage()
80 for d in defectList:
81 intrp = im.Factory(im, d.getBBox())
82 expect = np.empty_like(intrp.getArray())
83 expect[:] = self.setVal
84 self.assertImagesEqual(intrp, expect)
86 if display:
87 disp = afwDisplay.Display()
88 disp.mtv(ccdImage.getImage(), title=self._testMethodName + ": Defects Interpolated")
89 for d in defectList:
90 afwDisplay.utils.drawBBox(d.getBBox(), ctype=afwDisplay.CYAN, borderWidth=.5)
91 disp.incrDefaultFrame()
93 def testDefectsFromMaskedImage(self):
94 """Test creation of a DefectList from a MaskedImage."""
95 mim = afwImage.MaskedImageF(10, 10)
97 # Nothing masked -> no defects.
98 defectList = ipIsr.Defects.fromMask(mim, "BAD")
99 self.assertEqual(len(defectList), 0)
101 # Mask a single pixel.
102 mask = mim.getMask()
103 mask[5, 5, afwImage.LOCAL] = mask.getPlaneBitMask("BAD")
104 defectList = ipIsr.Defects.fromMask(mim, "BAD")
105 self.assertEqual(len(defectList), 1)
106 self.assertEqual(defectList[0].getX0(), 5)
107 self.assertEqual(defectList[0].getY0(), 5)
109 # Setting a different plane does not register as a defect.
110 mask[1, 1, afwImage.LOCAL] = mask.getPlaneBitMask("SUSPECT")
111 defectList = ipIsr.Defects.fromMask(mim, "SUSPECT")
112 self.assertEqual(len(defectList), 1)
114 # But adding another BAD pixel does.
115 mask[9, 9, afwImage.LOCAL] = mask.getPlaneBitMask("BAD")
116 defectList = ipIsr.Defects.fromMask(mim, "BAD")
117 self.assertEqual(len(defectList), 2)
120class MemoryTester(lsst.utils.tests.MemoryTestCase):
121 pass
124def setup_module(module):
125 lsst.utils.tests.init()
128if __name__ == "__main__": 128 ↛ 129line 128 didn't jump to line 129, because the condition on line 128 was never true
129 lsst.utils.tests.init()
130 unittest.main()