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

1import os 

2import unittest 

3import lsst.utils.tests 

4 

5from lsst.sims.utils import SpecMap, defaultSpecMap 

6 

7 

8def setup_module(module): 

9 lsst.utils.tests.init() 

10 

11 

12class SpecMapTest(unittest.TestCase): 

13 

14 def verifyFile(self, file_name, dir_name, testSpecMap=defaultSpecMap): 

15 """ 

16 Verify that testSpecMap[file_name] results in os.path.join(dir_name, file_name+'.gz') 

17 """ 

18 test_name = testSpecMap[file_name] 

19 control_name = os.path.join(dir_name, file_name + '.gz') 

20 msg = '%s should map to %s; it actually maps to %s' % (file_name, control_name, test_name) 

21 self.assertEqual(test_name, control_name, msg=msg) 

22 

23 add_space = file_name + ' ' 

24 self.assertNotEqual(add_space, file_name) 

25 test_name = testSpecMap[add_space] 

26 msg = '%s should map to %s; it actually maps to %s' % (add_space, control_name, test_name) 

27 self.assertEqual(test_name, control_name, msg=msg) 

28 

29 add_space = ' ' + file_name 

30 self.assertNotEqual(add_space, file_name) 

31 test_name = testSpecMap[add_space] 

32 msg = '%s should map to %s; it actually maps to %s' % (add_space, control_name, test_name) 

33 self.assertEqual(test_name, control_name, msg=msg) 

34 

35 add_gz = file_name + '.gz' 

36 self.assertNotEqual(add_gz, file_name) 

37 test_name = testSpecMap[add_gz] 

38 msg = '%s should map to %s; it actually maps to %s' % (add_gz, control_name, test_name) 

39 self.assertEqual(test_name, control_name, msg=msg) 

40 

41 def testMLT(self): 

42 """ 

43 Test that defaultSpecMap correctly locates MLT dwarf spectra 

44 """ 

45 self.verifyFile('lte004-3.5-0.0a+0.0.BT-Settl.spec', 'starSED/mlt') 

46 

47 def test_m_spec(self): 

48 """ 

49 Test that defaultSpecMap correctly finds old MLT dwarf spectra 

50 that begin with 'm' 

51 """ 

52 self.verifyFile('m5.1Full.dat', 'starSED/old_mlt') 

53 

54 def test_l4_spec(self): 

55 """ 

56 Test that defaultSpecMap correctly finds l4Full.dat 

57 """ 

58 self.verifyFile('l4Full.dat', 'starSED/old_mlt') 

59 

60 def test_L_spec(self): 

61 """ 

62 Test that defaultSpecMap correctly find the L#_# spectra 

63 """ 

64 self.verifyFile('L2_0Full.dat', 'starSED/old_mlt') 

65 

66 def test_burrows_spec(self): 

67 """ 

68 Test that defaultSpecMap correctly find the burrows spectra 

69 """ 

70 self.verifyFile('burrows+2006c91.21_T1400_g5.5_cf_0.3X', 

71 'starSED/old_mlt') 

72 

73 def testBergeron(self): 

74 """ 

75 Test that defaultSpecMap correctly locates the bergeron spectra 

76 """ 

77 self.verifyFile('bergeron_4750_85.dat_4900', 'starSED/wDs') 

78 

79 def testKurucz(self): 

80 """ 

81 Test that defaultSpecMap correctly locates the kurucz spectra 

82 """ 

83 self.verifyFile('km30_5000.fits_g10_5040', 'starSED/kurucz') 

84 self.verifyFile('kp10_9000.fits_g40_9100', 'starSED/kurucz') 

85 

86 def testGalaxy(self): 

87 """ 

88 Test that defaultSpecMap correctly locates the galaxy SEDs 

89 """ 

90 self.verifyFile('Const.79E06.002Z.spec', 'galaxySED') 

91 self.verifyFile('Inst.79E06.02Z.spec', 'galaxySED') 

92 self.verifyFile('Exp.40E08.02Z.spec', 'galaxySED') 

93 self.verifyFile('Burst.40E08.002Z.spec', 'galaxySED') 

94 

95 def testDirDict(self): 

96 """ 

97 Test a user-defined SpecMap with a dirDict 

98 """ 

99 dirDictTestMap = SpecMap(dirDict={'(^lte)': 'silly_sub_dir'}) 

100 self.verifyFile('lte_11111.txt', 'silly_sub_dir', 

101 testSpecMap=dirDictTestMap) 

102 self.verifyFile('Const.79E06.002Z.spec', 'galaxySED', 

103 testSpecMap=dirDictTestMap) 

104 self.verifyFile('Inst.79E06.02Z.spec', 'galaxySED', 

105 testSpecMap=dirDictTestMap) 

106 self.verifyFile('Exp.40E08.02Z.spec', 'galaxySED', 

107 testSpecMap=dirDictTestMap) 

108 self.verifyFile('Burst.40E08.002Z.spec', 'galaxySED', 

109 testSpecMap=dirDictTestMap) 

110 self.verifyFile('km30_5000.fits_g10_5040', 

111 'starSED/kurucz', testSpecMap=dirDictTestMap) 

112 self.verifyFile('kp10_9000.fits_g40_9100', 

113 'starSED/kurucz', testSpecMap=dirDictTestMap) 

114 self.verifyFile('burrows+2006c91.21_T1400_g5.5_cf_0.3X', 

115 'starSED/old_mlt', testSpecMap=dirDictTestMap) 

116 self.verifyFile('L2_0Full.dat', 'starSED/old_mlt', 

117 testSpecMap=dirDictTestMap) 

118 self.verifyFile('m5.1Full.dat', 'starSED/old_mlt', 

119 testSpecMap=dirDictTestMap) 

120 

121 def testFileDict(self): 

122 """ 

123 Test a user-defined SpecMap with a fileDict 

124 """ 

125 fileDictTestMap = SpecMap(fileDict={'abcd.txt': 'file_dict_test_dir/abcd.txt.gz'}) 

126 

127 self.assertEqual(fileDictTestMap['abcd.txt'], 'file_dict_test_dir/abcd.txt.gz') 

128 self.verifyFile('lte_11111.txt', 'starSED/mlt', 

129 testSpecMap=fileDictTestMap) 

130 self.verifyFile('Const.79E06.002Z.spec', 'galaxySED', 

131 testSpecMap=fileDictTestMap) 

132 self.verifyFile('Inst.79E06.02Z.spec', 'galaxySED', 

133 testSpecMap=fileDictTestMap) 

134 self.verifyFile('Exp.40E08.02Z.spec', 'galaxySED', 

135 testSpecMap=fileDictTestMap) 

136 self.verifyFile('Burst.40E08.002Z.spec', 'galaxySED', 

137 testSpecMap=fileDictTestMap) 

138 self.verifyFile('km30_5000.fits_g10_5040', 

139 'starSED/kurucz', testSpecMap=fileDictTestMap) 

140 self.verifyFile('kp10_9000.fits_g40_9100', 

141 'starSED/kurucz', testSpecMap=fileDictTestMap) 

142 self.verifyFile('burrows+2006c91.21_T1400_g5.5_cf_0.3X', 

143 'starSED/old_mlt', testSpecMap=fileDictTestMap) 

144 self.verifyFile('L2_0Full.dat', 'starSED/old_mlt', 

145 testSpecMap=fileDictTestMap) 

146 self.verifyFile('m5.1Full.dat', 'starSED/old_mlt', 

147 testSpecMap=fileDictTestMap) 

148 

149 def testFileAndDirDict(self): 

150 """ 

151 Test a user-defined SpecMap with both a fileDict and a dirDict 

152 """ 

153 testMap = SpecMap(fileDict={'abcd.txt': 'file_dir/abcd.txt.gz'}, 

154 dirDict={'(^burrows)': 'dir_dir'}) 

155 

156 self.assertEqual(testMap['abcd.txt'], 'file_dir/abcd.txt.gz') 

157 self.verifyFile('lte_11111.txt', 'starSED/mlt', testSpecMap=testMap) 

158 self.verifyFile('Const.79E06.002Z.spec', 

159 'galaxySED', testSpecMap=testMap) 

160 self.verifyFile('Inst.79E06.02Z.spec', 

161 'galaxySED', testSpecMap=testMap) 

162 self.verifyFile('Exp.40E08.02Z.spec', 'galaxySED', testSpecMap=testMap) 

163 self.verifyFile('Burst.40E08.002Z.spec', 

164 'galaxySED', testSpecMap=testMap) 

165 self.verifyFile('km30_5000.fits_g10_5040', 

166 'starSED/kurucz', testSpecMap=testMap) 

167 self.verifyFile('kp10_9000.fits_g40_9100', 

168 'starSED/kurucz', testSpecMap=testMap) 

169 self.verifyFile('burrows+2006c91.21_T1400_g5.5_cf_0.3X', 

170 'dir_dir', testSpecMap=testMap) 

171 self.verifyFile('L2_0Full.dat', 'starSED/old_mlt', testSpecMap=testMap) 

172 self.verifyFile('m5.1Full.dat', 'starSED/old_mlt', testSpecMap=testMap) 

173 

174 def test_contains(self): 

175 """ 

176 Test that 'k in SpecMap' works as it should 

177 """ 

178 

179 testMap = SpecMap(fileDict={'abcd.txt': 'file_dir/abcd.txt.gz'}, 

180 dirDict={'(^burrows)': 'dir_dir'}) 

181 

182 self.assertFalse('banana' in testMap) 

183 self.assertTrue('abcd.txt' in testMap) 

184 self.assertTrue('burrows_123.txt' in testMap) 

185 

186 

187class MemoryTestClass(lsst.utils.tests.MemoryTestCase): 

188 pass 

189 

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

191 lsst.utils.tests.init() 

192 unittest.main()