From 3ca48d11fe27906a0b4d4d7543c9ebe669e6ef9c Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Wed, 9 Oct 2024 17:15:33 +0200 Subject: [PATCH] [ui/plot] plotting chuncks of the data --- pyrelacs/ui/plots/continously.py | 94 +++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/pyrelacs/ui/plots/continously.py b/pyrelacs/ui/plots/continously.py index 8fb0114..e6644ba 100644 --- a/pyrelacs/ui/plots/continously.py +++ b/pyrelacs/ui/plots/continously.py @@ -19,49 +19,77 @@ class Continously: self.figure.setBackground("w") self.daq_plot = self.figure.addPlot(row=0, col=0) pen = pg.mkPen("red") - self.time = np.zeros(self.buffer.size) - self.data = np.zeros(self.buffer.size) - log.debug(self.data.size) - log.debug(self.time.size) + # self.time = np.zeros(self.buffer.size) + # self.data = np.zeros(self.buffer.size) self.line = self.daq_plot.plot( - self.time, - self.data, + # self.time, + [0], pen=pen, setCliptoView=True, symbol="o", ) - while self.buffer.totalcount() < 4000: + # self.item = 0 + # while self.buffer.totalcount() < 3_000_000: + # log.debug(self.buffer.totalcount()) + # self.time = np.roll(self.time, -1) + # self.data = np.roll(self.data, -1) + # try: + # item, time_index = self.buffer.get(self.item) + # except IndexError: + # item = 0 + # time_index = 0 + # self.time[-1] = time_index + # self.data[-1] = item + # self.line.setData(self.time, self.data) + # self.item += 1 + + self.plot_index = 0 + self.CHUNK_PLOT = 1000 + self.timer = QTimer() + self.timer.setInterval(200) + self.timer.timeout.connect(self.update_plot) + self.timer.start() + + # self.update_plot() + + def update_plot(self): + log.debug(self.buffer.totalcount()) + + if self.buffer.totalcount() > self.CHUNK_PLOT: + log.debug(self.buffer.totalcount()) - self.time = np.roll(self.time, -1) - self.data = np.roll(self.data, -1) try: - item, time_index = self.buffer.get(self.buffer.write_index() - 1) + # item, time_index = self.buffer.get(self.buffer.write_index() - 1) + items = self.buffer.read( + self.buffer.write_index() - self.CHUNK_PLOT, count=self.CHUNK_PLOT + ) + # times = (np.arange(len(items)) / self.buffer.samplerate) + self.time[-1] + except IndexError: item = 0 + items = np.zeros(self.CHUNK_PLOT) + times = np.zeros(self.CHUNK_PLOT) + # log.debug("Stopping the timer") + # self.timer.stop() time_index = 0 - self.time[-1] = time_index - self.data[-1] = item - self.line.setData(self.time, self.data) + log.debug("No Data Available") + # self.time = np.roll(self.time, -len(items)) + # self.data = np.roll(self.data, -len(items)) + # + # # self.time[-len(times) :] = times + # self.data[-len(items) :] = items - # self.timer = QTimer() - # self.timer.setInterval(1) - # self.timer.timeout.connect(self.update_plot) - # self.timer.start() + self.line.setData( + # self.time, + items, + ) + self.plot_index += len(items) + else: + # self.timer.stop() + # embed() + # exit() + pass - # self.update_plot() - # - # def update_plot(self): - # log.debug(self.buffer.totalcount()) - # while self.buffer.totalcount() < 4000: - # log.debug(self.buffer.totalcount()) - # self.time = np.roll(self.time, -1) - # self.data = np.roll(self.data, -1) - # try: - # item, time_index = self.buffer.get(self.buffer.write_index() - 1) - # except IndexError: - # item = 0 - # time_index = 0 - # self.time[-1] = time_index - # self.data[-1] = item - # self.line.setData(self.time, self.data) + def stop_plotting(self): + self.timer.stop()