Hide keyboard shortcuts

Hot-keys 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

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 

14import astropy.units as u 

15 

16from astro_metadata_translator import merge_headers 

17from astro_metadata_translator.tests import MetadataAssertHelper, read_test_file 

18 

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

20 

21 

22class HscTestCase(unittest.TestCase, MetadataAssertHelper): 

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

24 

25 def test_hsc_translator(self): 

26 test_data = (("fitsheader-hsc.yaml", 

27 dict(telescope="Subaru", 

28 instrument="HSC", 

29 boresight_rotation_coord="sky", 

30 dark_time=30.0*u.s, 

31 detector_exposure_id=180804850, 

32 detector_name="12", 

33 detector_unique_name="1_12", 

34 detector_num=50, 

35 detector_serial="120", 

36 exposure_id=904024, 

37 exposure_group="904024", 

38 exposure_time=30.0*u.s, 

39 object="STRIPE82L", 

40 observation_counter=904024, 

41 observation_id="HSCA90402400", 

42 observation_type="science", 

43 observation_reason="science", 

44 observing_day=20131102, 

45 physical_filter="HSC-I", 

46 pressure=621.7*u.hPa, 

47 relative_humidity=33.1, 

48 science_program="o13015", 

49 temperature=272.35*u.K, 

50 visit_id=904024, 

51 )), 

52 ("fitsheader-hsc-HSCA04090107.yaml", 

53 dict(telescope="Subaru", 

54 instrument="HSC", 

55 boresight_rotation_coord="sky", 

56 dark_time=150.0*u.s, 

57 detector_exposure_id=8180037, 

58 detector_name="07", 

59 detector_unique_name="1_07", 

60 detector_num=37, 

61 detector_serial="061", 

62 exposure_id=40900, 

63 exposure_group="40900", 

64 exposure_time=150.0*u.s, 

65 object="SSP-Wide", 

66 observation_counter=40900, 

67 observation_id="HSCA04090000", 

68 observation_type="science", 

69 observation_reason="science", 

70 observing_day=20151010, 

71 physical_filter="HSC-R", 

72 pressure=625.4*u.hPa, 

73 relative_humidity=8.6, 

74 science_program="o15426", 

75 temperature=278.35*u.K, 

76 visit_id=40900, 

77 )), 

78 ) 

79 for file, expected in test_data: 

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

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

82 

83 def test_suprimecam_translator(self): 

84 # In this case the airmass is average during observation 

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

86 test_data = (("fitsheader-suprimecam-CORR40535770.yaml", 

87 dict(telescope="Subaru", 

88 instrument="SuprimeCam", 

89 boresight_rotation_coord="unknown", 

90 dark_time=200.0*u.s, 

91 detector_exposure_id=535770, 

92 detector_name="nausicaa", 

93 detector_unique_name="nausicaa", 

94 detector_num=0, 

95 detector_serial="w67c1", 

96 exposure_id=53577, 

97 exposure_group="53577", 

98 exposure_time=200.0*u.s, 

99 object="Ecliptic Deep Field", 

100 observation_counter=53577, 

101 observation_id="SUPE00535770", 

102 observation_type="science", 

103 observation_reason="science", 

104 observing_day=20070423, 

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

106 pressure=621.5*u.hPa, 

107 relative_humidity=4.9, 

108 science_program="o07222", 

109 temperature=273.15*u.K, 

110 visit_id=53577, 

111 wcs_params=dict(amdelta=0.015))), 

112 ) 

113 for file, expected in test_data: 

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

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

116 

117 def test_merging_hsc(self): 

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

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

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

121 

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

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

124 

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

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

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

128 

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

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

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

132 

133 # Drop but retain first MJD-STR without sorting 

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

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

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

137 

138 # Drop but retain first MJD-STR 

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

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

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

142 

143 

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

145 unittest.main()