-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_extract.py
39 lines (31 loc) · 1.17 KB
/
data_extract.py
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
def extract_galaxy_data(filename):
fileid = filename.split('.')[0]
gdata = {
"fileid": fileid,
"data": []
}
with open(filename) as input_file:
for line in input_file:
if line.startswith("#"):
if line.find(":") != -1:
line = line.split("#")[1]
line = [elem.strip() for elem in line.split(":")]
if len(line) > 1:
gdata[line[0]] = line[1]
else:
line = [elem.strip() for elem in line.split(" ")[1:] if len(elem.strip()) > 0]
if len(line) > 0:
gdata["data"].append(tuple(line))
else:
line = [elem.strip() for elem in line.split(" ") if len(elem.strip()) > 0]
if len(line) > 0:
gdata["data"].append(tuple(line))
data = dict()
for idx in range(len(gdata["data"][0])):
param = gdata["data"][0][idx]
param_data = []
for elem in gdata["data"][1:]:
param_data.append(elem[idx])
data[param] = param_data
gdata["data"] = data
return gdata