Compare commits

...

3 Commits

2 changed files with 38 additions and 17 deletions

View File

@ -6,11 +6,13 @@ from PyQt6.QtWidgets import QApplication
from pyrelacs import info
from pyrelacs.ui.mainwindow import PyRelacs
from pyrelacs.util.logging import config_logging
import resources
log = config_logging()
from . import resources # best created with pyside6-rcc resources.qrc -o resources.py (rcc produces an error...)
from pyrelacs import (
resources,
) # best created with pyside6-rcc resources.qrc -o resources.py (rcc produces an error...)
def main():
app = QApplication(sys.argv)

View File

@ -44,6 +44,7 @@ class PyRelacs(QMainWindow):
self.power_plot.addLegend()
self.beat_plot.setBackground("w")
self.power_plot.setBackground("w")
self.power_plot.setLogMode(x=False, y=True)
self.threadpool = QThreadPool()
self.repros = Repro()
@ -67,7 +68,10 @@ class PyRelacs(QMainWindow):
self.setCentralWidget(widget)
filename = path.joinpath(path.cwd(), "data.nix")
self.nix_file = nix.File.open(str(filename), nix.FileMode.ReadWrite)
if filename.exists():
self.nix_file = nix.File.open(str(filename), nix.FileMode.ReadOnly)
else:
self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
def create_actions(self):
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
@ -80,17 +84,23 @@ class PyRelacs(QMainWindow):
self._rlx_aboutaction.setEnabled(True)
self._rlx_aboutaction.triggered.connect(self.on_about)
self._daq_connectaction = QAction(QIcon(":icons/connect.png"), "Connect DAQ", self)
self._daq_connectaction = QAction(
QIcon(":icons/connect.png"), "Connect DAQ", self
)
self._daq_connectaction.setStatusTip("Connect to daq device")
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
self._daq_connectaction.triggered.connect(self.connect_dac)
self._daq_disconnectaction = QAction(QIcon(":/icons/disconnect.png"), "Disconnect DAQ", self)
self._daq_disconnectaction = QAction(
QIcon(":/icons/disconnect.png"), "Disconnect DAQ", self
)
self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device")
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
self._daq_calibaction = QAction(QIcon(":/icons/calibration.png"), "Plot calibration", self)
self._daq_calibaction = QAction(
QIcon(":/icons/calibration.png"), "Plot calibration", self
)
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
self._daq_calibaction.triggered.connect(self.plot_calibration)
@ -205,21 +215,24 @@ class PyRelacs(QMainWindow):
beat = stim[:] + fish[:]
beat_squared = beat**2
f, powerspec = welch(beat, fs=40_000.0)
powerspec = decibel(powerspec)
f, powerspec = welch(
beat_squared,
window="flattop",
fs=40_000.0,
nperseg=100_000,
)
f_sq, powerspec_sq = welch(beat_squared, fs=40_000.0)
powerspec_sq = decibel(powerspec_sq)
peaks = find_peaks(powerspec_sq, prominence=10)[0]
peaks = find_peaks(powerspec, prominence=0.001)[0]
pen = pg.mkPen(colors[i])
self.beat_plot.plot(
np.arange(0, len(beat)) / 40_000.0,
beat_squared,
beat,
pen=pen,
name=stim.name,
)
self.power_plot.plot(f_sq, powerspec_sq, pen=pen, name=stim.name)
self.power_plot.plot(f[peaks], powerspec_sq[peaks], pen=None, symbol="x")
self.power_plot.plot(f, powerspec, pen=pen, name=stim.name)
self.power_plot.plot(f[peaks], powerspec[peaks], pen=None, symbol="x")
def connect_dac(self):
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
@ -261,8 +274,12 @@ class PyRelacs(QMainWindow):
self.threadpool.start(worker)
def add_to_textfield(self, s: str):
self.text.appendPlainText(s)
def on_exit(self):
print("exit button!")
log.info("exit button!")
self.add_to_textfield("exiting")
self.close()
def on_about(self, e):
@ -270,10 +287,12 @@ class PyRelacs(QMainWindow):
about.show()
def print_output(self, s):
print(s)
log.info(s)
self.add_to_textfield(s)
def thread_complete(self):
print("THREAD COMPLETE!")
log.info("Thread complete!")
self.add_to_textfield("Thread complete!")
def progress_fn(self, n):
print("%d%% done" % n)