Coverage for tests/test_instrument.py: 94%
33 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 09:20 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 09:20 +0000
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/>.
22"""Tests of the Instrument class."""
24import datetime
25import unittest
27import astropy.units as u
28from astro_metadata_translator import ObservationInfo
29from astropy.coordinates import SkyCoord
30from astropy.time import Time
32from lsst.daf.butler import DimensionUniverse
33from lsst.obs.base import Instrument, makeExposureRecordFromObsInfo
34from lsst.obs.base.instrument_tests import DummyCam, InstrumentTestData, InstrumentTests
37class InstrumentTestCase(InstrumentTests, unittest.TestCase):
38 """Test for Instrument."""
40 instrument = DummyCam()
42 data = InstrumentTestData(
43 name="DummyCam", nDetectors=2, firstDetectorName="RXX_S00", physical_filters={"dummy_g", "dummy_u"}
44 )
46 def test_getCamera(self):
47 """No camera defined in DummyCam."""
48 return
50 def test_collectionTimestamps(self):
51 self.assertEqual(
52 Instrument.formatCollectionTimestamp("2018-05-03"),
53 "20180503T000000Z",
54 )
55 self.assertEqual(
56 Instrument.formatCollectionTimestamp("2018-05-03T14:32:16"),
57 "20180503T143216Z",
58 )
59 self.assertEqual(
60 Instrument.formatCollectionTimestamp("20180503T143216Z"),
61 "20180503T143216Z",
62 )
63 self.assertEqual(
64 Instrument.formatCollectionTimestamp(datetime.datetime(2018, 5, 3, 14, 32, 16)),
65 "20180503T143216Z",
66 )
67 formattedNow = Instrument.makeCollectionTimestamp()
68 self.assertIsInstance(formattedNow, str)
69 datetimeThen1 = datetime.datetime.strptime(formattedNow, "%Y%m%dT%H%M%S%z")
70 self.assertEqual(datetimeThen1.tzinfo, datetime.UTC)
72 def test_group_name(self):
73 """Test group name to ID conversion."""
74 self.assertEqual(self.instrument.group_name_to_group_id("1:234-5.6"), 123456)
75 with self.assertRaises(ValueError):
76 self.instrument.group_name_to_group_id("no_int")
78 def test_sky_angle_case_insensitive(self):
79 """Test that makeExposureRecordFromObsInfo transfers sky_angle
80 regardless of the boresight_rotation_coord capitalization.
81 """
82 obs_info = ObservationInfo(
83 instrument="DummyCam",
84 exposure_id=1,
85 exposure_time=10.0 * u.s,
86 exposure_time_requested=10.0 * u.s,
87 datetime_begin=Time("2025-01-01T00:00:00", scale="utc"),
88 datetime_end=Time("2025-01-01T00:00:10", scale="utc"),
89 observing_day=20250101,
90 observation_type="science",
91 physical_filter="g",
92 tracking_radec=SkyCoord("00:00:00.0 +00:00:00.0", unit="deg"),
93 boresight_rotation_angle=45.0 * u.deg,
94 boresight_rotation_coord="SKY",
95 )
96 record = makeExposureRecordFromObsInfo(obs_info, DimensionUniverse())
97 self.assertEqual(record.sky_angle, 45.0)
100if __name__ == "__main__": 100 ↛ 101line 100 didn't jump to line 101 because the condition on line 100 was never true
101 unittest.main()