-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_data.py
executable file
·71 lines (63 loc) · 1.97 KB
/
parse_data.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
#!/usr/bin/env python
import sys
import re
if len(sys.argv) < 2:
print("Not enough or too many parameters! ({})".format(len(sys.argv)))
print("Usage: {} ORIGINAL [NORANGES-OUTPUT [RANGES-OUTPUT]]".format(sys.argv[0]))
print("Removes 31st column from ORIGINAL to output NORANGES-OUTPUT")
print("Parses the 31st column into RANGES-OUTPUT")
sys.exit(1)
if len(sys.argv) > 2:
fw = open(sys.argv[2], 'w')
else:
fw = open(sys.argv[1]+"-noranges.txt", 'w')
if len(sys.argv) > 3:
fwr = open(sys.argv[3], 'w')
else:
fwr = open(sys.argv[1]+"-ranges.txt", 'w')
#patternfull = r"[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+"
patterns = re.compile(r"(^[^\t]+(?:\t[^\t]+){29})\t([^\t]+)((?:\t[^\t]+)*)")
i = 0
try:
with open(sys.argv[1],'r') as f:
for x in f:
x = x.rstrip()
if not x:
continue
matches = patterns.match(x)
if matches:
i = i+1
# test for extra imu columns
if matches.group(3):
parts = matches.group(3).split('\t')
reparts = []
for p in parts:
# change imu identifiers to numbers
if p.startswith('/'):
if p == "/base_imu":
out = 0
else:
# only take numbers from the frame_id
out = int(''.join(i for i in p if i.isdigit()))
else:
out = p
reparts.append(str(out))
fw.write(matches.group(1) + '\t'.join(reparts) + '\n')
else:
fw.write(matches.group(1) + '\n')
if matches.group(2) and matches.group(2) != 'NaN':
splitted = matches.group(2).split('|')
for line in splitted:
if line != '':
fwr.write(line+'\n')
else:
print "No match: "+x+"\n"
except IOError as e:
print "Error opening datafile!"
print "I/O error({0}): {1}".format(e.errno, e.strerror)
fw.close()
fwr.close()
sys.exit(2)
fw.close()
fwr.close()
print "Done %d lines!" % i