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 physical_filter="HSC-I", 

43 pressure=621.7*u.hPa, 

44 relative_humidity=33.1, 

45 science_program="o13015", 

46 temperature=272.35*u.K, 

47 visit_id=904024, 

48 )), 

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

50 dict(telescope="Subaru", 

51 instrument="HSC", 

52 boresight_rotation_coord="sky", 

53 dark_time=150.0*u.s, 

54 detector_exposure_id=8180037, 

55 detector_name="07", 

56 detector_unique_name="1_07", 

57 detector_num=37, 

58 detector_serial="061", 

59 exposure_id=40900, 

60 exposure_group="40900", 

61 exposure_time=150.0*u.s, 

62 object="SSP-Wide", 

63 observation_id="HSCA04090000", 

64 observation_type="science", 

65 physical_filter="HSC-R", 

66 pressure=625.4*u.hPa, 

67 relative_humidity=8.6, 

68 science_program="o15426", 

69 temperature=278.35*u.K, 

70 visit_id=40900, 

71 )), 

72 ) 

73 for file, expected in test_data: 

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

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

76 

77 def test_suprimecam_translator(self): 

78 # In this case the airmass is average during observation 

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

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

81 dict(telescope="Subaru", 

82 instrument="SuprimeCam", 

83 boresight_rotation_coord="unknown", 

84 dark_time=200.0*u.s, 

85 detector_exposure_id=535770, 

86 detector_name="nausicaa", 

87 detector_unique_name="nausicaa", 

88 detector_num=0, 

89 detector_serial="w67c1", 

90 exposure_id=53577, 

91 exposure_group="53577", 

92 exposure_time=200.0*u.s, 

93 object="Ecliptic Deep Field", 

94 observation_id="SUPE00535770", 

95 observation_type="science", 

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

97 pressure=621.5*u.hPa, 

98 relative_humidity=4.9, 

99 science_program="o07222", 

100 temperature=273.15*u.K, 

101 visit_id=53577, 

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

103 ) 

104 for file, expected in test_data: 

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

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

107 

108 def test_merging_hsc(self): 

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

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

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

112 

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

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

115 

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

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

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

119 

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

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

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

123 

124 # Drop but retain first MJD-STR without sorting 

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

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

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

128 

129 # Drop but retain first MJD-STR 

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

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

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

133 

134 

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

136 unittest.main()