MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / Graph

Class Graph

python_package/examples/enophone/enophone_streaming.py:11–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class Graph:
12 def __init__(self, board_shim):
13 self.board_id = board_shim.get_board_id()
14 self.board_shim = board_shim
15 self.exg_channels = BoardShim.get_exg_channels(self.board_id)
16 self.sampling_rate = BoardShim.get_sampling_rate(self.board_id)
17 self.update_speed_ms = 50
18 self.window_size = 10
19 self.num_points = self.window_size * self.sampling_rate
20 self.plot_names = ['Quality A2', 'Quality A1', 'Quality C4', 'Quality C3']
21 self.mains = None
22 self.app = QtWidgets.QApplication([])
23 self.win = pg.GraphicsLayoutWidget(title='Enophone Live Streaming', size=(800, 600), show=True)
24 self._init_timeseries()
25
26 timer = QtCore.QTimer()
27 timer.timeout.connect(self.update)
28 timer.start(self.update_speed_ms)
29 QtWidgets.QApplication.instance().exec()
30
31 def _init_timeseries(self):
32 self.plots = list()
33 self.curves = list()
34 self.legends = list()
35
36 for i in range(len(self.exg_channels)):
37 p = self.win.addPlot(row=i, col=0)
38 legend = p.addLegend(brush='k')
39 p.showAxis('left', False)
40 p.setMenuEnabled('left', False)
41 p.showAxis('bottom', False)
42 p.setMenuEnabled('bottom', False)
43 p.setYRange(-100, 100, padding=0)
44 if i == 0:
45 p.setTitle('Live Enophone Data')
46 self.plots.append(p)
47 curve = p.plot(name=self.plot_names[i])
48 self.curves.append(curve)
49 self.legends.append(legend)
50
51 def update(self):
52
53 data = self.board_shim.get_current_board_data(self.num_points)
54
55 if data.shape[1] > 3 * self.sampling_rate:
56 if self.mains is None:
57 self.mains = enotools.detect_mains(data)
58 quality = enotools.quality(data)
59 data = enotools.referencing(data, mode='mastoid')
60 data = enotools.signal_filtering(data, filter_cut=250, bandpass_range=[3, 40], bandstop_range=self.mains)
61
62 for count, channel in enumerate(self.exg_channels):
63 name = self.plot_names[count] + ': ' + str(quality[count])
64 self.curves[count].setData(data[channel].tolist())
65 self.legends[count].getLabel(self.curves[count]).setText(name)
66 if quality[count] >= 99:
67 self.legends[count].setLabelTextColor('g')
68 elif quality[count] >= 95:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected