2
0
forked from awendt/pyrelacs
minipyrelacs/pyrelacs/ui/plots/continously.py

68 lines
2.1 KiB
Python

import time
import pyqtgraph as pg
from IPython import embed
import numpy as np
from PyQt6.QtCore import QTimer
from pyrelacs.dataio.circbuffer import CircBuffer
from pyrelacs.util.logging import config_logging
log = config_logging()
class Continously:
def __init__(self, figure: pg.GraphicsLayoutWidget, buffer: CircBuffer):
self.figure = figure
self.buffer = buffer
def plot_daq(self, *args, **kwargs):
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.line = self.daq_plot.plot(
self.time,
self.data,
pen=pen,
setCliptoView=True,
symbol="o",
)
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)
# self.timer = QTimer()
# self.timer.setInterval(1)
# self.timer.timeout.connect(self.update_plot)
# self.timer.start()
# 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)