def plot_sensors_until_enter_press(self, chan_names, in_socket, n_bytes, n_rows, n_cols): log.info("Starting Plot for plot") from braindecode.online.live_plot import LivePlot log.info("Import") live_plot = LivePlot(plot_freq=150) log.info("Liveplot created") live_plot.initPlots(chan_names) log.info("Initialized") enter_pressed = False while not enter_pressed: array = '' while len(array) < n_bytes: array += in_socket.recv(n_bytes - len(array)) array = np.fromstring(array, dtype=np.float32) array = array.reshape(n_rows, n_cols, order='F') live_plot.accept_samples(array.T) # check if enter is pressed i,o,e = gevent.select.select([sys.stdin],[],[],0.001) for s in i: if s == sys.stdin: _ = sys.stdin.readline() enter_pressed = True live_plot.close() log.info("Plot finished")
def handle(self, in_socket, address): log.info('New connection from {:s}!'.format(str(address))) assert np.little_endian, "Should be in little endian" n_rows = in_socket.recv(4) n_rows = np.fromstring(n_rows, dtype=np.int32)[0] log.info("Number of rows: {:d}".format(n_rows)) n_cols = in_socket.recv(4) n_cols = np.fromstring(n_cols, dtype=np.int32)[0] log.info("Number of columns: {:d}".format(n_cols)) n_numbers = n_rows * n_cols n_bytes = n_numbers * 4 # float32 log.info("Numbers in total: {:d}".format(n_numbers)) live_plot = LivePlot(plot_freq=150) live_plot.initPlots(self.sensor_names) while True: array = '' while len(array) < n_bytes: array += in_socket.recv(n_bytes - len(array)) array = np.fromstring(array, dtype=np.float32) array = array.reshape(n_rows, n_cols, order='F') live_plot.accept_samples(array.T)