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# This file is part of obs_base. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 unittest 

23 

24from astropy.time import Time 

25import astropy.units as u 

26 

27from astro_metadata_translator import FitsTranslator, StubTranslator, ObservationInfo 

28from lsst.daf.base import DateTime 

29import lsst.afw.image 

30from lsst.obs.base import MakeRawVisitInfoViaObsInfo 

31 

32 

33class NewTranslator(FitsTranslator, StubTranslator): 

34 _trivial_map = { 

35 "exposure_time": "EXPTIME", 

36 "exposure_id": "EXP-ID", 

37 } 

38 

39 def to_location(self): 

40 return None 

41 

42 def to_detector_exposure_id(self): 

43 return self.to_exposure_id() 

44 

45 

46class MakeTestableVisitInfo(MakeRawVisitInfoViaObsInfo): 

47 metadataTranslator = NewTranslator 

48 

49 

50class TestMakeRawVisitInfoViaObsInfo(unittest.TestCase): 

51 

52 def setUp(self): 

53 # Reference values 

54 self.exposure_time = 6.2*u.s 

55 self.exposure_id = 54321 

56 self.datetime_begin = Time("2001-01-02T03:04:05.123456789", format="isot", scale="utc") 

57 self.datetime_begin.precision = 9 

58 self.datetime_end = Time("2001-01-02T03:04:07.123456789", format="isot", scale="utc") 

59 self.datetime_end.precision = 9 

60 

61 self.header = { 

62 "DATE-OBS": self.datetime_begin.isot, 

63 "DATE-END": self.datetime_end.isot, 

64 "INSTRUME": "SomeCamera", 

65 "TELESCOP": "LSST", 

66 "TIMESYS": "UTC", 

67 "EXPTIME": self.exposure_time, 

68 "EXP-ID": self.exposure_id, 

69 "EXTRA1": "an abitrary key and value", 

70 "EXTRA2": 5, 

71 } 

72 

73 def testMakeRawVisitInfoViaObsInfo(self): 

74 maker = MakeTestableVisitInfo() 

75 beforeLength = len(self.header) 

76 

77 # Capture the warnings from StubTranslator since they are 

78 # confusing to people but irrelevant for the test. 

79 with self.assertWarns(UserWarning): 

80 with self.assertLogs(level="WARNING"): 

81 visitInfo = maker(self.header) 

82 

83 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s")) 

84 # TODO DM-13943: note that in this test visitInfo.getExposureId() and 

85 # visitInfo.id are the same, but that's not true generally. 

86 self.assertEqual(visitInfo.getExposureId(), self.exposure_id) 

87 self.assertEqual(visitInfo.id, self.exposure_id) 

88 self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC)) 

89 # The header can possibly grow with header fix up provenance. 

90 self.assertGreaterEqual(len(self.header), beforeLength) 

91 self.assertEqual(visitInfo.getInstrumentLabel(), "SomeCamera") 

92 

93 def testObservationInfo2VisitInfo(self): 

94 

95 with self.assertWarns(UserWarning): 

96 obsInfo = ObservationInfo(self.header, translator_class=NewTranslator) 

97 

98 # No log specified so no log message should appear 

99 visitInfo = MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(obsInfo) 

100 self.assertIsInstance(visitInfo, lsst.afw.image.VisitInfo) 

101 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s")) 

102 # TODO DM-13943: note that in this test visitInfo.getExposureId() and 

103 # visitInfo.id are the same, but that's not true generally. 

104 self.assertEqual(visitInfo.getExposureId(), self.exposure_id) 

105 self.assertEqual(visitInfo.id, self.exposure_id) 

106 self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC)) 

107 self.assertEqual(visitInfo.getInstrumentLabel(), "SomeCamera") 

108 

109 

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

111 unittest.main()