From 1fe854b74e2f636afd2404bb43b56969c7d59757 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Thu, 24 Oct 2024 11:50:49 +0200 Subject: [PATCH] [ui] moving creation of nix to nix_file --- pyrelacs/ui/mainwindow.py | 74 ++++++++++++++------------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/pyrelacs/ui/mainwindow.py b/pyrelacs/ui/mainwindow.py index 709a06c..6ce3a43 100644 --- a/pyrelacs/ui/mainwindow.py +++ b/pyrelacs/ui/mainwindow.py @@ -10,7 +10,6 @@ from PyQt6.QtWidgets import ( QPushButton, QTabWidget, QToolBar, - QVBoxLayout, QWidget, QMainWindow, QPlainTextEdit, @@ -50,6 +49,8 @@ class PyRelacs(QMainWindow): super().__init__() # loaded config self.config = config + + # check if daq is connencted else None if self.config.settings.daq: start = time.time() self.mccdaq = MccDaq() @@ -65,8 +66,6 @@ class PyRelacs(QMainWindow): ) # Ensure icons are displayed with text self.setWindowTitle("PyRelacs") - self.create_nix_file(f"{_root}/test.nix", self.config.metadata) - self.mutex = QMutex() self.figure = pg.GraphicsLayoutWidget() @@ -76,22 +75,6 @@ class PyRelacs(QMainWindow): self.text = QPlainTextEdit() self.text.setReadOnly(True) - self.setMenuBar(QMenuBar(self)) - self.setStatusBar(QStatusBar(self)) - self.create_actions() - self.create_toolbars() - self.repro_tabs = QTabWidget() - self.create_repros_tabs() - - layout = QGridLayout() - layout.addWidget(self.figure, 0, 0, 2, 2) - layout.addWidget(self.repro_tabs, 2, 0, 2, 2) - layout.addWidget(self.text, 4, 0, 1, 1) - - widget = QWidget() - widget.setLayout(layout) - self.setCentralWidget(widget) - SAMPLERATE = pq.Quantity( self.config.pyrelacs.data.input.inputsamplerate, self.config.pyrelacs.data.input.inputsamplerateunit, @@ -109,6 +92,7 @@ class PyRelacs(QMainWindow): self.buffer = CircBuffer( size=int(BUFFERSIZE.base), samplerate=float(SAMPLERATE.base), + channels=2, mutex=self.mutex, ) self.continously_plot = Continously(self.figure, self.buffer) @@ -116,11 +100,26 @@ class PyRelacs(QMainWindow): if self.mccdaq: log.debug("Creating Daq Generator") - self.daq_producer = DaqProducer(self.buffer, self.mccdaq.daq_device, [1, 1]) + self.daq_producer = DaqProducer(self.buffer, self.mccdaq.daq_device, [1, 2]) log.debug("Creating Sinus Generator") self.sinus_producer = SinProducer(self.buffer) - self.nix_writer = NixWriter(self.buffer) + self.nix_writer = NixWriter(self.buffer, self.config) + self.setMenuBar(QMenuBar(self)) + self.setStatusBar(QStatusBar(self)) + self.create_actions() + self.create_toolbars() + self.repro_tabs = QTabWidget() + self.create_repros_tabs() + + layout = QGridLayout() + layout.addWidget(self.figure, 0, 0, 2, 2) + layout.addWidget(self.repro_tabs, 2, 0, 2, 2) + layout.addWidget(self.text, 4, 0, 1, 1) + + widget = QWidget() + widget.setLayout(layout) + self.setCentralWidget(widget) def create_actions(self): self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self) @@ -224,10 +223,6 @@ class PyRelacs(QMainWindow): repro_names, file_names = self.repros.names_of_repros( include_repros=self.config.settings.repros ) - nix_blocks = { - rep: self.nix_file.create_block(f"{rep}", "Data Repro") - for rep in repro_names - } figures_repros = {rep: pg.GraphicsLayoutWidget() for rep in repro_names} for rep, fn in zip(repro_names, file_names): tab = QWidget() @@ -239,7 +234,6 @@ class PyRelacs(QMainWindow): lambda checked, n=rep, f=fn: self.run_repro( n, f, - nix_blocks, figures_repros, self.mccdaq, self.config, @@ -254,20 +248,18 @@ class PyRelacs(QMainWindow): self, name_of_repro: str, file_of_repro: str, - nix_block, figures, *args, ): self.text.appendPlainText(f"started Repro {name_of_repro}, {file_of_repro}") - nix_block_repro = nix_block[name_of_repro] + figure_repro = figures[name_of_repro] worker = Worker( self.repros.run_repro, name_of_repro, file_of_repro, - nix_block_repro, figure_repro, - *args[-2:], + *args[-1:], ) worker.signals.result.connect(self.print_output) worker.signals.finished.connect(self.thread_complete) @@ -275,22 +267,6 @@ class PyRelacs(QMainWindow): self.threadpool.start(worker) - def create_nix_file(self, file_path, metadata): - self.nix_file = nixio.File.open( - path=f"{file_path}", mode=nixio.FileMode.Overwrite - ) - self.block = self.nix_file.create_block("recording", "testfile") - self.section = self.nix_file.create_section("metadata", "config.yaml") - for key, value in asdict(metadata).items(): - self.section[key] = value - - self.data_array_analog1 = self.block.create_data_array( - "Analog1", "ndarray", shape=(1000,), dtype=nixio.DataType.Double - ) - self.data_array_analog2 = self.block.create_data_array( - "Analog2", "ndarray", shape=(1000,), dtype=nixio.DataType.Double - ) - def recenter_continously_plot(self): self.continously_plot.refresh() @@ -320,7 +296,9 @@ class PyRelacs(QMainWindow): self.continously_plot.plot() def record(self): - self.create_nix_file("test.nix", self.config.metadata) + self.data_array_analog1, self.data_array_analog2 = ( + self.nix_writer.create_nix_file(f"{_root}/test/", self.config.metadata) + ) log.debug("Created nix file") nix_writer = Worker( @@ -359,7 +337,7 @@ class PyRelacs(QMainWindow): except AttributeError: log.debug("Did not generate Sinus") - if hasattr(PyRelacs, "daq_device"): + if self.config.settings.daq: log.debug("Stopping DAQ") self.daq_producer.stop_aquisition()