Coverage for tests/test_filter_defs.py: 18%

55 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-27 11:48 +0000

1# This file is part of obs_lsst. 

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 COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22import os 

23import unittest 

24from lsst.obs.lsst import ( 

25 LSSTCAM_FILTER_DEFINITIONS, 

26 LATISS_FILTER_DEFINITIONS, 

27 LSSTCAM_IMSIM_FILTER_DEFINITIONS, 

28 TS3_FILTER_DEFINITIONS, 

29 TS8_FILTER_DEFINITIONS, 

30 COMCAM_FILTER_DEFINITIONS, 

31 GENERIC_FILTER_DEFINITIONS, 

32) 

33import lsst.obs.lsst.translators # noqa: F401 -- register the translators 

34 

35from astro_metadata_translator import ObservationInfo 

36from astro_metadata_translator.tests import read_test_file 

37 

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

39 

40 

41class FilterDefTestCase(unittest.TestCase): 

42 """Each test reads in raw headers from YAML files, constructs an 

43 `ObservationInfo`, and checks that the filter definitions for the 

44 corresponding instrument contains the `physical_filter` value 

45 computed by the translator code. 

46 """ 

47 

48 datadir = os.path.join(TESTDIR, "headers") 

49 

50 def assert_in_filter_defs(self, header_file, filter_def_set): 

51 header = read_test_file(header_file, dir=self.datadir) 

52 obs_info = ObservationInfo(header, pedantic=True, filename=header_file) 

53 self.assertIn(obs_info.physical_filter, filter_def_set) 

54 

55 def test_lsstCam_filterdefs(self): 

56 filter_def_set = set(_.physical_filter for _ in LSSTCAM_FILTER_DEFINITIONS) 

57 test_data = ( 

58 "lsstCam-MC_C_20190319_000001_R10_S02.yaml", 

59 "lsstCam-MC_C_20190319_000001_R22_S21.yaml", 

60 "lsstCam-MC_C_20190322_000002_R10_S22.yaml", 

61 "lsstCam-MC_C_20190406_000643_R10_S00.yaml", 

62 ) 

63 for filename in test_data: 

64 with self.subTest(f"Testing {filename}"): 

65 self.assert_in_filter_defs(filename, filter_def_set) 

66 

67 def test_latiss_filterdefs(self): 

68 filter_def_set = set(_.physical_filter for _ in LATISS_FILTER_DEFINITIONS) 

69 test_data = ( 

70 "latiss-2018-09-20-05700065-det000.yaml", 

71 "latiss-AT_O_20190306_000014.yaml", 

72 "latiss-AT_O_20190329_000022-ats-wfs_ccd.yaml", 

73 "latiss-AT_O_20190915_000037.yaml", 

74 "latiss-AT_O_20191031_000004.yaml", 

75 "latiss-AT_O_20191104_000003.yaml", 

76 "latiss-AT_O_20191113_000061.yaml", 

77 "latiss-AT_O_20200121_000045.yaml", 

78 "latiss-AT_O_20200128_000335.yaml", 

79 "latiss-AT_O_20200128_000379.yaml", 

80 "latiss-AT_O_20210210_000011.yaml", 

81 "latiss-AT_O_20210212_000006.yaml", 

82 "latiss-AT_O_20220405_000348.yaml", 

83 "latiss-AT_O_20220405_000349.yaml", 

84 "latiss-AT_O_20230321_000053.yaml", 

85 "latiss-future.yaml", 

86 ) 

87 for filename in test_data: 

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

89 self.assert_in_filter_defs(filename, filter_def_set) 

90 

91 def test_imsim_filterdefs(self): 

92 filter_def_set = set( 

93 _.physical_filter for _ in LSSTCAM_IMSIM_FILTER_DEFINITIONS 

94 ) 

95 test_data = ( 

96 "imsim-bias-lsst_a_3010002_R11_S00.yaml", 

97 "imsim-dark-lsst_a_4010003_R11_S11.yaml", 

98 "imsim-flats-lsst_a_5000007_R11_S20_i.yaml", 

99 "imsim-lsst_a_204595_R11_S02_i.yaml", 

100 ) 

101 for filename in test_data: 

102 with self.subTest(f"Testing {filename}"): 

103 self.assert_in_filter_defs(filename, filter_def_set) 

104 

105 def test_ts3_filterdefs(self): 

106 filter_def_set = set(_.physical_filter for _ in TS3_FILTER_DEFINITIONS) 

107 test_data = ( 

108 "ts3-E2V-CCD250-411_lambda_flat_1000_025_20181115075559.yaml", 

109 "ts3-ITL-3800C-098_lambda_flat_1000_067_20160722020740.yaml", 

110 ) 

111 for filename in test_data: 

112 with self.subTest(f"Testing {filename}"): 

113 self.assert_in_filter_defs(filename, filter_def_set) 

114 

115 def test_ts8_filterdefs(self): 

116 filter_def_set = set(_.physical_filter for _ in TS8_FILTER_DEFINITIONS) 

117 test_data = ( 

118 "ts8-E2V-CCD250-179_lambda_bias_024_6006D_20180724104156.yaml", 

119 "ts8-E2V-CCD250-200-Dev_lambda_flat_0700_6006D_20180724102845.yaml", 

120 "ts8-E2V-CCD250-220_fe55_fe55_094_6288_20171215114006.yaml", 

121 "ts8-TS_C_20220711_000174_R22_S00.yaml", 

122 "ts8-TS_C_20230512_000021_R22_S02.yaml", 

123 ) 

124 for filename in test_data: 

125 with self.subTest(f"Testing {filename}"): 

126 self.assert_in_filter_defs(filename, filter_def_set) 

127 

128 def test_comCam_filterdefs(self): 

129 filter_def_set = set(_.physical_filter for _ in COMCAM_FILTER_DEFINITIONS) 

130 test_data = ( 

131 "comCam-CC_C_20190526_000223_R22_S01.yaml", 

132 "comCam-CC_C_20190530_000001_R22_S00.yaml", 

133 "comCam-CC_H_20100217_006001_R22_S00.yaml", 

134 ) 

135 for filename in test_data: 

136 with self.subTest(f"Testing {filename}"): 

137 self.assert_in_filter_defs(filename, filter_def_set) 

138 

139 def test_generic_filterdefs(self): 

140 filter_def_set = set(_.physical_filter for _ in GENERIC_FILTER_DEFINITIONS) 

141 test_data = ( 

142 "phosim-lsst_a_204595_f3_R11_S02_E000.yaml", 

143 "lsstCam-MC_H_20100217_000032_R22_S00.yaml", # This is a phosim header 

144 "UCD-E2V-CCD250-112-04_flat_flat_100_20181205153143.yaml", 

145 "UCD-ITL-3800C-002_flat_flat_100_20180530080354.yaml", 

146 ) 

147 for filename in test_data: 

148 with self.subTest(f"Testing {filename}"): 

149 self.assert_in_filter_defs(filename, filter_def_set)