-
Notifications
You must be signed in to change notification settings - Fork 3
/
blseq2plt.py
executable file
·43 lines (36 loc) · 1.05 KB
/
blseq2plt.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
#!/usr/bin/python
# blseq2plt.py - Generate plot output from logfile
# Andrew Elwell <[email protected]>
# Licenced under GPL2+
# See the TOA_Blitzortung.pdf (http://blitzortung.org) and
# https://sites.google.com/site/blitzgraphs/ for background
# into the data format.
import struct
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
logfile = open("sample.dat")
try:
for line in logfile:
line = line.rstrip()
# we should really check that ident == '$BLSEQ'
(ident, timestamp, data) = line.split(',')
(data,checksum) = data.split('*')
# split data string into chunks for each pair of readings
# if using 2 channel firmware:
chan1 = []
chan2 = []
readings = [data[k:k+4] for k in xrange(0,len(data),4)]
for v in readings:
c1,c2 = struct.unpack('B B',v.decode('hex'))
chan1.append(c1)
chan2.append(c2)
fig = plt.figure()
plt.plot(chan1, label='Channel 1')
plt.plot(chan2, label='Channel 2')
plt.title(timestamp)
plt.legend()
#plt.show()
fig.savefig(timestamp + '.png')
finally:
logfile.close()