From 523f5dc34684448558fc576b1cca46c50657a1fc Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Thu, 10 Oct 2024 09:58:54 +0200 Subject: [PATCH] [ui/plot] rewriting continous plot, plotting chucks of the buffer --- pyrelacs/ui/plots/continously.py | 58 +++++++++----------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/pyrelacs/ui/plots/continously.py b/pyrelacs/ui/plots/continously.py index e6644ba..f851e21 100644 --- a/pyrelacs/ui/plots/continously.py +++ b/pyrelacs/ui/plots/continously.py @@ -19,76 +19,48 @@ 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) + self.time = np.zeros(self.buffer.size) + self.data = np.zeros(self.buffer.size) self.line = self.daq_plot.plot( - # self.time, - [0], + self.time, + self.data, pen=pen, - setCliptoView=True, - symbol="o", + # symbol="o", ) - # 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.plot_index = 0 + self.CHUNK_PLOT = 1_000 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()) try: - # 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, items = self.buffer.read( + self.buffer.write_index() - self.CHUNK_PLOT, extend=self.CHUNK_PLOT ) - # times = (np.arange(len(items)) / self.buffer.samplerate) + self.time[-1] - - except IndexError: - item = 0 + except IndexError as e: items = np.zeros(self.CHUNK_PLOT) times = np.zeros(self.CHUNK_PLOT) - # log.debug("Stopping the timer") - # self.timer.stop() - time_index = 0 log.debug("No Data Available") + log.debug(f"Index Error {e}") + # self.time = np.roll(self.time, -len(items)) # self.data = np.roll(self.data, -len(items)) # - # # self.time[-len(times) :] = times + # self.time[-len(times) :] = times # self.data[-len(items) :] = items self.line.setData( - # self.time, + times, items, ) - self.plot_index += len(items) + # self.plot_index += len(items) else: - # self.timer.stop() - # embed() - # exit() pass def stop_plotting(self):