Coverage for tests/test_makeRawVisitInfoViaObsInfo.py: 31%
50 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-06 13:04 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-06 13:04 -0800
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
24import astropy.units as u
25import lsst.afw.image
26from astro_metadata_translator import FitsTranslator, ObservationInfo, StubTranslator
27from astropy.time import Time
28from lsst.daf.base import DateTime
29from lsst.obs.base import MakeRawVisitInfoViaObsInfo
32class NewTranslator(FitsTranslator, StubTranslator):
33 _trivial_map = {
34 "exposure_time": "EXPTIME",
35 "exposure_id": "EXP-ID",
36 }
38 def to_location(self):
39 return None
41 def to_detector_exposure_id(self):
42 return self.to_exposure_id()
45class MakeTestableVisitInfo(MakeRawVisitInfoViaObsInfo):
46 metadataTranslator = NewTranslator
49class TestMakeRawVisitInfoViaObsInfo(unittest.TestCase):
50 def setUp(self):
51 # Reference values
52 self.exposure_time = 6.2 * u.s
53 self.exposure_id = 54321
54 self.datetime_begin = Time("2001-01-02T03:04:05.123456789", format="isot", scale="utc")
55 self.datetime_begin.precision = 9
56 self.datetime_end = Time("2001-01-02T03:04:07.123456789", format="isot", scale="utc")
57 self.datetime_end.precision = 9
59 self.header = {
60 "DATE-OBS": self.datetime_begin.isot,
61 "DATE-END": self.datetime_end.isot,
62 "INSTRUME": "SomeCamera",
63 "TELESCOP": "LSST",
64 "TIMESYS": "UTC",
65 "EXPTIME": self.exposure_time,
66 "EXP-ID": self.exposure_id,
67 "EXTRA1": "an abitrary key and value",
68 "EXTRA2": 5,
69 }
71 def testMakeRawVisitInfoViaObsInfo(self):
72 maker = MakeTestableVisitInfo()
73 beforeLength = len(self.header)
75 # Capture the warnings from StubTranslator since they are
76 # confusing to people but irrelevant for the test.
77 with self.assertWarns(UserWarning):
78 with self.assertLogs(level="WARNING"):
79 visitInfo = maker(self.header)
81 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s"))
82 with self.assertWarns(FutureWarning):
83 # TODO: tested for backward-compatibility; remove on DM-32138
84 self.assertEqual(visitInfo.getExposureId(), self.exposure_id)
85 self.assertEqual(visitInfo.id, self.exposure_id)
86 self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC))
87 # The header can possibly grow with header fix up provenance.
88 self.assertGreaterEqual(len(self.header), beforeLength)
89 self.assertEqual(visitInfo.getInstrumentLabel(), "SomeCamera")
91 def testObservationInfo2VisitInfo(self):
93 with self.assertWarns(UserWarning):
94 obsInfo = ObservationInfo(self.header, translator_class=NewTranslator)
96 # No log specified so no log message should appear
97 visitInfo = MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(obsInfo)
98 self.assertIsInstance(visitInfo, lsst.afw.image.VisitInfo)
99 self.assertAlmostEqual(visitInfo.getExposureTime(), self.exposure_time.to_value("s"))
100 with self.assertWarns(FutureWarning):
101 # TODO: tested for backward-compatibility; remove on DM-32138
102 self.assertEqual(visitInfo.getExposureId(), self.exposure_id)
103 self.assertEqual(visitInfo.id, self.exposure_id)
104 self.assertEqual(visitInfo.getDate(), DateTime("2001-01-02T03:04:06.123456789Z", DateTime.UTC))
105 self.assertEqual(visitInfo.getInstrumentLabel(), "SomeCamera")
108if __name__ == "__main__": 108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never true
109 unittest.main()