-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathca_plotter.py
257 lines (198 loc) · 8.65 KB
/
ca_plotter.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import sys
import nett_python as nett
from float_vector_message_pb2 import *
from float_message_pb2 import *
from color_table_message_pb2 import *
import pyqtgraph as pg
import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
import helper
use_ip_endpoint = None
fixed_selection = None
if len(sys.argv) != 3:
print 'switching to default view mode'
use_ip_endpoint = 'tcp://127.0.0.1:2001'
else:
print 'using fixed view mode'
use_ip_endpoint = sys.argv[1]
fixed_selection = int(sys.argv[2])
nett.initialize(use_ip_endpoint)
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setDockOptions(QtGui.QMainWindow.AnimatedDocks)
self.setWindowTitle('Activity Chart')
if fixed_selection != None:
self.setWindowTitle('Firing Rate: ' +str(fixed_selection))
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
win = pg.PlotWidget()
self.setCentralWidget(win)
self.plot = win.getPlotItem()
self.plot_legend = self.plot.addLegend()
self.ca_e_data = {}
self.ca_i_data = {}
self.curves_e = {}
self.curves_i = {}
f = open('color_table.bin', "rb")
msg = color_table_message()
msg.ParseFromString(f.read())
f.close()
self.color_table = msg
#hack
for i in range(0,68):
self.ca_e_data[i] = np.array( [] )
self.ca_i_data[i] = np.array( [] )
self.setup_color()
self.init_actions()
self.init_menus()
self.monitor_feed_ = monitor_feed()
self.connect(self.monitor_feed_, self.monitor_feed_.signal_ca_e, self.update_data_e)
self.connect(self.monitor_feed_, self.monitor_feed_.signal_ca_i, self.update_data_i)
self.monitor_feed_.start()
self.monitor_reset = monitor_reset()
self.connect(self.monitor_reset, self.monitor_reset.signal, self.reset_data)
self.monitor_reset.start()
self.monitor_selection = monitor_selection()
self.connect(self.monitor_selection, self.monitor_selection.signal, self.set_selection)
self.monitor_color = monitor_color()
self.connect(self.monitor_color, self.monitor_color.signal, self.color_update)
self.monitor_color.start()
#only listen to update when in non fixed mode
if fixed_selection == None:
self.monitor_selection.start()
else:
self.set_selection(float_vector_message()) #fake selection message
def color_update(self, msg):
print 'color update!'
self.color_table = msg
def setup_color(self):
self.plot.showGrid(x=True, y=True, alpha=0.3)
def init_actions(self):
self.exit_action = QtGui.QAction('Quit', self)
self.exit_action.setShortcut('Ctrl+Q')
self.exit_action.setStatusTip('Exit application')
self.connect(self.exit_action, QtCore.SIGNAL('triggered()'), self.close)
def init_menus(self):
self.addAction(self.exit_action)
def update_data_i(self, data):
for x in range(0, len(data.value)):
self.ca_i_data[x] = np.append(self.ca_i_data[x], data.value[x])
#only update values in current selection:
for keys in self.curves_i:
pen = self.create_pen(keys, False)
self.plot.removeItem(self.curves_i[keys])
self.curves_i[keys] = self.plot.plot(self.ca_i_data[keys], pen = pen, name = 'i' + str(int(keys)) + ': ' +"{0:.3f}".format(self.ca_i_data[keys][-1]))
def update_data_e(self, data):
self.plot_legend.scene().removeItem(self.plot_legend)
self.plot_legend = self.plot.addLegend()
for x in range(0, len(data.value)):
self.ca_e_data[x] = np.append(self.ca_e_data[x], data.value[x])
#only update values in current selection:
for keys in self.curves_e:
pen = self.create_pen(keys, True)
self.plot.removeItem(self.curves_e[keys])
self.curves_e[keys] = self.plot.plot(self.ca_e_data[keys], pen = pen, name = 'e' + str(int(keys)) + ': ' + "{0:.3f}".format(self.ca_e_data[keys][-1]))
def create_pen(self, key, is_e):
pen = pg.mkPen(color=(0,0,0))
if self.color_table != None:
for x in range(0, len(self.color_table.value)):
if self.color_table.value[x].region_number == key:
if is_e == True:
pen = pg.mkPen(color = (self.color_table.value[x].color_e_r, self.color_table.value[x].color_e_g, self.color_table.value[x].color_e_b))
pen.setWidth(int(self.color_table.value[x].thickness_e))
if self.color_table.value[x].style_e == "SolidLine":
pen.setStyle(QtCore.Qt.SolidLine)
elif self.color_table.value[x].style_e == "DashLine":
pen.setStyle(QtCore.Qt.DashLine)
elif self.color_table.value[x].style_e == "DashDotLine":
pen.setStyle(QtCore.Qt.DashDotLine)
elif self.color_table.value[x].style_e == "DashDotDotLine":
pen.setStyle(QtCore.Qt.DashDotDotLine)
else:
pen = pg.mkPen(color = (self.color_table.value[x].color_i_r, self.color_table.value[x].color_i_g, self.color_table.value[x].color_i_b))
pen.setWidth(int(self.color_table.value[x].thickness_i))
if self.color_table.value[x].style_i == "SolidLine":
pen.setStyle(QtCore.Qt.SolidLine)
elif self.color_table.value[x].style_i == "DashLine":
pen.setStyle(QtCore.Qt.DashLine)
elif self.color_table.value[x].style_i == "DashDotLine":
pen.setStyle(QtCore.Qt.DashDotLine)
elif self.color_table.value[x].style_i == "DashDotDotLine":
pen.setStyle(QtCore.Qt.DashDotDotLine)
return pen
def reset_data(self):
self.clear_selection()
def clear_selection(self):
self.plot_legend.scene().removeItem(self.plot_legend)
for keys in self.curves_i:
self.plot.removeItem(self.curves_i[keys])
self.curves_i = {}
for keys in self.curves_e:
self.plot.removeItem(self.curves_e[keys])
self.curves_e = {}
self.plot_legend = self.plot.addLegend()
def set_selection(self, msg):
if fixed_selection != None:
msg.value.append(fixed_selection)
self.clear_selection()
for value in msg.value:
pen = self.create_pen(value, False)
self.curves_i[value] = self.plot.plot(self.ca_i_data[value], pen = pen, name='i' + str(int(value)) + ': ' +"{0:.3f}".format(self.ca_i_data[value][-1]))
pen = self.create_pen(value, True)
self.curves_e[value] = self.plot.plot(self.ca_e_data[value], pen = pen, name = 'e' + str(int(value)) + ': ' +"{0:.3f}".format(self.ca_e_data[value][-1]))
class monitor_feed(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.signal_ca_e = QtCore.SIGNAL("signal_e")
self.signal_ca_i = QtCore.SIGNAL("signal_i")
self.ca_e_slot_in = nett.slot_in_float_vector_message()
self.ca_i_slot_in = nett.slot_in_float_vector_message()
ip = helper.obtain_ip_address_compute()
self.ca_e_slot_in.connect('tcp://'+ip+':8000', 'fr_e')
self.ca_i_slot_in.connect('tcp://'+ip+':8000', 'fr_i')
def run(self):
msg = float_vector_message()
while True:
msg.ParseFromString(self.ca_e_slot_in.receive())
self.emit(self.signal_ca_e, msg )
msg = float_vector_message()
msg.ParseFromString(self.ca_i_slot_in.receive())
self.emit(self.signal_ca_i, msg )
class monitor_reset(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.signal = QtCore.SIGNAL("signal")
self.reset_slot_in = nett.slot_in_float_message()
self.reset_slot_in.connect('tcp://127.0.0.1:2003', 'reset')
def run(self):
msg = float_message()
while True:
msg.ParseFromString(self.reset_slot_in.receive())
self.emit(self.signal)
class monitor_selection(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.signal = QtCore.SIGNAL("signal")
self.area_list_slot_in = nett.slot_in_float_vector_message()
self.area_list_slot_in.connect('tcp://127.0.0.1:2014', 'regions_selected')
def run(self):
msg = float_vector_message()
while True:
msg.ParseFromString(self.area_list_slot_in.receive())
self.emit(self.signal, msg)
class monitor_color(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.signal = QtCore.SIGNAL("signal")
self.color_slot_in = nett.slot_in_color_table_message()
self.color_slot_in.connect('tcp://127.0.0.1:2008', 'color_table')
def run(self):
msg = color_table_message()
while True:
msg.ParseFromString(self.color_slot_in.receive())
self.emit(self.signal, msg)
app = QtGui.QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())