Add log, refactor skipping
This commit is contained in:
parent
2a439bc65f
commit
74745ad28f
@ -2,6 +2,10 @@ import numpy as np
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from PyQt6.QtWidgets import QWidget
|
from PyQt6.QtWidgets import QWidget
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Plot(pg.GraphicsLayoutWidget):
|
class Plot(pg.GraphicsLayoutWidget):
|
||||||
"""
|
"""
|
||||||
pyqtgraph plot widget for showing voltage and LED vs time
|
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.getAxis("right").setRange(0, 110) # Adding some margin
|
||||||
# self.showGrid(x=True, y=True)
|
# self.showGrid(x=True, y=True)
|
||||||
self.MAX_DATA_POINTS = max_data_points
|
self.MAX_DATA_POINTS = max_data_points
|
||||||
self.data_t = np.empty(self.MAX_DATA_POINTS, dtype=float)
|
self.data_t = None
|
||||||
self.data_v = np.empty(self.MAX_DATA_POINTS, dtype=float)
|
self.data_v = None
|
||||||
self.data_l = np.empty(self.MAX_DATA_POINTS, dtype=float)
|
self.data_l = None
|
||||||
self.n_data_array = 0
|
self.n_data_array = None
|
||||||
self.n_data_total = 0
|
self.n_data_total = None
|
||||||
self.n_data_skip = 0
|
self.n_data_take_every_nth = None
|
||||||
|
|
||||||
self.v_line = pg.PlotCurveItem(
|
self.v_line = pg.PlotCurveItem(
|
||||||
[],
|
[],
|
||||||
@ -66,6 +70,9 @@ class Plot(pg.GraphicsLayoutWidget):
|
|||||||
)
|
)
|
||||||
self.l_box.addItem(self.l_line)
|
self.l_box.addItem(self.l_line)
|
||||||
self.v_box.addItem(self.v_line)
|
self.v_box.addItem(self.v_line)
|
||||||
|
|
||||||
|
self.clear_data()
|
||||||
|
|
||||||
self.update_views()
|
self.update_views()
|
||||||
self.v_plot_item.getViewBox().sigResized.connect(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
|
# if the array is full, keep only every second data point
|
||||||
# and skip every second data point.
|
# and skip every second data point.
|
||||||
if self.n_data_array == self.MAX_DATA_POINTS:
|
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):
|
for i in range(0, self.MAX_DATA_POINTS//2):
|
||||||
self.data_t[i] = self.data_t[2 * i]
|
self.data_t[i] = self.data_t[2 * i]
|
||||||
self.data_v[i] = self.data_v[2 * i]
|
self.data_v[i] = self.data_v[2 * i]
|
||||||
self.data_l[i] = self.data_l[2 * i]
|
self.data_l[i] = self.data_l[2 * i]
|
||||||
self.n_data_array = self.MAX_DATA_POINTS//2
|
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
|
# 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_t[self.n_data_array] = time
|
||||||
self.data_v[self.n_data_array] = voltage
|
self.data_v[self.n_data_array] = voltage
|
||||||
self.data_l[self.n_data_array] = led
|
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.data_l = np.empty(self.MAX_DATA_POINTS, dtype=float)
|
||||||
self.n_data_array = 0
|
self.n_data_array = 0
|
||||||
self.n_data_total = 0
|
self.n_data_total = 0
|
||||||
self.n_data_skip = 0
|
self.n_data_take_every_nth = 1
|
||||||
self.v_line.setData([], [])
|
self.v_line.setData([], [])
|
||||||
self.l_line.setData([], [])
|
self.l_line.setData([], [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user