Compare commits
39 Commits
5c3c2c407a
...
calibratio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
565d6e5318 | ||
|
|
b35a9212ac | ||
|
|
56c8b59ccd | ||
|
|
cbc86598b0 | ||
|
|
031b5098d5 | ||
|
|
c33e4cc32f | ||
|
|
4868b0e196 | ||
|
|
00f6b11740 | ||
|
|
e0491c5917 | ||
|
|
9c80091d16 | ||
| b0897bf52d | |||
| 09dd7f3d51 | |||
|
|
2e264fb582 | ||
| 0a00875d2e | |||
|
|
ab51fa7475 | ||
|
|
6a3a610cd3 | ||
|
|
8b02b9083f | ||
|
|
5dadf1bd7c | ||
|
|
9e8dc06c26 | ||
|
|
bf8f3f5cb7 | ||
| 0378317d7b | |||
| b2f223168c | |||
| 58decf0283 | |||
| fe6e438189 | |||
| d241d88168 | |||
| a1b0e723f6 | |||
| a818bf75a4 | |||
|
|
13d4db25fa | ||
|
|
5c274c713d | ||
|
|
85c9637ce3 | ||
|
|
7cf9683744 | ||
|
|
2110286abb | ||
|
|
f04f28dd11 | ||
|
|
e9a509c0f7 | ||
|
|
bdd323ad20 | ||
|
|
cadf2e5dde | ||
|
|
a7b73fa09a | ||
|
|
3433ef7132 | ||
|
|
a16fe0b735 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -161,3 +161,8 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# ignore created data files
|
||||
*.nix
|
||||
|
||||
# ignore reource.py as it is created by pyside6-rcc resources.qrc -o resources.py
|
||||
resources.py
|
||||
@@ -5,9 +5,13 @@ 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/))
|
||||
|
||||
# Installation
|
||||
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)).
|
||||
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)).
|
||||
|
||||
After successful installing, you can use clone the reposity and install it with
|
||||
For MacOs if you run into problems with the libusb library if installed with homebrew, there is an issue thread on the uldaq repository.
|
||||
|
||||
[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
|
||||
pip install -e .
|
||||
|
||||
229
poetry.lock
generated
229
poetry.lock
generated
@@ -1,4 +1,22 @@
|
||||
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
|
||||
# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "asttokens"
|
||||
version = "2.4.1"
|
||||
description = "Annotate AST trees with source code positions"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "asttokens-2.4.1-py2.py3-none-any.whl", hash = "sha256:051ed49c3dcae8913ea7cd08e46a606dba30b79993209636c4875bc1d637bc24"},
|
||||
{file = "asttokens-2.4.1.tar.gz", hash = "sha256:b03869718ba9a6eb027e134bfdf69f38a236d681c83c160d510768af11254ba0"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
six = ">=1.12.0"
|
||||
|
||||
[package.extras]
|
||||
astroid = ["astroid (>=1,<2)", "astroid (>=2,<4)"]
|
||||
test = ["astroid (>=1,<2)", "astroid (>=2,<4)", "pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
@@ -124,6 +142,31 @@ files = [
|
||||
docs = ["ipython", "matplotlib", "numpydoc", "sphinx"]
|
||||
tests = ["pytest", "pytest-cov", "pytest-xdist"]
|
||||
|
||||
[[package]]
|
||||
name = "decorator"
|
||||
version = "5.1.1"
|
||||
description = "Decorators for Humans"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
files = [
|
||||
{file = "decorator-5.1.1-py3-none-any.whl", hash = "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186"},
|
||||
{file = "decorator-5.1.1.tar.gz", hash = "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "executing"
|
||||
version = "2.1.0"
|
||||
description = "Get the currently executing AST node of a frame, and other information"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "executing-2.1.0-py2.py3-none-any.whl", hash = "sha256:8d63781349375b5ebccc3142f4b30350c0cd9c79f921cde38be2be4637e98eaf"},
|
||||
{file = "executing-2.1.0.tar.gz", hash = "sha256:8ea27ddd260da8150fa5a708269c4a10e76161e2496ec3e587da9e3c0fe4b9ab"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
tests = ["asttokens (>=2.1.0)", "coverage", "coverage-enable-subprocess", "ipython", "littleutils", "pytest", "rich"]
|
||||
|
||||
[[package]]
|
||||
name = "fonttools"
|
||||
version = "4.53.1"
|
||||
@@ -227,6 +270,61 @@ files = [
|
||||
[package.dependencies]
|
||||
numpy = ">=1.19.3"
|
||||
|
||||
[[package]]
|
||||
name = "ipython"
|
||||
version = "8.27.0"
|
||||
description = "IPython: Productive Interactive Computing"
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
files = [
|
||||
{file = "ipython-8.27.0-py3-none-any.whl", hash = "sha256:f68b3cb8bde357a5d7adc9598d57e22a45dfbea19eb6b98286fa3b288c9cd55c"},
|
||||
{file = "ipython-8.27.0.tar.gz", hash = "sha256:0b99a2dc9f15fd68692e898e5568725c6d49c527d36a9fb5960ffbdeaa82ff7e"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
colorama = {version = "*", markers = "sys_platform == \"win32\""}
|
||||
decorator = "*"
|
||||
jedi = ">=0.16"
|
||||
matplotlib-inline = "*"
|
||||
pexpect = {version = ">4.3", markers = "sys_platform != \"win32\" and sys_platform != \"emscripten\""}
|
||||
prompt-toolkit = ">=3.0.41,<3.1.0"
|
||||
pygments = ">=2.4.0"
|
||||
stack-data = "*"
|
||||
traitlets = ">=5.13.0"
|
||||
|
||||
[package.extras]
|
||||
all = ["ipython[black,doc,kernel,matplotlib,nbconvert,nbformat,notebook,parallel,qtconsole]", "ipython[test,test-extra]"]
|
||||
black = ["black"]
|
||||
doc = ["docrepr", "exceptiongroup", "intersphinx-registry", "ipykernel", "ipython[test]", "matplotlib", "setuptools (>=18.5)", "sphinx (>=1.3)", "sphinx-rtd-theme", "sphinxcontrib-jquery", "tomli", "typing-extensions"]
|
||||
kernel = ["ipykernel"]
|
||||
matplotlib = ["matplotlib"]
|
||||
nbconvert = ["nbconvert"]
|
||||
nbformat = ["nbformat"]
|
||||
notebook = ["ipywidgets", "notebook"]
|
||||
parallel = ["ipyparallel"]
|
||||
qtconsole = ["qtconsole"]
|
||||
test = ["packaging", "pickleshare", "pytest", "pytest-asyncio (<0.22)", "testpath"]
|
||||
test-extra = ["curio", "ipython[test]", "matplotlib (!=3.2.0)", "nbformat", "numpy (>=1.23)", "pandas", "trio"]
|
||||
|
||||
[[package]]
|
||||
name = "jedi"
|
||||
version = "0.19.1"
|
||||
description = "An autocompletion tool for Python that can be used for text editors."
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
{file = "jedi-0.19.1-py2.py3-none-any.whl", hash = "sha256:e983c654fe5c02867aef4cdfce5a2fbb4a50adc0af145f70504238f18ef5e7e0"},
|
||||
{file = "jedi-0.19.1.tar.gz", hash = "sha256:cf0496f3651bc65d7174ac1b7d043eff454892c708a87d1b683e57b569927ffd"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
parso = ">=0.8.3,<0.9.0"
|
||||
|
||||
[package.extras]
|
||||
docs = ["Jinja2 (==2.11.3)", "MarkupSafe (==1.1.1)", "Pygments (==2.8.1)", "alabaster (==0.7.12)", "babel (==2.9.1)", "chardet (==4.0.0)", "commonmark (==0.8.1)", "docutils (==0.17.1)", "future (==0.18.2)", "idna (==2.10)", "imagesize (==1.2.0)", "mock (==1.0.1)", "packaging (==20.9)", "pyparsing (==2.4.7)", "pytz (==2021.1)", "readthedocs-sphinx-ext (==2.1.4)", "recommonmark (==0.5.0)", "requests (==2.25.1)", "six (==1.15.0)", "snowballstemmer (==2.1.0)", "sphinx (==1.8.5)", "sphinx-rtd-theme (==0.4.3)", "sphinxcontrib-serializinghtml (==1.1.4)", "sphinxcontrib-websupport (==1.2.4)", "urllib3 (==1.26.4)"]
|
||||
qa = ["flake8 (==5.0.4)", "mypy (==0.971)", "types-setuptools (==67.2.0.1)"]
|
||||
testing = ["Django", "attrs", "colorama", "docopt", "pytest (<7.0.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "kiwisolver"
|
||||
version = "1.4.7"
|
||||
@@ -437,6 +535,20 @@ python-dateutil = ">=2.7"
|
||||
[package.extras]
|
||||
dev = ["meson-python (>=0.13.1)", "numpy (>=1.25)", "pybind11 (>=2.6)", "setuptools (>=64)", "setuptools_scm (>=7)"]
|
||||
|
||||
[[package]]
|
||||
name = "matplotlib-inline"
|
||||
version = "0.1.7"
|
||||
description = "Inline Matplotlib backend for Jupyter"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "matplotlib_inline-0.1.7-py3-none-any.whl", hash = "sha256:df192d39a4ff8f21b1895d72e6a13f5fcc5099f00fa84384e0ea28c2cc0653ca"},
|
||||
{file = "matplotlib_inline-0.1.7.tar.gz", hash = "sha256:8423b23ec666be3d16e16b60bdd8ac4e86e840ebd1dd11a30b9f117f2fa0ab90"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
traitlets = "*"
|
||||
|
||||
[[package]]
|
||||
name = "mdurl"
|
||||
version = "0.1.2"
|
||||
@@ -520,6 +632,35 @@ files = [
|
||||
{file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parso"
|
||||
version = "0.8.4"
|
||||
description = "A Python Parser"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
{file = "parso-0.8.4-py2.py3-none-any.whl", hash = "sha256:a418670a20291dacd2dddc80c377c5c3791378ee1e8d12bffc35420643d43f18"},
|
||||
{file = "parso-0.8.4.tar.gz", hash = "sha256:eb3a7b58240fb99099a345571deecc0f9540ea5f4dd2fe14c2a99d6b281ab92d"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
qa = ["flake8 (==5.0.4)", "mypy (==0.971)", "types-setuptools (==67.2.0.1)"]
|
||||
testing = ["docopt", "pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "pexpect"
|
||||
version = "4.9.0"
|
||||
description = "Pexpect allows easy control of interactive console applications."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "pexpect-4.9.0-py2.py3-none-any.whl", hash = "sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523"},
|
||||
{file = "pexpect-4.9.0.tar.gz", hash = "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
ptyprocess = ">=0.5"
|
||||
|
||||
[[package]]
|
||||
name = "pillow"
|
||||
version = "10.4.0"
|
||||
@@ -617,6 +758,45 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa
|
||||
typing = ["typing-extensions"]
|
||||
xmp = ["defusedxml"]
|
||||
|
||||
[[package]]
|
||||
name = "prompt-toolkit"
|
||||
version = "3.0.48"
|
||||
description = "Library for building powerful interactive command lines in Python"
|
||||
optional = false
|
||||
python-versions = ">=3.7.0"
|
||||
files = [
|
||||
{file = "prompt_toolkit-3.0.48-py3-none-any.whl", hash = "sha256:f49a827f90062e411f1ce1f854f2aedb3c23353244f8108b89283587397ac10e"},
|
||||
{file = "prompt_toolkit-3.0.48.tar.gz", hash = "sha256:d6623ab0477a80df74e646bdbc93621143f5caf104206aa29294d53de1a03d90"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
wcwidth = "*"
|
||||
|
||||
[[package]]
|
||||
name = "ptyprocess"
|
||||
version = "0.7.0"
|
||||
description = "Run a subprocess in a pseudo terminal"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "ptyprocess-0.7.0-py2.py3-none-any.whl", hash = "sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35"},
|
||||
{file = "ptyprocess-0.7.0.tar.gz", hash = "sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pure-eval"
|
||||
version = "0.2.3"
|
||||
description = "Safely evaluate AST nodes without side effects"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "pure_eval-0.2.3-py3-none-any.whl", hash = "sha256:1db8e35b67b3d218d818ae653e27f06c3aa420901fa7b081ca98cbedc874e0d0"},
|
||||
{file = "pure_eval-0.2.3.tar.gz", hash = "sha256:5f4e983f40564c576c7c8635ae88db5956bb2229d7e9237d03b3c0b0190eaf42"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
tests = ["pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "pygments"
|
||||
version = "2.18.0"
|
||||
@@ -827,6 +1007,25 @@ files = [
|
||||
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stack-data"
|
||||
version = "0.6.3"
|
||||
description = "Extract data from python stack frames and tracebacks for informative displays"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "stack_data-0.6.3-py3-none-any.whl", hash = "sha256:d5558e0c25a4cb0853cddad3d77da9891a08cb85dd9f9f91b9f8cd66e511e695"},
|
||||
{file = "stack_data-0.6.3.tar.gz", hash = "sha256:836a778de4fec4dcd1dcd89ed8abff8a221f58308462e1c4aa2a3cf30148f0b9"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
asttokens = ">=2.1.0"
|
||||
executing = ">=1.2.0"
|
||||
pure-eval = "*"
|
||||
|
||||
[package.extras]
|
||||
tests = ["cython", "littleutils", "pygments", "pytest", "typeguard"]
|
||||
|
||||
[[package]]
|
||||
name = "tomlkit"
|
||||
version = "0.13.2"
|
||||
@@ -838,6 +1037,21 @@ files = [
|
||||
{file = "tomlkit-0.13.2.tar.gz", hash = "sha256:fff5fe59a87295b278abd31bec92c15d9bc4a06885ab12bcea52c71119392e79"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "traitlets"
|
||||
version = "5.14.3"
|
||||
description = "Traitlets Python configuration system"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "traitlets-5.14.3-py3-none-any.whl", hash = "sha256:b74e89e397b1ed28cc831db7aea759ba6640cb3de13090ca145426688ff1ac4f"},
|
||||
{file = "traitlets-5.14.3.tar.gz", hash = "sha256:9ed0579d3502c94b4b3732ac120375cda96f923114522847de4b3bb98b96b6b7"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["myst-parser", "pydata-sphinx-theme", "sphinx"]
|
||||
test = ["argcomplete (>=3.0.3)", "mypy (>=1.7.0)", "pre-commit", "pytest (>=7.0,<8.2)", "pytest-mock", "pytest-mypy-testing"]
|
||||
|
||||
[[package]]
|
||||
name = "typer"
|
||||
version = "0.12.5"
|
||||
@@ -877,7 +1091,18 @@ files = [
|
||||
{file = "uldaq-1.2.3.tar.gz", hash = "sha256:2d405ead334bb4e37c20b72d8ec498f0e372b08f1d3323f622abe0581ac28b98"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wcwidth"
|
||||
version = "0.2.13"
|
||||
description = "Measures the displayed width of unicode strings in a terminal"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859"},
|
||||
{file = "wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"},
|
||||
]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.12"
|
||||
content-hash = "7321f58bda2e65a4a0674d43997ce31402e0fed876a77b37a1b86d83d569707a"
|
||||
content-hash = "b1076b7f750e8f7e66542918ec746e74544fbfdb376875158f083fb573d18107"
|
||||
|
||||
@@ -16,11 +16,12 @@ classifiers = [
|
||||
"Intended Audience :: End Users/Desktop",
|
||||
]
|
||||
include = [
|
||||
{ path = "pyproject.toml" }
|
||||
{ path = "pyproject.toml" },
|
||||
"pyrelacs/resources.py"
|
||||
]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
python = "^3.10"
|
||||
uldaq = "^1.2.3"
|
||||
typer = "^0.12.5"
|
||||
matplotlib = "^3.9.2"
|
||||
@@ -34,6 +35,9 @@ pyqtgraph = "^0.13.7"
|
||||
[tool.poetry.scripts]
|
||||
pyrelacs = "pyrelacs.app:main"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ipython = "^8.27.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
0
pyrelacs/__init__.py
Normal file
0
pyrelacs/__init__.py
Normal file
181
pyrelacs/app.py
181
pyrelacs/app.py
@@ -1,183 +1,17 @@
|
||||
import pathlib
|
||||
from PyQt6.QtGui import QAction
|
||||
import sys
|
||||
|
||||
from PyQt6.QtCore import QSize, QThreadPool, QSettings
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication,
|
||||
QGridLayout,
|
||||
QPushButton,
|
||||
QToolBar,
|
||||
QWidget,
|
||||
QMainWindow,
|
||||
QPlainTextEdit,
|
||||
)
|
||||
import pyqtgraph as pg
|
||||
import uldaq
|
||||
from IPython import embed
|
||||
from scipy.signal import welch, find_peaks
|
||||
import numpy as np
|
||||
import nixio as nix
|
||||
from PyQt6.QtCore import QSettings
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
|
||||
from pyrelacs import info
|
||||
from pyrelacs.ui.mainwindow import PyRelacs
|
||||
from pyrelacs.util.logging import config_logging
|
||||
import pyrelacs.info as info
|
||||
from pyrelacs.worker import Worker
|
||||
from pyrelacs.repros.repros import Repro
|
||||
|
||||
log = config_logging()
|
||||
|
||||
|
||||
class PyRelacs(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("PyRelacs")
|
||||
self.setMinimumSize(1000, 1000)
|
||||
self.plot_graph = pg.PlotWidget()
|
||||
|
||||
self.threadpool = QThreadPool()
|
||||
self.repros = Repro()
|
||||
|
||||
self.daq_connect_button = QPushButton("Connect Daq")
|
||||
self.daq_connect_button.setCheckable(True)
|
||||
self.daq_connect_button.clicked.connect(self.connect_dac)
|
||||
|
||||
self.daq_disconnect_button = QPushButton("Disconnect Daq")
|
||||
self.daq_disconnect_button.setCheckable(True)
|
||||
self.daq_disconnect_button.clicked.connect(self.disconnect_dac)
|
||||
|
||||
self.plot_calibration_button = QPushButton("Plot Calibration")
|
||||
self.plot_calibration_button.setCheckable(True)
|
||||
self.plot_calibration_button.clicked.connect(self.plot_calibration)
|
||||
|
||||
self.text = QPlainTextEdit()
|
||||
self.text.setReadOnly(True)
|
||||
|
||||
layout = QGridLayout()
|
||||
layout.addWidget(self.plot_calibration_button, 0, 0)
|
||||
layout.addWidget(self.daq_disconnect_button, 0, 1)
|
||||
layout.addWidget(self.text, 3, 0, 1, 2)
|
||||
layout.addWidget(self.plot_graph, 2, 0, 1, 2)
|
||||
|
||||
self.toolbar = QToolBar("Repros")
|
||||
self.addToolBar(self.toolbar)
|
||||
self.repros_to_toolbar()
|
||||
|
||||
self.setFixedSize(QSize(400, 300))
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
self.nix_file = nix.File.open(
|
||||
str(pathlib.Path(__file__).parent / "data"), nix.FileMode.ReadOnly
|
||||
)
|
||||
|
||||
def plot_calibration(self):
|
||||
def decibel(power, ref_power=1.0, min_power=1e-20):
|
||||
"""Transform power to decibel relative to ref_power.
|
||||
|
||||
\\[ decibel = 10 \\cdot \\log_{10}(power/ref\\_power) \\]
|
||||
Power values smaller than `min_power` are set to `-np.inf`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
power: float or array
|
||||
Power values, for example from a power spectrum or spectrogram.
|
||||
ref_power: float or None or 'peak'
|
||||
Reference power for computing decibel.
|
||||
If set to `None` or 'peak', the maximum power is used.
|
||||
min_power: float
|
||||
Power values smaller than `min_power` are set to `-np.inf`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
decibel_psd: array
|
||||
Power values in decibel relative to `ref_power`.
|
||||
"""
|
||||
if np.isscalar(power):
|
||||
tmp_power = np.array([power])
|
||||
decibel_psd = np.array([power])
|
||||
else:
|
||||
tmp_power = power
|
||||
decibel_psd = power.copy()
|
||||
if ref_power is None or ref_power == "peak":
|
||||
ref_power = np.max(decibel_psd)
|
||||
decibel_psd[tmp_power <= min_power] = float("-inf")
|
||||
decibel_psd[tmp_power > min_power] = 10.0 * np.log10(
|
||||
decibel_psd[tmp_power > min_power] / ref_power
|
||||
)
|
||||
if np.isscalar(power):
|
||||
return decibel_psd[0]
|
||||
else:
|
||||
return decibel_psd
|
||||
|
||||
block = self.nix_file.blocks[0]
|
||||
for stim, fish in zip(
|
||||
list(block.data_arrays)[::2], list(block.data_arrays)[1::2]
|
||||
):
|
||||
beat = stim[:] + fish[:]
|
||||
beat_squared = beat**2
|
||||
|
||||
f, powerspec = welch(beat, fs=40_000.0)
|
||||
powerspec = decibel(powerspec)
|
||||
|
||||
f_sq, powerspec_sq = welch(beat_squared, fs=40_000.0)
|
||||
powerspec_sq = decibel(powerspec_sq)
|
||||
peaks = find_peaks(powerspec_sq, prominence=20)[0]
|
||||
pen = pg.mkPen()
|
||||
self.plot_graph.plot(
|
||||
np.arange(0, len(beat)) / 40_000.0, beat_squared, pen=pen
|
||||
)
|
||||
|
||||
def connect_dac(self):
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
try:
|
||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||
self.daq_device.connect()
|
||||
log.debug("Connected")
|
||||
except IndexError:
|
||||
log.debug("DAQ is not connected, closing")
|
||||
QApplication.quit()
|
||||
self.daq_connect_button.setDisabled(True)
|
||||
|
||||
def disconnect_dac(self):
|
||||
try:
|
||||
log.debug(f"{self.daq_device}")
|
||||
self.daq_device.disconnect()
|
||||
self.daq_device.release()
|
||||
log.debug(f"{self.daq_device}")
|
||||
self.daq_disconnect_button.setDisabled(True)
|
||||
self.daq_connect_button.setEnabled(True)
|
||||
except AttributeError:
|
||||
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):
|
||||
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
||||
worker = Worker(self.repros.run_repro, self.nix_file, n, fn)
|
||||
worker.signals.result.connect(self.print_output)
|
||||
worker.signals.finished.connect(self.thread_complete)
|
||||
worker.signals.progress.connect(self.progress_fn)
|
||||
|
||||
self.threadpool.start(worker)
|
||||
|
||||
def print_output(self, s):
|
||||
print(s)
|
||||
|
||||
def thread_complete(self):
|
||||
print("THREAD COMPLETE!")
|
||||
|
||||
def progress_fn(self, n):
|
||||
print("%d%% done" % n)
|
||||
from pyrelacs import (
|
||||
resources,
|
||||
) # best created with pyside6-rcc resources.qrc -o resources.py (rcc produces an error...)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -185,6 +19,7 @@ def main():
|
||||
app.setApplicationName(info.NAME)
|
||||
app.setApplicationVersion(str(info.VERSION))
|
||||
app.setOrganizationDomain(info.ORGANIZATION)
|
||||
# app.setAttribute(Qt.ApplicationAttribute.AA_DontShowIconsInMenus, False)
|
||||
|
||||
# read window settings
|
||||
settings = QSettings(info.ORGANIZATION, info.NAME)
|
||||
|
||||
BIN
pyrelacs/data
BIN
pyrelacs/data
Binary file not shown.
0
pyrelacs/devices/__init__.py
Normal file
0
pyrelacs/devices/__init__.py
Normal file
@@ -12,13 +12,32 @@ log = config_logging()
|
||||
|
||||
|
||||
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:
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||
if len(devices) == 0:
|
||||
try:
|
||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||
except uldaq.ul_exception.ULException as e:
|
||||
log.error("Did not found daq devices, please connect one")
|
||||
exit(1)
|
||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||
raise e
|
||||
try:
|
||||
self.daq_device.connect()
|
||||
except uldaq.ul_exception.ULException:
|
||||
@@ -30,6 +49,10 @@ class MccDac:
|
||||
log.debug("Connected")
|
||||
|
||||
def connect_dac(self):
|
||||
"""
|
||||
Connecting to the DAQ device
|
||||
|
||||
"""
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||
if len(devices) == 0:
|
||||
@@ -52,6 +75,40 @@ class MccDac:
|
||||
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||
AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT,
|
||||
) -> 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]")
|
||||
|
||||
if channels[0] != channels[1]:
|
||||
@@ -85,6 +142,37 @@ class MccDac:
|
||||
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||
AOutScanFlag: uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT,
|
||||
) -> 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]")
|
||||
|
||||
buffer = c_double * len(data)
|
||||
@@ -109,7 +197,18 @@ class MccDac:
|
||||
|
||||
return data_analog_output
|
||||
|
||||
def set_analog_to_zero(self, channels: list[int] = [0, 1]):
|
||||
def set_analog_to_zero(self, channels: list[int] = [0, 1]) -> None:
|
||||
"""
|
||||
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:
|
||||
err = self.ao_device.a_out_list(
|
||||
channels[0],
|
||||
@@ -126,16 +225,37 @@ class MccDac:
|
||||
log.error("disconnection dac")
|
||||
self.disconnect_dac()
|
||||
|
||||
def diggital_trigger(self) -> None:
|
||||
data = self.read_bit(channel=0)
|
||||
def digital_trigger(self, ch: int = 0) -> None:
|
||||
"""
|
||||
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:
|
||||
self.write_bit(channel=0, bit=0)
|
||||
self.write_bit(channel=ch, bit=0)
|
||||
time.time_ns()
|
||||
self.write_bit(channel=0, bit=1)
|
||||
self.write_bit(channel=ch, bit=1)
|
||||
else:
|
||||
self.write_bit(channel=0, bit=1)
|
||||
self.write_bit(channel=ch, bit=1)
|
||||
|
||||
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(
|
||||
uldaq.DigitalPortType.AUXPORT, channel, uldaq.DigitalDirection.OUTPUT
|
||||
)
|
||||
@@ -143,55 +263,36 @@ class MccDac:
|
||||
uldaq.DigitalPortType.AUXPORT, bit_number=channel, data=bit
|
||||
)
|
||||
|
||||
def read_bit(self, channel: int = 0):
|
||||
def read_bit(self, channel: int = 0) -> int:
|
||||
"""
|
||||
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)
|
||||
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):
|
||||
self.daq_device.disconnect()
|
||||
self.daq_device.release()
|
||||
|
||||
def check_attenuator(self):
|
||||
"""
|
||||
ident : attdev-1
|
||||
strobepin : 6
|
||||
datainpin : 5
|
||||
dataoutpin: -1
|
||||
cspin : 4
|
||||
mutepin : 7
|
||||
zcenpin : -1
|
||||
def check_attenuator(self) -> None:
|
||||
"""
|
||||
For checking the attenuator in the DAC device that was implemented to attenuate the
|
||||
analog signal to mV.
|
||||
|
||||
Writes to Channel 0 of the analog output with different attenuation levels
|
||||
0, 0, -2, -5, -10, -20, -50 dB and the second 0 has a software mute
|
||||
|
||||
"""
|
||||
SAMPLERATE = 40_000.0
|
||||
DURATION = 5
|
||||
AMPLITUDE = 1
|
||||
@@ -201,7 +302,6 @@ class MccDac:
|
||||
# data_channels = np.concatenate((data, data))
|
||||
|
||||
db_values = [0, 0, -2, -5, -10, -20, -50]
|
||||
db_values = [0, -10, -20]
|
||||
for i, db_value in enumerate(db_values):
|
||||
log.info(f"Attenuating the Channels, with {db_value}")
|
||||
if i == 1:
|
||||
@@ -219,7 +319,7 @@ class MccDac:
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
Range=uldaq.Range.BIP10VOLTS,
|
||||
)
|
||||
self.diggital_trigger()
|
||||
self.digital_trigger()
|
||||
|
||||
try:
|
||||
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||
@@ -248,6 +348,16 @@ class MccDac:
|
||||
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
|
||||
strobepin : 6
|
||||
datainpin : 5
|
||||
@@ -255,8 +365,23 @@ class MccDac:
|
||||
cspin : 4
|
||||
mutepin : 7
|
||||
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()
|
||||
hardware_possible_db = np.arange(-95.5, 32.0, 0.5)
|
||||
byte_number = np.arange(1, 256)
|
||||
@@ -283,9 +408,18 @@ class MccDac:
|
||||
self.write_bit(channel=4, bit=1)
|
||||
|
||||
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]):
|
||||
self.write_bit(channel=ch, bit=b)
|
||||
|
||||
def deactivate_attenuator(self):
|
||||
"""
|
||||
Writes a 0 to the mute pin, which is deactivating the attenuator
|
||||
|
||||
"""
|
||||
# mute should be enabled for starting calibration
|
||||
self.write_bit(channel=7, bit=0)
|
||||
|
||||
BIN
pyrelacs/icons/connect.png
Normal file
BIN
pyrelacs/icons/connect.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
BIN
pyrelacs/icons/disconnect.png
Normal file
BIN
pyrelacs/icons/disconnect.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
BIN
pyrelacs/icons/exit.png
Normal file
BIN
pyrelacs/icons/exit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
BIN
pyrelacs/icons/record.png
Normal file
BIN
pyrelacs/icons/record.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
BIN
pyrelacs/icons/relacstuxheader.png
Normal file
BIN
pyrelacs/icons/relacstuxheader.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 255 KiB |
BIN
pyrelacs/icons/stop.png
Normal file
BIN
pyrelacs/icons/stop.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -3,6 +3,7 @@ import pathlib
|
||||
|
||||
|
||||
def load_project_settings(project_root):
|
||||
print(project_root)
|
||||
# Read the pyproject.toml file
|
||||
with open(pathlib.Path.joinpath(project_root, "pyproject.toml"), "r") as f:
|
||||
pyproject_content = f.read()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import signal
|
||||
import sys
|
||||
import faulthandler
|
||||
import time
|
||||
|
||||
@@ -8,13 +6,14 @@ import uldaq
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.signal import welch, csd
|
||||
from scipy.signal import welch
|
||||
from scipy.signal import find_peaks
|
||||
|
||||
from pyrelacs.devices.mccdac import MccDac
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
log = config_logging()
|
||||
# for more information on seg faults
|
||||
faulthandler.enable()
|
||||
|
||||
|
||||
@@ -60,7 +59,7 @@ class Calibration(MccDac):
|
||||
time.sleep(1)
|
||||
|
||||
log.debug("Starting the Scan")
|
||||
self.diggital_trigger()
|
||||
self.digital_trigger()
|
||||
|
||||
try:
|
||||
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||
@@ -109,7 +108,7 @@ class Calibration(MccDac):
|
||||
self.SAMPLERATE,
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
)
|
||||
self.diggital_trigger()
|
||||
self.digital_trigger()
|
||||
log.info(self.ao_device)
|
||||
ai_status = uldaq.ScanStatus.RUNNING
|
||||
ao_status = uldaq.ScanStatus.RUNNING
|
||||
@@ -133,15 +132,20 @@ class Calibration(MccDac):
|
||||
channel1 = np.array(readout[::2])
|
||||
channel2 = np.array(readout[1::2])
|
||||
|
||||
block.create_data_array(
|
||||
stim_data = block.create_data_array(
|
||||
f"stimulus_{db_value}",
|
||||
"Array",
|
||||
"nix.regular_sampled",
|
||||
shape=data.shape,
|
||||
data=channel1,
|
||||
label="Voltage",
|
||||
unit="V",
|
||||
)
|
||||
block.create_data_array(
|
||||
stim_data.append_sampled_dimension(
|
||||
self.SAMPLERATE,
|
||||
label="time",
|
||||
unit="s",
|
||||
)
|
||||
fish_data = block.create_data_array(
|
||||
f"fish_{db_value}",
|
||||
"Array",
|
||||
shape=data.shape,
|
||||
@@ -149,88 +153,13 @@ class Calibration(MccDac):
|
||||
label="Voltage",
|
||||
unit="V",
|
||||
)
|
||||
fish_data.append_sampled_dimension(
|
||||
self.SAMPLERATE,
|
||||
label="time",
|
||||
unit="s",
|
||||
)
|
||||
|
||||
beat = channel1 + channel2
|
||||
beat_square = beat**2
|
||||
|
||||
f, powerspec = welch(beat, fs=self.SAMPLERATE)
|
||||
powerspec = decibel(powerspec)
|
||||
|
||||
f_sq, powerspec_sq = welch(beat_square, fs=self.SAMPLERATE)
|
||||
powerspec_sq = decibel(powerspec_sq)
|
||||
peaks = find_peaks(powerspec_sq, prominence=20)[0]
|
||||
|
||||
f_stim, powerspec_stim = welch(channel1, fs=self.SAMPLERATE)
|
||||
powerspec_stim = decibel(powerspec_stim)
|
||||
|
||||
f_in, powerspec_in = welch(channel2, fs=self.SAMPLERATE)
|
||||
powerspec_in = decibel(powerspec_in)
|
||||
|
||||
# axes[0, 0].plot(
|
||||
# t,
|
||||
# channel1,
|
||||
# label=f"{db_value} Readout Channel0",
|
||||
# color=colors[i],
|
||||
# )
|
||||
# axes[0, 0].plot(
|
||||
# t,
|
||||
# channel2,
|
||||
# label=f"{db_value} Readout Channel1",
|
||||
# color=colors_in[i],
|
||||
# )
|
||||
#
|
||||
# axes[0, 1].plot(
|
||||
# f_stim,
|
||||
# powerspec_stim,
|
||||
# label=f"{db_value} powerspec Channel0",
|
||||
# color=colors[i],
|
||||
# )
|
||||
# axes[0, 1].plot(
|
||||
# f_in,
|
||||
# powerspec_in,
|
||||
# label=f"{db_value} powerspec Channel2",
|
||||
# color=colors_in[i],
|
||||
# )
|
||||
# axes[0, 1].set_xlabel("Freq [HZ]")
|
||||
# axes[0, 1].set_ylabel("dB")
|
||||
#
|
||||
# axes[1, 0].plot(
|
||||
# t,
|
||||
# beat,
|
||||
# label="Beat",
|
||||
# color=colors[i],
|
||||
# )
|
||||
# axes[1, 0].plot(
|
||||
# t,
|
||||
# beat**2,
|
||||
# label="Beat squared",
|
||||
# color=colors_in[i],
|
||||
# )
|
||||
# axes[1, 0].legend()
|
||||
#
|
||||
# axes[1, 1].plot(
|
||||
# f,
|
||||
# powerspec,
|
||||
# color=colors[i],
|
||||
# )
|
||||
# axes[1, 1].plot(
|
||||
# f_sq,
|
||||
# powerspec_sq,
|
||||
# color=colors_in[i],
|
||||
# label=f"dB {db_value}, first peak {np.min(f_sq[peaks])}",
|
||||
# )
|
||||
# axes[1, 1].scatter(
|
||||
# f_sq[peaks],
|
||||
# powerspec_sq[peaks],
|
||||
# color="maroon",
|
||||
# )
|
||||
# axes[1, 1].set_xlabel("Freq [HZ]")
|
||||
# axes[1, 1].set_ylabel("dB")
|
||||
# axes[0, 0].legend()
|
||||
# axes[1, 1].legend()
|
||||
# plt.show()
|
||||
self.set_analog_to_zero()
|
||||
self.disconnect_dac()
|
||||
|
||||
|
||||
def decibel(power, ref_power=1.0, min_power=1e-20):
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
import sys
|
||||
import importlib.util
|
||||
import ast
|
||||
import pathlib
|
||||
from typing import Tuple
|
||||
|
||||
from IPython import embed
|
||||
import nixio as nix
|
||||
import importlib.util
|
||||
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
log = config_logging()
|
||||
|
||||
|
||||
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:
|
||||
pass
|
||||
|
||||
@@ -26,14 +34,27 @@ class Repro:
|
||||
log.error("Could not load the module of the repro")
|
||||
else:
|
||||
sys.modules[name] = module
|
||||
spec.loader.exec_module(module)
|
||||
if spec.loader is not None:
|
||||
spec.loader.exec_module(module)
|
||||
else:
|
||||
log.error(f"{spec.loader} is None")
|
||||
if hasattr(module, name):
|
||||
rep_class = getattr(module, name)
|
||||
rep_class.run(nix_file)
|
||||
else:
|
||||
raise AttributeError(f"{file.name} has no {name} class")
|
||||
|
||||
def names_of_repros(self):
|
||||
def names_of_repros(self) -> Tuple[list, list]:
|
||||
"""
|
||||
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
|
||||
python_files = list(file_path_cur.glob("**/*.py"))
|
||||
exclude_files = ["repros.py", "__init__.py"]
|
||||
|
||||
10
pyrelacs/resources.qrc
Normal file
10
pyrelacs/resources.qrc
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>icons/exit.png</file>
|
||||
<file>icons/connect.png</file>
|
||||
<file>icons/disconnect.png</file>
|
||||
<file>icons/record.png</file>
|
||||
<file>icons/stop.png</file>
|
||||
<file>icons/relacstuxheader.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
0
pyrelacs/ui/__init__.py
Normal file
0
pyrelacs/ui/__init__.py
Normal file
54
pyrelacs/ui/about.py
Normal file
54
pyrelacs/ui/about.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from PyQt6.QtGui import QPixmap
|
||||
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLabel, QVBoxLayout, QWidget
|
||||
from PyQt6.QtCore import Qt
|
||||
|
||||
|
||||
class AboutDialog(QDialog):
|
||||
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
self.setModal(True)
|
||||
about = About(self)
|
||||
self.setLayout(QVBoxLayout())
|
||||
self.layout().addWidget(about)
|
||||
bbox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
|
||||
bbox.accepted.connect(self.accept)
|
||||
self.layout().addWidget(bbox)
|
||||
|
||||
|
||||
class About(QWidget):
|
||||
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
self.setLayout(QVBoxLayout())
|
||||
|
||||
heading = QLabel("pyRelacs")
|
||||
font = heading.font()
|
||||
font.setPointSize(18)
|
||||
font.setBold(True)
|
||||
heading.setFont(font)
|
||||
heading.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
subheading = QLabel("relacsed electrophysiological recordings")
|
||||
subheading.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
nix_link = QLabel("https://github.com/relacs")
|
||||
nix_link.setOpenExternalLinks(True)
|
||||
nix_link.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
rtd_link = QLabel("https://relacs.net")
|
||||
rtd_link.setOpenExternalLinks(True)
|
||||
rtd_link.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
iconlabel = QLabel()
|
||||
pixmap = QPixmap(":/icons/relacstuxheader.png")
|
||||
s = pixmap.size()
|
||||
new_height = int(s.height() * 300/s.width())
|
||||
pixmap = pixmap.scaled(300, new_height, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.FastTransformation)
|
||||
iconlabel.setPixmap(pixmap)
|
||||
iconlabel.setMaximumWidth(300)
|
||||
iconlabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
iconlabel.setScaledContents(True)
|
||||
|
||||
self.layout().addWidget(heading)
|
||||
self.layout().addWidget(subheading)
|
||||
self.layout().addWidget(iconlabel)
|
||||
self.layout().addWidget(nix_link)
|
||||
self.layout().addWidget(rtd_link)
|
||||
227
pyrelacs/ui/mainwindow.py
Normal file
227
pyrelacs/ui/mainwindow.py
Normal file
@@ -0,0 +1,227 @@
|
||||
from PyQt6.QtGui import QAction, QIcon, QKeySequence
|
||||
from PyQt6.QtCore import Qt, QSize, QThreadPool
|
||||
from PyQt6.QtWidgets import (
|
||||
QGridLayout,
|
||||
QPushButton,
|
||||
QToolBar,
|
||||
QWidget,
|
||||
QMainWindow,
|
||||
QPlainTextEdit,
|
||||
QMenuBar,
|
||||
QStatusBar,
|
||||
)
|
||||
import uldaq
|
||||
import numpy as np
|
||||
import nixio as nix
|
||||
import pyqtgraph as pg
|
||||
|
||||
from pathlib import Path as path
|
||||
from scipy.signal import welch, find_peaks
|
||||
|
||||
from pyrelacs.worker import Worker
|
||||
from pyrelacs.repros.repros import Repro
|
||||
from pyrelacs.util.logging import config_logging
|
||||
from pyrelacs.ui.about import AboutDialog
|
||||
from pyrelacs.ui.plots.calibration import CalibrationPlot
|
||||
|
||||
log = config_logging()
|
||||
_root = path(__file__).parent.parent
|
||||
|
||||
from IPython import embed
|
||||
|
||||
|
||||
class PyRelacs(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setToolButtonStyle(
|
||||
Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
||||
) # Ensure icons are displayed with text
|
||||
self.setWindowTitle("PyRelacs")
|
||||
|
||||
self.figure = pg.GraphicsLayoutWidget()
|
||||
|
||||
filename = path.joinpath(path.cwd(), "data.nix")
|
||||
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)
|
||||
|
||||
self.calibration_plot = CalibrationPlot(self.figure, self.nix_file)
|
||||
|
||||
self.threadpool = QThreadPool()
|
||||
self.repros = Repro()
|
||||
|
||||
self.text = QPlainTextEdit()
|
||||
self.text.setReadOnly(True)
|
||||
|
||||
self.setMenuBar(QMenuBar(self))
|
||||
self.setStatusBar(QStatusBar(self))
|
||||
self.create_actions()
|
||||
self.create_buttons()
|
||||
self.create_toolbars()
|
||||
|
||||
layout = QGridLayout()
|
||||
layout.addWidget(self.figure, 0, 0, 2, 2)
|
||||
layout.addWidget(self.text, 2, 0, 1, 2)
|
||||
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def create_actions(self):
|
||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||
self._rlx_exitaction.setStatusTip("Close relacs")
|
||||
self._rlx_exitaction.setShortcut(QKeySequence("Alt+q"))
|
||||
self._rlx_exitaction.triggered.connect(self.on_exit)
|
||||
|
||||
self._rlx_aboutaction = QAction("about")
|
||||
self._rlx_aboutaction.setStatusTip("Show about dialog")
|
||||
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.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.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.setStatusTip("Calibrate the attenuator device")
|
||||
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
||||
self._daq_calibaction.triggered.connect(self.calibration_plot.plot)
|
||||
self.create_menu()
|
||||
|
||||
def create_menu(self):
|
||||
menu = self.menuBar()
|
||||
if menu is not None:
|
||||
file_menu = menu.addMenu("&File")
|
||||
device_menu = menu.addMenu("&DAQ")
|
||||
help_menu = menu.addMenu("&Help")
|
||||
|
||||
if file_menu is not None:
|
||||
file_menu.addAction(self._rlx_exitaction)
|
||||
file_menu.addAction(self._rlx_aboutaction)
|
||||
|
||||
if device_menu is not None:
|
||||
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()
|
||||
|
||||
self.setMenuBar(menu)
|
||||
|
||||
def create_toolbars(self):
|
||||
rlx_toolbar = QToolBar("Relacs")
|
||||
rlx_toolbar.addAction(self._rlx_exitaction)
|
||||
rlx_toolbar.setIconSize(QSize(24, 24))
|
||||
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, rlx_toolbar)
|
||||
daq_toolbar = QToolBar("DAQ")
|
||||
daq_toolbar.addAction(self._daq_connectaction)
|
||||
daq_toolbar.addAction(self._daq_disconnectaction)
|
||||
daq_toolbar.addAction(self._daq_calibaction)
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||
|
||||
repro_toolbar = QToolBar("Repros")
|
||||
repro_names, file_names = self.repros.names_of_repros()
|
||||
for rep, fn in zip(repro_names, file_names):
|
||||
repro_action = QAction(rep, self)
|
||||
repro_action.setStatusTip(rep)
|
||||
repro_action.triggered.connect(
|
||||
lambda checked, n=rep, f=fn: self.run_repro(n, f)
|
||||
)
|
||||
repro_toolbar.addAction(repro_action)
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, repro_toolbar)
|
||||
|
||||
def create_buttons(self):
|
||||
self.daq_connect_button = QPushButton("Connect Daq")
|
||||
self.daq_connect_button.setCheckable(True)
|
||||
self.daq_connect_button.clicked.connect(self.connect_dac)
|
||||
|
||||
self.daq_disconnect_button = QPushButton("Disconnect Daq")
|
||||
self.daq_disconnect_button.setCheckable(True)
|
||||
self.daq_disconnect_button.clicked.connect(self.disconnect_dac)
|
||||
|
||||
self.plot_calibration_button = QPushButton("Plot Calibration")
|
||||
self.plot_calibration_button.setCheckable(True)
|
||||
self.plot_calibration_button.clicked.connect(self.calibration_plot.plot)
|
||||
|
||||
def connect_dac(self):
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
try:
|
||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||
except IndexError:
|
||||
log.error("DAQ is not connected")
|
||||
log.error("Please connect a DAQ device to the system")
|
||||
|
||||
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):
|
||||
try:
|
||||
log.debug(f"{self.daq_device}")
|
||||
self.daq_device.disconnect()
|
||||
self.daq_device.release()
|
||||
log.debug(f"{self.daq_device}")
|
||||
self.daq_disconnect_button.setDisabled(True)
|
||||
self.daq_connect_button.setEnabled(True)
|
||||
except AttributeError:
|
||||
log.debug("DAQ was not connected")
|
||||
|
||||
def run_repro(self, n, fn):
|
||||
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
||||
worker = Worker(self.repros.run_repro, self.nix_file, n, fn)
|
||||
worker.signals.result.connect(self.print_output)
|
||||
worker.signals.finished.connect(self.thread_complete)
|
||||
worker.signals.progress.connect(self.progress_fn)
|
||||
|
||||
self.threadpool.start(worker)
|
||||
|
||||
def add_to_textfield(self, s: str):
|
||||
self.text.appendPlainText(s)
|
||||
|
||||
def on_exit(self):
|
||||
log.info("exit button!")
|
||||
self.add_to_textfield("exiting")
|
||||
self.close()
|
||||
|
||||
def on_about(self, e):
|
||||
about = AboutDialog(self)
|
||||
about.show()
|
||||
|
||||
def print_output(self, s):
|
||||
log.info(s)
|
||||
self.add_to_textfield(s)
|
||||
|
||||
def thread_complete(self):
|
||||
log.info("Thread complete!")
|
||||
self.add_to_textfield("Thread complete!")
|
||||
|
||||
def progress_fn(self, n):
|
||||
print("%d%% done" % n)
|
||||
113
pyrelacs/ui/plots/calibration.py
Normal file
113
pyrelacs/ui/plots/calibration.py
Normal file
@@ -0,0 +1,113 @@
|
||||
from IPython import embed
|
||||
import pyqtgraph as pg
|
||||
import numpy as np
|
||||
from scipy.signal import welch, find_peaks
|
||||
from scipy.integrate import romb
|
||||
|
||||
|
||||
class CalibrationPlot:
|
||||
def __init__(self, figure: pg.GraphicsLayoutWidget, nix_file):
|
||||
self.figure = figure
|
||||
self.nix_file = nix_file
|
||||
|
||||
def plot(self):
|
||||
self.figure.setBackground("w")
|
||||
self.beat_plot = self.figure.addPlot(row=0, col=0)
|
||||
self.power_plot = self.figure.addPlot(row=1, col=0)
|
||||
self.beat_plot.addLegend()
|
||||
self.power_plot.addLegend()
|
||||
# self.power_plot.setLogMode(x=False, y=True)
|
||||
|
||||
block = self.nix_file.blocks[0]
|
||||
colors = ["red", "green", "blue", "black", "yellow"]
|
||||
for i, (stim, fish) in enumerate(
|
||||
zip(list(block.data_arrays)[::2], list(block.data_arrays)[1::2])
|
||||
):
|
||||
f_stim, stim_power = welch(
|
||||
stim[:],
|
||||
fs=40_000.0,
|
||||
window="flattop",
|
||||
nperseg=100_000,
|
||||
)
|
||||
stim_power = self.decibel(stim_power)
|
||||
stim_max_power_index = np.argmax(stim_power)
|
||||
freq_stim = f_stim[stim_max_power_index]
|
||||
|
||||
f_fish, fish_power = welch(
|
||||
fish[:],
|
||||
fs=40_000.0,
|
||||
window="flattop",
|
||||
nperseg=100_000,
|
||||
)
|
||||
fish_power = self.decibel(fish_power)
|
||||
fish_max_power_index = np.argmax(fish_power)
|
||||
freq_fish = f_fish[fish_max_power_index]
|
||||
|
||||
beat_frequency = np.abs(freq_fish - freq_stim)
|
||||
|
||||
beat = stim[:] + fish[:]
|
||||
beat_squared = beat**2
|
||||
|
||||
f, powerspec = welch(
|
||||
beat_squared,
|
||||
window="flattop",
|
||||
fs=40_000.0,
|
||||
nperseg=100_000,
|
||||
)
|
||||
powerspec = self.decibel(powerspec)
|
||||
|
||||
padding = 20
|
||||
integration_window = powerspec[
|
||||
(f > beat_frequency - padding) & (f < beat_frequency + padding)
|
||||
]
|
||||
|
||||
peaks = find_peaks(powerspec, prominence=40)[0]
|
||||
|
||||
pen = pg.mkPen(colors[i])
|
||||
|
||||
self.beat_plot.plot(
|
||||
np.arange(0, len(beat)) / 40_000.0,
|
||||
beat,
|
||||
pen=pen,
|
||||
name=stim.name,
|
||||
)
|
||||
self.power_plot.plot(f, powerspec, pen=pen, name=stim.name)
|
||||
self.power_plot.plot(f[peaks], powerspec[peaks], pen=None, symbol="x")
|
||||
|
||||
def decibel(self, power, ref_power=1.0, min_power=1e-20):
|
||||
"""Transform power to decibel relative to ref_power.
|
||||
|
||||
\\[ decibel = 10 \\cdot \\log_{10}(power/ref\\_power) \\]
|
||||
Power values smaller than `min_power` are set to `-np.inf`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
power: float or array
|
||||
Power values, for example from a power spectrum or spectrogram.
|
||||
ref_power: float or None or 'peak'
|
||||
Reference power for computing decibel.
|
||||
If set to `None` or 'peak', the maximum power is used.
|
||||
min_power: float
|
||||
Power values smaller than `min_power` are set to `-np.inf`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
decibel_psd: array
|
||||
Power values in decibel relative to `ref_power`.
|
||||
"""
|
||||
if np.isscalar(power):
|
||||
tmp_power = np.array([power])
|
||||
decibel_psd = np.array([power])
|
||||
else:
|
||||
tmp_power = power
|
||||
decibel_psd = power.copy()
|
||||
if ref_power is None or ref_power == "peak":
|
||||
ref_power = np.max(decibel_psd)
|
||||
decibel_psd[tmp_power <= min_power] = float("-inf")
|
||||
decibel_psd[tmp_power > min_power] = 10.0 * np.log10(
|
||||
decibel_psd[tmp_power > min_power] / ref_power
|
||||
)
|
||||
if np.isscalar(power):
|
||||
return decibel_psd[0]
|
||||
else:
|
||||
return decibel_psd
|
||||
0
pyrelacs/util/__init__.py
Normal file
0
pyrelacs/util/__init__.py
Normal file
Reference in New Issue
Block a user