diff --git a/cpdctrl_gui/ui/widgets/plot.py b/cpdctrl_gui/ui/widgets/plot.py index 075299f..26b6369 100644 --- a/cpdctrl_gui/ui/widgets/plot.py +++ b/cpdctrl_gui/ui/widgets/plot.py @@ -2,6 +2,10 @@ import numpy as np import pyqtgraph as pg from PyQt6.QtWidgets import QWidget + +import logging +log = logging.getLogger(__name__) + class Plot(pg.GraphicsLayoutWidget): """ pyqtgraph plot widget for showing voltage and LED vs time @@ -44,12 +48,12 @@ class Plot(pg.GraphicsLayoutWidget): # self.getAxis("right").setRange(0, 110) # Adding some margin # self.showGrid(x=True, y=True) self.MAX_DATA_POINTS = max_data_points - self.data_t = np.empty(self.MAX_DATA_POINTS, dtype=float) - self.data_v = np.empty(self.MAX_DATA_POINTS, dtype=float) - self.data_l = np.empty(self.MAX_DATA_POINTS, dtype=float) - self.n_data_array = 0 - self.n_data_total = 0 - self.n_data_skip = 0 + self.data_t = None + self.data_v = None + self.data_l = None + self.n_data_array = None + self.n_data_total = None + self.n_data_take_every_nth = None self.v_line = pg.PlotCurveItem( [], @@ -66,6 +70,9 @@ class Plot(pg.GraphicsLayoutWidget): ) self.l_box.addItem(self.l_line) self.v_box.addItem(self.v_line) + + self.clear_data() + self.update_views() self.v_plot_item.getViewBox().sigResized.connect(self.update_views) @@ -90,14 +97,16 @@ class Plot(pg.GraphicsLayoutWidget): # if the array is full, keep only every second data point # and skip every second data point. if self.n_data_array == self.MAX_DATA_POINTS: + log.debug(f"Reached {self.MAX_DATA_POINTS} data points, taking only 1/{self.n_data_take_every_nth+1} data points from now on") for i in range(0, self.MAX_DATA_POINTS//2): self.data_t[i] = self.data_t[2 * i] self.data_v[i] = self.data_v[2 * i] self.data_l[i] = self.data_l[2 * i] self.n_data_array = self.MAX_DATA_POINTS//2 - self.n_data_skip += 1 + self.n_data_take_every_nth += 1 + # skip data points to keep a constant interval - if self.n_data_skip == 0 or self.n_data_total % self.n_data_skip == 0: + if self.n_data_total % self.n_data_take_every_nth == 0: self.data_t[self.n_data_array] = time self.data_v[self.n_data_array] = voltage self.data_l[self.n_data_array] = led @@ -117,6 +126,6 @@ class Plot(pg.GraphicsLayoutWidget): self.data_l = np.empty(self.MAX_DATA_POINTS, dtype=float) self.n_data_array = 0 self.n_data_total = 0 - self.n_data_skip = 0 + self.n_data_take_every_nth = 1 self.v_line.setData([], []) self.l_line.setData([], [])