8 coords=re.match(
r'^\s*{\s*(\d+),\s*(-?\d+),\s*(\d+),\s*(\d+),\s*(-?\d+)\s*},?', header_line)
11 return [
int(x)
for x
in coords.groups()]
15 hash_positionStrings=oldFormat.split()[1:]
16 theHash =
int(hash_positionStrings[0])
17 thePositions = [
int(x)
for x
in hash_positionStrings[1].
split(
',')]
19 return result + thePositions
25 newFormatPosition =
str(newFormat[1:])
26 joinedPosition =
"".
join(newFormatPosition)[1:-1]
27 spaceStripped = re.sub(
r'[\s+]',
'', joinedPosition)
28 newFormatHash =
str(newFormat[0])
29 return " : "+newFormatHash.rjust(4)+
" "+spaceStripped
34 module_file =
open(fname,
'r')
35 module_data = module_file.read()
36 module_lines = module_data.splitlines()
38 for modules
in module_lines:
40 modules = modules.split()
42 if modules[0] ==
"else" and modules[1] ==
"if":
43 geographicalID = modules[2].
split(
'"')
44 modulename = geographicalID[1]
45 elif modules[0] ==
"if":
46 geographicalID = modules[1].
split(
'"')
47 modulename = geographicalID[1]
49 golden_modules.append(modulename)
52 for modules
in module_lines:
54 goldens = modules.split(
'=')
55 modules = modules.split()
57 if modules[0] ==
"else" and modules[1] ==
"if":
58 golden_hashID =
" : " + goldens[3].
split(
';')[0]
59 golden_bec = goldens[4].
split(
';')[0].strip()
60 golden_layer = goldens[5].
split(
';')[0].strip()
61 golden_phi = goldens[6].
split(
';')[0].strip()
62 golden_eta = goldens[7].
split(
';')[0].strip()
63 modulehash = golden_hashID +
" " + golden_bec +
"," + golden_layer +
"," + golden_phi +
"," + golden_eta
64 elif modules[0] ==
"if":
65 golden_hashIds = modules[4].
split(
';')[0]
66 golden_bec = modules[5].
split(
'=')[1].
split(
';')[0]
67 golden_layer = modules[6].
split(
'=')[1].
split(
';')[0]
68 golden_phi = modules[8].
split(
';')[0]
69 golden_eta = modules[10].
split(
';')[0].strip()
70 if len(golden_hashIds) == 1:
71 golden_hashID =
" : " + golden_hashIds
72 elif len(golden_hashIds) == 2:
73 golden_hashID =
" : " + golden_hashIds
74 elif len(golden_hashIds) == 3:
75 golden_hashID =
" : " + golden_hashIds
76 elif len(golden_hashIds) == 4:
77 golden_hashID =
" : " + golden_hashIds
78 modulehash = golden_hashID +
" " + golden_bec +
"," + golden_layer +
"," + golden_phi +
"," + golden_eta
80 golden_hash.append(modulehash)
81 return dict(zip(golden_modules, golden_hash))
91 module_file =
open(fname,
'r')
92 module_data = module_file.read()
93 module_lines = module_data.splitlines()
95 for modules
in module_lines:
97 modules = modules.split()
102 geographicalID = modules[0].
split(
'"')
103 modulename = geographicalID[1]
104 module_names.append(modulename)
105 if "names" in modules:
108 found_positions =
False
110 for position_line
in module_lines:
111 if len(position_line) != 0:
113 if "}};" in position_line:
118 module_positions.append(position)
119 if "values" in position_line:
121 return dict(zip(module_names,module_positions))
125 module_file =
open(fname,
'r')
126 module_data = module_file.read()
127 module_lines = module_data.splitlines()
128 for module
in module_lines:
131 components = module.split(
',')
132 thisModuleName = components[0]
133 thisModulePosition = [
int(x)
for x
in components[1:]]
134 result[thisModuleName] = thisModulePosition
138 if __name__ ==
"__main__":
144 print (
"#name, hash, bec, layer, phi, eta")
145 for n
in name_position_dict1:
154 Examples of extraction to lists
155 ===============================
156 myList = [*name_position_dict]
160 for (k,v) in name_position_dict.items():