Coverage for tests/test_subaru.py: 28%

35 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-04 14:10 -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. 

11 

12import os.path 

13import unittest 

14 

15import astropy.units as u 

16 

17from astro_metadata_translator import merge_headers 

18from astro_metadata_translator.tests import MetadataAssertHelper, read_test_file 

19 

20TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

21 

22 

23class HscTestCase(unittest.TestCase, MetadataAssertHelper): 

24 """Test HSC translations.""" 

25 

26 datadir = os.path.join(TESTDIR, "data") 

27 

28 def test_hsc_translator(self): 

29 test_data = ( 

30 ( 

31 "fitsheader-hsc.yaml", 

32 dict( 

33 telescope="Subaru", 

34 instrument="HSC", 

35 boresight_rotation_coord="sky", 

36 dark_time=30.0 * u.s, 

37 detector_exposure_id=180804850, 

38 detector_name="12", 

39 detector_unique_name="1_12", 

40 detector_num=50, 

41 detector_serial="120", 

42 exposure_id=904024, 

43 exposure_group="904024", 

44 exposure_time=30.0 * u.s, 

45 focus_z=3.7 * u.mm, 

46 group_counter_end=904024, 

47 group_counter_start=904024, 

48 has_simulated_content=False, 

49 object="STRIPE82L", 

50 observation_counter=904024, 

51 observation_id="HSCA90402400", 

52 observation_type="science", 

53 observation_reason="science", 

54 observing_day=20131102, 

55 physical_filter="HSC-I", 

56 pressure=621.7 * u.hPa, 

57 relative_humidity=33.1, 

58 science_program="o13015", 

59 temperature=272.35 * u.K, 

60 visit_id=904024, 

61 ), 

62 ), 

63 ( 

64 "fitsheader-hsc-HSCA04090107.yaml", 

65 dict( 

66 telescope="Subaru", 

67 instrument="HSC", 

68 boresight_rotation_coord="sky", 

69 dark_time=150.0 * u.s, 

70 detector_exposure_id=8180037, 

71 detector_name="07", 

72 detector_unique_name="1_07", 

73 detector_num=37, 

74 detector_serial="061", 

75 exposure_id=40900, 

76 exposure_group="40900", 

77 exposure_time=150.0 * u.s, 

78 focus_z=3.83 * u.mm, 

79 group_counter_end=40900, 

80 group_counter_start=40900, 

81 has_simulated_content=False, 

82 object="SSP-Wide", 

83 observation_counter=40900, 

84 observation_id="HSCA04090000", 

85 observation_type="science", 

86 observation_reason="science", 

87 observing_day=20151010, 

88 physical_filter="HSC-R", 

89 pressure=625.4 * u.hPa, 

90 relative_humidity=8.6, 

91 science_program="o15426", 

92 temperature=278.35 * u.K, 

93 visit_id=40900, 

94 ), 

95 ), 

96 ) 

97 for file, expected in test_data: 

98 with self.subTest(f"Testing {file}"): 

99 self.assertObservationInfoFromYaml(file, dir=self.datadir, **expected) 

100 

101 def test_suprimecam_translator(self): 

102 # In this case the airmass is average during observation 

103 # but it looks like ALTITUDE is from a different time so loosen amdelta 

104 test_data = ( 

105 ( 

106 "fitsheader-suprimecam-CORR40535770.yaml", 

107 dict( 

108 telescope="Subaru", 

109 instrument="SuprimeCam", 

110 boresight_rotation_coord="unknown", 

111 dark_time=200.0 * u.s, 

112 detector_exposure_id=535770, 

113 detector_name="nausicaa", 

114 detector_unique_name="nausicaa", 

115 detector_num=0, 

116 detector_serial="w67c1", 

117 exposure_id=53577, 

118 exposure_group="53577", 

119 exposure_time=200.0 * u.s, 

120 group_counter_end=53577, 

121 group_counter_start=53577, 

122 has_simulated_content=False, 

123 object="Ecliptic Deep Field", 

124 observation_counter=53577, 

125 observation_id="SUPE00535770", 

126 observation_type="science", 

127 observation_reason="science", 

128 observing_day=20070423, 

129 physical_filter="W-S-R+", 

130 pressure=621.5 * u.hPa, 

131 relative_humidity=4.9, 

132 science_program="o07222", 

133 temperature=273.15 * u.K, 

134 visit_id=53577, 

135 wcs_params=dict(amdelta=0.015), 

136 ), 

137 ), 

138 ) 

139 for file, expected in test_data: 

140 with self.subTest(f"Testing {file}"): 

141 self.assertObservationInfoFromYaml(file, dir=self.datadir, **expected) 

142 

143 def test_merging_hsc(self): 

144 files = ("fitsheader-hsc-HSCA04090107.yaml", "fitsheader-hsc.yaml") 

145 headers = [read_test_file(f, dir=self.datadir) for f in files] 

146 merged = merge_headers(headers, mode="first", sort=False) 

147 

148 # The MJD-STR should come from the first file 

149 self.assertAlmostEqual(merged["MJD-STR"], 57305.34729859) 

150 

151 # If we sort then MJD-STR should come from the oldest file 

152 merged = merge_headers(headers, mode="first", sort=True) 

153 self.assertAlmostEqual(merged["MJD-STR"], 56598.26106374757) 

154 

155 # Drop headers that differ, MJD-STR should not appear 

156 merged = merge_headers(headers, mode="drop", sort=True) 

157 self.assertNotIn("MJD-STR", merged) 

158 

159 # Drop but retain first MJD-STR without sorting 

160 merged = merge_headers(headers, mode="drop", sort=False, first=["MJD-STR", "UT-STR"]) 

161 self.assertAlmostEqual(merged["MJD-STR"], 57305.34729859) 

162 self.assertEqual(merged["UT-STR"], "08:20:06.598") 

163 

164 # Drop but retain first MJD-STR 

165 merged = merge_headers(headers, mode="drop", sort=True, first=["MJD-STR", "UT-STR"]) 

166 self.assertAlmostEqual(merged["MJD-STR"], 56598.26106374757) 

167 self.assertEqual(merged["UT-STR"], "06:15:55.908") 

168 

169 

170if __name__ == "__main__": 170 ↛ 171line 170 didn't jump to line 171, because the condition on line 170 was never true

171 unittest.main()