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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

import os 

import unittest 

import lsst.utils.tests 

 

from lsst.sims.utils import SpecMap, defaultSpecMap 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class SpecMapTest(unittest.TestCase): 

 

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

""" 

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

""" 

test_name = testSpecMap[file_name] 

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

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

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

 

add_space = file_name + ' ' 

self.assertNotEqual(add_space, file_name) 

test_name = testSpecMap[add_space] 

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

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

 

add_space = ' ' + file_name 

self.assertNotEqual(add_space, file_name) 

test_name = testSpecMap[add_space] 

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

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

 

add_gz = file_name + '.gz' 

self.assertNotEqual(add_gz, file_name) 

test_name = testSpecMap[add_gz] 

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

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

 

def testMLT(self): 

""" 

Test that defaultSpecMap correctly locates MLT dwarf spectra 

""" 

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

 

def test_m_spec(self): 

""" 

Test that defaultSpecMap correctly finds old MLT dwarf spectra 

that begin with 'm' 

""" 

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

 

def test_l4_spec(self): 

""" 

Test that defaultSpecMap correctly finds l4Full.dat 

""" 

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

 

def test_L_spec(self): 

""" 

Test that defaultSpecMap correctly find the L#_# spectra 

""" 

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

 

def test_burrows_spec(self): 

""" 

Test that defaultSpecMap correctly find the burrows spectra 

""" 

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

'starSED/old_mlt') 

 

def testBergeron(self): 

""" 

Test that defaultSpecMap correctly locates the bergeron spectra 

""" 

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

 

def testKurucz(self): 

""" 

Test that defaultSpecMap correctly locates the kurucz spectra 

""" 

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

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

 

def testGalaxy(self): 

""" 

Test that defaultSpecMap correctly locates the galaxy SEDs 

""" 

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

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

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

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

 

def testDirDict(self): 

""" 

Test a user-defined SpecMap with a dirDict 

""" 

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

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

testSpecMap=dirDictTestMap) 

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

testSpecMap=dirDictTestMap) 

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

testSpecMap=dirDictTestMap) 

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

testSpecMap=dirDictTestMap) 

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

testSpecMap=dirDictTestMap) 

self.verifyFile('km30_5000.fits_g10_5040', 

'starSED/kurucz', testSpecMap=dirDictTestMap) 

self.verifyFile('kp10_9000.fits_g40_9100', 

'starSED/kurucz', testSpecMap=dirDictTestMap) 

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

'starSED/old_mlt', testSpecMap=dirDictTestMap) 

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

testSpecMap=dirDictTestMap) 

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

testSpecMap=dirDictTestMap) 

 

def testFileDict(self): 

""" 

Test a user-defined SpecMap with a fileDict 

""" 

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

 

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

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

testSpecMap=fileDictTestMap) 

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

testSpecMap=fileDictTestMap) 

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

testSpecMap=fileDictTestMap) 

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

testSpecMap=fileDictTestMap) 

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

testSpecMap=fileDictTestMap) 

self.verifyFile('km30_5000.fits_g10_5040', 

'starSED/kurucz', testSpecMap=fileDictTestMap) 

self.verifyFile('kp10_9000.fits_g40_9100', 

'starSED/kurucz', testSpecMap=fileDictTestMap) 

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

'starSED/old_mlt', testSpecMap=fileDictTestMap) 

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

testSpecMap=fileDictTestMap) 

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

testSpecMap=fileDictTestMap) 

 

def testFileAndDirDict(self): 

""" 

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

""" 

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

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

 

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

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

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

'galaxySED', testSpecMap=testMap) 

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

'galaxySED', testSpecMap=testMap) 

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

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

'galaxySED', testSpecMap=testMap) 

self.verifyFile('km30_5000.fits_g10_5040', 

'starSED/kurucz', testSpecMap=testMap) 

self.verifyFile('kp10_9000.fits_g40_9100', 

'starSED/kurucz', testSpecMap=testMap) 

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

'dir_dir', testSpecMap=testMap) 

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

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

 

def test_contains(self): 

""" 

Test that 'k in SpecMap' works as it should 

""" 

 

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

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

 

self.assertFalse('banana' in testMap) 

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

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

 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()