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# Copyright 2008-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 

23"""Test ability to get an eimage from the butler. 

24**Note that this is an lsstSim specific test and 

25should not be considered generalizable. 

26""" 

27import os 

28import unittest 

29 

30import numpy as np 

31 

32import lsst.utils 

33import lsst.geom as geom 

34from lsst.afw.image import RotType 

35import lsst.utils.tests 

36import lsst.daf.persistence as dafPersistence 

37from lsst.afw.coord import Observatory, Weather 

38from lsst.daf.base import DateTime 

39 

40obsLsstSimDir = lsst.utils.getPackageDir('obs_lsstSim') 

41InputDir = os.path.join(obsLsstSimDir, 'tests', 'data') 

42 

43 

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

45 """Test the accessors for various bits of metadata attached to eimages. 

46 The exposure is read in setUpClass. The different methods of VisitInfo 

47 are tested separately to simplify error reporting. 

48 """ 

49 @classmethod 

50 def setUpClass(cls): 

51 # For lsstSim specific reasons, we need to specify the raft and sensor 

52 dataId = dict(visit=840, raft='2,2', sensor='1,1') 

53 butler = dafPersistence.Butler(InputDir) 

54 cls.exposure = butler.get('eimage', dataId=dataId) 

55 cls.visit_info = cls.exposure.getInfo().getVisitInfo() 

56 

57 @classmethod 

58 def tearDownClass(cls): 

59 del cls.exposure 

60 del cls.visit_info 

61 

62 def test_getWcs(self): 

63 """Test whether the Exposure has a Wcs attached.""" 

64 

65 # Test for a Wcs object 

66 self.assertIsNotNone(self.exposure.getWcs()) 

67 

68 def test_getBoresightAirmass(self): 

69 self.assertEqual(1.00015190967402, self.visit_info.getBoresightAirmass()) 

70 

71 def test_getBoresightAzAlt(self): 

72 coord = geom.SpherePoint(0.0, 89.0, geom.degrees) 

73 self.assertEqual(coord, self.visit_info.getBoresightAzAlt()) 

74 

75 def test_getBoresightRaDec(self): 

76 coord = geom.SpherePoint(53.0091385, -27.4389488, geom.degrees) 

77 self.assertEqual(coord, self.visit_info.getBoresightRaDec()) 

78 

79 def test_getBoresightRotAngle(self): 

80 # Note test eimage header has ROTANG=236.983652. boresightRotAngle is -ROTANG. 

81 angle = geom.Angle(-236.983652, geom.degrees) 

82 self.assertAnglesAlmostEqual(angle, self.visit_info.getBoresightRotAngle()) 

83 

84 def test_getDarkTime(self): 

85 self.assertEqual(30.0, self.visit_info.getDarkTime()) 

86 

87 def test_getDate(self): 

88 date = DateTime("1994-01-02T01:46:59.520000913", DateTime.TAI) 

89 self.assertEqual(date, self.visit_info.getDate()) 

90 

91 def test_getEra(self): 

92 # numpy.isnan fails on afw:Angle, so just get a number out and test that. 

93 self.assertTrue(np.isnan(self.visit_info.getEra().asRadians())) 

94 

95 def test_getExposureId(self): 

96 self.assertEqual(430204, self.visit_info.getExposureId()) 

97 

98 def test_getExposureTime(self): 

99 self.assertEqual(30.0, self.visit_info.getExposureTime()) 

100 

101 def test_getObservatory(self): 

102 observatory = Observatory(geom.Angle(-70.749417, geom.degrees), 

103 geom.Angle(-30.244633, geom.degrees), 2663) 

104 self.assertEqual(observatory, self.visit_info.getObservatory()) 

105 

106 def test_getRotType(self): 

107 self.assertEqual(RotType.SKY, self.visit_info.getRotType()) 

108 

109 def test_getWeather(self): 

110 def test_weather(w1, w2): 

111 """Test equality of two Weather objects 

112 @param[in] w1 First Weather object 

113 @param[in] w2 Second Weather object 

114 """ 

115 humid_bool = np.isnan(w1.getHumidity()) and np.isnan(w2.getHumidity()) 

116 if not humid_bool: 

117 humid_bool = (w1.getHumidity() == w2.getHumidity()) 

118 self.assertEqual(w1.getAirTemperature(), w2.getAirTemperature()) 

119 self.assertEqual(w1.getAirPressure(), w2.getAirPressure()) 

120 self.assertTrue(humid_bool) 

121 

122 weather = Weather(20, 69327.64145580001, 40.) 

123 test_weather(weather, self.visit_info.getWeather()) 

124 

125 

126def setup_module(module): 

127 lsst.utils.tests.init() 

128 

129 

130class MemoryTestCase(lsst.utils.tests.MemoryTestCase): 

131 pass 

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()