diff --git a/pyrelacs/ui/plots/continously.py b/pyrelacs/ui/plots/continously.py index c3b1e73..9d8b427 100644 --- a/pyrelacs/ui/plots/continously.py +++ b/pyrelacs/ui/plots/continously.py @@ -1,3 +1,5 @@ +import time + import pyqtgraph as pg from IPython import embed import numpy as np @@ -24,7 +26,7 @@ class Continously: pen = pg.mkPen("red") self.time = np.zeros(self.buffer.size) - self.data = np.zeros(self.buffer.size) + self.data = np.empty(self.buffer.size) self.line = self.continous_ax.plot( self.time, self.data, @@ -34,37 +36,32 @@ class Continously: # self.plot_index = 0 self.timer = QTimer() - self.CHUNK_PLOT = 10_000 - self.timer.setInterval(200) + self.CHUNK_PLOT = 500 + self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen + self.last_plotted_index = 0 + self.timer.setInterval(150) self.timer.timeout.connect(self.update_plot) self.timer.start() def update_plot(self): - # log.debug(self.buffer.totalcount()) - if self.buffer.totalcount() > self.CHUNK_PLOT: - log.debug(self.buffer.totalcount()) - try: - times, items = self.buffer.read( - self.buffer.write_index() - self.CHUNK_PLOT - 1_000, - extend=self.CHUNK_PLOT, - ) - except IndexError as e: - items = np.zeros(self.CHUNK_PLOT) - times = np.zeros(self.CHUNK_PLOT) - 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.data[-len(items) :] = items + current_index = self.buffer.write_index() + total_count = self.buffer.totalcount() + start_time = time.time() + if total_count - self.last_plotted_index >= self.CHUNK_PLOT: + times, items = self.buffer.read( + self.last_plotted_index, + extend=self.CHUNK_PLOT, + ) + self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :] + self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :] self.line.setData( - times, - items, + self.time, + self.data, ) - # self.plot_index += len(items) + self.last_plotted_index += self.CHUNK_PLOT + end_time = time.time() + log.debug(f"total time for plotting {end_time - start_time}") else: pass