Coverage for tests/test_butler.py: 23%

Shortcuts 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

122 statements  

1# 

2# LSST Data Management System 

3# Copyright 2012-2017 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 os 

24import sys 

25 

26import unittest 

27import warnings 

28from lsst.utils import getPackageDir 

29import lsst.utils.tests 

30import lsst.daf.persistence as dafPersist 

31import lsst.afw.cameraGeom.utils as cameraGeomUtils 

32from lsst.daf.base import DateTime 

33from lsst.afw.image import RotType, FilterLabel 

34from lsst.geom import degrees, radians, SpherePoint 

35 

36try: 

37 type(display) 

38except NameError: 

39 display = False 

40 

41frame = 0 

42 

43 

44class GetRawTestCase(lsst.utils.tests.TestCase): 

45 

46 """Testing butler raw image retrieval""" 

47 

48 def setUp(self): 

49 datadir = self.getTestDataDir() 

50 self.repoPath = os.path.join(datadir, "DATA") 

51 self.calibPath = os.path.join(datadir, "CALIB") 

52 self.butler = dafPersist.Butler(root=self.repoPath, 

53 calibRoot=self.calibPath) 

54 self.size = (2112, 4644) 

55 self.dataId = {'visit': 1038843} 

56 self.filter = "i" 

57 self.filterLabel = FilterLabel.fromBandPhysical("i", "i.MP9702") 

58 self.exposureTime = 615.037 

59 self.darkTime = 615.0 

60 self.dateAvg = DateTime(54771.610881712964, DateTime.MJD, DateTime.TAI) 

61 self.boresightRaDec = SpherePoint(135.40941055, -2.39999432, degrees) 

62 self.boresightAzAlt = SpherePoint(122.34, 52.02, degrees) 

63 self.boresightAirmass = 1.269 

64 self.boresightRotAngle = 0*degrees 

65 self.rotType = RotType.SKY 

66 self.obs_longitude = -155.468876*degrees 

67 self.obs_latitude = 19.825252*degrees 

68 self.obs_elevation = 4215 

69 self.weath_airTemperature = 0.90 

70 self.weath_airPressure = 617.65*100 # 100 Pascal/millibar 

71 self.weath_humidity = 39.77 

72 # NOTE: if we deal with DM-8053 and get UT1 implemented, 

73 # ERA will change slightly. 

74 self.era = 4.55388*radians 

75 

76 def tearDown(self): 

77 del self.butler 

78 

79 def assertExposure(self, exp, ccd, checkFilter=True): 

80 print("dataId: ", self.dataId) 

81 print("ccd: ", ccd) 

82 print("width: ", exp.getWidth()) 

83 print("height: ", exp.getHeight()) 

84 print("detector name: ", exp.getDetector().getName()) 

85 with warnings.catch_warnings(): 

86 # surpress Filter warnings; we already know this is deprecated 

87 warnings.simplefilter('ignore', category=FutureWarning) 

88 print("filter name: ", exp.getFilter().getCanonicalName()) 

89 print("filter label: ", exp.getFilterLabel()) 

90 

91 self.assertEqual(exp.getWidth(), self.size[0]) 

92 self.assertEqual(exp.getHeight(), self.size[1]) 

93 self.assertEqual(exp.getDetector().getName(), "ccd%02d" % ccd) 

94 

95 if checkFilter: 

96 self.assertEqual(exp.getFilterLabel(), self.filterLabel) 

97 with warnings.catch_warnings(): 

98 # suppress Filter warnings; we already know this is deprecated 

99 warnings.simplefilter('ignore', category=FutureWarning) 

100 self.assertEqual(exp.getFilter().getCanonicalName(), self.filter) 

101 

102 if display and ccd % 18 == 0: 

103 global frame 

104 frame += 1 

105 ccd = exp.getDetector() 

106 for amp in ccd: 

107 amp = amp 

108 print(ccd.getId(), amp.getId(), amp.getDataSec().toString(), 

109 amp.getBiasSec().toString(), amp.getElectronicParams().getGain()) 

110 cameraGeomUtils.showCcd(ccd, ccdImage=exp, frame=frame) 

111 

112 def getTestDataDir(self): 

113 try: 

114 datadir = getPackageDir("testdata_cfht") 

115 except LookupError as e: 

116 warnings.warn(e.args[0]) 

117 raise unittest.SkipTest("Skipping test as testdata_cfht is not setup") 

118 return datadir 

119 

120 def testRaw(self): 

121 """Test retrieval of raw image""" 

122 if display: 

123 global frame 

124 frame += 1 

125 cameraGeomUtils.showCamera(self.butler.mapper.camera, frame=frame) 

126 

127 for ccd in range(36): 

128 raw = self.butler.get("raw", self.dataId, ccd=ccd, immediate=True) 

129 

130 self.assertExposure(raw, ccd) 

131 

132 visitInfo = raw.getInfo().getVisitInfo() 

133 self.assertAlmostEqual(visitInfo.getDate().get(), self.dateAvg.get()) 

134 self.assertAnglesAlmostEqual(visitInfo.getEra(), self.era, maxDiff=0.1*degrees) 

135 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposureTime) 

136 self.assertAlmostEqual(visitInfo.getDarkTime(), self.darkTime) 

137 self.assertSpherePointsAlmostEqual(visitInfo.getBoresightRaDec(), self.boresightRaDec) 

138 self.assertSpherePointsAlmostEqual(visitInfo.getBoresightAzAlt(), self.boresightAzAlt) 

139 self.assertAlmostEqual(visitInfo.getBoresightAirmass(), self.boresightAirmass) 

140 self.assertTrue(visitInfo.getBoresightRotAngle(), self.boresightRotAngle) 

141 self.assertEqual(visitInfo.getRotType(), self.rotType) 

142 observatory = visitInfo.getObservatory() 

143 self.assertAnglesAlmostEqual(observatory.getLongitude(), self.obs_longitude) 

144 self.assertAnglesAlmostEqual(observatory.getLatitude(), self.obs_latitude) 

145 self.assertAlmostEqual(observatory.getElevation(), self.obs_elevation) 

146 weather = visitInfo.getWeather() 

147 self.assertAlmostEqual(weather.getAirTemperature(), self.weath_airTemperature) 

148 self.assertAlmostEqual(weather.getAirPressure(), self.weath_airPressure) 

149 self.assertAlmostEqual(weather.getHumidity(), self.weath_humidity) 

150 

151 def getDetrend(self, detrend): 

152 """Test retrieval of detrend image""" 

153 for ccd in range(36): 

154 flat = self.butler.get(detrend, self.dataId, ccd=ccd, immediate=True) 

155 

156 self.assertExposure(flat, ccd, checkFilter=False) 

157 

158 def testFlat(self): 

159 self.getDetrend("flat") 

160 

161 def testBias(self): 

162 self.getDetrend("bias") 

163 

164 def testFringe(self): 

165 self.getDetrend("fringe") 

166 

167 def testPackageName(self): 

168 name = dafPersist.Butler.getMapperClass(root=self.repoPath).packageName 

169 self.assertEqual(name, "obs_cfht") 

170 

171 

172def setup_module(module): 

173 lsst.utils.tests.init() 

174 

175 

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

177 pass 

178 

179 

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

181 if "--display" in sys.argv: 

182 display = True 

183 lsst.utils.tests.init() 

184 unittest.main()