-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_raw_timeseries.py
131 lines (112 loc) · 4.09 KB
/
plot_raw_timeseries.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import pkg_resources
import pylab
import numpy as np
import sys
import tables
import motmot.fview_ext_trig.easy_decode as easy_decode
import matplotlib.ticker as mticker
from optparse import OptionParser
import pytz, datetime, time
pacific = pytz.timezone('US/Pacific')
import scipy.io
def doit(fname,options):
fname = sys.argv[1]
h5 = tables.openFile(fname,mode='r')
stroke_data=h5.root.stroke_data[:]
stroke_times = stroke_data['trigger_timestamp']
time_data=h5.root.time_data[:]
gain,offset,resids = easy_decode.get_gain_offset_resids(
input=time_data['framestamp'],
output=time_data['timestamp'])
top = h5.root.time_data.attrs.top
wordstream = h5.root.ain_wordstream[:]
wordstream = wordstream['word'] # extract into normal numpy array
r=easy_decode.easy_decode(wordstream,gain,offset,top)
if r is not None:
chans = r.dtype.fields.keys()
chans.sort()
chans.remove('timestamps')
if 0:
Vcc = h5.root.ain_wordstream.attrs.Vcc
print 'Vcc read from file at',Vcc
else:
Vcc=3.3
print 'Vcc',Vcc
ADCmax = (2**10)-1
analog_gain = Vcc/ADCmax
else:
chans = []
names = h5.root.ain_wordstream.attrs.channel_names
if r is not None:
dt = r['timestamps'][1]-r['timestamps'][0]
samps_per_sec = 1.0/dt
adc_duration = n_adc_samples*dt
print '%d samples at %.1f samples/sec = %.1f seconds'%(n_adc_samples,
samps_per_sec,
adc_duration)
t0 = r['timestamps'][0]
stroke_times_zero_offset = stroke_times-t0
if len(stroke_times_zero_offset):
stroke_data_duration = stroke_times_zero_offset[-1]
total_duration = max(stroke_data_duration,adc_duration)
else:
t0 = 0
N_subplots = len(chans)+5
ax=None
for i in range(N_subplots):
ax = pylab.subplot(N_subplots,1,i+1,sharex=ax)
if i < len(chans):
try:
label = names[int(chans[i])]
except Exception, err:
print 'ERROR: ingnoring exception %s'%(err,)
label = 'channel %s'%chans[i]
ax.plot(r['timestamps']-t_offset,r[chans[i]]*analog_gain,
label=label)
ax.set_ylabel('V')
ax.legend()
elif i == len(chans):
if np.all(np.isnan(stroke_data['right'])):
continue
ax.set_ylabel('R (degrees)')
ax.legend()
elif i == len(chans)+1:
if np.all(np.isnan(stroke_data['left'])):
continue
ax.set_ylabel('L (degrees)')
ax.legend()
elif i == len(chans)+2:
if np.all(np.isnan(stroke_data['left_antenna'])):
continue
ax.plot(stroke_times-t0,stroke_data['left_antenna'],label='Lant')
ax.set_ylabel('L antenna (degrees)')
ax.legend()
elif i == len(chans)+3:
if np.all(np.isnan(stroke_data['right_antenna'])):
continue
ax.plot(stroke_times-t0,stroke_data['right_antenna'],label='Rant')
ax.set_ylabel('R antenna (degrees)')
ax.legend()
elif i == len(chans)+4:
if np.all(np.isnan(stroke_data['head'])):
continue
ax.plot(stroke_times-t0,stroke_data['head'],label='H')
ax.set_ylabel('head (degrees)')
ax.legend()
ax.xaxis.set_major_formatter(mticker.FormatStrFormatter("%s"))
ax.yaxis.set_major_formatter(mticker.FormatStrFormatter("%s"))
ax.set_xlabel('Time (sec)')
ax.set_xlim((t_plot_start,t_plot_start+total_duration))
if options.timestamps:
pylab.gcf().autofmt_xdate()
pylab.show()
def main():
usage = '%prog [options] FILE'
parser = OptionParser(usage)
parser.add_option("--timestamps", action='store_true',
default=False)
(options, args) = parser.parse_args()
fname = args[0]
doit(fname,options)
if __name__=='__main__':
main()