[dataio/test] adding a sin producer for testing
This commit is contained in:
parent
52a0821601
commit
aaa42db2ae
53
pyrelacs/dataio/sin_producer.py
Normal file
53
pyrelacs/dataio/sin_producer.py
Normal file
@ -0,0 +1,53 @@
|
||||
from math import sin
|
||||
import time
|
||||
from PyQt6.QtGui import QAction
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from IPython import embed
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
|
||||
log = config_logging()
|
||||
|
||||
|
||||
# stopbutton: QAction
|
||||
class SinProducer:
|
||||
def __init__(
|
||||
self,
|
||||
buffer: CircBuffer,
|
||||
) -> None:
|
||||
self.buffer = buffer
|
||||
|
||||
# self.stopbutton = stopbutton
|
||||
|
||||
def produce_sin(
|
||||
self,
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
AMPLITUDE = 2
|
||||
FREQUENCY = 10
|
||||
|
||||
log.debug("producing Sin")
|
||||
start_time = time.time()
|
||||
t = 0
|
||||
while time.time() - start_time < 2:
|
||||
|
||||
s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t)
|
||||
|
||||
self.buffer.append(s)
|
||||
t += 1 / self.buffer.samplerate
|
||||
time.sleep(1 / self.buffer.samplerate)
|
||||
|
||||
data = self.buffer.get_all()
|
||||
log.debug(data.shape[0])
|
||||
log.debug(data.shape[0] / self.buffer.samplerate)
|
||||
# plt.plot(np.arange(data.size) / self.buffer.samplerate, data)
|
||||
# plt.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
buf = CircBuffer(1_000_000, 1, samplerate=10000)
|
||||
pro_sin = SinProducer(buf)
|
||||
pro_sin.produce_sin()
|
@ -24,6 +24,7 @@ import numpy as np
|
||||
|
||||
|
||||
from pyrelacs.dataio.daq_producer import DaqProducer
|
||||
from pyrelacs.dataio.sin_producer import SinProducer
|
||||
from pyrelacs.worker import Worker
|
||||
from pyrelacs.repros.repros import Repro
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
@ -54,7 +55,7 @@ class PyRelacs(QMainWindow):
|
||||
if filename.exists():
|
||||
self.nix_file = nix.File.open(str(filename), nix.FileMode.ReadOnly)
|
||||
filename = path.joinpath(path.cwd(), "calibration.nix")
|
||||
self.nix_calibration = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||
self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||
|
||||
self.calibration_plot = CalibrationPlot(self.figure, self.nix_file)
|
||||
|
||||
@ -77,10 +78,12 @@ class PyRelacs(QMainWindow):
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
self.buffer = CircBuffer(size=1_000_000, samplerate=40_000)
|
||||
self.connect_dac()
|
||||
SAMPLERATE = 10000
|
||||
self.buffer = CircBuffer(size=1_000_000, samplerate=SAMPLERATE)
|
||||
# self.connect_dac()
|
||||
|
||||
self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
self.sin_producer = SinProducer(self.buffer)
|
||||
self.continously_plot = Continously(self.figure, self.buffer)
|
||||
|
||||
def create_actions(self):
|
||||
@ -118,7 +121,10 @@ class PyRelacs(QMainWindow):
|
||||
self._run_action = QAction(QIcon(":/icons/record.png"), "Run", self)
|
||||
self._run_action.triggered.connect(self.run_daq)
|
||||
|
||||
self._stop_recording = QAction(QIcon(":/icons/record.png"), "Stop", self)
|
||||
self._run_sinus_action = QAction(QIcon(":/icons/record.png"), "Sinus", self)
|
||||
self._run_sinus_action.triggered.connect(self.run_sinus)
|
||||
|
||||
self._stop_recording = QAction("Stop", self)
|
||||
self._stop_recording.triggered.connect(self.stop_recording)
|
||||
|
||||
self.create_menu()
|
||||
@ -161,6 +167,7 @@ class PyRelacs(QMainWindow):
|
||||
daq_toolbar.addAction(self._daq_disconnectaction)
|
||||
daq_toolbar.addAction(self._daq_calibaction)
|
||||
daq_toolbar.addAction(self._run_action)
|
||||
daq_toolbar.addAction(self._run_sinus_action)
|
||||
daq_toolbar.addAction(self._stop_recording)
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||
|
||||
@ -196,6 +203,16 @@ class PyRelacs(QMainWindow):
|
||||
self.continously_plot.plot_daq()
|
||||
# self.threadpool.start(plot_daq)
|
||||
|
||||
def run_sinus(self):
|
||||
sinus_pro = Worker(self.sin_producer.produce_sin)
|
||||
sinus_pro.signals.result.connect(self.print_output)
|
||||
sinus_pro.signals.finished.connect(self.thread_complete)
|
||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(sinus_pro)
|
||||
|
||||
time.sleep(0.05)
|
||||
self.continously_plot.plot_daq()
|
||||
|
||||
def stop_recording(self):
|
||||
self.add_to_textfield("pressed")
|
||||
self._stop_recording.setEnabled(False)
|
||||
|
@ -1,4 +1,6 @@
|
||||
import pyqtgraph as pg
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
|
||||
from PyQt6.QtCore import QTimer
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
@ -15,10 +17,15 @@ class Continously:
|
||||
def plot_daq(self, *args, **kwargs):
|
||||
self.figure.setBackground("w")
|
||||
self.daq_plot = self.figure.addPlot(row=0, col=0)
|
||||
self.time = list(range(10))
|
||||
pen = pg.mkPen("red")
|
||||
self.data = list(range(10))
|
||||
self.line = self.daq_plot.plot(self.time, self.data, pen=pen)
|
||||
self.time = np.arange(self.buffer.size) / self.buffer.samplerate
|
||||
self.data = np.ones(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
|
||||
)
|
||||
# self.line.setXRrange(np.arange(0, 10, 1 / self.buffer.samplerate))
|
||||
|
||||
self.item = 0
|
||||
self.timer = QTimer()
|
||||
@ -29,12 +36,13 @@ class Continously:
|
||||
def update_plot(self):
|
||||
if self.buffer.totalcount() > 100:
|
||||
if self.buffer.write_index() > self.item:
|
||||
self.time = self.time[1:]
|
||||
self.time.append(self.time[-1] + 1)
|
||||
self.data = self.data[1:]
|
||||
item = self.buffer.get(self.item)
|
||||
self.data.append(item)
|
||||
self.line.setData(self.time, self.data)
|
||||
# self.time = self.time[1:]
|
||||
# self.time.append(self.time[-1] + 1)
|
||||
# self.data = self.data[1:]
|
||||
item = self.buffer.get_all()
|
||||
t = np.arange(item.shape[0]) / self.buffer.samplerate
|
||||
# self.data.append(item)
|
||||
self.line.setData(t, item)
|
||||
self.item += 1
|
||||
else:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user