Coverage for tests/test_subaru.py: 29%

36 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-20 11:09 +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. 

11 

12import os.path 

13import unittest 

14 

15import astropy.time 

16import astropy.units as u 

17 

18from astro_metadata_translator import merge_headers 

19from astro_metadata_translator.tests import MetadataAssertHelper, read_test_file 

20 

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

22 

23 

24class HscTestCase(unittest.TestCase, MetadataAssertHelper): 

25 """Test HSC translations.""" 

26 

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

28 

29 def test_hsc_translator(self): 

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 focus_z=3.7 * u.mm, 

47 group_counter_end=904024, 

48 group_counter_start=904024, 

49 has_simulated_content=False, 

50 object="STRIPE82L", 

51 observation_counter=904024, 

52 observation_id="HSCA90402400", 

53 observation_type="science", 

54 observation_reason="science", 

55 observing_day=20131102, 

56 observing_day_offset=astropy.time.TimeDelta(0, format="sec", scale="tai"), 

57 physical_filter="HSC-I", 

58 pressure=621.7 * u.hPa, 

59 relative_humidity=33.1, 

60 science_program="o13015", 

61 temperature=272.35 * u.K, 

62 visit_id=904024, 

63 ), 

64 ), 

65 ( 

66 "fitsheader-hsc-HSCA04090107.yaml", 

67 dict( 

68 telescope="Subaru", 

69 instrument="HSC", 

70 boresight_rotation_coord="sky", 

71 dark_time=150.0 * u.s, 

72 detector_exposure_id=8180037, 

73 detector_name="07", 

74 detector_unique_name="1_07", 

75 detector_num=37, 

76 detector_serial="061", 

77 exposure_id=40900, 

78 exposure_group="40900", 

79 exposure_time=150.0 * u.s, 

80 focus_z=3.83 * u.mm, 

81 group_counter_end=40900, 

82 group_counter_start=40900, 

83 has_simulated_content=False, 

84 object="SSP-Wide", 

85 observation_counter=40900, 

86 observation_id="HSCA04090000", 

87 observation_type="science", 

88 observation_reason="science", 

89 observing_day=20151010, 

90 physical_filter="HSC-R", 

91 pressure=625.4 * u.hPa, 

92 relative_humidity=8.6, 

93 science_program="o15426", 

94 temperature=278.35 * u.K, 

95 visit_id=40900, 

96 ), 

97 ), 

98 ) 

99 for file, expected in test_data: 

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

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

102 

103 def test_suprimecam_translator(self): 

104 # In this case the airmass is average during observation 

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

106 test_data = ( 

107 ( 

108 "fitsheader-suprimecam-CORR40535770.yaml", 

109 dict( 

110 telescope="Subaru", 

111 instrument="SuprimeCam", 

112 boresight_rotation_coord="unknown", 

113 dark_time=200.0 * u.s, 

114 detector_exposure_id=535770, 

115 detector_name="nausicaa", 

116 detector_unique_name="nausicaa", 

117 detector_num=0, 

118 detector_serial="w67c1", 

119 exposure_id=53577, 

120 exposure_group="53577", 

121 exposure_time=200.0 * u.s, 

122 group_counter_end=53577, 

123 group_counter_start=53577, 

124 has_simulated_content=False, 

125 object="Ecliptic Deep Field", 

126 observation_counter=53577, 

127 observation_id="SUPE00535770", 

128 observation_type="science", 

129 observation_reason="science", 

130 observing_day=20070423, 

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

132 pressure=621.5 * u.hPa, 

133 relative_humidity=4.9, 

134 science_program="o07222", 

135 temperature=273.15 * u.K, 

136 visit_id=53577, 

137 wcs_params=dict(amdelta=0.015), 

138 ), 

139 ), 

140 ) 

141 for file, expected in test_data: 

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

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

144 

145 def test_merging_hsc(self): 

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

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

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

149 

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

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

152 

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

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

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

156 

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

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

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

160 

161 # Drop but retain first MJD-STR without sorting 

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

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

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

165 

166 # Drop but retain first MJD-STR 

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

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

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

170 

171 

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

173 unittest.main()