Coverage for tests/test_subaru.py: 31%
35 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-18 02:21 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-18 02:21 -0700
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.units as u
17from astro_metadata_translator import merge_headers
18from astro_metadata_translator.tests import MetadataAssertHelper, read_test_file
20TESTDIR = os.path.abspath(os.path.dirname(__file__))
23class HscTestCase(unittest.TestCase, MetadataAssertHelper):
24 datadir = os.path.join(TESTDIR, "data")
26 def test_hsc_translator(self):
27 test_data = (
28 (
29 "fitsheader-hsc.yaml",
30 dict(
31 telescope="Subaru",
32 instrument="HSC",
33 boresight_rotation_coord="sky",
34 dark_time=30.0 * u.s,
35 detector_exposure_id=180804850,
36 detector_name="12",
37 detector_unique_name="1_12",
38 detector_num=50,
39 detector_serial="120",
40 exposure_id=904024,
41 exposure_group="904024",
42 exposure_time=30.0 * u.s,
43 group_counter_end=904024,
44 group_counter_start=904024,
45 has_simulated_content=False,
46 object="STRIPE82L",
47 observation_counter=904024,
48 observation_id="HSCA90402400",
49 observation_type="science",
50 observation_reason="science",
51 observing_day=20131102,
52 physical_filter="HSC-I",
53 pressure=621.7 * u.hPa,
54 relative_humidity=33.1,
55 science_program="o13015",
56 temperature=272.35 * u.K,
57 visit_id=904024,
58 ),
59 ),
60 (
61 "fitsheader-hsc-HSCA04090107.yaml",
62 dict(
63 telescope="Subaru",
64 instrument="HSC",
65 boresight_rotation_coord="sky",
66 dark_time=150.0 * u.s,
67 detector_exposure_id=8180037,
68 detector_name="07",
69 detector_unique_name="1_07",
70 detector_num=37,
71 detector_serial="061",
72 exposure_id=40900,
73 exposure_group="40900",
74 exposure_time=150.0 * u.s,
75 group_counter_end=40900,
76 group_counter_start=40900,
77 has_simulated_content=False,
78 object="SSP-Wide",
79 observation_counter=40900,
80 observation_id="HSCA04090000",
81 observation_type="science",
82 observation_reason="science",
83 observing_day=20151010,
84 physical_filter="HSC-R",
85 pressure=625.4 * u.hPa,
86 relative_humidity=8.6,
87 science_program="o15426",
88 temperature=278.35 * u.K,
89 visit_id=40900,
90 ),
91 ),
92 )
93 for file, expected in test_data:
94 with self.subTest(f"Testing {file}"):
95 self.assertObservationInfoFromYaml(file, dir=self.datadir, **expected)
97 def test_suprimecam_translator(self):
98 # In this case the airmass is average during observation
99 # but it looks like ALTITUDE is from a different time so loosen amdelta
100 test_data = (
101 (
102 "fitsheader-suprimecam-CORR40535770.yaml",
103 dict(
104 telescope="Subaru",
105 instrument="SuprimeCam",
106 boresight_rotation_coord="unknown",
107 dark_time=200.0 * u.s,
108 detector_exposure_id=535770,
109 detector_name="nausicaa",
110 detector_unique_name="nausicaa",
111 detector_num=0,
112 detector_serial="w67c1",
113 exposure_id=53577,
114 exposure_group="53577",
115 exposure_time=200.0 * u.s,
116 group_counter_end=53577,
117 group_counter_start=53577,
118 has_simulated_content=False,
119 object="Ecliptic Deep Field",
120 observation_counter=53577,
121 observation_id="SUPE00535770",
122 observation_type="science",
123 observation_reason="science",
124 observing_day=20070423,
125 physical_filter="W-S-R+",
126 pressure=621.5 * u.hPa,
127 relative_humidity=4.9,
128 science_program="o07222",
129 temperature=273.15 * u.K,
130 visit_id=53577,
131 wcs_params=dict(amdelta=0.015),
132 ),
133 ),
134 )
135 for file, expected in test_data:
136 with self.subTest(f"Testing {file}"):
137 self.assertObservationInfoFromYaml(file, dir=self.datadir, **expected)
139 def test_merging_hsc(self):
140 files = ("fitsheader-hsc-HSCA04090107.yaml", "fitsheader-hsc.yaml")
141 headers = [read_test_file(f, dir=self.datadir) for f in files]
142 merged = merge_headers(headers, mode="first", sort=False)
144 # The MJD-STR should come from the first file
145 self.assertAlmostEqual(merged["MJD-STR"], 57305.34729859)
147 # If we sort then MJD-STR should come from the oldest file
148 merged = merge_headers(headers, mode="first", sort=True)
149 self.assertAlmostEqual(merged["MJD-STR"], 56598.26106374757)
151 # Drop headers that differ, MJD-STR should not appear
152 merged = merge_headers(headers, mode="drop", sort=True)
153 self.assertNotIn("MJD-STR", merged)
155 # Drop but retain first MJD-STR without sorting
156 merged = merge_headers(headers, mode="drop", sort=False, first=["MJD-STR", "UT-STR"])
157 self.assertAlmostEqual(merged["MJD-STR"], 57305.34729859)
158 self.assertEqual(merged["UT-STR"], "08:20:06.598")
160 # Drop but retain first MJD-STR
161 merged = merge_headers(headers, mode="drop", sort=True, first=["MJD-STR", "UT-STR"])
162 self.assertAlmostEqual(merged["MJD-STR"], 56598.26106374757)
163 self.assertEqual(merged["UT-STR"], "06:15:55.908")
166if __name__ == "__main__": 166 ↛ 167line 166 didn't jump to line 167, because the condition on line 166 was never true
167 unittest.main()