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# 

2# LSST Data Management System 

3# 

4# Copyright 2008-2016 AURA/LSST. 

5# 

6# This product includes software developed by the 

7# LSST Project (http://www.lsst.org/). 

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 LSST License Statement and 

20# the GNU General Public License along with this program. If not, 

21# see <https://www.lsstcorp.org/LegalNotices/>. 

22# 

23import os 

24import unittest 

25from glob import glob 

26from shutil import rmtree 

27from subprocess import check_call 

28from tempfile import mkdtemp 

29 

30import lsst.geom as geom 

31import lsst.daf.persistence as dafPersist 

32import lsst.utils 

33from lsst.daf.base import DateTime 

34from lsst.afw.image import RotType 

35from lsst.geom import degrees, radians 

36from lsst.obs.hsc import HscMapper 

37 

38testDataPackage = "testdata_subaru" 

39try: 

40 testDataDirectory = lsst.utils.getPackageDir(testDataPackage) 

41except lsst.pex.exceptions.NotFoundError: 

42 testDataDirectory = None 

43 

44 

45def createDataRepository(mapperName, inputPath, calibPath): 

46 """ 

47 Construct a data repository for a particular mapper containing a given set 

48 of input data and return its path. 

49 

50 @param[in] mapperName Name of mapper class for use with repository. 

51 @param[in] inputPath Location of data files which will be ingested. 

52 @param[in] calibPath Location of calibs. 

53 """ 

54 repoPath = mkdtemp() 

55 with open(os.path.join(repoPath, "_mapper"), "w") as _mapper: 

56 _mapper.write(mapperName) 

57 ingest_cmd = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "bin", "hscIngestImages.py") 

58 check_call([ingest_cmd, repoPath, "--calib", calibPath] + glob(os.path.join(inputPath, "*.fits.gz"))) 

59 return repoPath 

60 

61 

62class IngestRawTestCase(lsst.utils.tests.TestCase): 

63 """Ensure that we can ingest raw data to a repository.""" 

64 @unittest.skipIf(testDataDirectory is None, "%s is not available" % testDataPackage) 

65 def setUp(self): 

66 rawPath = os.path.join(testDataDirectory, "hsc", "raw") 

67 calibPath = os.path.join(testDataDirectory, "hsc", "calib") 

68 self.repoPath = createDataRepository("lsst.obs.hsc.HscMapper", rawPath, calibPath) 

69 

70 def tearDown(self): 

71 rmtree(self.repoPath) 

72 

73 def testIngest(self): 

74 self.assertTrue(os.path.exists(os.path.join(self.repoPath, "registry.sqlite3"))) 

75 

76 def testMapperName(self): 

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

78 self.assertEqual(name, "obs_subaru") 

79 

80 

81class GetDataTestCase(lsst.utils.tests.TestCase): 

82 """Demonstrate retrieval of data from a repository.""" 

83 @unittest.skipIf(testDataDirectory is None, "%s is not available" % testDataPackage) 

84 def setUp(self): 

85 rawPath = os.path.join(testDataDirectory, "hsc", "raw") 

86 calibPath = os.path.join(testDataDirectory, "hsc", "calib") 

87 self.repoPath = createDataRepository("lsst.obs.hsc.HscMapper", rawPath, calibPath) 

88 self.butler = dafPersist.Butler(root=self.repoPath, calibRoot=calibPath) 

89 

90 # The following properties of the provided data are known a priori. 

91 self.visit = 904024 

92 self.ccdNum = 50 

93 self.filter = 'i' 

94 self.rawSize = (2144, 4241) 

95 self.ccdSize = (2048, 4176) 

96 self.exptime = 30.0 

97 self.darktime = self.exptime # No explicit darktime 

98 self.dateAvg = DateTime(56598.26165414352, DateTime.MJD, DateTime.TAI) 

99 self.boresightRaDec = geom.SpherePoint(320.7499250000, 0.500019444, degrees) 

100 self.boresightAzAlt = geom.SpherePoint(226.68922661, 63.04359233, degrees) 

101 self.boresightAirmass = 1.121626027604189 

102 self.boresightRotAngle = 270.0*degrees 

103 self.rotType = RotType.SKY 

104 self.obs_longitude = -155.476667*degrees 

105 self.obs_latitude = 19.825556*degrees 

106 self.obs_elevation = 4139 

107 self.weath_airTemperature = -0.8 

108 self.weath_airPressure = 62170. 

109 self.weath_humidity = 33.1 

110 # NOTE: if we deal with DM-8053 and get UT1 implemented, ERA will change slightly. 

111 self.era = 2.3659570321481826*radians 

112 

113 def tearDown(self): 

114 del self.butler 

115 rmtree(self.repoPath) 

116 

117 def testRaw(self): 

118 """Test retrieval of raw image""" 

119 raw = self.butler.get("raw", visit=self.visit, ccd=self.ccdNum) 

120 ccd = raw.getDetector() 

121 self.assertEqual(raw.getDimensions(), geom.Extent2I(*self.rawSize)) 

122 self.assertEqual(raw.getFilter().getFilterProperty().getName(), self.filter) 

123 self.assertEqual(ccd.getId(), self.ccdNum) 

124 self.assertEqual(ccd.getBBox().getDimensions(), geom.Extent2I(*self.ccdSize)) 

125 

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

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

128 self.assertAnglesAlmostEqual(visitInfo.getEra(), self.era) 

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

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

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

132 self.assertAnglesAlmostEqual(visitInfo.getBoresightRotAngle(), self.boresightRotAngle) 

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

134 self.assertEqual(visitInfo.getExposureTime(), self.exptime) 

135 self.assertEqual(visitInfo.getDarkTime(), self.darktime) 

136 observatory = visitInfo.getObservatory() 

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

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

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

140 weather = visitInfo.getWeather() 

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

142 self.assertAlmostEqual(weather.getAirPressure(), self.weath_airPressure, places=4) 

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

144 

145 def testPupil(self): 

146 """Test retrieval of pupil (without checking value)""" 

147 raw = self.butler.get("raw", visit=self.visit, ccd=self.ccdNum) 

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

149 camera = self.butler.get("camera", visit=self.visit, ccd=self.ccdNum) 

150 size = 16.4 

151 npix = 1024 

152 

153 pupilFactory = camera.getPupilFactory(visitInfo, size, npix) 

154 self.assertIsInstance(pupilFactory, lsst.obs.hsc.hscPupil.HscPupilFactory) 

155 

156 pupil = pupilFactory.getPupil(geom.Point2D(0.0, 0.0)) 

157 self.assertEqual(pupil.size, size) 

158 self.assertEqual(pupil.scale, size/npix) 

159 self.assertEqual(pupil.illuminated.shape, (npix, npix)) 

160 

161 def testRawMetadata(self): 

162 """Test retrieval of raw image metadata""" 

163 md = self.butler.get("raw_md", visit=self.visit, ccd=self.ccdNum) 

164 self.assertEqual(md.getScalar("DET-ID"), self.ccdNum) 

165 

166 def testBias(self): 

167 """Test retrieval of bias frame""" 

168 bias = self.butler.get("bias", visit=self.visit, ccd=self.ccdNum) 

169 self.assertEqual(bias.getDimensions(), geom.Extent2I(*self.ccdSize)) 

170 self.assertEqual(bias.getDetector().getId(), self.ccdNum) 

171 

172 def testDark(self): 

173 """Test retrieval of dark frame""" 

174 dark = self.butler.get("dark", visit=self.visit, ccd=self.ccdNum) 

175 self.assertEqual(dark.getDimensions(), geom.Extent2I(*self.ccdSize)) 

176 self.assertEqual(dark.getDetector().getId(), self.ccdNum) 

177 self.assertEqual(dark.getInfo().getVisitInfo().getExposureTime(), 1.0) 

178 

179 def testFlat(self): 

180 """Test retrieval of flat""" 

181 flat = self.butler.get("flat", visit=self.visit, ccd=self.ccdNum) 

182 self.assertEqual(flat.getDimensions(), geom.Extent2I(*self.ccdSize)) 

183 self.assertEqual(flat.getDetector().getId(), self.ccdNum) 

184 

185 def testLinearizer(self): 

186 lin1 = self.butler.get('linearizer', ccdnum=1) 

187 lin2 = self.butler.get('linearizer', ccdnum=2) 

188 self.assertIsNotNone(lin1) 

189 self.assertIsNotNone(lin2) 

190 self.assertNotEqual(lin1, lin2) 

191 

192 

193class TestMemory(lsst.utils.tests.MemoryTestCase): 

194 def setUp(self): 

195 HscMapper.clearCache() 

196 lsst.utils.tests.MemoryTestCase.setUp(self) 

197 

198 

199def setup_module(module): 

200 lsst.utils.tests.init() 

201 

202 

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

204 lsst.utils.tests.init() 

205 unittest.main()