Coverage for tests / test_subaru.py: 32%
34 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 08:43 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 08:43 +0000
1# This file is part of astro_metadata_translator.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the LICENSE file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12import os.path
13import unittest
15import astropy.time
16import astropy.units as u
18from astro_metadata_translator import merge_headers
19from astro_metadata_translator.tests import MetadataAssertHelper, read_test_file
21TESTDIR = os.path.abspath(os.path.dirname(__file__))
24class HscTestCase(unittest.TestCase, MetadataAssertHelper):
25 """Test HSC translations."""
27 datadir = os.path.join(TESTDIR, "data")
29 def test_hsc_translator(self) -> None:
30 test_data = (
31 (
32 "fitsheader-hsc.yaml",
33 dict(
34 telescope="Subaru",
35 instrument="HSC",
36 boresight_rotation_coord="sky",
37 dark_time=30.0 * u.s,
38 detector_exposure_id=180804850,
39 detector_name="12",
40 detector_unique_name="1_12",
41 detector_num=50,
42 detector_serial="120",
43 exposure_id=904024,
44 exposure_group="904024",
45 exposure_time=30.0 * u.s,
46 exposure_time_requested=30.0 * u.s,
47 focus_z=3.7 * u.mm,
48 group_counter_end=904024,
49 group_counter_start=904024,
50 has_simulated_content=False,
51 object="STRIPE82L",
52 observation_counter=904024,
53 observation_id="HSCA90402400",
54 observation_type="science",
55 observation_reason="science",
56 observing_day=20131102,
57 observing_day_offset=astropy.time.TimeDelta(0, format="sec", scale="tai"),
58 physical_filter="HSC-I",
59 pressure=621.7 * u.hPa,
60 relative_humidity=33.1,
61 science_program="o13015",
62 temperature=272.35 * u.K,
63 visit_id=904024,
64 ),
65 ),
66 (
67 "fitsheader-hsc-HSCA04090107.yaml",
68 dict(
69 telescope="Subaru",
70 instrument="HSC",
71 boresight_rotation_coord="sky",
72 dark_time=150.0 * u.s,
73 detector_exposure_id=8180037,
74 detector_name="07",
75 detector_unique_name="1_07",
76 detector_num=37,
77 detector_serial="061",
78 exposure_id=40900,
79 exposure_group="40900",
80 exposure_time=150.0 * u.s,
81 exposure_time_requested=150.0 * u.s,
82 focus_z=3.83 * u.mm,
83 group_counter_end=40900,
84 group_counter_start=40900,
85 has_simulated_content=False,
86 object="SSP-Wide",
87 observation_counter=40900,
88 observation_id="HSCA04090000",
89 observation_type="science",
90 observation_reason="science",
91 observing_day=20151010,
92 physical_filter="HSC-R",
93 pressure=625.4 * u.hPa,
94 relative_humidity=8.6,
95 science_program="o15426",
96 temperature=278.35 * u.K,
97 visit_id=40900,
98 ),
99 ),
100 )
101 for file, expected in test_data:
102 with self.subTest(f"Testing {file}"):
103 self.assertObservationInfoFromYaml(file, dir=self.datadir, **expected)
105 def test_suprimecam_translator(self) -> None:
106 # In this case the airmass is average during observation
107 # but it looks like ALTITUDE is from a different time so loosen amdelta
108 test_data = (
109 (
110 "fitsheader-suprimecam-CORR40535770.yaml",
111 dict(
112 telescope="Subaru",
113 instrument="SuprimeCam",
114 boresight_rotation_coord="unknown",
115 dark_time=200.0 * u.s,
116 detector_exposure_id=535770,
117 detector_name="nausicaa",
118 detector_unique_name="nausicaa",
119 detector_num=0,
120 detector_serial="w67c1",
121 exposure_id=53577,
122 exposure_group="53577",
123 exposure_time=200.0 * u.s,
124 exposure_time_requested=200.0 * u.s,
125 group_counter_end=53577,
126 group_counter_start=53577,
127 has_simulated_content=False,
128 object="Ecliptic Deep Field",
129 observation_counter=53577,
130 observation_id="SUPE00535770",
131 observation_type="science",
132 observation_reason="science",
133 observing_day=20070423,
134 physical_filter="W-S-R+",
135 pressure=621.5 * u.hPa,
136 relative_humidity=4.9,
137 science_program="o07222",
138 temperature=273.15 * u.K,
139 visit_id=53577,
140 wcs_params=dict(amdelta=0.015),
141 ),
142 ),
143 )
144 for file, expected in test_data:
145 with self.subTest(f"Testing {file}"):
146 self.assertObservationInfoFromYaml(file, dir=self.datadir, **expected)
148 def test_merging_hsc(self) -> None:
149 files = ("fitsheader-hsc-HSCA04090107.yaml", "fitsheader-hsc.yaml")
150 headers = [read_test_file(f, dir=self.datadir) for f in files]
151 merged = merge_headers(headers, mode="first", sort=False)
153 # The MJD-STR should come from the first file
154 self.assertAlmostEqual(merged["MJD-STR"], 57305.34729859)
156 # If we sort then MJD-STR should come from the oldest file
157 merged = merge_headers(headers, mode="first", sort=True)
158 self.assertAlmostEqual(merged["MJD-STR"], 56598.26106374757)
160 # Drop headers that differ, MJD-STR should not appear
161 merged = merge_headers(headers, mode="drop", sort=True)
162 self.assertNotIn("MJD-STR", merged)
164 # Drop but retain first MJD-STR without sorting
165 merged = merge_headers(headers, mode="drop", sort=False, first=["MJD-STR", "UT-STR"])
166 self.assertAlmostEqual(merged["MJD-STR"], 57305.34729859)
167 self.assertEqual(merged["UT-STR"], "08:20:06.598")
169 # Drop but retain first MJD-STR
170 merged = merge_headers(headers, mode="drop", sort=True, first=["MJD-STR", "UT-STR"])
171 self.assertAlmostEqual(merged["MJD-STR"], 56598.26106374757)
172 self.assertEqual(merged["UT-STR"], "06:15:55.908")
175if __name__ == "__main__":
176 unittest.main()