Coverage for python/lsst/sims/utils/fileMaps.py : 35%

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
1from builtins import object
2import os
3import re
5__all__ = ["SpecMap", "defaultSpecMap"]
8class SpecMap(object):
10 subdir_map = {'(^km)|(^kp)': 'starSED/kurucz',
11 '(^bergeron)': 'starSED/wDs',
12 '(^burrows)|(^(m|L|l)[0-9])': 'starSED/old_mlt',
13 '(^lte)': 'starSED/mlt',
14 '^(Exp|Inst|Burst|Const)': 'galaxySED'}
16 def __init__(self, fileDict=None, dirDict=None):
17 """
18 @param [in] fileDict is a dict mapping the names of files to their
19 relative paths, one-to-one, e.g.
21 fileDict = {'A.dat':'ssmSED/A.dat.gz',
22 'Sa.dat':'ssmSED/Sa.dat.gz'}
24 @param [in] dirDict is a dict mapping forms of names of file to their
25 sub directories using regular expressions, e.g.
27 dirDict = {'(^km)|(^kp)':'starSED/kurucz',
28 '(^bergeron)':'starSED/wDs'}
30 which maps files begining in either 'km' or 'kp' to files with
31 the same names in the directory starSED/kurucz and maps files
32 beginning with 'bergeron' to files with the same names in the
33 directory starSED/wDs
35 These dicts will take precedence over the subdir_map that is defined
36 as a class member variable of the SpecMap class.
37 """
38 if fileDict: 38 ↛ 41line 38 didn't jump to line 41, because the condition on line 38 was never false
39 self.fileDict = fileDict
40 else:
41 self.fileDict = {}
43 if dirDict: 43 ↛ 44line 43 didn't jump to line 44, because the condition on line 43 was never true
44 self.dirDict = dirDict
45 else:
46 self.dirDict = {}
48 def __setitem__(self, key, val):
49 self.fileDict[key] = val
51 def __getitem__(self, item):
53 item = item.strip()
55 if item in self.fileDict:
56 return self.fileDict[item]
58 for key, val in sorted(self.dirDict.items()):
59 if re.match(key, item):
60 full_name = item if item.endswith('.gz') else item + '.gz'
61 return os.path.join(val, full_name)
63 for key, val in sorted(self.subdir_map.items()):
64 if re.match(key, item):
65 full_name = item if item.endswith('.gz') else item + '.gz'
66 return os.path.join(val, full_name)
68 raise KeyError("No path found for spectrum name: %s" % (item))
70 def __contains__(self, item):
71 """
72 Returns True if there is a map for 'item'; False if not.
74 This exists primarily so that phoSim input catalog classes
75 can identify columns which have no sedFilePath and then remove
76 them when writing the catalog.
77 """
78 try:
79 self.__getitem__(item)
80 return True
81 except:
82 return False
84defaultSpecMap = SpecMap(
85 fileDict={'A.dat': 'ssmSED/A.dat.gz',
86 'Sa.dat': 'ssmSED/Sa.dat.gz',
87 'O.dat': 'ssmSED/O.dat.gz',
88 'harris_V.dat': 'ssmSED/harris_V.dat.gz',
89 'Cg.dat': 'ssmSED/Cg.dat.gz',
90 'Sv.dat': 'ssmSED/Sv.dat.gz',
91 'X.dat': 'ssmSED/X.dat.gz',
92 'K.dat': 'ssmSED/K.dat.gz',
93 'L.dat': 'ssmSED/L.dat.gz',
94 'D.dat': 'ssmSED/D.dat.gz',
95 'Sq.dat': 'ssmSED/Sq.dat.gz',
96 'C.dat': 'ssmSED/C.dat.gz',
97 'T.dat': 'ssmSED/T.dat.gz',
98 'Xk.dat': 'ssmSED/Xk.dat.gz',
99 'R.dat': 'ssmSED/R.dat.gz',
100 'Ch.dat': 'ssmSED/Ch.dat.gz',
101 'kurucz_sun': 'ssmSED/kurucz_sun.gz',
102 'Sr.dat': 'ssmSED/Sr.dat.gz',
103 'Cgh.dat': 'ssmSED/Cgh.dat.gz',
104 'Cb.dat': 'ssmSED/Cb.dat.gz',
105 'Xc.dat': 'ssmSED/Xc.dat.gz',
106 'Xe.dat': 'ssmSED/Xe.dat.gz',
107 'Q.dat': 'ssmSED/Q.dat.gz',
108 'S.dat': 'ssmSED/S.dat.gz',
109 'B.dat': 'ssmSED/B.dat.gz',
110 'V.dat': 'ssmSED/V.dat.gz',
111 'agn.spec': 'agnSED/agn.spec.gz',
112 'BD1000.dat': 'starSED/gizis_SED/BD1000_interp.dat.gz',
113 'BD1000e.dat': 'starSED/gizis_SED/BD1000e_interp.dat.gz',
114 'BD1500.dat': 'starSED/gizis_SED/BD1500_interp.dat.gz',
115 'BD1800.dat': 'starSED/gizis_SED/BD1800_interp.dat.gz',
116 'BD2000.dat': 'starSED/gizis_SED/BD2000_interp.dat.gz',
117 'BD325.dat': 'starSED/gizis_SED/BD325_interp.dat.gz',
118 'BD555.dat': 'starSED/gizis_SED/BD555_interp.dat.gz',
119 'PNastrom.dat': 'starSED/gizis_SED/PNastrom_interp.dat.gz',
120 'RedE1astrom.dat': 'starSED/gizis_SED/RedE1astrom_interp.dat.gz',
121 'RedE2astrom.dat': 'starSED/gizis_SED/RedE2astrom_interp.dat.gz',
122 'sed_flat.txt': 'flatSED/sed_flat.txt.gz',
123 'sed_flat_norm.txt': 'flatSED/sed_flat.txt.gz'})