Compare commits
7 Commits
main
...
fa1db4138e
| Author | SHA1 | Date | |
|---|---|---|---|
| fa1db4138e | |||
| 2155b285b7 | |||
| 1421ad2198 | |||
| 5a7843e866 | |||
| a569014cba | |||
| 7347278c8f | |||
| 2ede519b95 |
3
.gitignore
vendored
@@ -163,6 +163,3 @@ cython_debug/
|
|||||||
|
|
||||||
# ignore created data files
|
# ignore created data files
|
||||||
*.nix
|
*.nix
|
||||||
|
|
||||||
# ignore reource.py as it is created by pyside6-rcc resources.qrc -o resources.py
|
|
||||||
resources.py
|
|
||||||
@@ -5,13 +5,9 @@ Relaxed ELectrophysiology Acquisition, Control, and Stimulation in python
|
|||||||
Implementing [relacs](https://github.com/relacs/relacs) with MCC USB 1608GX-2AO / 1808X devices ([multifunction-usb-daq-devices](https://digilent.com/shop/mcc-daq/data-acquisition/low-cost-daq/))
|
Implementing [relacs](https://github.com/relacs/relacs) with MCC USB 1608GX-2AO / 1808X devices ([multifunction-usb-daq-devices](https://digilent.com/shop/mcc-daq/data-acquisition/low-cost-daq/))
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
You have to install the MCC library (follow the installing instructions for [linux/macOS](https://github.com/mccdaq/uldaq) or [windows](https://github.com/mccdaq/mcculw)).
|
You have to install the MCC library (follow the installing instructions for [linux](https://github.com/mccdaq/uldaq) or [windows](https://github.com/mccdaq/mcculw)).
|
||||||
|
|
||||||
For MacOs if you run into problems with the libusb library if installed with homebrew, there is an issue thread on the uldaq repository.
|
After successful installing, you can use clone the reposity and install it with
|
||||||
|
|
||||||
[https://github.com/mccdaq/uldaq/issues/44](https://github.com/mccdaq/uldaq/issues/44)
|
|
||||||
|
|
||||||
After successful installing, you can use clone the repository and install it with
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pip install -e .
|
pip install -e .
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import pathlib
|
||||||
|
|
||||||
from PyQt6.QtCore import QSettings
|
from PyQt6.QtCore import QSettings, Qt
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
|
||||||
from pyrelacs import info
|
from . import info
|
||||||
from pyrelacs.ui.mainwindow import PyRelacs
|
from .ui.mainwindow import PyRelacs
|
||||||
from pyrelacs.util.logging import config_logging
|
from .util.logging import config_logging
|
||||||
import resources
|
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
from . import resources # best created with pyside6-rcc resources.qrc -o resources.py (rcc produces an error...)
|
from . import resources
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|||||||
@@ -12,32 +12,13 @@ log = config_logging()
|
|||||||
|
|
||||||
|
|
||||||
class MccDac:
|
class MccDac:
|
||||||
"""
|
|
||||||
Represents the Digital/Analog Converter from Meassuring Computing.
|
|
||||||
provides methods for writing and reading the Analog / Digital input and output.
|
|
||||||
|
|
||||||
Connects to the DAC device.
|
|
||||||
|
|
||||||
Attributes
|
|
||||||
----------
|
|
||||||
daq_device : uldaq.DaqDevice
|
|
||||||
DaqDevice for handling connecting, releasing and disconnecting
|
|
||||||
ai_device : uldaq.AiDevice
|
|
||||||
The Analog input Device
|
|
||||||
ao_device :
|
|
||||||
Analog output Device
|
|
||||||
dio_device :
|
|
||||||
Digital Input Output
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
try:
|
if len(devices) == 0:
|
||||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
|
||||||
except uldaq.ul_exception.ULException as e:
|
|
||||||
log.error("Did not found daq devices, please connect one")
|
log.error("Did not found daq devices, please connect one")
|
||||||
raise e
|
exit(1)
|
||||||
|
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||||
try:
|
try:
|
||||||
self.daq_device.connect()
|
self.daq_device.connect()
|
||||||
except uldaq.ul_exception.ULException:
|
except uldaq.ul_exception.ULException:
|
||||||
@@ -49,10 +30,6 @@ class MccDac:
|
|||||||
log.debug("Connected")
|
log.debug("Connected")
|
||||||
|
|
||||||
def connect_dac(self):
|
def connect_dac(self):
|
||||||
"""
|
|
||||||
Connecting to the DAQ device
|
|
||||||
|
|
||||||
"""
|
|
||||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
if len(devices) == 0:
|
if len(devices) == 0:
|
||||||
@@ -75,40 +52,6 @@ class MccDac:
|
|||||||
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||||
AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT,
|
AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT,
|
||||||
) -> Array[c_double]:
|
) -> Array[c_double]:
|
||||||
"""
|
|
||||||
Reading the analog input of the DAC device
|
|
||||||
Creates a c_double Array for storing the acquired data
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
channels : list[int]
|
|
||||||
channels to read from, provide only two int's in a list (ex [0, 1] or [0, 4])
|
|
||||||
for sampling from the range(channel0, channel4)
|
|
||||||
|
|
||||||
duration : int
|
|
||||||
duration of sampling period
|
|
||||||
|
|
||||||
samplerate : float
|
|
||||||
samplerate for the duration of sampling
|
|
||||||
|
|
||||||
AiInputMode : uldaq.AiInputMode = uldaq.AiInputMode.SINGLE_ENDED
|
|
||||||
Contains attributes indicating A/D channel input modes.
|
|
||||||
Compares to Ground
|
|
||||||
|
|
||||||
Range : uldaq.Range = uldaq.Range.BIP10VOLTS
|
|
||||||
Range of the output
|
|
||||||
|
|
||||||
ScanOption : uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO
|
|
||||||
Specific Flags for acuiring the input
|
|
||||||
|
|
||||||
AInScanFlag : uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT
|
|
||||||
Scaling of the data
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Array[c_double]
|
|
||||||
|
|
||||||
"""
|
|
||||||
assert len(channels) == 2, log.error("You can only provide two channels [0, 1]")
|
assert len(channels) == 2, log.error("You can only provide two channels [0, 1]")
|
||||||
|
|
||||||
if channels[0] != channels[1]:
|
if channels[0] != channels[1]:
|
||||||
@@ -142,37 +85,6 @@ class MccDac:
|
|||||||
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||||
AOutScanFlag: uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT,
|
AOutScanFlag: uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT,
|
||||||
) -> Array[c_double]:
|
) -> Array[c_double]:
|
||||||
"""
|
|
||||||
Writes data to the DAC device.
|
|
||||||
Creates a c_double Array for writing the data
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
data : Union[list, npt.NDArray]
|
|
||||||
data which should be written to the DAC
|
|
||||||
|
|
||||||
channels : list[int]
|
|
||||||
channels to read from, provide only two int's in a list (ex [0, 1])
|
|
||||||
for sampling from the range(channel0, channel1)
|
|
||||||
DAC USB 1608GX-2AO has only 2 output channels
|
|
||||||
|
|
||||||
samplerate : float
|
|
||||||
samplerate for the duration of sampling
|
|
||||||
|
|
||||||
Range : uldaq.Range = uldaq.Range.BIP10VOLTS
|
|
||||||
Range of the output
|
|
||||||
|
|
||||||
ScanOption : uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO
|
|
||||||
Specific Flags for acuiring the input
|
|
||||||
|
|
||||||
AOutScanFlag : uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT
|
|
||||||
For Scaling the data
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Array[c_double]
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert len(channels) == 2, log.error("You can only provide two channels [0, 1]")
|
assert len(channels) == 2, log.error("You can only provide two channels [0, 1]")
|
||||||
|
|
||||||
buffer = c_double * len(data)
|
buffer = c_double * len(data)
|
||||||
@@ -197,18 +109,7 @@ class MccDac:
|
|||||||
|
|
||||||
return data_analog_output
|
return data_analog_output
|
||||||
|
|
||||||
def set_analog_to_zero(self, channels: list[int] = [0, 1]) -> None:
|
def set_analog_to_zero(self, channels: list[int] = [0, 1]):
|
||||||
"""
|
|
||||||
Sets all analog outputs to zero
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
channels : list[int]
|
|
||||||
channels to read from, provide only two int's in a list (ex [0, 1])
|
|
||||||
for sampling from the range(channel0, channel1)
|
|
||||||
DAC USB 1608GX-2AO has only 2 output channels
|
|
||||||
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
err = self.ao_device.a_out_list(
|
err = self.ao_device.a_out_list(
|
||||||
channels[0],
|
channels[0],
|
||||||
@@ -225,37 +126,16 @@ class MccDac:
|
|||||||
log.error("disconnection dac")
|
log.error("disconnection dac")
|
||||||
self.disconnect_dac()
|
self.disconnect_dac()
|
||||||
|
|
||||||
def digital_trigger(self, ch: int = 0) -> None:
|
def diggital_trigger(self) -> None:
|
||||||
"""
|
data = self.read_bit(channel=0)
|
||||||
Writes a 1 to a specified digital channel, if the channel is already on 1 switches it to
|
|
||||||
0 and after Nano second it writes a 1 to the specified digital channel
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
ch : int
|
|
||||||
Channel to trigger
|
|
||||||
"""
|
|
||||||
data = self.read_bit(channel=ch)
|
|
||||||
if data:
|
if data:
|
||||||
self.write_bit(channel=ch, bit=0)
|
self.write_bit(channel=0, bit=0)
|
||||||
time.time_ns()
|
time.time_ns()
|
||||||
self.write_bit(channel=ch, bit=1)
|
self.write_bit(channel=0, bit=1)
|
||||||
else:
|
else:
|
||||||
self.write_bit(channel=ch, bit=1)
|
self.write_bit(channel=0, bit=1)
|
||||||
|
|
||||||
def write_bit(self, channel: int = 0, bit: int = 1) -> None:
|
def write_bit(self, channel: int = 0, bit: int = 1) -> None:
|
||||||
"""
|
|
||||||
Writes a 0 / 1 to a specified digitial channel
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
channel : int
|
|
||||||
Digital channel to write
|
|
||||||
|
|
||||||
bit : int
|
|
||||||
0 / 1 for writing to the digital channel
|
|
||||||
|
|
||||||
"""
|
|
||||||
self.dio_device.d_config_bit(
|
self.dio_device.d_config_bit(
|
||||||
uldaq.DigitalPortType.AUXPORT, channel, uldaq.DigitalDirection.OUTPUT
|
uldaq.DigitalPortType.AUXPORT, channel, uldaq.DigitalDirection.OUTPUT
|
||||||
)
|
)
|
||||||
@@ -263,36 +143,55 @@ class MccDac:
|
|||||||
uldaq.DigitalPortType.AUXPORT, bit_number=channel, data=bit
|
uldaq.DigitalPortType.AUXPORT, bit_number=channel, data=bit
|
||||||
)
|
)
|
||||||
|
|
||||||
def read_bit(self, channel: int = 0) -> int:
|
def read_bit(self, channel: int = 0):
|
||||||
"""
|
|
||||||
Reads a 0 / 1 from the specified digital channel
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
channel : int
|
|
||||||
Digital channel to read from
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bit : int
|
|
||||||
0 or 1 from the digital channel
|
|
||||||
"""
|
|
||||||
bit = self.dio_device.d_bit_in(uldaq.DigitalPortType.AUXPORT, channel)
|
bit = self.dio_device.d_bit_in(uldaq.DigitalPortType.AUXPORT, channel)
|
||||||
return bit
|
return bit
|
||||||
|
|
||||||
|
def read_digitalio(
|
||||||
|
self,
|
||||||
|
channels: list[int],
|
||||||
|
duration,
|
||||||
|
samplerate,
|
||||||
|
ScanOptions: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||||
|
DInScanFlag: uldaq.DInScanFlag = uldaq.DInScanFlag.DEFAULT,
|
||||||
|
):
|
||||||
|
if channels[0] == channels[1]:
|
||||||
|
channel_len = 1
|
||||||
|
else:
|
||||||
|
channel_len = len(channels)
|
||||||
|
|
||||||
|
buffer_len = np.shape(np.arange(0, duration, 1 / samplerate))[0]
|
||||||
|
data_digital_input = uldaq.create_int_buffer(channel_len, buffer_len)
|
||||||
|
|
||||||
|
self.dio_device.d_config_port(
|
||||||
|
uldaq.DigitalPortType.AUXPORT, uldaq.DigitalDirection.INPUT
|
||||||
|
)
|
||||||
|
scan_rate = self.dio_device.d_in_scan(
|
||||||
|
uldaq.DigitalPortType.AUXPORT0,
|
||||||
|
uldaq.DigitalPortType.AUXPORT0,
|
||||||
|
len(data_digital_input),
|
||||||
|
samplerate,
|
||||||
|
ScanOptions,
|
||||||
|
DInScanFlag,
|
||||||
|
data_digital_input,
|
||||||
|
)
|
||||||
|
return data_digital_input
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
self.daq_device.disconnect()
|
self.daq_device.disconnect()
|
||||||
self.daq_device.release()
|
self.daq_device.release()
|
||||||
|
|
||||||
def check_attenuator(self) -> None:
|
def check_attenuator(self):
|
||||||
"""
|
"""
|
||||||
For checking the attenuator in the DAC device that was implemented to attenuate the
|
ident : attdev-1
|
||||||
analog signal to mV.
|
strobepin : 6
|
||||||
|
datainpin : 5
|
||||||
Writes to Channel 0 of the analog output with different attenuation levels
|
dataoutpin: -1
|
||||||
0, 0, -2, -5, -10, -20, -50 dB and the second 0 has a software mute
|
cspin : 4
|
||||||
|
mutepin : 7
|
||||||
|
zcenpin : -1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SAMPLERATE = 40_000.0
|
SAMPLERATE = 40_000.0
|
||||||
DURATION = 5
|
DURATION = 5
|
||||||
AMPLITUDE = 1
|
AMPLITUDE = 1
|
||||||
@@ -302,6 +201,7 @@ class MccDac:
|
|||||||
# data_channels = np.concatenate((data, data))
|
# data_channels = np.concatenate((data, data))
|
||||||
|
|
||||||
db_values = [0, 0, -2, -5, -10, -20, -50]
|
db_values = [0, 0, -2, -5, -10, -20, -50]
|
||||||
|
db_values = [0, -10, -20]
|
||||||
for i, db_value in enumerate(db_values):
|
for i, db_value in enumerate(db_values):
|
||||||
log.info(f"Attenuating the Channels, with {db_value}")
|
log.info(f"Attenuating the Channels, with {db_value}")
|
||||||
if i == 1:
|
if i == 1:
|
||||||
@@ -319,7 +219,7 @@ class MccDac:
|
|||||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||||
Range=uldaq.Range.BIP10VOLTS,
|
Range=uldaq.Range.BIP10VOLTS,
|
||||||
)
|
)
|
||||||
self.digital_trigger()
|
self.diggital_trigger()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||||
@@ -348,16 +248,6 @@ class MccDac:
|
|||||||
mute_channel2: bool = False,
|
mute_channel2: bool = False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Setting the attenuation level of the chip that is connected to the DAQ
|
|
||||||
The attenuation level is set by writing to the connected digital output pin 5
|
|
||||||
where the strobepin 6 is signaling the when the bit was send.
|
|
||||||
The cspin is set from 1 to 0 for the start and 0 to 1 for signaling the end
|
|
||||||
of the data write process.
|
|
||||||
|
|
||||||
The mute pin should be set to 1 for the device to be working.
|
|
||||||
|
|
||||||
More information in the AttCS3310.pdf in the doc
|
|
||||||
|
|
||||||
ident : attdev-1
|
ident : attdev-1
|
||||||
strobepin : 6
|
strobepin : 6
|
||||||
datainpin : 5
|
datainpin : 5
|
||||||
@@ -365,23 +255,8 @@ class MccDac:
|
|||||||
cspin : 4
|
cspin : 4
|
||||||
mutepin : 7
|
mutepin : 7
|
||||||
zcenpin : -1
|
zcenpin : -1
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
db_channel1 : float
|
|
||||||
dB Attenuation level for the first channel
|
|
||||||
|
|
||||||
db_channel2 : float
|
|
||||||
dB Attenuation level for the second channel
|
|
||||||
|
|
||||||
mute_channel1 : bool
|
|
||||||
Software mute for the first channel
|
|
||||||
|
|
||||||
mute_channel2 : bool
|
|
||||||
Software mute for the second channel
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.activate_attenuator()
|
self.activate_attenuator()
|
||||||
hardware_possible_db = np.arange(-95.5, 32.0, 0.5)
|
hardware_possible_db = np.arange(-95.5, 32.0, 0.5)
|
||||||
byte_number = np.arange(1, 256)
|
byte_number = np.arange(1, 256)
|
||||||
@@ -408,18 +283,9 @@ class MccDac:
|
|||||||
self.write_bit(channel=4, bit=1)
|
self.write_bit(channel=4, bit=1)
|
||||||
|
|
||||||
def activate_attenuator(self):
|
def activate_attenuator(self):
|
||||||
"""
|
|
||||||
Activation of the attenuator, where the cspin and mute pin is set to 1,
|
|
||||||
and the datapin and strobpin to 0
|
|
||||||
|
|
||||||
"""
|
|
||||||
for ch, b in zip([4, 5, 6, 7], [1, 0, 0, 1]):
|
for ch, b in zip([4, 5, 6, 7], [1, 0, 0, 1]):
|
||||||
self.write_bit(channel=ch, bit=b)
|
self.write_bit(channel=ch, bit=b)
|
||||||
|
|
||||||
def deactivate_attenuator(self):
|
def deactivate_attenuator(self):
|
||||||
"""
|
|
||||||
Writes a 0 to the mute pin, which is deactivating the attenuator
|
|
||||||
|
|
||||||
"""
|
|
||||||
# mute should be enabled for starting calibration
|
# mute should be enabled for starting calibration
|
||||||
self.write_bit(channel=7, bit=0)
|
self.write_bit(channel=7, bit=0)
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 38 KiB |
@@ -1,3 +1,5 @@
|
|||||||
|
import signal
|
||||||
|
import sys
|
||||||
import faulthandler
|
import faulthandler
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -6,14 +8,13 @@ import uldaq
|
|||||||
from IPython import embed
|
from IPython import embed
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from scipy.signal import welch
|
from scipy.signal import welch, csd
|
||||||
from scipy.signal import find_peaks
|
from scipy.signal import find_peaks
|
||||||
|
|
||||||
from pyrelacs.devices.mccdac import MccDac
|
from pyrelacs.devices.mccdac import MccDac
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
# for more information on seg faults
|
|
||||||
faulthandler.enable()
|
faulthandler.enable()
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class Calibration(MccDac):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
log.debug("Starting the Scan")
|
log.debug("Starting the Scan")
|
||||||
self.digital_trigger()
|
self.diggital_trigger()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||||
@@ -108,7 +109,7 @@ class Calibration(MccDac):
|
|||||||
self.SAMPLERATE,
|
self.SAMPLERATE,
|
||||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||||
)
|
)
|
||||||
self.digital_trigger()
|
self.diggital_trigger()
|
||||||
log.info(self.ao_device)
|
log.info(self.ao_device)
|
||||||
ai_status = uldaq.ScanStatus.RUNNING
|
ai_status = uldaq.ScanStatus.RUNNING
|
||||||
ao_status = uldaq.ScanStatus.RUNNING
|
ao_status = uldaq.ScanStatus.RUNNING
|
||||||
@@ -132,20 +133,15 @@ class Calibration(MccDac):
|
|||||||
channel1 = np.array(readout[::2])
|
channel1 = np.array(readout[::2])
|
||||||
channel2 = np.array(readout[1::2])
|
channel2 = np.array(readout[1::2])
|
||||||
|
|
||||||
stim_data = block.create_data_array(
|
block.create_data_array(
|
||||||
f"stimulus_{db_value}",
|
f"stimulus_{db_value}",
|
||||||
"nix.regular_sampled",
|
"Array",
|
||||||
shape=data.shape,
|
shape=data.shape,
|
||||||
data=channel1,
|
data=channel1,
|
||||||
label="Voltage",
|
label="Voltage",
|
||||||
unit="V",
|
unit="V",
|
||||||
)
|
)
|
||||||
stim_data.append_sampled_dimension(
|
block.create_data_array(
|
||||||
self.SAMPLERATE,
|
|
||||||
label="time",
|
|
||||||
unit="s",
|
|
||||||
)
|
|
||||||
fish_data = block.create_data_array(
|
|
||||||
f"fish_{db_value}",
|
f"fish_{db_value}",
|
||||||
"Array",
|
"Array",
|
||||||
shape=data.shape,
|
shape=data.shape,
|
||||||
@@ -153,11 +149,6 @@ class Calibration(MccDac):
|
|||||||
label="Voltage",
|
label="Voltage",
|
||||||
unit="V",
|
unit="V",
|
||||||
)
|
)
|
||||||
fish_data.append_sampled_dimension(
|
|
||||||
self.SAMPLERATE,
|
|
||||||
label="time",
|
|
||||||
unit="s",
|
|
||||||
)
|
|
||||||
|
|
||||||
beat = channel1 + channel2
|
beat = channel1 + channel2
|
||||||
beat_square = beat**2
|
beat_square = beat**2
|
||||||
|
|||||||
@@ -1,24 +1,15 @@
|
|||||||
import sys
|
import sys
|
||||||
import ast
|
import ast
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
from IPython import embed
|
|
||||||
import nixio as nix
|
import nixio as nix
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
|
from IPython import embed
|
||||||
|
|
||||||
class Repro:
|
class Repro:
|
||||||
"""
|
|
||||||
Repro Class that searches in the repro folder for classes instances and executes the
|
|
||||||
the run function in the searched class
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -34,27 +25,14 @@ class Repro:
|
|||||||
log.error("Could not load the module of the repro")
|
log.error("Could not load the module of the repro")
|
||||||
else:
|
else:
|
||||||
sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
if spec.loader is not None:
|
spec.loader.exec_module(module)
|
||||||
spec.loader.exec_module(module)
|
|
||||||
else:
|
|
||||||
log.error(f"{spec.loader} is None")
|
|
||||||
if hasattr(module, name):
|
if hasattr(module, name):
|
||||||
rep_class = getattr(module, name)
|
rep_class = getattr(module, name)
|
||||||
rep_class.run(nix_file)
|
rep_class.run(nix_file)
|
||||||
else:
|
else:
|
||||||
raise AttributeError(f"{file.name} has no {name} class")
|
raise AttributeError(f"{file.name} has no {name} class")
|
||||||
|
|
||||||
def names_of_repros(self) -> Tuple[list, list]:
|
def names_of_repros(self):
|
||||||
"""
|
|
||||||
Searches for class names in the repro folder in all python files
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Tuple[list, list]
|
|
||||||
list of class names
|
|
||||||
list of file names from the class names
|
|
||||||
"""
|
|
||||||
|
|
||||||
file_path_cur = pathlib.Path(__file__).parent
|
file_path_cur = pathlib.Path(__file__).parent
|
||||||
python_files = list(file_path_cur.glob("**/*.py"))
|
python_files = list(file_path_cur.glob("**/*.py"))
|
||||||
exclude_files = ["repros.py", "__init__.py"]
|
exclude_files = ["repros.py", "__init__.py"]
|
||||||
|
|||||||
@@ -5,6 +5,5 @@
|
|||||||
<file>icons/disconnect.png</file>
|
<file>icons/disconnect.png</file>
|
||||||
<file>icons/record.png</file>
|
<file>icons/record.png</file>
|
||||||
<file>icons/stop.png</file>
|
<file>icons/stop.png</file>
|
||||||
<file>icons/relacstuxheader.png</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import pathlib
|
||||||
|
|
||||||
from PyQt6.QtGui import QPixmap
|
from PyQt6.QtGui import QPixmap
|
||||||
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLabel, QVBoxLayout, QWidget
|
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLabel, QVBoxLayout, QWidget
|
||||||
from PyQt6.QtCore import Qt
|
from PyQt6.QtCore import Qt
|
||||||
@@ -38,7 +40,8 @@ class About(QWidget):
|
|||||||
rtd_link.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
rtd_link.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
iconlabel = QLabel()
|
iconlabel = QLabel()
|
||||||
pixmap = QPixmap(":/icons/relacstuxheader.png")
|
_root = pathlib.Path(__file__).parent.parent
|
||||||
|
pixmap = QPixmap(str(pathlib.Path.joinpath(_root, "icons/relacstuxheader.png")))
|
||||||
s = pixmap.size()
|
s = pixmap.size()
|
||||||
new_height = int(s.height() * 300/s.width())
|
new_height = int(s.height() * 300/s.width())
|
||||||
pixmap = pixmap.scaled(300, new_height, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.FastTransformation)
|
pixmap = pixmap.scaled(300, new_height, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.FastTransformation)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from PyQt6.QtWidgets import (
|
|||||||
QMainWindow,
|
QMainWindow,
|
||||||
QPlainTextEdit,
|
QPlainTextEdit,
|
||||||
QMenuBar,
|
QMenuBar,
|
||||||
QStatusBar,
|
QStatusBar
|
||||||
)
|
)
|
||||||
import uldaq
|
import uldaq
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -18,26 +18,22 @@ import pyqtgraph as pg
|
|||||||
from pathlib import Path as path
|
from pathlib import Path as path
|
||||||
from scipy.signal import welch, find_peaks
|
from scipy.signal import welch, find_peaks
|
||||||
|
|
||||||
from pyrelacs.worker import Worker
|
from ..worker import Worker
|
||||||
from pyrelacs.repros.repros import Repro
|
from ..repros.repros import Repro
|
||||||
from pyrelacs.util.logging import config_logging
|
from ..util.logging import config_logging
|
||||||
from pyrelacs.ui.about import AboutDialog
|
from .about import AboutDialog
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
_root = path(__file__).parent.parent
|
_root = path(__file__).parent.parent
|
||||||
|
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
|
|
||||||
|
|
||||||
class PyRelacs(QMainWindow):
|
class PyRelacs(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setToolButtonStyle(
|
# self.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) # Ensure icons are displayed with text
|
||||||
Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
|
||||||
) # Ensure icons are displayed with text
|
|
||||||
self.setWindowTitle("PyRelacs")
|
self.setWindowTitle("PyRelacs")
|
||||||
self.beat_plot = pg.PlotWidget()
|
self.setMinimumSize(1000, 1000)
|
||||||
self.power_plot = pg.PlotWidget()
|
self.plot_graph = pg.PlotWidget()
|
||||||
|
|
||||||
self.threadpool = QThreadPool()
|
self.threadpool = QThreadPool()
|
||||||
self.repros = Repro()
|
self.repros = Repro()
|
||||||
@@ -52,19 +48,21 @@ class PyRelacs(QMainWindow):
|
|||||||
self.create_toolbars()
|
self.create_toolbars()
|
||||||
|
|
||||||
layout = QGridLayout()
|
layout = QGridLayout()
|
||||||
layout.addWidget(self.beat_plot, 0, 0, 1, 2)
|
layout.addWidget(self.plot_calibration_button, 0, 0)
|
||||||
layout.addWidget(self.power_plot, 1, 0, 1, 2)
|
layout.addWidget(self.daq_disconnect_button, 0, 1)
|
||||||
layout.addWidget(self.text, 2, 0, 1, 2)
|
layout.addWidget(self.text, 3, 0, 1, 2)
|
||||||
|
layout.addWidget(self.plot_graph, 2, 0, 1, 2)
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
self.setCentralWidget(widget)
|
self.setCentralWidget(widget)
|
||||||
|
|
||||||
filename = path.joinpath(path.cwd(), "data")
|
filename = path.joinpath(path.cwd(), "data.nix")
|
||||||
self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
self.nix_file = nix.File.open(
|
||||||
|
str(filename), nix.FileMode.Overwrite
|
||||||
|
)
|
||||||
|
|
||||||
def create_actions(self):
|
def create_actions(self):
|
||||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
self._rlx_exitaction = QAction(QIcon(str(path.joinpath(_root, "icons/exit.png"))), "Exit", self)
|
||||||
self._rlx_exitaction.setStatusTip("Close relacs")
|
self._rlx_exitaction.setStatusTip("Close relacs")
|
||||||
self._rlx_exitaction.setShortcut(QKeySequence("Alt+q"))
|
self._rlx_exitaction.setShortcut(QKeySequence("Alt+q"))
|
||||||
self._rlx_exitaction.triggered.connect(self.on_exit)
|
self._rlx_exitaction.triggered.connect(self.on_exit)
|
||||||
@@ -74,17 +72,17 @@ class PyRelacs(QMainWindow):
|
|||||||
self._rlx_aboutaction.setEnabled(True)
|
self._rlx_aboutaction.setEnabled(True)
|
||||||
self._rlx_aboutaction.triggered.connect(self.on_about)
|
self._rlx_aboutaction.triggered.connect(self.on_about)
|
||||||
|
|
||||||
self._daq_connectaction = QAction(QIcon(":icons/connect.png"), "Connect DAQ", self)
|
self._daq_connectaction = QAction(QIcon(str(path.joinpath(_root, "icons/connect.png"))), "Connect DAQ", self)
|
||||||
self._daq_connectaction.setStatusTip("Connect to daq device")
|
self._daq_connectaction.setStatusTip("Connect to daq device")
|
||||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||||
self._daq_connectaction.triggered.connect(self.connect_dac)
|
self._daq_connectaction.triggered.connect(self.connect_dac)
|
||||||
|
|
||||||
self._daq_disconnectaction = QAction(QIcon(":/icons/disconnect.png"), "Disconnect DAQ", self)
|
self._daq_disconnectaction = QAction(QIcon(str(path.joinpath(_root, "icons/disconnect.png"))), "Disconnect DAQ", self)
|
||||||
self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device")
|
self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device")
|
||||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||||
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
|
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
|
||||||
|
|
||||||
self._daq_calibaction = QAction(QIcon(":/icons/calibration.png"), "Plot calibration", self)
|
self._daq_calibaction = QAction(QIcon(str(path.joinpath(_root, "icons/calibration.png"))), "Plot calibration", self)
|
||||||
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
|
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
|
||||||
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
||||||
self._daq_calibaction.triggered.connect(self.plot_calibration)
|
self._daq_calibaction.triggered.connect(self.plot_calibration)
|
||||||
@@ -92,28 +90,19 @@ class PyRelacs(QMainWindow):
|
|||||||
|
|
||||||
def create_menu(self):
|
def create_menu(self):
|
||||||
menu = self.menuBar()
|
menu = self.menuBar()
|
||||||
if menu is not None:
|
file_menu = menu.addMenu("&File")
|
||||||
file_menu = menu.addMenu("&File")
|
file_menu.addAction(self._rlx_exitaction)
|
||||||
device_menu = menu.addMenu("&DAQ")
|
file_menu.addAction(self._rlx_aboutaction)
|
||||||
help_menu = menu.addMenu("&Help")
|
|
||||||
|
|
||||||
if file_menu is not None:
|
device_menu = menu.addMenu("&DAQ")
|
||||||
file_menu.addAction(self._rlx_exitaction)
|
device_menu.addAction(self._daq_connectaction)
|
||||||
file_menu.addAction(self._rlx_aboutaction)
|
device_menu.addAction(self._daq_disconnectaction)
|
||||||
|
device_menu.addSeparator()
|
||||||
if device_menu is not None:
|
device_menu.addAction(self._daq_calibaction)
|
||||||
device_menu.addAction(self._daq_connectaction)
|
|
||||||
device_menu.addAction(self._daq_disconnectaction)
|
|
||||||
device_menu.addSeparator()
|
|
||||||
device_menu.addAction(self._daq_calibaction)
|
|
||||||
|
|
||||||
if help_menu is not None:
|
|
||||||
help_menu.addSeparator()
|
|
||||||
# help_menu.addAction(self._help_action)
|
|
||||||
else:
|
|
||||||
log.error("could not create file menu and device menu")
|
|
||||||
self.on_exit()
|
|
||||||
|
|
||||||
|
help_menu = menu.addMenu("&Help")
|
||||||
|
help_menu.addSeparator()
|
||||||
|
# help_menu.addAction(self._help_action)
|
||||||
self.setMenuBar(menu)
|
self.setMenuBar(menu)
|
||||||
|
|
||||||
def create_toolbars(self):
|
def create_toolbars(self):
|
||||||
@@ -192,9 +181,8 @@ class PyRelacs(QMainWindow):
|
|||||||
return decibel_psd
|
return decibel_psd
|
||||||
|
|
||||||
block = self.nix_file.blocks[0]
|
block = self.nix_file.blocks[0]
|
||||||
colors = ["red", "green", "blue", "black", "yellow"]
|
for stim, fish in zip(
|
||||||
for i, (stim, fish) in enumerate(
|
list(block.data_arrays)[::2], list(block.data_arrays)[1::2]
|
||||||
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
|
||||||
@@ -205,35 +193,22 @@ 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(colors[i])
|
pen = pg.mkPen()
|
||||||
self.beat_plot.plot(
|
self.plot_graph.plot(
|
||||||
np.arange(0, len(beat)) / 40_000.0,
|
np.arange(0, len(beat)) / 40_000.0, beat_squared, pen=pen
|
||||||
beat_squared,
|
|
||||||
pen=pen,
|
|
||||||
# name=stim.name,
|
|
||||||
)
|
)
|
||||||
self.power_plot.plot(f_sq, powerspec_sq, pen=pen)
|
|
||||||
self.power_plot.plot(f[peaks], powerspec_sq[peaks], pen=None, symbol="x")
|
|
||||||
|
|
||||||
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)
|
||||||
try:
|
try:
|
||||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
|
self.daq_device.connect()
|
||||||
|
log.debug("Connected")
|
||||||
except IndexError:
|
except IndexError:
|
||||||
log.error("DAQ is not connected")
|
log.debug("DAQ is not connected, closing")
|
||||||
log.error("Please connect a DAQ device to the system")
|
self.on_exit()
|
||||||
|
self.daq_connect_button.setDisabled(True)
|
||||||
if hasattr(PyRelacs, "daq_device"):
|
|
||||||
try:
|
|
||||||
self.daq_device.connect()
|
|
||||||
log.debug("Connected")
|
|
||||||
except uldaq.ul_exception.ULException as e:
|
|
||||||
log.error(f"Could not Connect to DAQ: {e}")
|
|
||||||
self.daq_connect_button.setDisabled(True)
|
|
||||||
else:
|
|
||||||
log.debug("Already handeld the error")
|
|
||||||
pass
|
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
try:
|
try:
|
||||||
@@ -246,6 +221,16 @@ class PyRelacs(QMainWindow):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
log.debug("DAQ was not connected")
|
log.debug("DAQ was not connected")
|
||||||
|
|
||||||
|
def repros_to_toolbar(self):
|
||||||
|
repro_names, file_names = self.repros.names_of_repros()
|
||||||
|
for rep, fn in zip(repro_names, file_names):
|
||||||
|
individual_repro_button = QAction(rep, self)
|
||||||
|
individual_repro_button.setStatusTip("Button")
|
||||||
|
individual_repro_button.triggered.connect(
|
||||||
|
lambda checked, n=rep, f=fn: self.run_repro(n, f)
|
||||||
|
)
|
||||||
|
self.toolbar.addAction(individual_repro_button)
|
||||||
|
|
||||||
def run_repro(self, n, fn):
|
def run_repro(self, n, fn):
|
||||||
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
||||||
worker = Worker(self.repros.run_repro, self.nix_file, n, fn)
|
worker = Worker(self.repros.run_repro, self.nix_file, n, fn)
|
||||||
|
|||||||