Spaces:
Sleeping
Sleeping
Milo Sobral
commited on
Commit
·
fcba0a9
1
Parent(s):
a64c5cc
Working on making things work outside of the hardware of the Portiloop
Browse files- portiloop/notebooks/tests.ipynb +16 -26
- portiloop/src/__init__.py +1 -0
- portiloop/src/capture.py +25 -17
- portiloop/src/detection.py +3 -1
- portiloop/src/stimulation.py +6 -1
- setup.py +3 -2
portiloop/notebooks/tests.ipynb
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
{
|
12 |
"data": {
|
13 |
"application/vnd.jupyter.widget-view+json": {
|
14 |
-
"model_id": "
|
15 |
"version_major": 2,
|
16 |
"version_minor": 0
|
17 |
},
|
@@ -22,28 +22,21 @@
|
|
22 |
"metadata": {},
|
23 |
"output_type": "display_data"
|
24 |
},
|
25 |
-
{
|
26 |
-
"name": "stdout",
|
27 |
-
"output_type": "stream",
|
28 |
-
"text": [
|
29 |
-
"DEBUG:/home/mendel/portiloop-software/portiloop/sounds/stimulus.wav\n"
|
30 |
-
]
|
31 |
-
},
|
32 |
{
|
33 |
"name": "stderr",
|
34 |
"output_type": "stream",
|
35 |
"text": [
|
36 |
-
"Exception in thread Thread-
|
37 |
"Traceback (most recent call last):\n",
|
38 |
-
" File \"
|
39 |
" self.run()\n",
|
40 |
-
" File \"
|
41 |
" self._target(*self._args, **self._kwargs)\n",
|
42 |
-
" File \"
|
43 |
-
"
|
44 |
-
" File \"
|
45 |
-
" self.
|
46 |
-
"
|
47 |
"\n"
|
48 |
]
|
49 |
}
|
@@ -58,19 +51,11 @@
|
|
58 |
"\n",
|
59 |
"cap = Capture(detector_cls=my_detector_class, stimulator_cls=my_stimulator_class)"
|
60 |
]
|
61 |
-
},
|
62 |
-
{
|
63 |
-
"cell_type": "code",
|
64 |
-
"execution_count": null,
|
65 |
-
"id": "cded6bbc",
|
66 |
-
"metadata": {},
|
67 |
-
"outputs": [],
|
68 |
-
"source": []
|
69 |
}
|
70 |
],
|
71 |
"metadata": {
|
72 |
"kernelspec": {
|
73 |
-
"display_name": "Python 3",
|
74 |
"language": "python",
|
75 |
"name": "python3"
|
76 |
},
|
@@ -84,7 +69,12 @@
|
|
84 |
"name": "python",
|
85 |
"nbconvert_exporter": "python",
|
86 |
"pygments_lexer": "ipython3",
|
87 |
-
"version": "3.7.
|
|
|
|
|
|
|
|
|
|
|
88 |
}
|
89 |
},
|
90 |
"nbformat": 4,
|
|
|
11 |
{
|
12 |
"data": {
|
13 |
"application/vnd.jupyter.widget-view+json": {
|
14 |
+
"model_id": "f46843d136af4c79a73841b997fa3284",
|
15 |
"version_major": 2,
|
16 |
"version_minor": 0
|
17 |
},
|
|
|
22 |
"metadata": {},
|
23 |
"output_type": "display_data"
|
24 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
{
|
26 |
"name": "stderr",
|
27 |
"output_type": "stream",
|
28 |
"text": [
|
29 |
+
"Exception in thread Thread-3:\n",
|
30 |
"Traceback (most recent call last):\n",
|
31 |
+
" File \"C:\\Users\\milos\\AppData\\Local\\Programs\\Python\\Python37\\lib\\threading.py\", line 917, in _bootstrap_inner\n",
|
32 |
" self.run()\n",
|
33 |
+
" File \"C:\\Users\\milos\\AppData\\Local\\Programs\\Python\\Python37\\lib\\threading.py\", line 865, in run\n",
|
34 |
" self._target(*self._args, **self._kwargs)\n",
|
35 |
+
" File \"c:\\users\\milos\\documents\\github\\portiloop-software\\portiloop\\src\\capture.py\", line 927, in start_capture\n",
|
36 |
+
" detector = detector_cls(threshold, channel=channel) if detector_cls is not None else None\n",
|
37 |
+
" File \"c:\\users\\milos\\documents\\github\\portiloop-software\\portiloop\\src\\detection.py\", line 56, in __init__\n",
|
38 |
+
" self.interpreters.append(edgetpu.make_interpreter(model_path))\n",
|
39 |
+
"NameError: name 'edgetpu' is not defined\n",
|
40 |
"\n"
|
41 |
]
|
42 |
}
|
|
|
51 |
"\n",
|
52 |
"cap = Capture(detector_cls=my_detector_class, stimulator_cls=my_stimulator_class)"
|
53 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
],
|
56 |
"metadata": {
|
57 |
"kernelspec": {
|
58 |
+
"display_name": "Python 3.7.0b2 ('venv': venv)",
|
59 |
"language": "python",
|
60 |
"name": "python3"
|
61 |
},
|
|
|
69 |
"name": "python",
|
70 |
"nbconvert_exporter": "python",
|
71 |
"pygments_lexer": "ipython3",
|
72 |
+
"version": "3.7.0b2"
|
73 |
+
},
|
74 |
+
"vscode": {
|
75 |
+
"interpreter": {
|
76 |
+
"hash": "770b75f59a9c369b74cb4cefed633f309c892e213e0ed32eed0937c0a5627480"
|
77 |
+
}
|
78 |
}
|
79 |
},
|
80 |
"nbformat": 4,
|
portiloop/src/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ADS = False
|
portiloop/src/capture.py
CHANGED
@@ -8,12 +8,16 @@ from datetime import datetime
|
|
8 |
import multiprocessing as mp
|
9 |
import warnings
|
10 |
from threading import Thread, Lock
|
11 |
-
import
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
from portiloop.src.stimulation import UpStateDelayer
|
14 |
|
15 |
-
|
16 |
-
from portiloop.src.hardware.leds import LEDs, Color
|
17 |
from portiloop.src.processing import FilterPipeline, int_to_float
|
18 |
from portiloop.src.config import mod_config, LEADOFF_CONFIG, FRONTEND_CONFIG, to_ads_frequency
|
19 |
from portiloop.src.utils import FileReader, LiveDisplay, DummyAlsaMixer, EDFRecorder, EDF_PATH
|
@@ -164,22 +168,25 @@ class Capture:
|
|
164 |
self._pause_detect_lock = Lock()
|
165 |
self._pause_detect = True
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
warnings.warn(f"No ALSA mixer found.")
|
171 |
self.mixer = DummyAlsaMixer()
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
warnings.warn(f"Could not find mixer PCM, using {mixers[0]} instead.")
|
176 |
-
self.mixer = alsaaudio.Mixer(control=mixers[0])
|
177 |
-
except ALSAAudioError as e:
|
178 |
-
warnings.warn(f"No ALSA mixer found.")
|
179 |
self.mixer = DummyAlsaMixer()
|
180 |
-
|
181 |
-
self.volume = self.mixer.getvolume()[0] # we will set the same volume on all channels
|
182 |
-
|
183 |
|
184 |
# widgets ===============================
|
185 |
|
@@ -528,9 +535,10 @@ class Capture:
|
|
528 |
self.b_test_stimulus.on_click(self.on_b_test_stimulus)
|
529 |
self.b_test_impedance.on_click(self.on_b_test_impedance)
|
530 |
self.b_pause.observe(self.on_b_pause, 'value')
|
531 |
-
|
532 |
self.display_buttons()
|
533 |
|
|
|
534 |
def __del__(self):
|
535 |
self.b_capture.close()
|
536 |
|
|
|
8 |
import multiprocessing as mp
|
9 |
import warnings
|
10 |
from threading import Thread, Lock
|
11 |
+
from portiloop.src import ADS
|
12 |
+
|
13 |
+
if ADS:
|
14 |
+
import alsaaudio
|
15 |
+
from portiloop.src.hardware.frontend import Frontend
|
16 |
+
from portiloop.src.hardware.leds import LEDs, Color
|
17 |
|
18 |
from portiloop.src.stimulation import UpStateDelayer
|
19 |
|
20 |
+
|
|
|
21 |
from portiloop.src.processing import FilterPipeline, int_to_float
|
22 |
from portiloop.src.config import mod_config, LEADOFF_CONFIG, FRONTEND_CONFIG, to_ads_frequency
|
23 |
from portiloop.src.utils import FileReader, LiveDisplay, DummyAlsaMixer, EDFRecorder, EDF_PATH
|
|
|
168 |
self._pause_detect_lock = Lock()
|
169 |
self._pause_detect = True
|
170 |
|
171 |
+
if ADS:
|
172 |
+
try:
|
173 |
+
mixers = alsaaudio.mixers()
|
174 |
+
if len(mixers) <= 0:
|
175 |
+
warnings.warn(f"No ALSA mixer found.")
|
176 |
+
self.mixer = DummyAlsaMixer()
|
177 |
+
elif 'PCM' in mixers:
|
178 |
+
self.mixer = alsaaudio.Mixer(control='PCM')
|
179 |
+
else:
|
180 |
+
warnings.warn(f"Could not find mixer PCM, using {mixers[0]} instead.")
|
181 |
+
self.mixer = alsaaudio.Mixer(control=mixers[0])
|
182 |
+
except ALSAAudioError as e:
|
183 |
warnings.warn(f"No ALSA mixer found.")
|
184 |
self.mixer = DummyAlsaMixer()
|
185 |
+
|
186 |
+
self.volume = self.mixer.getvolume()[0] # we will set the same volume on all channels
|
187 |
+
else:
|
|
|
|
|
|
|
|
|
188 |
self.mixer = DummyAlsaMixer()
|
189 |
+
self.volume = self.mixer.getvolume()[0]
|
|
|
|
|
190 |
|
191 |
# widgets ===============================
|
192 |
|
|
|
535 |
self.b_test_stimulus.on_click(self.on_b_test_stimulus)
|
536 |
self.b_test_impedance.on_click(self.on_b_test_impedance)
|
537 |
self.b_pause.observe(self.on_b_pause, 'value')
|
538 |
+
|
539 |
self.display_buttons()
|
540 |
|
541 |
+
|
542 |
def __del__(self):
|
543 |
self.b_capture.close()
|
544 |
|
portiloop/src/detection.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from abc import ABC, abstractmethod
|
2 |
import time
|
3 |
from pathlib import Path
|
|
|
4 |
|
5 |
-
|
|
|
6 |
import numpy as np
|
7 |
|
8 |
|
|
|
1 |
from abc import ABC, abstractmethod
|
2 |
import time
|
3 |
from pathlib import Path
|
4 |
+
from portiloop.src import ADS
|
5 |
|
6 |
+
if ADS:
|
7 |
+
from pycoral.utils import edgetpu
|
8 |
import numpy as np
|
9 |
|
10 |
|
portiloop/src/stimulation.py
CHANGED
@@ -3,7 +3,12 @@ from enum import Enum
|
|
3 |
import time
|
4 |
from threading import Thread, Lock
|
5 |
from pathlib import Path
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
import wave
|
8 |
import pylsl
|
9 |
from scipy.signal import find_peaks
|
|
|
3 |
import time
|
4 |
from threading import Thread, Lock
|
5 |
from pathlib import Path
|
6 |
+
|
7 |
+
from portiloop.src import ADS
|
8 |
+
|
9 |
+
if ADS:
|
10 |
+
import alsaaudio
|
11 |
+
|
12 |
import wave
|
13 |
import pylsl
|
14 |
from scipy.signal import find_peaks
|
setup.py
CHANGED
@@ -11,10 +11,11 @@ setup(
|
|
11 |
'portilooplot',
|
12 |
'ipywidgets',
|
13 |
'python-periphery',
|
14 |
-
|
15 |
'pylsl-coral',
|
16 |
'scipy',
|
17 |
'pycoral',
|
18 |
-
'
|
|
|
19 |
]
|
20 |
)
|
|
|
11 |
'portilooplot',
|
12 |
'ipywidgets',
|
13 |
'python-periphery',
|
14 |
+
# 'spidev',
|
15 |
'pylsl-coral',
|
16 |
'scipy',
|
17 |
'pycoral',
|
18 |
+
'matplotlib',
|
19 |
+
# 'pyalsaaudio'
|
20 |
]
|
21 |
)
|