Compare commits
50 Commits
0e0aaf9f04
...
datastream
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0113e94625 | ||
|
|
cce7c55fe7 | ||
|
|
6c49f19b43 | ||
|
|
2ef018ef07 | ||
|
|
3ab7a33b52 | ||
|
|
acd41302c7 | ||
|
|
1fe854b74e | ||
|
|
a53ff62d96 | ||
|
|
3d3d9a0cdd | ||
|
|
8f6c9b1e5e | ||
|
|
574e9a8110 | ||
|
|
75619cf1c8 | ||
|
|
02911e57f8 | ||
|
|
557535ffa4 | ||
|
|
110629dae0 | ||
|
|
7c4b5098c1 | ||
|
|
e2b7ed3a61 | ||
|
|
038327bfeb | ||
|
|
4f7ebbe8c3 | ||
|
|
12e82dceee | ||
|
|
e4e86cbc49 | ||
|
|
e36db5e7b0 | ||
|
|
33f046c072 | ||
|
|
6d2eb09c65 | ||
|
|
4029034174 | ||
|
|
9fd4892325 | ||
|
|
85b5a71ccb | ||
|
|
5d62cb0384 | ||
|
|
64cd1b00ad | ||
|
|
f703687ed7 | ||
|
|
4e0a1f0ac5 | ||
|
|
4864538213 | ||
|
|
28dd0b7080 | ||
|
|
b94078634d | ||
|
|
e3c867f4fd | ||
|
|
13897f29e3 | ||
|
|
afc37adb1a | ||
|
|
b87e7f1ffa | ||
|
|
f576f33cc5 | ||
|
|
e16211b988 | ||
|
|
b22ef04317 | ||
|
|
d2f7d0e966 | ||
|
|
cc9089f503 | ||
|
|
351850e05c | ||
|
|
e44e021982 | ||
|
|
93fe2951cd | ||
|
|
452c3dcecb | ||
|
|
e999d25951 | ||
|
|
30bd705e1a | ||
|
|
38123cdff3 |
95
poetry.lock
generated
95
poetry.lock
generated
@@ -142,6 +142,19 @@ files = [
|
||||
docs = ["ipython", "matplotlib", "numpydoc", "sphinx"]
|
||||
tests = ["pytest", "pytest-cov", "pytest-xdist"]
|
||||
|
||||
[[package]]
|
||||
name = "dacite"
|
||||
version = "1.8.1"
|
||||
description = "Simple creation of data classes from dictionaries."
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
{file = "dacite-1.8.1-py3-none-any.whl", hash = "sha256:cc31ad6fdea1f49962ea42db9421772afe01ac5442380d9a99fcf3d188c61afe"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
dev = ["black", "coveralls", "mypy", "pre-commit", "pylint", "pytest (>=5)", "pytest-benchmark", "pytest-cov"]
|
||||
|
||||
[[package]]
|
||||
name = "decorator"
|
||||
version = "5.1.1"
|
||||
@@ -985,6 +998,86 @@ files = [
|
||||
[package.dependencies]
|
||||
six = ">=1.5"
|
||||
|
||||
[[package]]
|
||||
name = "pyyaml"
|
||||
version = "6.0.2"
|
||||
description = "YAML parser and emitter for Python"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:0a9a2848a5b7feac301353437eb7d5957887edbf81d56e903999a75a3d743086"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:29717114e51c84ddfba879543fb232a6ed60086602313ca38cce623c1d62cfbf"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8824b5a04a04a047e72eea5cec3bc266db09e35de6bdfe34c9436ac5ee27d237"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7c36280e6fb8385e520936c3cb3b8042851904eba0e58d277dca80a5cfed590b"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec031d5d2feb36d1d1a24380e4db6d43695f3748343d99434e6f5f9156aaa2ed"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:936d68689298c36b53b29f23c6dbb74de12b4ac12ca6cfe0e047bedceea56180"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:23502f431948090f597378482b4812b0caae32c22213aecf3b55325e049a6c68"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-win32.whl", hash = "sha256:2e99c6826ffa974fe6e27cdb5ed0021786b03fc98e5ee3c5bfe1fd5015f42b99"},
|
||||
{file = "PyYAML-6.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:a4d3091415f010369ae4ed1fc6b79def9416358877534caf6a0fdd2146c87a3e"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cc1c1159b3d456576af7a3e4d1ba7e6924cb39de8f67111c735f6fc832082774"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1e2120ef853f59c7419231f3bf4e7021f1b936f6ebd222406c3b60212205d2ee"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d225db5a45f21e78dd9358e58a98702a0302f2659a3c6cd320564b75b86f47c"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5ac9328ec4831237bec75defaf839f7d4564be1e6b25ac710bd1a96321cc8317"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ad2a3decf9aaba3d29c8f537ac4b243e36bef957511b4766cb0057d32b0be85"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:797b4f722ffa07cc8d62053e4cff1486fa6dc094105d13fea7b1de7d8bf71c9e"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-win32.whl", hash = "sha256:11d8f3dd2b9c1207dcaf2ee0bbbfd5991f571186ec9cc78427ba5bd32afae4b5"},
|
||||
{file = "PyYAML-6.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:e10ce637b18caea04431ce14fabcf5c64a1c61ec9c56b071a4b7ca131ca52d44"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4"},
|
||||
{file = "PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183"},
|
||||
{file = "PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:24471b829b3bf607e04e88d79542a9d48bb037c2267d7927a874e6c205ca7e9a"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d7fded462629cfa4b685c5416b949ebad6cec74af5e2d42905d41e257e0869f5"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d84a1718ee396f54f3a086ea0a66d8e552b2ab2017ef8b420e92edbc841c352d"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9056c1ecd25795207ad294bcf39f2db3d845767be0ea6e6a34d856f006006083"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:82d09873e40955485746739bcb8b4586983670466c23382c19cffecbf1fd8706"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-win32.whl", hash = "sha256:43fa96a3ca0d6b1812e01ced1044a003533c47f6ee8aca31724f78e93ccc089a"},
|
||||
{file = "PyYAML-6.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:01179a4a8559ab5de078078f37e5c1a30d76bb88519906844fd7bdea1b7729ff"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:688ba32a1cffef67fd2e9398a2efebaea461578b0923624778664cc1c914db5d"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a8786accb172bd8afb8be14490a16625cbc387036876ab6ba70912730faf8e1f"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d8e03406cac8513435335dbab54c0d385e4a49e4945d2909a581c83647ca0290"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f753120cb8181e736c57ef7636e83f31b9c0d1722c516f7e86cf15b7aa57ff12"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3b1fdb9dc17f5a7677423d508ab4f243a726dea51fa5e70992e59a7411c89d19"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:0b69e4ce7a131fe56b7e4d770c67429700908fc0752af059838b1cfb41960e4e"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a9f8c2e67970f13b16084e04f134610fd1d374bf477b17ec1599185cf611d725"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-win32.whl", hash = "sha256:6395c297d42274772abc367baaa79683958044e5d3835486c16da75d2a694631"},
|
||||
{file = "PyYAML-6.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:39693e1f8320ae4f43943590b49779ffb98acb81f788220ea932a6b6c51004d8"},
|
||||
{file = "pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quantities"
|
||||
version = "0.16.0"
|
||||
description = "Support for physical quantities with units, based on numpy"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "quantities-0.16.0-py3-none-any.whl", hash = "sha256:189e573953e7864d8c303a3472f6ad39fbe0698c3d75c17059b70bc457c7c66d"},
|
||||
{file = "quantities-0.16.0.tar.gz", hash = "sha256:211cce2d268da7e202abab5c2533ce3200ff619dd8ac2a3cd98f861b8a57c6eb"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
numpy = ">=1.20"
|
||||
|
||||
[package.extras]
|
||||
doc = ["sphinx"]
|
||||
test = ["pytest", "wheel"]
|
||||
|
||||
[[package]]
|
||||
name = "rich"
|
||||
version = "13.9.2"
|
||||
@@ -1173,4 +1266,4 @@ files = [
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.11, <3.13"
|
||||
content-hash = "869348ffb24d0a55aee308a54cae333d5029c5aa52bc4082b720d766c63c2f9c"
|
||||
content-hash = "31433ed1dc0cc83dd7e781546dad5b8f068d59eaf692b4d3c12e07c604b1a6dd"
|
||||
|
||||
@@ -33,6 +33,9 @@ nixio = "^1.5.3"
|
||||
pyqtgraph = "^0.13.7"
|
||||
pytest = "^8.3.3"
|
||||
pglive = "^0.7.6"
|
||||
pyyaml = "^6.0.2"
|
||||
dacite = "^1.8.1"
|
||||
quantities = "^0.16.0"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
pyrelacs = "pyrelacs.app:main"
|
||||
|
||||
@@ -2,8 +2,10 @@ import sys
|
||||
|
||||
from PyQt6.QtCore import QSettings
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
from IPython import embed
|
||||
|
||||
from pyrelacs import info
|
||||
from pyrelacs.config.config_loader import load_config
|
||||
from pyrelacs.ui.mainwindow import PyRelacs
|
||||
|
||||
from pyrelacs import (
|
||||
@@ -25,8 +27,11 @@ def main():
|
||||
x = int(settings.value("app/pos_x", 100))
|
||||
y = int(settings.value("app/pos_y", 100))
|
||||
|
||||
# load config
|
||||
window = PyRelacs()
|
||||
# load the config
|
||||
|
||||
config = load_config()
|
||||
# start the app
|
||||
window = PyRelacs(config)
|
||||
window.setMinimumWidth(200)
|
||||
window.setMinimumHeight(200)
|
||||
window.resize(width, height)
|
||||
|
||||
@@ -1,12 +1,78 @@
|
||||
Settings:
|
||||
Repros: [Calibration]
|
||||
Path: ~/projects/pyrelacs/test/
|
||||
settings:
|
||||
# If true daq should be used, else starts without daq
|
||||
daq: True
|
||||
# class names of the repros to run
|
||||
repros: [Calibration, Sinus]
|
||||
path: ~/projects/pyrelacs/test/
|
||||
# string to append after the file name
|
||||
postappend: ehpys
|
||||
|
||||
Metadata:
|
||||
Lab: Neuroethology
|
||||
metadata:
|
||||
SetupName : Setup1
|
||||
Maintainer : Your name
|
||||
Creator : Whoever
|
||||
SetupLocation : virtual
|
||||
Lab : XYZ-Lab
|
||||
Institute : Your institute
|
||||
University : Your university
|
||||
Address : Your institute's address
|
||||
|
||||
PyRelacs:
|
||||
Input:
|
||||
Name: DAQ
|
||||
Samplingrate: 40_000
|
||||
|
||||
pyrelacs:
|
||||
data:
|
||||
input:
|
||||
inputsamplerate : 20
|
||||
# Unit is rescaled to Hz
|
||||
inputsamplerateunit : kHz
|
||||
# BufferSize
|
||||
inputtracecapacity : 600
|
||||
# Unit is rescaled to s
|
||||
inputtracecapacityunit : s
|
||||
inputunipolar : false
|
||||
inputtraceid : [ V-1, EOD, LocalEOD-1, GlobalEFieldStimulus ]
|
||||
inputtracescale : [ 100, 1, 10, 1 ]
|
||||
inputtraceunit : [ mV, mV, mV, mV ]
|
||||
inputtracedevice : [ ai-1, ai-1, ai-1, ai-1 ]
|
||||
inputtracechannel : [ 0, 2, 4, 6 ]
|
||||
inputtracereference : [ ground, ground, ground, ground ]
|
||||
inputtracemaxvalue : [ 100, 2, 2, 10 ]
|
||||
inputtracecenter : [ true, false, false, false ]
|
||||
output:
|
||||
outputtraceid : [ GlobalEField, GlobalEFieldAM, LocalEField, I ]
|
||||
outputtracedevice : [ ao-1, ao-1, ao-1, ao-1 ]
|
||||
outputtracechannel : [ 0, 1, 2, 3 ]
|
||||
outputtracescale : [ 1, 1, 1, 1 ]
|
||||
outputtraceunit : [ V, V, V, V ]
|
||||
outputtracemaxrate : [ 40, 40, 40, 40]
|
||||
outputtracemaxrateunit : [kHz, kHz, kHz, kHz]
|
||||
outputtracemodality : [ electric, electric, electric, current ]
|
||||
|
||||
sinus:
|
||||
inputsamplerate : 20
|
||||
inputsamplerateunit : kHz
|
||||
# BufferSize
|
||||
inputtracecapacity : 600
|
||||
inputtracecapacityunit : s
|
||||
outputtraceid : [ Sinus ]
|
||||
outputtracedevice : [ ao-0 ]
|
||||
outputtracechannel : [ 0 ]
|
||||
outputtracescale : [ 1 ]
|
||||
outputtraceunit : [ V ]
|
||||
outputtracemaxrate : [ 40 ]
|
||||
outputtracemaxrateunit : [kHz]
|
||||
outputtracemodality : [ electric ]
|
||||
|
||||
devices:
|
||||
DAQFlexCore:
|
||||
analogoutputpins : [0, 1]
|
||||
analoginputpinshigh : [0, 1, 2, 3,4,5,6,7]
|
||||
analoginputpinslow : [1,2]
|
||||
digitalpins : [0,1,2,3]
|
||||
|
||||
CS3310DIO:
|
||||
ident : attdev-1
|
||||
strobepin : 6
|
||||
datainpin : 5
|
||||
dataoutpin : -1
|
||||
cspin : 4
|
||||
mutepin : 7
|
||||
zcenpin : -1
|
||||
|
||||
132
pyrelacs/config/config_loader.py
Normal file
132
pyrelacs/config/config_loader.py
Normal file
@@ -0,0 +1,132 @@
|
||||
from typing import TypedDict, Union
|
||||
from dataclasses import dataclass
|
||||
import pathlib
|
||||
|
||||
|
||||
import dacite
|
||||
import yaml
|
||||
from dacite import from_dict
|
||||
from IPython import embed
|
||||
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
log = config_logging()
|
||||
|
||||
|
||||
@dataclass
|
||||
class ValueUnit:
|
||||
value: int
|
||||
unit: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Settings:
|
||||
daq: bool
|
||||
repros: list[str]
|
||||
path: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Metadata:
|
||||
SetupName: str
|
||||
Maintainer: str
|
||||
Creator: str
|
||||
SetupLocation: str
|
||||
Lab: str
|
||||
Institute: str
|
||||
University: str
|
||||
Address: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Input:
|
||||
inputsamplerate: int
|
||||
inputsamplerateunit: str
|
||||
# BufferSize
|
||||
inputtracecapacity: int
|
||||
inputtracecapacityunit: str
|
||||
inputunipolar: bool
|
||||
inputtraceid: list[str]
|
||||
inputtracescale: list[int]
|
||||
inputtraceunit: list[str]
|
||||
inputtracedevice: list[str]
|
||||
inputtracechannel: list[int]
|
||||
inputtracereference: list[str]
|
||||
inputtracemaxvalue: list[int]
|
||||
inputtracecenter: list[bool]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Output:
|
||||
outputtraceid: list[str]
|
||||
outputtracedevice: list[str]
|
||||
outputtracechannel: list[int]
|
||||
outputtracescale: list[int]
|
||||
outputtraceunit: list[str]
|
||||
outputtracemaxrate: list[int]
|
||||
outputtracemaxrateunit: list[str]
|
||||
outputtracemodality: list[str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Data:
|
||||
input: Input
|
||||
output: Output
|
||||
|
||||
|
||||
@dataclass
|
||||
class Sinus:
|
||||
inputsamplerate: int
|
||||
inputsamplerateunit: str
|
||||
# BufferSize
|
||||
inputtracecapacity: int
|
||||
inputtracecapacityunit: str
|
||||
outputtraceid: list[str]
|
||||
outputtracedevice: list[str]
|
||||
outputtracechannel: list[int]
|
||||
outputtracescale: list[int]
|
||||
outputtraceunit: list[str]
|
||||
outputtracemaxrate: list[int]
|
||||
outputtracemaxrateunit: list[str]
|
||||
outputtracemodality: list[str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class PyRelacs:
|
||||
data: Data
|
||||
sinus: Sinus
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
settings: Settings
|
||||
metadata: Metadata
|
||||
pyrelacs: PyRelacs
|
||||
|
||||
|
||||
def load_config():
|
||||
pyrelacs_config_path = pathlib.Path(__file__).parent.parent / "config.yaml"
|
||||
log.debug(pyrelacs_config_path)
|
||||
if not pyrelacs_config_path.is_file():
|
||||
log.error("Config File was not found")
|
||||
with open(pyrelacs_config_path, "r") as config_file:
|
||||
try:
|
||||
data = yaml.full_load(config_file)
|
||||
try:
|
||||
config = from_dict(data_class=Config, data=data)
|
||||
return config
|
||||
except dacite.DaciteError as e:
|
||||
log.error(f"Invalid Config, {e}")
|
||||
except yaml.YAMLError as e:
|
||||
raise yaml.YAMLError(f"Error parsing YAML file: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pyrelacs_config_path = pathlib.Path(__file__).parent.parent / "config.yaml"
|
||||
log.debug(pyrelacs_config_path)
|
||||
if not pyrelacs_config_path.is_file():
|
||||
log.error("Config File was not found")
|
||||
with open(pyrelacs_config_path, "r") as config_file:
|
||||
data = yaml.full_load(config_file)
|
||||
embed()
|
||||
exit()
|
||||
@@ -9,7 +9,7 @@ class CircBuffer:
|
||||
self,
|
||||
size: int,
|
||||
channels: int = 1,
|
||||
samplerate: int = 40_000,
|
||||
samplerate: float = 40_000.0,
|
||||
mutex: QMutex = QMutex(),
|
||||
):
|
||||
self.__size = size
|
||||
|
||||
@@ -21,7 +21,6 @@ class DaqProducer:
|
||||
self.device = device
|
||||
self.ai_device = self.device.get_ai_device()
|
||||
self.channels = channels
|
||||
|
||||
self.stop = False
|
||||
|
||||
def read_analog_continously(
|
||||
@@ -41,7 +40,7 @@ class DaqProducer:
|
||||
)
|
||||
|
||||
# let the buffer for the daq device hold 5 seconds of data
|
||||
daq_buffer_size = self.buffer.samplerate * 5
|
||||
daq_buffer_size = int(self.buffer.samplerate * 30)
|
||||
|
||||
data_in = uldaq.create_float_buffer(channel_range.size, daq_buffer_size)
|
||||
log.debug(f"Buffersize for daq {len(data_in)}")
|
||||
@@ -70,7 +69,12 @@ class DaqProducer:
|
||||
prev_count = 0
|
||||
prev_index = 0
|
||||
while not self.stop:
|
||||
daq_status, transfer_status = self.ai_device.get_scan_status()
|
||||
try:
|
||||
daq_status, transfer_status = self.ai_device.get_scan_status()
|
||||
except uldaq.ul_exception.ULException as e:
|
||||
log.error("Could not get the scan status")
|
||||
log.error("Stopping writting")
|
||||
break
|
||||
# The index into the data buffer immediately following the last sample transferred.
|
||||
current_index = transfer_status.current_index
|
||||
# total samples since start of the scan
|
||||
@@ -79,7 +83,7 @@ class DaqProducer:
|
||||
channel_samples = transfer_status.current_scan_count
|
||||
|
||||
new_data_count = total_samples - prev_count
|
||||
# check if counts if new data is bigger than the buffer
|
||||
# check if new data is bigger than the buffer
|
||||
# if that happends stop the acquisition
|
||||
if new_data_count > len(data_in):
|
||||
self.ai_device.scan_stop()
|
||||
@@ -92,23 +96,54 @@ class DaqProducer:
|
||||
if prev_index + chunk_size > len(data_in) - 1:
|
||||
log.debug("Chunk wraps around buffersize")
|
||||
first_chunk = len(data_in) - prev_index
|
||||
|
||||
data_first_channel = data_in[
|
||||
prev_index : prev_index + first_chunk : 2
|
||||
]
|
||||
data_second_channel = data_in[
|
||||
prev_index + 1 : prev_index + first_chunk : 2
|
||||
]
|
||||
|
||||
[
|
||||
self.buffer.append(data_in[prev_index + i])
|
||||
for i in range(first_chunk)
|
||||
self.buffer.append(data_first_channel[i], channel=0)
|
||||
for i in range(int(first_chunk / 2))
|
||||
]
|
||||
|
||||
[
|
||||
self.buffer.append(data_second_channel[i], channel=1)
|
||||
for i in range(int(first_chunk / 2))
|
||||
]
|
||||
second_chunk = chunk_size - first_chunk
|
||||
data_first_channel = data_in[0:second_chunk:2]
|
||||
data_second_channel = data_in[1:second_chunk:2]
|
||||
|
||||
[
|
||||
self.buffer.append(data_in[i])
|
||||
for i in range(second_chunk)
|
||||
self.buffer.append(data_first_channel[i], channel=0)
|
||||
for i in range(int(second_chunk / 2))
|
||||
]
|
||||
[
|
||||
self.buffer.append(data_second_channel[i], channel=1)
|
||||
for i in range(int(second_chunk / 2))
|
||||
]
|
||||
else:
|
||||
log.debug("Writing chunk to buffer")
|
||||
# appending to the first channel
|
||||
|
||||
data_first_channel = data_in[
|
||||
prev_index : prev_index + chunk_size : 2
|
||||
]
|
||||
data_second_channel = data_in[
|
||||
prev_index + 1 : prev_index + chunk_size : 2
|
||||
]
|
||||
[
|
||||
self.buffer.append(data_in[prev_index + i])
|
||||
for i in range(chunk_size)
|
||||
self.buffer.append(data_first_channel[i], channel=0)
|
||||
for i in range(int(chunk_size / 2))
|
||||
]
|
||||
|
||||
self.buffer.append(data_in[current_index])
|
||||
[
|
||||
self.buffer.append(data_second_channel[i], channel=1)
|
||||
for i in range(int(chunk_size / 2))
|
||||
]
|
||||
|
||||
if total_samples - prev_count > len(data_in):
|
||||
self.ai_device.scan_stop()
|
||||
@@ -124,33 +159,70 @@ class DaqProducer:
|
||||
|
||||
self.ai_device.scan_stop()
|
||||
daq_status, transfer_status = self.ai_device.get_scan_status()
|
||||
current_index = transfer_status.current_index
|
||||
log.debug(daq_status)
|
||||
chunk_size = transfer_status.current_total_count - prev_count
|
||||
|
||||
log.debug(transfer_status.current_index)
|
||||
log.debug(transfer_status.current_total_count)
|
||||
log.debug(transfer_status.current_scan_count)
|
||||
log.debug(self.buffer.totalcount())
|
||||
log.debug(f"DAQ current index {transfer_status.current_index}")
|
||||
log.debug(f"DAQ total count {transfer_status.current_total_count}")
|
||||
log.debug(
|
||||
f"DAQ Samples per channel {transfer_status.current_scan_count}"
|
||||
)
|
||||
log.debug("Appending last chunk")
|
||||
|
||||
if prev_index + chunk_size > len(data_in) - 1:
|
||||
log.debug("Chunk wraps around buffersize")
|
||||
first_chunk = len(data_in) - prev_index
|
||||
[
|
||||
self.buffer.append(data_in[prev_index + i])
|
||||
for i in range(first_chunk)
|
||||
|
||||
data_first_channel = data_in[
|
||||
prev_index : prev_index + first_chunk : 2
|
||||
]
|
||||
second_chunk = chunk_size - first_chunk
|
||||
[self.buffer.append(data_in[i]) for i in range(second_chunk)]
|
||||
else:
|
||||
log.debug("Writing chunk to buffer")
|
||||
[
|
||||
self.buffer.append(data_in[prev_index + i])
|
||||
for i in range(chunk_size)
|
||||
data_second_channel = data_in[
|
||||
prev_index + 1 : prev_index + first_chunk : 2
|
||||
]
|
||||
|
||||
self.buffer.append(data_in[current_index])
|
||||
[
|
||||
self.buffer.append(data_first_channel[i], channel=0)
|
||||
for i in range(int(first_chunk / 2))
|
||||
]
|
||||
|
||||
[
|
||||
self.buffer.append(data_second_channel[i], channel=1)
|
||||
for i in range(int(first_chunk / 2))
|
||||
]
|
||||
second_chunk = chunk_size - first_chunk
|
||||
data_first_channel = data_in[0:second_chunk:2]
|
||||
data_second_channel = data_in[1:second_chunk:2]
|
||||
|
||||
[
|
||||
self.buffer.append(data_first_channel[i], channel=0)
|
||||
for i in range(int(second_chunk / 2))
|
||||
]
|
||||
[
|
||||
self.buffer.append(data_second_channel[i], channel=1)
|
||||
for i in range(int(second_chunk / 2))
|
||||
]
|
||||
else:
|
||||
log.debug("Writing chunk to buffer")
|
||||
# appending to the first channel
|
||||
|
||||
data_first_channel = data_in[
|
||||
prev_index : prev_index + chunk_size : 2
|
||||
]
|
||||
data_second_channel = data_in[
|
||||
prev_index + 1 : prev_index + chunk_size : 2
|
||||
]
|
||||
[
|
||||
self.buffer.append(data_first_channel[i], channel=0)
|
||||
for i in range(int(chunk_size / 2))
|
||||
]
|
||||
|
||||
[
|
||||
self.buffer.append(data_second_channel[i], channel=1)
|
||||
for i in range(int(chunk_size / 2))
|
||||
]
|
||||
log.info("stopping")
|
||||
log.debug(self.buffer.totalcount())
|
||||
log.debug(self.ai_device.get_scan_status())
|
||||
|
||||
break
|
||||
break
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
from datetime import datetime
|
||||
import itertools
|
||||
import string
|
||||
import time
|
||||
from dataclasses import asdict
|
||||
|
||||
from IPython import embed
|
||||
from PyQt6.QtCore import QMutex
|
||||
import nixio
|
||||
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
@@ -8,36 +15,95 @@ log = config_logging()
|
||||
|
||||
|
||||
class NixWriter:
|
||||
def __init__(self, buffer: CircBuffer) -> None:
|
||||
def __init__(self, buffer: CircBuffer, config) -> None:
|
||||
self.buffer = buffer
|
||||
self.config = config
|
||||
|
||||
def write_nix(self, *args, **kwargs):
|
||||
self._write_header()
|
||||
items = 0
|
||||
chunk = 1000
|
||||
def write_nix(
|
||||
self,
|
||||
data_array: nixio.DataArray,
|
||||
mutex: QMutex,
|
||||
channel: int = 0,
|
||||
chunk_size=1000,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
index = 0
|
||||
log.debug("Starting the writing")
|
||||
self.write = True
|
||||
while self.write:
|
||||
log.debug(items)
|
||||
try:
|
||||
data, _ = self.buffer.read(items, extend=chunk)
|
||||
self.data_array.append(data)
|
||||
except IndexError as e:
|
||||
log.debug(f"{e}")
|
||||
total_count = self.buffer.totalcount(channel=channel)
|
||||
if total_count - index >= chunk_size:
|
||||
mutex.lock()
|
||||
log.debug(index)
|
||||
try:
|
||||
_, data = self.buffer.read(
|
||||
index, extend=chunk_size, channel=channel
|
||||
)
|
||||
if index == 0:
|
||||
data_array.write_direct(data)
|
||||
else:
|
||||
data_array.append(data)
|
||||
index += chunk_size
|
||||
except IndexError as e:
|
||||
time.sleep(0.001)
|
||||
log.debug(f"{e}")
|
||||
mutex.unlock()
|
||||
else:
|
||||
time.sleep(0.001)
|
||||
continue
|
||||
items += chunk
|
||||
total_count = self.buffer.totalcount(channel=channel)
|
||||
try:
|
||||
mutex.lock()
|
||||
_, data = self.buffer.read(
|
||||
index, extend=total_count - index, channel=channel
|
||||
)
|
||||
data_array.append(data)
|
||||
mutex.unlock()
|
||||
index += total_count - index
|
||||
except IndexError as e:
|
||||
log.error(f"Could not read the last samples, {e}")
|
||||
|
||||
log.debug("Stoppint the writing")
|
||||
log.debug(f"Samples written {items}")
|
||||
embed()
|
||||
exit()
|
||||
self.nix_file.close()
|
||||
log.debug(f"Samples written {index}")
|
||||
|
||||
def _write_header(self):
|
||||
"""
|
||||
Writing the header of the nix file
|
||||
"""
|
||||
self.nix_file = nixio.File.open(path="data.nix", mode=nixio.FileMode.Overwrite)
|
||||
self.block = self.nix_file.create_block("recording", "testfile")
|
||||
self.data_array = self.block.create_data_array(
|
||||
"Analog1", "ndarray", shape=(1000,), dtype=nixio.DataType.Double
|
||||
)
|
||||
|
||||
def generate_letter_sequence(self):
|
||||
alphabet = string.ascii_lowercase
|
||||
for size in range(2, 3):
|
||||
for combo in itertools.product(alphabet, repeat=size):
|
||||
yield "".join(combo)
|
||||
|
||||
def create_nix_file(self, file_path, metadata):
|
||||
data_time = datetime.now().strftime("%Y-%m-%t_%H-%M-%S")
|
||||
sequence_generator = self.generate_letter_sequence()
|
||||
sequence = next(sequence_generator)
|
||||
|
||||
self.nix_file = nixio.File.open(
|
||||
path=f"{file_path}/{data_time}_{sequence}.nix",
|
||||
mode=nixio.FileMode.Overwrite,
|
||||
)
|
||||
self.block = self.nix_file.create_block("recording", "testfile")
|
||||
self.section = self.nix_file.create_section("metadata", "config.yaml")
|
||||
for key, value in asdict(metadata).items():
|
||||
self.section[key] = value
|
||||
|
||||
self.data_array_analog1 = self.block.create_data_array(
|
||||
"Analog1", "ndarray", shape=(1000,), dtype=nixio.DataType.Double
|
||||
)
|
||||
self.data_array_analog2 = self.block.create_data_array(
|
||||
"Analog2", "ndarray", shape=(1000,), dtype=nixio.DataType.Double
|
||||
)
|
||||
return self.data_array_analog1, self.data_array_analog2
|
||||
|
||||
def stop_writing(self):
|
||||
self.write = False
|
||||
|
||||
@@ -8,7 +8,6 @@ from pyrelacs.util.logging import config_logging
|
||||
log = config_logging()
|
||||
|
||||
|
||||
# stopbutton: QAction
|
||||
class SinProducer:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -39,12 +38,7 @@ class SinProducer:
|
||||
|
||||
log.debug(f"duration sinus {end_time-start_time}")
|
||||
log.debug(f"Stimulation time {t}")
|
||||
log.debug(f"{self.buffer.totalcount()}")
|
||||
# data = self.buffer.get_all()
|
||||
# log.debug(data.shape[0])
|
||||
# log.debug(data.shape[0] / self.buffer.samplerate)
|
||||
# plt.plot(np.arange(data.size) / self.buffer.samplerate, data)
|
||||
# plt.show()
|
||||
log.debug(f"Total samples produced {self.buffer.totalcount()}")
|
||||
|
||||
def stop_request(self):
|
||||
self.stop = True
|
||||
|
||||
@@ -41,13 +41,16 @@ class MccDaq:
|
||||
try:
|
||||
self.daq_device.connect()
|
||||
except uldaq.ul_exception.ULException:
|
||||
self.disconnect_dac()
|
||||
self.disconnect_daq()
|
||||
self.connect_dac()
|
||||
|
||||
self.ai_device = self.daq_device.get_ai_device()
|
||||
self.ao_device = self.daq_device.get_ao_device()
|
||||
self.dio_device = self.daq_device.get_dio_device()
|
||||
log.debug("Connected")
|
||||
|
||||
log.debug("Connected to MccDaq")
|
||||
log.debug("Activating the Attenuator")
|
||||
self.activate_attenuator()
|
||||
|
||||
def connect_dac(self):
|
||||
"""
|
||||
@@ -194,7 +197,7 @@ class MccDaq:
|
||||
except Exception as e:
|
||||
print(f"{e}")
|
||||
self.set_analog_to_zero()
|
||||
self.disconnect_dac()
|
||||
self.disconnect_daq()
|
||||
|
||||
return data_analog_output
|
||||
|
||||
@@ -221,10 +224,10 @@ class MccDaq:
|
||||
uldaq.AOutListFlag.DEFAULT,
|
||||
[0, 0],
|
||||
)
|
||||
except Exception as e:
|
||||
log.error("f{e}")
|
||||
except Exception as er:
|
||||
log.error(f"{er}")
|
||||
log.error("disconnection dac")
|
||||
self.disconnect_dac()
|
||||
# self.disconnect_daq()
|
||||
|
||||
def digital_trigger(self, ch: int = 0) -> None:
|
||||
"""
|
||||
@@ -281,7 +284,9 @@ class MccDaq:
|
||||
bit = self.dio_device.d_bit_in(uldaq.DigitalPortType.AUXPORT, channel)
|
||||
return bit
|
||||
|
||||
def disconnect_dac(self):
|
||||
def disconnect_daq(self):
|
||||
log.debug("Disconnecting DAQ")
|
||||
self.deactivate_attenuator()
|
||||
self.daq_device.disconnect()
|
||||
self.daq_device.release()
|
||||
|
||||
@@ -329,12 +334,12 @@ class MccDaq:
|
||||
except uldaq.ul_exception.ULException:
|
||||
log.debug("Operation timed out")
|
||||
self.write_bit(channel=0, bit=0)
|
||||
self.disconnect_dac()
|
||||
self.disconnect_daq()
|
||||
self.connect_dac()
|
||||
self.set_analog_to_zero()
|
||||
finally:
|
||||
self.write_bit(channel=0, bit=0)
|
||||
self.disconnect_dac()
|
||||
self.disconnect_daq()
|
||||
self.connect_dac()
|
||||
self.set_analog_to_zero()
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import uldaq
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.signal import welch, find_peaks
|
||||
import pyqtgraph as pg
|
||||
|
||||
from pyrelacs.devices.mccdaq import MccDaq
|
||||
from pyrelacs.util.logging import config_logging
|
||||
@@ -15,40 +17,50 @@ log = config_logging()
|
||||
faulthandler.enable()
|
||||
|
||||
|
||||
class Calibration(MccDaq):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
class Calibration:
|
||||
def __init__(self, config, mccdaq: MccDaq) -> None:
|
||||
self.config = config
|
||||
self.mccdaq = mccdaq
|
||||
self.SAMPLERATE = 40_000.0
|
||||
self.DURATION = 5
|
||||
self.AMPLITUDE = 1
|
||||
self.SINFREQ = 750
|
||||
|
||||
@staticmethod
|
||||
def run(nix_file: nix.File):
|
||||
calb = Calibration()
|
||||
calb.check_beat(nix_file)
|
||||
def run(*args, **kwargs):
|
||||
nix_block = args[0]
|
||||
figure = args[1]
|
||||
mccdaq = args[2]
|
||||
config = args[3]
|
||||
calb = Calibration(config, mccdaq)
|
||||
calb.check_beat(nix_block)
|
||||
calb.plot(figure, nix_block)
|
||||
|
||||
return "finished"
|
||||
|
||||
def check_amplitude(self):
|
||||
db_values = [0.0, -5.0, -10.0, -20.0, -50.0]
|
||||
colors = ["red", "green", "blue", "black", "yellow"]
|
||||
self.set_attenuation_level(db_channel1=0.0, db_channel2=0.0)
|
||||
self.mccdaq.set_attenuation_level(db_channel1=0.0, db_channel2=0.0)
|
||||
# write to ananlog 1
|
||||
t = np.arange(0, self.DURATION, 1 / self.SAMPLERATE)
|
||||
data = self.AMPLITUDE * np.sin(2 * np.pi * self.SINFREQ * t)
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
for i, db_value in enumerate(db_values):
|
||||
self.set_attenuation_level(db_channel1=db_value, db_channel2=db_value)
|
||||
self.mccdaq.set_attenuation_level(
|
||||
db_channel1=db_value, db_channel2=db_value
|
||||
)
|
||||
log.debug(f"{db_value}")
|
||||
|
||||
stim = self.write_analog(
|
||||
stim = self.mccdaq.write_analog(
|
||||
data,
|
||||
[0, 0],
|
||||
self.SAMPLERATE,
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
)
|
||||
|
||||
data_channel_one = self.read_analog(
|
||||
data_channel_one = self.mccdaq.read_analog(
|
||||
[0, 0],
|
||||
self.DURATION,
|
||||
self.SAMPLERATE,
|
||||
@@ -57,21 +69,21 @@ class Calibration(MccDaq):
|
||||
time.sleep(1)
|
||||
|
||||
log.debug("Starting the Scan")
|
||||
self.digital_trigger()
|
||||
self.mccdaq.digital_trigger()
|
||||
|
||||
try:
|
||||
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||
self.mccdaq.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||
log.debug("Scan finished")
|
||||
self.write_bit(channel=0, bit=0)
|
||||
self.mccdaq.write_bit(channel=0, bit=0)
|
||||
time.sleep(1)
|
||||
self.set_analog_to_zero()
|
||||
self.mccdaq.set_analog_to_zero()
|
||||
except uldaq.ul_exception.ULException:
|
||||
log.debug("Operation timed out")
|
||||
# reset the diggital trigger
|
||||
self.write_bit(channel=0, bit=0)
|
||||
self.mccdaq.write_bit(channel=0, bit=0)
|
||||
time.sleep(1)
|
||||
self.set_analog_to_zero()
|
||||
self.disconnect_dac()
|
||||
self.mccdaq.set_analog_to_zero()
|
||||
# self.mccdaq.disconnect_daq()
|
||||
|
||||
if i == 0:
|
||||
ax.plot(t, stim, label=f"Input_{db_value}", color=colors[i])
|
||||
@@ -80,34 +92,33 @@ class Calibration(MccDaq):
|
||||
ax.legend()
|
||||
plt.show()
|
||||
|
||||
self.disconnect_dac()
|
||||
# self.mccdaq.disconnect_daq()
|
||||
|
||||
def check_beat(self, nix_file: nix.File):
|
||||
self.set_attenuation_level(db_channel1=-10.0, db_channel2=0.0)
|
||||
def check_beat(self, nix_block: nix.Block):
|
||||
self.mccdaq.set_attenuation_level(db_channel1=-10.0, db_channel2=0.0)
|
||||
t = np.arange(0, self.DURATION, 1 / self.SAMPLERATE)
|
||||
data = self.AMPLITUDE * np.sin(2 * np.pi * self.SINFREQ * t)
|
||||
# data = np.concatenate((data, data))
|
||||
db_values = [0.0, -5.0, -8.5, -10.0]
|
||||
colors = ["red", "blue", "black", "green"]
|
||||
colors_in = ["lightcoral", "lightblue", "grey", "lightgreen"]
|
||||
block = nix_file.create_block("Calibration", "data")
|
||||
# fig, axes = plt.subplots(2, 2, sharex="col")
|
||||
for i, db_value in enumerate(db_values):
|
||||
self.set_attenuation_level(db_channel1=db_value)
|
||||
stim = self.write_analog(
|
||||
self.mccdaq.set_attenuation_level(db_channel1=db_value)
|
||||
stim = self.mccdaq.write_analog(
|
||||
data,
|
||||
[0, 0],
|
||||
self.SAMPLERATE,
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
)
|
||||
readout = self.read_analog(
|
||||
readout = self.mccdaq.read_analog(
|
||||
[0, 1],
|
||||
self.DURATION,
|
||||
self.SAMPLERATE,
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
)
|
||||
self.digital_trigger()
|
||||
log.info(self.ao_device)
|
||||
self.mccdaq.digital_trigger()
|
||||
log.info(self.mccdaq.ao_device)
|
||||
ai_status = uldaq.ScanStatus.RUNNING
|
||||
ao_status = uldaq.ScanStatus.RUNNING
|
||||
|
||||
@@ -119,10 +130,10 @@ class Calibration(MccDaq):
|
||||
):
|
||||
# log.debug("Scanning")
|
||||
time.time_ns()
|
||||
ai_status = self.ai_device.get_scan_status()[0]
|
||||
ao_status = self.ao_device.get_scan_status()[0]
|
||||
ai_status = self.mccdaq.ai_device.get_scan_status()[0]
|
||||
ao_status = self.mccdaq.ao_device.get_scan_status()[0]
|
||||
|
||||
self.write_bit(channel=0, bit=0)
|
||||
self.mccdaq.write_bit(channel=0, bit=0)
|
||||
log.debug(
|
||||
f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}"
|
||||
)
|
||||
@@ -130,7 +141,7 @@ class Calibration(MccDaq):
|
||||
channel1 = np.array(readout[::2])
|
||||
channel2 = np.array(readout[1::2])
|
||||
|
||||
stim_data = block.create_data_array(
|
||||
stim_data = nix_block.create_data_array(
|
||||
f"stimulus_{db_value}",
|
||||
"nix.regular_sampled",
|
||||
shape=data.shape,
|
||||
@@ -143,7 +154,7 @@ class Calibration(MccDaq):
|
||||
label="time",
|
||||
unit="s",
|
||||
)
|
||||
fish_data = block.create_data_array(
|
||||
fish_data = nix_block.create_data_array(
|
||||
f"fish_{db_value}",
|
||||
"Array",
|
||||
shape=data.shape,
|
||||
@@ -157,7 +168,72 @@ class Calibration(MccDaq):
|
||||
unit="s",
|
||||
)
|
||||
|
||||
self.set_analog_to_zero()
|
||||
time.time_ns()
|
||||
self.mccdaq.set_analog_to_zero()
|
||||
|
||||
def plot(self, figure, block):
|
||||
self.figure = figure
|
||||
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)
|
||||
|
||||
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 = 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 = 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 = 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(power, ref_power=1.0, min_power=1e-20):
|
||||
0
pyrelacs/repros/calibration/config.yaml
Normal file
0
pyrelacs/repros/calibration/config.yaml
Normal file
@@ -22,9 +22,7 @@ class Repro:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def run_repro(
|
||||
self, nix_file: nix.File, name: str, file: pathlib.Path, *args, **kwargs
|
||||
) -> None:
|
||||
def run_repro(self, name: str, file: pathlib.Path, *args, **kwargs) -> None:
|
||||
spec = importlib.util.spec_from_file_location("rep", file)
|
||||
if not spec:
|
||||
log.error("Could not load the file")
|
||||
@@ -40,14 +38,19 @@ class Repro:
|
||||
log.error(f"{spec.loader} is None")
|
||||
if hasattr(module, name):
|
||||
rep_class = getattr(module, name)
|
||||
rep_class.run(nix_file)
|
||||
rep_class.run(*args, **kwargs)
|
||||
else:
|
||||
raise AttributeError(f"{file.name} has no {name} class")
|
||||
|
||||
def names_of_repros(self) -> Tuple[list, list]:
|
||||
def names_of_repros(self, include_repros: list[str]) -> Tuple[list, list]:
|
||||
"""
|
||||
Searches for class names in the repro folder in all python files
|
||||
|
||||
Parameters
|
||||
----------
|
||||
include_repros : list[str]
|
||||
List of repros to include in the pyrelacs instance
|
||||
|
||||
Returns
|
||||
-------
|
||||
Tuple[list, list]
|
||||
@@ -73,4 +76,7 @@ class Repro:
|
||||
repro_names.extend(class_name)
|
||||
file_names.append(python_file)
|
||||
file.close()
|
||||
|
||||
repro_names = [r for r in repro_names if r in include_repros]
|
||||
file_names = [f for r, f in zip(repro_names, file_names) if r in include_repros]
|
||||
return repro_names, file_names
|
||||
|
||||
17
pyrelacs/repros/sinus/sinus.py
Normal file
17
pyrelacs/repros/sinus/sinus.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import nixio
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
|
||||
log = config_logging()
|
||||
|
||||
|
||||
class Sinus:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def run(config, mccdaq, nix_block: nixio.Block, figure) -> None:
|
||||
log.debug(config)
|
||||
log.debug(mccdaq)
|
||||
log.debug(nix_block)
|
||||
log.debug(figure)
|
||||
@@ -1,10 +1,14 @@
|
||||
import time
|
||||
from pathlib import Path as path
|
||||
from datetime import datetime
|
||||
from dataclasses import asdict
|
||||
|
||||
from PyQt6.QtGui import QAction, QIcon, QKeySequence
|
||||
from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex, QTimer
|
||||
from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex
|
||||
from PyQt6.QtWidgets import (
|
||||
QGridLayout,
|
||||
QPushButton,
|
||||
QTabWidget,
|
||||
QToolBar,
|
||||
QWidget,
|
||||
QMainWindow,
|
||||
@@ -13,18 +17,20 @@ from PyQt6.QtWidgets import (
|
||||
QStatusBar,
|
||||
)
|
||||
|
||||
import uldaq
|
||||
import nixio as nix
|
||||
|
||||
import nixio
|
||||
import pyqtgraph as pg
|
||||
import numpy as np
|
||||
import quantities as pq
|
||||
|
||||
from pyrelacs.devices.mccdaq import MccDaq
|
||||
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
from pyrelacs.dataio.daq_producer import DaqProducer
|
||||
from pyrelacs.dataio.nix_writer import NixWriter
|
||||
from pyrelacs.dataio.sin_producer import SinProducer
|
||||
|
||||
from pyrelacs.worker import Worker
|
||||
from pyrelacs.repros.repros import Repro
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
|
||||
from pyrelacs.ui.about import AboutDialog
|
||||
from pyrelacs.ui.plots.calibration import CalibrationPlot
|
||||
@@ -39,71 +45,81 @@ from IPython import embed
|
||||
|
||||
|
||||
class PyRelacs(QMainWindow):
|
||||
def __init__(self):
|
||||
def __init__(self, config):
|
||||
super().__init__()
|
||||
# loaded config
|
||||
self.config = config
|
||||
|
||||
# check if daq is connencted else None
|
||||
if self.config.settings.daq:
|
||||
start = time.time()
|
||||
self.mccdaq = MccDaq()
|
||||
end = time.time()
|
||||
log.debug(f"Connection to DAQ took {end - start}")
|
||||
else:
|
||||
self.mccdaq = None
|
||||
|
||||
self.repros = Repro()
|
||||
|
||||
self.setToolButtonStyle(
|
||||
Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
||||
) # Ensure icons are displayed with text
|
||||
self.setWindowTitle("PyRelacs")
|
||||
|
||||
self.mutex = QMutex()
|
||||
self.timer = QTimer(self)
|
||||
self.timer.setInterval(200)
|
||||
|
||||
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)
|
||||
# filename = path.joinpath(path.cwd(), "calibration.nix")
|
||||
# self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||
#
|
||||
# self.calibration_plot = CalibrationPlot(self.figure, self.nix_file)
|
||||
# self.nix_file.close()
|
||||
|
||||
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_toolbars()
|
||||
SAMPLERATE = pq.Quantity(
|
||||
self.config.pyrelacs.data.input.inputsamplerate,
|
||||
self.config.pyrelacs.data.input.inputsamplerateunit,
|
||||
).rescale("Hz")
|
||||
|
||||
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)
|
||||
|
||||
SAMPLERATE = 40_000
|
||||
INPUTTRACECAPACITY = pq.Quantity(
|
||||
self.config.pyrelacs.data.input.inputtracecapacity,
|
||||
self.config.pyrelacs.data.input.inputtracecapacityunit,
|
||||
).rescale("s")
|
||||
start = time.time()
|
||||
BUFFERSIZE = SAMPLERATE * 10 * 60
|
||||
BUFFERSIZE = (SAMPLERATE * INPUTTRACECAPACITY).simplified
|
||||
end = time.time()
|
||||
log.debug(f"Buffer allocation took {end - start}")
|
||||
|
||||
self.buffer = CircBuffer(
|
||||
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
||||
size=int(BUFFERSIZE.base),
|
||||
samplerate=float(SAMPLERATE.base),
|
||||
channels=2,
|
||||
mutex=self.mutex,
|
||||
)
|
||||
self.continously_plot = Continously(self.figure, self.buffer)
|
||||
self.continously_plot.plot()
|
||||
# self.continously_plot.plot()
|
||||
|
||||
start = time.time()
|
||||
self.connect_dac()
|
||||
end = time.time()
|
||||
log.debug(f"Connection to DAQ took {end - start}")
|
||||
|
||||
if hasattr(PyRelacs, "daq_device"):
|
||||
if self.mccdaq:
|
||||
log.debug("Creating Daq Generator")
|
||||
self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
else:
|
||||
log.debug("Creating Sinus Generator")
|
||||
self.sinus_producer = SinProducer(self.buffer)
|
||||
self.daq_producer = DaqProducer(self.buffer, self.mccdaq.daq_device, [4, 5])
|
||||
log.debug("Creating Sinus Generator")
|
||||
self.sinus_producer = SinProducer(self.buffer)
|
||||
|
||||
self.nix_writer = NixWriter(self.buffer)
|
||||
self.nix_writer = NixWriter(self.buffer, self.config)
|
||||
self.setMenuBar(QMenuBar(self))
|
||||
self.setStatusBar(QStatusBar(self))
|
||||
self.create_actions()
|
||||
self.create_toolbars()
|
||||
self.repro_tabs = QTabWidget()
|
||||
self.create_repros_tabs()
|
||||
|
||||
layout = QGridLayout()
|
||||
layout.addWidget(self.figure, 0, 0, 2, 2)
|
||||
layout.addWidget(self.repro_tabs, 2, 0, 2, 2)
|
||||
layout.addWidget(self.text, 4, 0, 1, 1)
|
||||
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def create_actions(self):
|
||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||
@@ -119,16 +135,17 @@ class PyRelacs(QMainWindow):
|
||||
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)
|
||||
if self.mccdaq:
|
||||
self._daq_connectaction.setStatusTip("Connect to daq device")
|
||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||
self._daq_connectaction.triggered.connect(self.mccdaq.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_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.mccdaq.disconnect_daq)
|
||||
|
||||
# self._daq_calibaction = QAction(
|
||||
# QIcon(":/icons/calibration.png"), "Plot calibration", self
|
||||
@@ -137,7 +154,7 @@ class PyRelacs(QMainWindow):
|
||||
# # self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
||||
# self._daq_calibaction.triggered.connect(self.calibration_plot.plot)
|
||||
|
||||
self._run_action = QAction(QIcon(":/icons/record.png"), "Run", self)
|
||||
self._run_action = QAction(QIcon(":/icons/record.png"), "RunDAQ", self)
|
||||
self._run_action.triggered.connect(self.run_daq)
|
||||
|
||||
self._run_sinus_action = QAction(QIcon(":/icons/record.png"), "Sinus", self)
|
||||
@@ -167,8 +184,9 @@ class PyRelacs(QMainWindow):
|
||||
file_menu.addAction(self._rlx_aboutaction)
|
||||
|
||||
if device_menu is not None:
|
||||
device_menu.addAction(self._daq_connectaction)
|
||||
device_menu.addAction(self._daq_disconnectaction)
|
||||
if self.config.settings.daq:
|
||||
device_menu.addAction(self._daq_connectaction)
|
||||
device_menu.addAction(self._daq_disconnectaction)
|
||||
device_menu.addSeparator()
|
||||
# device_menu.addAction(self._daq_calibaction)
|
||||
device_menu.addAction(self._run_action)
|
||||
@@ -189,8 +207,9 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, rlx_toolbar)
|
||||
daq_toolbar = QToolBar("DAQ")
|
||||
daq_toolbar.addAction(self._daq_connectaction)
|
||||
daq_toolbar.addAction(self._daq_disconnectaction)
|
||||
if self.config.settings.daq:
|
||||
daq_toolbar.addAction(self._daq_connectaction)
|
||||
daq_toolbar.addAction(self._daq_disconnectaction)
|
||||
# daq_toolbar.addAction(self._daq_calibaction)
|
||||
daq_toolbar.addAction(self._run_action)
|
||||
daq_toolbar.addAction(self._run_sinus_action)
|
||||
@@ -200,16 +219,53 @@ class PyRelacs(QMainWindow):
|
||||
daq_toolbar.addAction(self._record)
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||
|
||||
repro_toolbar = QToolBar("Repros")
|
||||
repro_names, file_names = self.repros.names_of_repros()
|
||||
def create_repros_tabs(self):
|
||||
repro_names, file_names = self.repros.names_of_repros(
|
||||
include_repros=self.config.settings.repros
|
||||
)
|
||||
figures_repros = {rep: pg.GraphicsLayoutWidget() for rep in repro_names}
|
||||
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)
|
||||
tab = QWidget()
|
||||
tab_layout = QGridLayout()
|
||||
|
||||
run_repro_button = QPushButton(f"Run {rep}")
|
||||
run_repro_button.setCheckable(True)
|
||||
run_repro_button.clicked.connect(
|
||||
lambda checked, n=rep, f=fn: self.run_repro(
|
||||
n,
|
||||
f,
|
||||
figures_repros,
|
||||
self.mccdaq,
|
||||
self.config,
|
||||
)
|
||||
)
|
||||
repro_toolbar.addAction(repro_action)
|
||||
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
|
||||
tab_layout.addWidget(run_repro_button, 0, 0, 1, 0)
|
||||
tab_layout.addWidget(figures_repros[rep], 1, 0, 1, 1)
|
||||
tab.setLayout(tab_layout)
|
||||
self.repro_tabs.addTab(tab, f"{rep}")
|
||||
|
||||
def run_repro(
|
||||
self,
|
||||
name_of_repro: str,
|
||||
file_of_repro: str,
|
||||
figures,
|
||||
*args,
|
||||
):
|
||||
self.text.appendPlainText(f"started Repro {name_of_repro}, {file_of_repro}")
|
||||
|
||||
figure_repro = figures[name_of_repro]
|
||||
worker = Worker(
|
||||
self.repros.run_repro,
|
||||
name_of_repro,
|
||||
file_of_repro,
|
||||
figure_repro,
|
||||
*args[-1:],
|
||||
)
|
||||
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 recenter_continously_plot(self):
|
||||
self.continously_plot.refresh()
|
||||
@@ -240,12 +296,35 @@ class PyRelacs(QMainWindow):
|
||||
self.continously_plot.plot()
|
||||
|
||||
def record(self):
|
||||
nix_writer = Worker(self.nix_writer.write_nix)
|
||||
self.data_array_analog1, self.data_array_analog2 = (
|
||||
self.nix_writer.create_nix_file(f"{_root}/test/", self.config.metadata)
|
||||
)
|
||||
log.debug("Created nix file")
|
||||
|
||||
nix_writer = Worker(
|
||||
self.nix_writer.write_nix,
|
||||
data_array=self.data_array_analog1,
|
||||
mutex=self.mutex,
|
||||
channel=0,
|
||||
chunk_size=1000,
|
||||
)
|
||||
nix_writer.signals.result.connect(self.print_output)
|
||||
nix_writer.signals.finished.connect(self.thread_complete)
|
||||
nix_writer.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(nix_writer)
|
||||
|
||||
nix_writer2 = Worker(
|
||||
self.nix_writer.write_nix,
|
||||
data_array=self.data_array_analog2,
|
||||
mutex=self.mutex,
|
||||
channel=0,
|
||||
chunk_size=1000,
|
||||
)
|
||||
nix_writer2.signals.result.connect(self.print_output)
|
||||
nix_writer2.signals.finished.connect(self.thread_complete)
|
||||
nix_writer2.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(nix_writer2)
|
||||
|
||||
def stop_recording(self):
|
||||
self.add_to_textfield("Stopping the recording")
|
||||
self.continously_plot.stop_plotting()
|
||||
@@ -258,37 +337,10 @@ class PyRelacs(QMainWindow):
|
||||
except AttributeError:
|
||||
log.debug("Did not generate Sinus")
|
||||
|
||||
if hasattr(PyRelacs, "daq_device"):
|
||||
if self.config.settings.daq:
|
||||
log.debug("Stopping DAQ")
|
||||
self.daq_producer.stop_aquisition()
|
||||
|
||||
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.info("DAQ is not connected")
|
||||
log.info("Please connect a DAQ device to the system")
|
||||
|
||||
def disconnect_dac(self):
|
||||
try:
|
||||
self.daq_device.disconnect()
|
||||
self.daq_device.release()
|
||||
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_calibration, 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)
|
||||
|
||||
@@ -296,7 +348,8 @@ class PyRelacs(QMainWindow):
|
||||
log.info("exit button!")
|
||||
self.stop_recording()
|
||||
self.add_to_textfield("exiting")
|
||||
self.disconnect_dac()
|
||||
if self.mccdaq:
|
||||
self.mccdaq.disconnect_daq()
|
||||
log.info("closing GUI")
|
||||
self.close()
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import time
|
||||
|
||||
import pyqtgraph as pg
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
@@ -13,6 +15,9 @@ class Continously:
|
||||
def __init__(self, figure: pg.GraphicsLayoutWidget, buffer: CircBuffer):
|
||||
self.figure = figure
|
||||
self.buffer = buffer
|
||||
self.last_plotted_index_analog_in_0 = 0
|
||||
self.last_plotted_index_analog_in_1 = 0
|
||||
self.timer = QTimer()
|
||||
|
||||
def plot(self, *args, **kwargs):
|
||||
self.figure.setBackground("w")
|
||||
@@ -20,56 +25,118 @@ class Continously:
|
||||
prev_plot = self.figure.getItem(row=0, col=0)
|
||||
if prev_plot:
|
||||
self.figure.removeItem(prev_plot)
|
||||
self.continous_ax = self.figure.addPlot(row=0, col=0)
|
||||
self.analog_in_0 = self.figure.addPlot(row=0, col=0)
|
||||
self.analog_in_1 = self.figure.addPlot(row=1, col=0)
|
||||
|
||||
pen = pg.mkPen("red")
|
||||
self.time = np.zeros(self.buffer.size)
|
||||
self.data = np.zeros(self.buffer.size)
|
||||
self.line = self.continous_ax.plot(
|
||||
self.time,
|
||||
self.data,
|
||||
self.time_analog_in_0 = np.zeros(self.buffer.size)
|
||||
self.data_analog_in_0 = np.empty(self.buffer.size)
|
||||
self.line_analog_in_0 = self.analog_in_0.plot(
|
||||
self.time_analog_in_0,
|
||||
self.data_analog_in_0,
|
||||
pen=pen,
|
||||
# symbol="o",
|
||||
)
|
||||
|
||||
pen = pg.mkPen("red")
|
||||
self.time_analog_in_1 = np.zeros(self.buffer.size)
|
||||
self.data_analog_in_1 = np.empty(self.buffer.size)
|
||||
self.line_analog_in_1 = self.analog_in_1.plot(
|
||||
self.time_analog_in_1,
|
||||
self.data_analog_in_1,
|
||||
pen=pen,
|
||||
# symbol="o",
|
||||
)
|
||||
|
||||
# self.plot_index = 0
|
||||
self.timer = QTimer()
|
||||
self.CHUNK_PLOT = 10_000
|
||||
self.timer.setInterval(200)
|
||||
self.CHUNK_PLOT = int(self.buffer.samplerate / 6)
|
||||
self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen
|
||||
self.timer.setInterval(150)
|
||||
self.timer.timeout.connect(self.update_plot)
|
||||
self.timer.timeout.connect(self.update_plot_1)
|
||||
self.timer.start()
|
||||
|
||||
def update_plot(self):
|
||||
# log.debug(self.buffer.totalcount())
|
||||
if self.buffer.totalcount() > self.CHUNK_PLOT:
|
||||
log.debug(self.buffer.totalcount())
|
||||
current_index = self.buffer.write_index()
|
||||
total_count = self.buffer.totalcount(channel=0)
|
||||
|
||||
start_time = time.time()
|
||||
if total_count - self.last_plotted_index_analog_in_0 >= self.CHUNK_PLOT:
|
||||
try:
|
||||
times, items = self.buffer.read(
|
||||
self.buffer.write_index() - self.CHUNK_PLOT - 1_000,
|
||||
self.last_plotted_index_analog_in_0,
|
||||
extend=self.CHUNK_PLOT,
|
||||
channel=0,
|
||||
)
|
||||
except IndexError as e:
|
||||
items = np.zeros(self.CHUNK_PLOT)
|
||||
times = np.zeros(self.CHUNK_PLOT)
|
||||
log.debug("No Data Available")
|
||||
log.debug(f"Index Error {e}")
|
||||
self.time_analog_in_0 = np.concatenate((self.time_analog_in_0, times))[
|
||||
-self.PLOT_HISTORY :
|
||||
]
|
||||
self.data_analog_in_0 = np.concatenate((self.data_analog_in_0, items))[
|
||||
-self.PLOT_HISTORY :
|
||||
]
|
||||
self.line_analog_in_0.setData(
|
||||
self.time_analog_in_0,
|
||||
self.data_analog_in_0,
|
||||
)
|
||||
self.last_plotted_index_analog_in_0 += self.CHUNK_PLOT
|
||||
except IndexError:
|
||||
log.error("Could not acces the data from the buffer for plotting")
|
||||
end_time = time.time()
|
||||
log.debug(f"total time for plotting {end_time - start_time}")
|
||||
else:
|
||||
pass
|
||||
|
||||
# self.time = np.roll(self.time, -len(items))
|
||||
# self.data = np.roll(self.data, -len(items))
|
||||
#
|
||||
# self.time[-len(times) :] = times
|
||||
# self.data[-len(items) :] = items
|
||||
def update_plot_1(self):
|
||||
total_count = self.buffer.totalcount(channel=1)
|
||||
|
||||
self.line.setData(
|
||||
times,
|
||||
items,
|
||||
)
|
||||
# self.plot_index += len(items)
|
||||
start_time = time.time()
|
||||
if total_count - self.last_plotted_index_analog_in_1 >= self.CHUNK_PLOT:
|
||||
try:
|
||||
times, items = self.buffer.read(
|
||||
self.last_plotted_index_analog_in_1,
|
||||
extend=self.CHUNK_PLOT,
|
||||
channel=1,
|
||||
)
|
||||
self.time_analog_in_1 = np.concatenate((self.time_analog_in_0, times))[
|
||||
-self.PLOT_HISTORY :
|
||||
]
|
||||
self.data_analog_in_1 = np.concatenate((self.data_analog_in_0, items))[
|
||||
-self.PLOT_HISTORY :
|
||||
]
|
||||
self.line_analog_in_1.setData(
|
||||
self.time_analog_in_1,
|
||||
self.data_analog_in_1,
|
||||
)
|
||||
self.last_plotted_index_analog_in_1 += self.CHUNK_PLOT
|
||||
except IndexError:
|
||||
log.error("Could not acces the data from the buffer for plotting")
|
||||
end_time = time.time()
|
||||
log.debug(f"total time for plotting {end_time - start_time}")
|
||||
else:
|
||||
pass
|
||||
|
||||
def stop_plotting(self):
|
||||
self.timer.stop()
|
||||
if self.last_plotted_index_analog_in_0 > 0:
|
||||
total_count = self.buffer.totalcount()
|
||||
times, items = self.buffer.read(
|
||||
self.last_plotted_index_analog_in_0,
|
||||
extend=total_count - self.last_plotted_index_analog_in_0,
|
||||
)
|
||||
self.time_analog_in_0 = np.concatenate((self.time_analog_in_0, times))[
|
||||
-self.PLOT_HISTORY :
|
||||
]
|
||||
self.data_analog_in_0 = np.concatenate((self.data_analog_in_0, items))[
|
||||
-self.PLOT_HISTORY :
|
||||
]
|
||||
self.line_analog_in_0.setData(
|
||||
self.time_analog_in_0,
|
||||
self.data_analog_in_0,
|
||||
)
|
||||
self.last_plotted_index_analog_in_0 += (
|
||||
total_count - self.last_plotted_index_analog_in_0
|
||||
)
|
||||
|
||||
def refresh(self):
|
||||
self.continous_ax.enableAutoRange()
|
||||
self.analog_in_0.enableAutoRange()
|
||||
self.analog_in_1.enableAutoRange()
|
||||
|
||||
Reference in New Issue
Block a user