-
Notifications
You must be signed in to change notification settings - Fork 2
/
read_pipe.py
executable file
·73 lines (64 loc) · 1.81 KB
/
read_pipe.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
#!/usr/local/epd/bin/python
import matplotlib
matplotlib.use('Agg')
import sys
from collections import OrderedDict
import struct
import time
import pandas
import matplotlib.pyplot as plt
import numpy as np
def rebin(a, newlength):
sh = newlength,a.shape[0]//newlength,1,a.shape[1]
return a.reshape(sh).mean(-1).mean(1)
def split_by_n(seq, n):
while seq:
yield seq[:n]
seq = seq[n:]
def get_token(s):
s = s.strip().strip("'").strip().strip("'").strip()
return s
def main():
"""docstring for main"""
d = OrderedDict()
while True:
line = sys.stdin.readline()
# print len(line),repr(line)
noOfChars = len(line)
# short descriptors have 54 chars
if noOfChars == 54:
tmp = get_token(line)
# long descriptor names have 134 chars
elif noOfChars == 134:
longdes = get_token(line)
d[tmp] = longdes
elif noOfChars == 15:
break
# each colum is piped as a double, so 8 chars.
ncols = len(d.keys())
n = 8 * ncols
unpacker = struct.Struct(ncols*'d')
l = []
while True:
data = sys.stdin.read(n)
if not data: break
l.append(unpacker.unpack(data))
if (len(l) % 100000) == 0:
print('100 k lines read.')
print len(l), 'lines of data collected.'
return d,l
if __name__ == '__main__':
d,l = main()
pdata = pandas.DataFrame(l)
ndata = pdata[0].values
limit = 100000
# if ndata.size > limit:
# ndata.shape=(ndata.size,1)
# print(ndata.shape)
# no_of_divides = int(round(np.log2(ndata.size/100000.0)))
# dsampled = rebin(ndata, ndata.size/no_of_divides)
# else:
# dsampled = ndata
plt.plot(dsampled,'r,')
plt.grid(True)
plt.savefig('foo_mpl.png')