Coverage for tests/test_subaru.py: 33%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

35 statements  

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 object="STRIPE82L", 

44 observation_counter=904024, 

45 observation_id="HSCA90402400", 

46 observation_type="science", 

47 observation_reason="science", 

48 observing_day=20131102, 

49 physical_filter="HSC-I", 

50 pressure=621.7 * u.hPa, 

51 relative_humidity=33.1, 

52 science_program="o13015", 

53 temperature=272.35 * u.K, 

54 visit_id=904024, 

55 ), 

56 ), 

57 ( 

58 "fitsheader-hsc-HSCA04090107.yaml", 

59 dict( 

60 telescope="Subaru", 

61 instrument="HSC", 

62 boresight_rotation_coord="sky", 

63 dark_time=150.0 * u.s, 

64 detector_exposure_id=8180037, 

65 detector_name="07", 

66 detector_unique_name="1_07", 

67 detector_num=37, 

68 detector_serial="061", 

69 exposure_id=40900, 

70 exposure_group="40900", 

71 exposure_time=150.0 * u.s, 

72 object="SSP-Wide", 

73 observation_counter=40900, 

74 observation_id="HSCA04090000", 

75 observation_type="science", 

76 observation_reason="science", 

77 observing_day=20151010, 

78 physical_filter="HSC-R", 

79 pressure=625.4 * u.hPa, 

80 relative_humidity=8.6, 

81 science_program="o15426", 

82 temperature=278.35 * u.K, 

83 visit_id=40900, 

84 ), 

85 ), 

86 ) 

87 for file, expected in test_data: 

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

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

90 

91 def test_suprimecam_translator(self): 

92 # In this case the airmass is average during observation 

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

94 test_data = ( 

95 ( 

96 "fitsheader-suprimecam-CORR40535770.yaml", 

97 dict( 

98 telescope="Subaru", 

99 instrument="SuprimeCam", 

100 boresight_rotation_coord="unknown", 

101 dark_time=200.0 * u.s, 

102 detector_exposure_id=535770, 

103 detector_name="nausicaa", 

104 detector_unique_name="nausicaa", 

105 detector_num=0, 

106 detector_serial="w67c1", 

107 exposure_id=53577, 

108 exposure_group="53577", 

109 exposure_time=200.0 * u.s, 

110 object="Ecliptic Deep Field", 

111 observation_counter=53577, 

112 observation_id="SUPE00535770", 

113 observation_type="science", 

114 observation_reason="science", 

115 observing_day=20070423, 

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

117 pressure=621.5 * u.hPa, 

118 relative_humidity=4.9, 

119 science_program="o07222", 

120 temperature=273.15 * u.K, 

121 visit_id=53577, 

122 wcs_params=dict(amdelta=0.015), 

123 ), 

124 ), 

125 ) 

126 for file, expected in test_data: 

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

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

129 

130 def test_merging_hsc(self): 

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

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

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

134 

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

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

137 

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

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

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

141 

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

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

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

145 

146 # Drop but retain first MJD-STR without sorting 

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

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

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

150 

151 # Drop but retain first MJD-STR 

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

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

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

155 

156 

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

158 unittest.main()