Coverage for tests/test_saturationCorrection.py: 20%

43 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-15 10:24 +0000

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# 

22 

23import unittest 

24 

25import lsst.utils.tests 

26import lsst.geom 

27import lsst.afw.image as afwImage 

28import lsst.ip.isr as ipIsr 

29 

30 

31class IsrTestCases(lsst.utils.tests.TestCase): 

32 

33 def testSaturation(self): 

34 """Test saturation threshold masking and interpolation. 

35 

36 The test image used here is a simulated 20x20 square with a 

37 10-pixel long defect in the y-direction. 

38 """ 

39 saturation = 1000 

40 

41 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(19, 19)) 

42 maskedImage = afwImage.MaskedImageF(bbox) 

43 maskedImage.set(100, 0x0, 1) 

44 

45 bbox = lsst.geom.Box2I(lsst.geom.Point2I(9, 5), 

46 lsst.geom.Point2I(9, 15)) 

47 submi = afwImage.MaskedImageF(maskedImage, bbox, afwImage.PARENT, False) 

48 submi.set(saturation, 0x0, 1) 

49 

50 ipIsr.makeThresholdMask( 

51 maskedImage=maskedImage, 

52 threshold=saturation, 

53 growFootprints=0, 

54 maskName='SAT', 

55 ) 

56 ipIsr.interpolateFromMask( 

57 maskedImage=maskedImage, 

58 fwhm=5.0, 

59 growSaturatedFootprints=1, 

60 maskNameList=['SAT'], 

61 ) 

62 

63 mask = maskedImage.getMask() 

64 bitmaskSat = mask.getPlaneBitMask('SAT') 

65 bitmaskInterp = mask.getPlaneBitMask('INTRP') 

66 height = maskedImage.getHeight() 

67 width = maskedImage.getWidth() 

68 

69 for j in range(height): 

70 for i in range(width): 

71 # Grown saturation mask; one around the mask at 9 

72 if i >= 8 and i <= 10: 

73 if (i, j) in [(8, 4), (8, 16), (10, 4), (10, 16)]: 

74 # Should not be saturated or interpolated at all 

75 self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, 0) 

76 self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskSat, 0) 

77 elif (j > 4 and j < 16) and (i == 8 or i == 10): 

78 # Not saturated but interpolated over 

79 self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, bitmaskInterp) 

80 elif (j == 4 or j == 16): 

81 # Interpolated over; bottom/top 

82 self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, bitmaskInterp) 

83 elif (j > 4 and j < 16 and i == 9): 

84 # Both saturated and interpolated over; guts of it 

85 self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, bitmaskInterp) 

86 self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskSat, bitmaskSat) 

87 else: 

88 # Neither; above or below the mask 

89 self.assertEqual(mask[i, j, afwImage.LOCAL], 0) 

90 else: 

91 self.assertEqual(mask[i, j, afwImage.LOCAL], 0) 

92 

93 

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

95 pass 

96 

97 

98def setup_module(module): 

99 lsst.utils.tests.init() 

100 

101 

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

103 lsst.utils.tests.init() 

104 unittest.main()