-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_ecoduet.py
executable file
·76 lines (58 loc) · 1.89 KB
/
parse_ecoduet.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
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
#! /usr/bin/python3
import os
import subprocess as sub
def p(arg): print("<",arg,">",sep="")
def error(msg):
print(msg)
exit(1)
def check(test, msg):
if not (test):
error(msg)
DEVNULL = open(os.devnull, 'w')
def parse_ecoduet(logpath):
"""
Parses the ecoduet log and returns N,Ne and the original and estimated lists with entries:
[ (match_index Dtotal Dtotal/sample SNR), ... ] sorted by the original/estimated source index.
"""
log = open(logpath, 'r')
lines = [ line.strip() for line in log.readlines() if line.strip() ]
log.close()
o = []
e = []
N = int(lines[0].split()[2])
Ne = int(lines[0].split()[5])
# State machine
NONE = 0
ORIGINAL = 1
ESTIMATED = 2
# state
line_is = NONE
for line in lines[1:]:
if line[0] == "e": # line starts with e_match
line_is = ORIGINAL
continue
elif line[0] == "o": # line starts with o_match
line_is = ESTIMATED
continue
elif line_is != NONE: # If the file obeys the specs at least we must be in some state by now.
# Parse degeneracies line.
if line[0] == "#":
if line_is == ORIGINAL:
deg_o = int(line.split("=")[1])
else:
deg_e = int(line.split("=")[1])
continue
# Parse normal values line.
l = line.split()
# (match, Dtotal,Dtotal_per_sample,SNR)
values = (int(l[0])-1, float(l[1]), float(l[2]), float(l[3]))
if line_is == ORIGINAL:
o.append(values)
else:
e.append(values)
else:
error("Unrecognized line precedes the original and estimated lines: <"+line+">")
return (N, Ne, deg_o, deg_e, o, e)
if __name__ == "__main__":
eco = parse_ecoduet("ecoduet.log")
p(eco)