Coverage for tests/test_makeRawVisitInfoViaObsInfo.py : 40%

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/>.
22import unittest
24from astropy.time import Time
25import astropy.units as u
27import lsst.log
28from astro_metadata_translator import FitsTranslator, StubTranslator, ObservationInfo
29from lsst.daf.base import DateTime
31from lsst.obs.base import MakeRawVisitInfoViaObsInfo
34class NewTranslator(FitsTranslator, StubTranslator):
35 _trivial_map = {
36 "exposure_time": "EXPTIME",
37 "exposure_id": "EXP-ID",
38 }
40 def to_location(self):
41 return None
43 def to_detector_exposure_id(self):
44 return self.to_exposure_id()
47class MakeTestableVisitInfo(MakeRawVisitInfoViaObsInfo):
48 metadataTranslator = NewTranslator
51class TestMakeRawVisitInfoViaObsInfo(unittest.TestCase):
53 def setUp(self):
54 # Reference values
55 self.exposure_time = 6.2*u.s
56 self.exposure_id = 54321
57 self.datetime_begin = Time("2001-01-02T03:04:05.123456789", format="isot", scale="utc")
58 self.datetime_begin.precision = 9
59 self.datetime_end = Time("2001-01-02T03:04:07.123456789", format="isot", scale="utc")
60 self.datetime_end.precision = 9
62 self.header = {
63 "DATE-OBS": self.datetime_begin.isot,
64 "DATE-END": self.datetime_end.isot,
65 "INSTRUME": "Irrelevant",
66 "TELESCOP": "LSST",
67 "TIMESYS": "UTC",
68 "EXPTIME": self.exposure_time,
69 "EXP-ID": self.exposure_id,
70 "EXTRA1": "an abitrary key and value",
71 "EXTRA2": 5,
72 }
74 def testMakeRawVisitInfoViaObsInfo(self):
75 maker = MakeTestableVisitInfo()
76 beforeLength = len(self.header)
78 # Capture the warnings from StubTranslator since they are
79 # confusing to people but irrelevant for the test.
80 with self.assertWarns(UserWarning):
81 with lsst.log.UsePythonLogging():
82 with self.assertLogs(level="WARNING"):
83 visitInfo = maker(self.header)
85 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s"))
86 self.assertEqual(visitInfo.getExposureId(), self.exposure_id)
87 self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC))
88 self.assertEqual(len(self.header), beforeLength)
90 def testObservationInfo2VisitInfo(self):
92 with self.assertWarns(UserWarning):
93 obsInfo = ObservationInfo(self.header, translator_class=NewTranslator)
95 # No log specified so no log message should appear
96 visitInfo = MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(obsInfo)
97 self.assertIsInstance(visitInfo, lsst.afw.image.VisitInfo)
98 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s"))
99 self.assertEqual(visitInfo.getExposureId(), self.exposure_id)
100 self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC))
103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 unittest.main()