Coverage for tests/test_ingest.py: 73%

63 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-23 17:40 -0700

1# This file is part of obs_decam. 

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 

22"""Unit tests for gen3 DECam raw data ingest. 

23""" 

24 

25import unittest 

26import os 

27import lsst.utils.tests 

28 

29from lsst.daf.butler import Butler, DataCoordinate 

30from lsst.obs.base.ingest_tests import IngestTestBase 

31import lsst.obs.decam 

32 

33testDataPackage = "testdata_decam" 

34try: 

35 testDataDirectory = lsst.utils.getPackageDir(testDataPackage) 

36except LookupError: 

37 testDataDirectory = None 

38 

39 

40class DecamTestBase(IngestTestBase): 

41 

42 ingestDir = os.path.dirname(__file__) 

43 instrumentClassName = "lsst.obs.decam.DarkEnergyCamera" 

44 

45 

46@unittest.skipIf(testDataDirectory is None, "testdata_decam must be set up") 

47class DecamIngestTestCase(DecamTestBase, lsst.utils.tests.TestCase): 

48 

49 curatedCalibrationDatasetTypes = ("camera", "defects") 

50 

51 # Decam ingests every detector in each raw file, so we 

52 # only have to specify one file here, but should get two dataIds 

53 # in the output repo. 

54 @property 

55 def file(self): 

56 return os.path.join(testDataDirectory, "rawData", "raw", "raw.fits") 

57 

58 dataIds = [dict(instrument="DECam", exposure=229388, detector=25), 

59 dict(instrument="DECam", exposure=229388, detector=1)] 

60 filterLabel = lsst.afw.image.FilterLabel(physical="z DECam SDSS c0004 9260.0 1520.0", band="z") 

61 

62 @property 

63 def visits(self): 

64 butler = Butler(self.root, collections=[self.outputRun]) 

65 return { 

66 DataCoordinate.standardize( 

67 instrument="DECam", 

68 visit=229388, 

69 universe=butler.registry.dimensions 

70 ): [ 

71 DataCoordinate.standardize( 

72 instrument="DECam", 

73 exposure=229388, 

74 universe=butler.registry.dimensions 

75 ) 

76 ] 

77 } 

78 

79 

80@unittest.skipIf(testDataDirectory is None, "testdata_decam must be set up") 

81class DecamIngestFullFileTestCase(DecamTestBase, lsst.utils.tests.TestCase): 

82 """Test ingesting a file that contains all "normal" DECam HDUs. 

83 """ 

84 

85 # No need to test writeCuratedCalibrations again 

86 curatedCalibrationDatasetTypes = None 

87 

88 # Decam ingests every detector in each raw file, so we 

89 # only have to specify one file here, but should get many dataIds 

90 # in the output repo. 

91 @property 

92 def file(self): 

93 return os.path.join(testDataDirectory, "rawData", "raw", "c4d_150227_012718_ori-stripped.fits.fz") 

94 

95 dataIds = [{"instrument": "DECam", "exposure": 415282, "detector": i} for i in range(1, 63)] 

96 filterLabel = lsst.afw.image.FilterLabel(physical="r DECam SDSS c0002 6415.0 1480.0", band="r") 

97 

98 @property 

99 def visits(self): 

100 butler = Butler(self.root, collections=[self.outputRun]) 

101 return { 

102 DataCoordinate.standardize( 

103 instrument="DECam", 

104 visit=415282, 

105 universe=butler.registry.dimensions 

106 ): [ 

107 DataCoordinate.standardize( 

108 instrument="DECam", 

109 exposure=415282, 

110 universe=butler.registry.dimensions 

111 ) 

112 ] 

113 } 

114 

115 def checkRepo(self, files=None): 

116 """Additional tests run on post-ingest repos. 

117 

118 See base class for additional information; note that using this hook 

119 rather than adding a new test_ method saves us from having to (slowly) 

120 run ingest again just to get a useful to repo to test against. 

121 """ 

122 butler = Butler(self.root) 

123 # Test that packing visit+detector data IDs into integers yields 

124 # results consistent with what we have historically gotten (from Gen2). 

125 for dataId in self.dataIds: 

126 expandedDataId = butler.registry.expandDataId(dataId) 

127 packed, bits = expandedDataId.pack("exposure_detector", returnMaxBits=True) 

128 self.assertEqual(packed, int(f"{dataId['exposure']}{dataId['detector']:02}")) 

129 self.assertEqual(bits, 32) 

130 

131 

132@unittest.skipIf(testDataDirectory is None, "testdata_decam must be set up") 

133class DecamIngestShuffledFullFileTestCase(DecamTestBase, lsst.utils.tests.TestCase): 

134 """Test ingesting a file that contains all detectors in a random order. 

135 """ 

136 

137 # No need to test writeCuratedCalibrations again 

138 curatedCalibrationDatasetTypes = None 

139 

140 # Decam ingests every detector in each raw file, so we 

141 # only have to specify one file here, but should get many dataIds 

142 # in the output repo. 

143 @property 

144 def file(self): 

145 return os.path.join(testDataDirectory, "rawData", "raw", 

146 "c4d_150227_012718_ori-stripped-shuffled.fits.fz") 

147 

148 dataIds = [{"instrument": "DECam", "exposure": 415282, "detector": i} for i in range(1, 63)] 

149 filterLabel = lsst.afw.image.FilterLabel(physical="r DECam SDSS c0002 6415.0 1480.0", band="r") 

150 

151 @property 

152 def visits(self): 

153 butler = Butler(self.root, collections=[self.outputRun]) 

154 return { 

155 DataCoordinate.standardize( 

156 instrument="DECam", 

157 visit=415282, 

158 universe=butler.registry.dimensions 

159 ): [ 

160 DataCoordinate.standardize( 

161 instrument="DECam", 

162 exposure=415282, 

163 universe=butler.registry.dimensions 

164 ) 

165 ] 

166 } 

167 

168 

169def setup_module(module): 

170 lsst.utils.tests.init() 

171 

172 

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

174 lsst.utils.tests.init() 

175 unittest.main()