Coverage for tests / test_cfht.py: 48%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-30 08:43 +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.time 

16import astropy.units as u 

17 

18from astro_metadata_translator import ObservationInfo 

19from astro_metadata_translator.tests import MetadataAssertHelper, read_test_file 

20 

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

22 

23 

24class MegaPrimeTestCase(unittest.TestCase, MetadataAssertHelper): 

25 """Test CFHT Megaprime translations.""" 

26 

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

28 

29 def test_megaprime_translator(self) -> None: 

30 test_data = ( 

31 ( 

32 "fitsheader-megaprime.yaml", 

33 dict( 

34 telescope="CFHT 3.6m", 

35 instrument="MegaPrime", 

36 boresight_rotation_coord="sky", 

37 boresight_rotation_angle=0 * u.degree, 

38 dark_time=615.0 * u.s, 

39 detector_exposure_id=37398350, 

40 detector_name="ccd02", 

41 detector_unique_name="ccd02", 

42 detector_num=2, 

43 detector_serial="8352-15-3", 

44 exposure_id=1038843, 

45 exposure_group="1038843", 

46 exposure_time=615.037 * u.s, 

47 exposure_time_requested=615.0 * u.s, 

48 focus_z=0.0 * u.mm, # default value 

49 group_counter_end=1038843, 

50 group_counter_start=1038843, 

51 has_simulated_content=False, 

52 object="w2.+2+2", 

53 observation_counter=1038843, 

54 observation_id="1038843", 

55 observation_type="science", 

56 observation_reason="science", 

57 observing_day=20081101, 

58 observing_day_offset=astropy.time.TimeDelta(0, format="sec", scale="tai"), 

59 physical_filter="i.MP9702", 

60 pressure=617.65 * u.hPa, 

61 relative_humidity=39.77, 

62 science_program="08BL05", 

63 temperature=0.9 * u.deg_C, 

64 visit_id=1038843, 

65 ), 

66 ), 

67 ( 

68 "fitsheader-megaprime-calexp-849375-14.yaml", 

69 dict( 

70 telescope="CFHT 3.6m", 

71 instrument="MegaPrime", 

72 boresight_rotation_coord="sky", 

73 boresight_rotation_angle=0 * u.degree, 

74 dark_time=300.0 * u.s, 

75 detector_exposure_id=30577599, 

76 detector_name="ccd99", 

77 detector_unique_name="ccd99", 

78 detector_num=99, 

79 detector_serial="8434-13-5", 

80 exposure_id=849375, 

81 exposure_group="849375", 

82 exposure_time=300.202 * u.s, 

83 exposure_time_requested=300.0 * u.s, 

84 focus_z=0.0 * u.mm, # default value 

85 group_counter_end=849375, 

86 group_counter_start=849375, 

87 has_simulated_content=False, 

88 object="D3", 

89 observation_counter=849375, 

90 observation_id="849375", 

91 observation_type="science", 

92 observation_reason="science", 

93 observing_day=20060520, 

94 physical_filter="r", 

95 pressure=615.79 * u.hPa, 

96 relative_humidity=15.76, 

97 science_program="06AL01", 

98 temperature=1.75 * u.deg_C, 

99 visit_id=849375, 

100 ), 

101 ), 

102 ) 

103 for file, expected in test_data: 

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

105 self.assertObservationInfoFromYaml(file, self.datadir, **expected) 

106 

107 def test_megaprime_stripping(self) -> None: 

108 header = read_test_file("fitsheader-megaprime.yaml", dir=self.datadir) 

109 v1 = ObservationInfo(header) 

110 

111 # Check that headers have been removed 

112 new_hdr = v1.stripped_header() 

113 self.assertNotIn("INSTRUME", new_hdr) 

114 self.assertNotIn("TELESCOP", new_hdr) 

115 self.assertIn("CCD", new_hdr) 

116 

117 

118if __name__ == "__main__": 

119 unittest.main()