forked from awendt/pyrelacs
96 lines
2.9 KiB
Python
96 lines
2.9 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)
|
|
self.line = self.daq_plot.plot(
|
|
# self.time,
|
|
[0],
|
|
pen=pen,
|
|
setCliptoView=True,
|
|
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.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 = (np.arange(len(items)) / self.buffer.samplerate) + self.time[-1]
|
|
|
|
except IndexError:
|
|
item = 0
|
|
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")
|
|
# 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
|
|
|
|
self.line.setData(
|
|
# self.time,
|
|
items,
|
|
)
|
|
self.plot_index += len(items)
|
|
else:
|
|
# self.timer.stop()
|
|
# embed()
|
|
# exit()
|
|
pass
|
|
|
|
def stop_plotting(self):
|
|
self.timer.stop()
|