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_id="HSCA90402400", 

41 observation_type="science", 

42 observation_reason="science", 

43 physical_filter="HSC-I", 

44 pressure=621.7*u.hPa, 

45 relative_humidity=33.1, 

46 science_program="o13015", 

47 temperature=272.35*u.K, 

48 visit_id=904024, 

49 )), 

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

51 dict(telescope="Subaru", 

52 instrument="HSC", 

53 boresight_rotation_coord="sky", 

54 dark_time=150.0*u.s, 

55 detector_exposure_id=8180037, 

56 detector_name="07", 

57 detector_unique_name="1_07", 

58 detector_num=37, 

59 detector_serial="061", 

60 exposure_id=40900, 

61 exposure_group="40900", 

62 exposure_time=150.0*u.s, 

63 object="SSP-Wide", 

64 observation_id="HSCA04090000", 

65 observation_type="science", 

66 observation_reason="science", 

67 physical_filter="HSC-R", 

68 pressure=625.4*u.hPa, 

69 relative_humidity=8.6, 

70 science_program="o15426", 

71 temperature=278.35*u.K, 

72 visit_id=40900, 

73 )), 

74 ) 

75 for file, expected in test_data: 

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

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

78 

79 def test_suprimecam_translator(self): 

80 # In this case the airmass is average during observation 

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

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

83 dict(telescope="Subaru", 

84 instrument="SuprimeCam", 

85 boresight_rotation_coord="unknown", 

86 dark_time=200.0*u.s, 

87 detector_exposure_id=535770, 

88 detector_name="nausicaa", 

89 detector_unique_name="nausicaa", 

90 detector_num=0, 

91 detector_serial="w67c1", 

92 exposure_id=53577, 

93 exposure_group="53577", 

94 exposure_time=200.0*u.s, 

95 object="Ecliptic Deep Field", 

96 observation_id="SUPE00535770", 

97 observation_type="science", 

98 observation_reason="science", 

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

100 pressure=621.5*u.hPa, 

101 relative_humidity=4.9, 

102 science_program="o07222", 

103 temperature=273.15*u.K, 

104 visit_id=53577, 

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

106 ) 

107 for file, expected in test_data: 

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

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

110 

111 def test_merging_hsc(self): 

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

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

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

115 

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

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

118 

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

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

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

122 

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

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

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

126 

127 # Drop but retain first MJD-STR without sorting 

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

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

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

131 

132 # Drop but retain first MJD-STR 

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

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

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

136 

137 

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

139 unittest.main()