Coverage for tests/test_subaru.py: 28%

35 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-21 10:05 +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.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 datadir = os.path.join(TESTDIR, "data") 

25 

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

44 group_counter_end=904024, 

45 group_counter_start=904024, 

46 has_simulated_content=False, 

47 object="STRIPE82L", 

48 observation_counter=904024, 

49 observation_id="HSCA90402400", 

50 observation_type="science", 

51 observation_reason="science", 

52 observing_day=20131102, 

53 physical_filter="HSC-I", 

54 pressure=621.7 * u.hPa, 

55 relative_humidity=33.1, 

56 science_program="o13015", 

57 temperature=272.35 * u.K, 

58 visit_id=904024, 

59 ), 

60 ), 

61 ( 

62 "fitsheader-hsc-HSCA04090107.yaml", 

63 dict( 

64 telescope="Subaru", 

65 instrument="HSC", 

66 boresight_rotation_coord="sky", 

67 dark_time=150.0 * u.s, 

68 detector_exposure_id=8180037, 

69 detector_name="07", 

70 detector_unique_name="1_07", 

71 detector_num=37, 

72 detector_serial="061", 

73 exposure_id=40900, 

74 exposure_group="40900", 

75 exposure_time=150.0 * u.s, 

76 focus_z=3.83 * u.mm, 

77 group_counter_end=40900, 

78 group_counter_start=40900, 

79 has_simulated_content=False, 

80 object="SSP-Wide", 

81 observation_counter=40900, 

82 observation_id="HSCA04090000", 

83 observation_type="science", 

84 observation_reason="science", 

85 observing_day=20151010, 

86 physical_filter="HSC-R", 

87 pressure=625.4 * u.hPa, 

88 relative_humidity=8.6, 

89 science_program="o15426", 

90 temperature=278.35 * u.K, 

91 visit_id=40900, 

92 ), 

93 ), 

94 ) 

95 for file, expected in test_data: 

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

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

98 

99 def test_suprimecam_translator(self): 

100 # In this case the airmass is average during observation 

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

102 test_data = ( 

103 ( 

104 "fitsheader-suprimecam-CORR40535770.yaml", 

105 dict( 

106 telescope="Subaru", 

107 instrument="SuprimeCam", 

108 boresight_rotation_coord="unknown", 

109 dark_time=200.0 * u.s, 

110 detector_exposure_id=535770, 

111 detector_name="nausicaa", 

112 detector_unique_name="nausicaa", 

113 detector_num=0, 

114 detector_serial="w67c1", 

115 exposure_id=53577, 

116 exposure_group="53577", 

117 exposure_time=200.0 * u.s, 

118 group_counter_end=53577, 

119 group_counter_start=53577, 

120 has_simulated_content=False, 

121 object="Ecliptic Deep Field", 

122 observation_counter=53577, 

123 observation_id="SUPE00535770", 

124 observation_type="science", 

125 observation_reason="science", 

126 observing_day=20070423, 

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

128 pressure=621.5 * u.hPa, 

129 relative_humidity=4.9, 

130 science_program="o07222", 

131 temperature=273.15 * u.K, 

132 visit_id=53577, 

133 wcs_params=dict(amdelta=0.015), 

134 ), 

135 ), 

136 ) 

137 for file, expected in test_data: 

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

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

140 

141 def test_merging_hsc(self): 

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

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

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

145 

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

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

148 

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

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

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

152 

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

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

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

156 

157 # Drop but retain first MJD-STR without sorting 

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

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

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

161 

162 # Drop but retain first MJD-STR 

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

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

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

166 

167 

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

169 unittest.main()