2
0
forked from awendt/pyrelacs

[app] adding powerspectrum as plot

This commit is contained in:
wendtalexander 2024-09-27 16:55:37 +02:00
parent a16fe0b735
commit 3433ef7132

View File

@ -31,8 +31,8 @@ class PyRelacs(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.setWindowTitle("PyRelacs") self.setWindowTitle("PyRelacs")
self.setMinimumSize(1000, 1000) self.beat_plot = pg.PlotWidget()
self.plot_graph = pg.PlotWidget() self.power_plot = pg.PlotWidget()
self.threadpool = QThreadPool() self.threadpool = QThreadPool()
self.repros = Repro() self.repros = Repro()
@ -49,20 +49,17 @@ class PyRelacs(QMainWindow):
self.plot_calibration_button.setCheckable(True) self.plot_calibration_button.setCheckable(True)
self.plot_calibration_button.clicked.connect(self.plot_calibration) self.plot_calibration_button.clicked.connect(self.plot_calibration)
self.text = QPlainTextEdit()
self.text.setReadOnly(True)
layout = QGridLayout() layout = QGridLayout()
layout.addWidget(self.plot_calibration_button, 0, 0) layout.addWidget(self.plot_calibration_button, 0, 0)
layout.addWidget(self.daq_disconnect_button, 0, 1) layout.addWidget(self.daq_disconnect_button, 0, 1)
layout.addWidget(self.text, 3, 0, 1, 2) layout.addWidget(self.beat_plot, 2, 0, 1, 2)
layout.addWidget(self.plot_graph, 2, 0, 1, 2) layout.addWidget(self.power_plot, 3, 0, 1, 2)
self.toolbar = QToolBar("Repros") self.toolbar = QToolBar("Repros")
self.addToolBar(self.toolbar) self.addToolBar(self.toolbar)
self.repros_to_toolbar() self.repros_to_toolbar()
self.setFixedSize(QSize(400, 300)) # self.setFixedSize(QSize(400, 300))
widget = QWidget() widget = QWidget()
widget.setLayout(layout) widget.setLayout(layout)
self.setCentralWidget(widget) self.setCentralWidget(widget)
@ -111,8 +108,9 @@ class PyRelacs(QMainWindow):
return decibel_psd return decibel_psd
block = self.nix_file.blocks[0] block = self.nix_file.blocks[0]
for stim, fish in zip( colors = ["red", "green", "blue", "black", "yellow"]
list(block.data_arrays)[::2], list(block.data_arrays)[1::2] for i, (stim, fish) in enumerate(
zip(list(block.data_arrays)[::2], list(block.data_arrays)[1::2])
): ):
beat = stim[:] + fish[:] beat = stim[:] + fish[:]
beat_squared = beat**2 beat_squared = beat**2
@ -123,10 +121,15 @@ class PyRelacs(QMainWindow):
f_sq, powerspec_sq = welch(beat_squared, fs=40_000.0) f_sq, powerspec_sq = welch(beat_squared, fs=40_000.0)
powerspec_sq = decibel(powerspec_sq) powerspec_sq = decibel(powerspec_sq)
peaks = find_peaks(powerspec_sq, prominence=20)[0] peaks = find_peaks(powerspec_sq, prominence=20)[0]
pen = pg.mkPen() pen = pg.mkPen(colors[i])
self.plot_graph.plot( self.beat_plot.plot(
np.arange(0, len(beat)) / 40_000.0, beat_squared, pen=pen np.arange(0, len(beat)) / 40_000.0,
beat_squared,
pen=pen,
name=stim.name,
) )
self.power_plot.plot(f_sq, powerspec_sq, pen=pen)
self.power_plot.scatter(f[peaks], powerspec_sq[peaks])
def connect_dac(self): def connect_dac(self):
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)