-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_PSEC4
More file actions
111 lines (95 loc) · 2.76 KB
/
plot_PSEC4
File metadata and controls
111 lines (95 loc) · 2.76 KB
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
#!/usr/bin/env python
import matplotlib.pyplot as plt
import bokeh.plotting as bkh
from bokeh.models import Range1d
from bokeh.models import HoverTool
import os
import datetime
import subprocess
def plot_PSEC(fname, oname=''):
# takes a PSEC4 log file, reads it and plots it to a bokeh file.
# <fname> = file to open and read
# <oname> = filename to write to. will be appended with '.html'
# Returns:
# <p> = bokeh plot object for further manipulation, if desired.
if oname == '':
oname = fname.strip('.txt')
f = open(fname, 'r')
# Samples is a list, and each sample contains
# a set of 6 lists which are the channels readings
samples = []
channels = [[],[],[],[],[],[]]
t = [0.0]
j = 0
vmin = 0.
vmax = 0.
for line in f:
if line[0] == '#':
continue
else:
line = [float(x)*1000. for x in line.split()]
t.append(t[-1]+0.1) # 100ps step size, or 0.1ns
for i in range(6):
channels[i].append(line[i])
if line[i] > vmax:
vmax = float(line[i])
if line[i] < vmin:
vmin = float(line[i])
j += 1
if j%256 == 0:
samples.append(channels)
channels = [[],[],[],[],[],[]]
f.close() # REMOVE FOR THE MAIN VERSION
print 'Read %d samples, in %d lines' % (len(samples), j)
#recover the user inputted name so it can be applied to graphs and whatever
stamp = oname.split('/')[-1].strip('.txt').strip('.html')
oname = oname.strip('.html')+'.html'
# output graph to a static HTML file
print "saving to %s" % (oname)
bkh.output_file(oname, title=stamp)
#create plot object
p = bkh.figure(plot_width=1000, title=stamp, x_axis_label='t-t0, ns', y_axis_label='Voltage, mV')
# Read the channels from each sample into long lists for plotting
channels = [[],[],[],[],[],[]]
t = [0.0]
for sample in samples:
for channel, ochannel in zip(sample, channels):
for data in channel:
ochannel.append(data)
for data in channels[0][1:]:
t.append(t[-1]+0.1) # 0.1ns step size
print 'Plotting...'
# Plot the data
cols = ['red', 'blue', 'orange', 'green', 'purple', 'black']
i = 0
data = []
#add data to the plot object with ColumnDataSource
# line = [<data structure>, <line colour>, <Channel ID>]
for channel in channels:
i += 1
line = [bkh.ColumnDataSource(data=dict(
x=t,
y=channel),
# column_names=['N', 'Voltage']
),
cols[i-1], # Line colour
str(i) # Channel Number
]
data.append(line)
# plot data
for line in data:
p.line('x', 'y',
line_width=1,
line_color=line[1],
legend=('Channel '+line[2]),
source=line[0],
# tools=['box_select', 'box_zoom', 'pan', 'xpan', 'wheel_zoom', 'undo', 'redo']
)
# Make data toggleable
p.legend.location = "top_left"
p.legend.click_policy="hide"
# set ranges
p.y_range = Range1d(1.1*vmin, 1.1*vmax)
bkh.save(p)
bkh.show(p)
return p