Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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/>. 

21 

22import unittest 

23 

24import numpy as np 

25 

26import lsst.utils.tests 

27import lsst.geom 

28import lsst.afw.image as afwImage 

29import lsst.meas.algorithms as measAlg 

30import lsst.ip.isr as ipIsr 

31 

32display = False # set to True to display images 

33if display: 33 ↛ 34line 33 didn't jump to line 34, because the condition on line 33 was never true

34 import lsst.afw.display as afwDisplay 

35 afwDisplay.setDefaultMaskTransparency(75) 

36 

37 

38class DefectTestCases(lsst.utils.tests.TestCase): 

39 

40 def setUp(self): 

41 self.setVal = 10. 

42 

43 def tearDown(self): 

44 del self.setVal 

45 

46 def testDefectBase(self): 

47 """Test DefectBases""" 

48 

49 defectList = measAlg.Defects() 

50 ccdImage = afwImage.MaskedImageF(250, 225) 

51 ccdImage.set(self.setVal, 0, self.setVal) 

52 # 

53 # Insert some defects into the Ccd 

54 # 

55 for x0, y0, x1, y1 in [ 

56 (34, 0, 35, 80), 

57 (34, 81, 34, 100), 

58 (180, 100, 182, 130), 

59 ]: 

60 bbox = lsst.geom.Box2I(lsst.geom.Point2I(x0, y0), lsst.geom.Point2I(x1, y1)) 

61 defectList.append(bbox) 

62 bad = ccdImage.Factory(ccdImage, bbox, afwImage.LOCAL) 

63 bad.set(100) 

64 

65 defectList.maskPixels(ccdImage, maskName="BAD") 

66 mask = ccdImage.getMask() 

67 bitMask = mask.getPlaneBitMask('BAD') 

68 for d in defectList: 

69 bad = mask.Factory(mask, d.getBBox(), afwImage.LOCAL) 

70 self.assertTrue((bad.getArray() & bitMask == bitMask).all()) 

71 

72 if display: 

73 disp = afwDisplay.Display() 

74 disp.mtv(ccdImage.getImage(), title=self._testMethodName + ": Defects") 

75 for d in defectList: 

76 afwDisplay.utils.drawBBox(d.getBBox(), ctype=afwDisplay.CYAN, borderWidth=.5) 

77 disp.incrDefaultFrame() 

78 

79 ipIsr.interpolateDefectList(ccdImage, defectList, 2.) 

80 im = ccdImage.getImage() 

81 for d in defectList: 

82 intrp = im.Factory(im, d.getBBox()) 

83 expect = np.empty_like(intrp.getArray()) 

84 expect[:] = self.setVal 

85 self.assertImagesEqual(intrp, expect) 

86 

87 if display: 

88 disp = afwDisplay.Display() 

89 disp.mtv(ccdImage.getImage(), title=self._testMethodName + ": Defects Interpolated") 

90 for d in defectList: 

91 afwDisplay.utils.drawBBox(d.getBBox(), ctype=afwDisplay.CYAN, borderWidth=.5) 

92 disp.incrDefaultFrame() 

93 

94 def testDefectsFromMaskedImage(self): 

95 """Test creation of a DefectList from a MaskedImage.""" 

96 mim = afwImage.MaskedImageF(10, 10) 

97 

98 # Nothing masked -> no defects. 

99 defectList = measAlg.Defects.fromMask(mim, "BAD") 

100 self.assertEqual(len(defectList), 0) 

101 

102 # Mask a single pixel. 

103 mask = mim.getMask() 

104 mask[5, 5, afwImage.LOCAL] = mask.getPlaneBitMask("BAD") 

105 defectList = measAlg.Defects.fromMask(mim, "BAD") 

106 self.assertEqual(len(defectList), 1) 

107 self.assertEqual(defectList[0].getX0(), 5) 

108 self.assertEqual(defectList[0].getY0(), 5) 

109 

110 # Setting a different plane does not register as a defect. 

111 mask[1, 1, afwImage.LOCAL] = mask.getPlaneBitMask("SUSPECT") 

112 defectList = measAlg.Defects.fromMask(mim, "SUSPECT") 

113 self.assertEqual(len(defectList), 1) 

114 

115 # But adding another BAD pixel does. 

116 mask[9, 9, afwImage.LOCAL] = mask.getPlaneBitMask("BAD") 

117 defectList = measAlg.Defects.fromMask(mim, "BAD") 

118 self.assertEqual(len(defectList), 2) 

119 

120 

121class MemoryTester(lsst.utils.tests.MemoryTestCase): 

122 pass 

123 

124 

125def setup_module(module): 

126 lsst.utils.tests.init() 

127 

128 

129if __name__ == "__main__": 129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never true

130 lsst.utils.tests.init() 

131 unittest.main()