Coverage for tests/test_isr.py: 33%

64 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-10 01:36 -0800

1# This file is part of obs_cfht. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://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 <http://www.gnu.org/licenses/>. 

21# 

22import os 

23import unittest 

24 

25import lsst.afw.image as afwImage 

26import lsst.utils.tests 

27 

28from lsst.obs.cfht import MegaPrime 

29from lsst.obs.cfht.cfhtIsrTask import CfhtIsrTask 

30 

31 

32testDataPackage = "testdata_cfht" 

33try: 

34 testDataDirectory = lsst.utils.getPackageDir(testDataPackage) 

35except LookupError: 

36 testDataDirectory = None 

37 

38 

39@unittest.skipIf(testDataDirectory is None, "Skipping tests as testdata_cfht is not setup") 

40class CfhtIsrTestCase(lsst.utils.tests.TestCase): 

41 """Test for the CFHT IsrTask wrapper.""" 

42 

43 def setUp(self): 

44 # We'll need a detector, so get the first one. 

45 self.camera = MegaPrime().getCamera() 

46 detector = self.camera[0] 

47 

48 # Get the override. 

49 self.configPath = os.path.join(lsst.utils.getPackageDir("obs_cfht"), "config", 

50 "isr.py") 

51 # Read the image data. 

52 imageLocation = os.path.join(testDataDirectory, "DATA/raw/08BL05/w2.+2+2/2008-11-01/i2", 

53 "1038843o.fits.fz") 

54 self.exposure = self.imageHandler(imageLocation, detector) 

55 

56 @staticmethod 

57 def imageHandler(location, detector=None): 

58 """Quick method to handle image reading. 

59 

60 Parameters 

61 ---------- 

62 location : `str` 

63 FITS file location. 

64 detector : `lsst.afw.cameraGeom.Detector`, optional 

65 Detector to attach to the exposure. 

66 

67 Returns 

68 ------- 

69 exp : `lsst.afw.image.Exposure` 

70 Fully constructed exposure. 

71 """ 

72 if detector: 

73 hdu = detector.getId() + 1 

74 else: 

75 hdu = 1 

76 

77 reader = afwImage.ExposureFitsReader(location) 

78 imReader = afwImage.ImageFitsReader(location, hdu=hdu) 

79 

80 exp = afwImage.makeExposure(afwImage.makeMaskedImage(imReader.read())) 

81 exp.setMetadata(reader.readMetadata()) 

82 exp.setInfo(reader.readExposureInfo()) 

83 

84 if detector: 

85 exp.setDetector(detector) 

86 

87 return exp 

88 

89 def test_processing(self): 

90 # Process image and confirm it doesn't fail. 

91 

92 config = CfhtIsrTask.ConfigClass() 

93 

94 # Manually fix config. 

95 config.doDark = False 

96 config.doDefect = False 

97 config.doFlat = False 

98 config.doBias = False 

99 config.doFringe = False 

100 config.fringeAfterFlat = False 

101 config.doWrite = False 

102 config.fringe.filters = ["i.MP9701", "i.MP9702", "z.MP9801"] 

103 config.fringe.pedestal = True 

104 config.fringe.small = 1 

105 config.fringe.large = 50 

106 config.doAssembleIsrExposures = True 

107 config.doSuspect = False 

108 config.fluxMag0T1 = {"i.MP9702": 100.0} 

109 

110 task = CfhtIsrTask(config=config) 

111 results = task.run(self.exposure, camera=self.camera) 

112 md = results.exposure.getMetadata() 

113 amplifiers = list(results.exposure.getDetector().getAmplifiers()) 

114 

115 # Check that saturation level are set correctly. 

116 self.assertEqual(md['SATURATE'], 65535) 

117 

118 # Check that the gain and read noise match what is in the 

119 # GAINA and GAINB/RDNOISEA RDNOISEB fields. 

120 self.assertEqual(md['GAINA'], amplifiers[0].getGain()) 

121 self.assertEqual(md['GAINB'], amplifiers[1].getGain()) 

122 self.assertEqual(md['RDNOISEA'], amplifiers[0].getReadNoise()) 

123 self.assertEqual(md['RDNOISEB'], amplifiers[1].getReadNoise()) 

124 

125 

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

127 pass 

128 

129 

130def setup_module(module): 

131 lsst.utils.tests.init() 

132 

133 

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

135 lsst.utils.tests.init() 

136 unittest.main()