-
Notifications
You must be signed in to change notification settings - Fork 1
/
connection_plotter_spconnectome.py
193 lines (146 loc) · 6.22 KB
/
connection_plotter_spconnectome.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
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
nett.initialize('tcp://127.0.0.1:2002')
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(MainWindow,self).__init__(parent)
self.setDockOptions(QtGui.QMainWindow.AnimatedDocks)
self.setWindowTitle('Connections')
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
win = pg.PlotWidget()
self.setCentralWidget(win)
self.plot = win.getPlotItem()
self.connection_data = {}
#hack
for i in range(0,68):
self.connection_data[i] = np.array( [] )
self.connection_curve = {}
self.setup_color()
self.init_actions()
self.init_menus()
self.monitor_feed_ = monitor_feed()
self.connect(self.monitor_feed_, self.monitor_feed_.signal, self.update_data)
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_selection.start()
self.monitor_color = monitor_color()
self.connect(self.monitor_color, self.monitor_color.signal, self.color_update)
self.monitor_color.start()
self.plot_legend = self.plot.addLegend()
f = open('color_table.bin', "rb")
msg = color_table_message()
msg.ParseFromString(f.read())
f.close()
self.color_table = msg
def color_update(self, msg):
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 clear_selection(self):
for keys in self.connection_curve:
self.plot.removeItem(self.connection_curve[keys])
self.plot_legend.removeItem(self.connection_curve[keys].name())
self.connection_curve = {}
def set_selection(self, msg):
self.clear_selection()
pen = pg.mkPen(color=(255, 0,0))
for value in msg.value:
self.connection_curve[value] = self.plot.plot(self.connection_data[value], pen = self.create_pen(value), name = 'r' +str(int(value)))
def create_pen(self, key):
if self.color_table != None:
for x in range(0, len(self.color_table.value)):
if self.color_table.value[x].region_number == key:
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)
return pen
def update_data(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.connection_data[x] = np.append(self.connection_data[x], data.value[x])
#update active curves only:
for keys in self.connection_curve:
self.plot.removeItem(self.connection_curve[keys])
self.plot_legend.removeItem(self.connection_curve[keys].name())
self.connection_curve[keys] = self.plot.plot(self.connection_data[keys], pen = self.create_pen(keys), name = 'r' +str(int(keys)))
def reset_data(self):
self.plot_legend.scene().removeItem(self.plot_legend)
self.plot_legend = self.plot.addLegend()
for keys in self.connection_data:
self.connection_data[keys] = np.array( [] )
self.plot_legend.removeItem(self.connection_curve[keys].name())
class monitor_feed(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.signal = QtCore.SIGNAL("signal")
self.connection_slot_in = nett.slot_in_float_vector_message()
ip = helper.obtain_ip_address_compute()
self.connection_slot_in.connect('tcp://'+ip+':8000', 'total_connections')
def run(self):
msg = float_vector_message()
while True:
msg.ParseFromString(self.connection_slot_in.receive())
self.emit(self.signal, 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_())