1
+ import os
1
2
import threading
2
3
import time
3
4
from typing import Any , Dict , Tuple
4
5
5
6
import mne
7
+ import pandas as pd
6
8
from mne .datasets import eegbci
7
9
from mne_realtime import MockLSLStream
8
10
@@ -19,6 +21,10 @@ def config_params():
19
21
20
22
def stream_thread (self ):
21
23
"""Load the appropriate data and start the stream. Then wait until running is set to False."""
24
+ while not self .params .recording .use_example_data .value and not os .path .exists (self .params .recording .file_path .value ):
25
+ print ("File path cannot be empty if 'Use Example Data' is False." )
26
+ time .sleep (1 )
27
+
22
28
if self .params .recording .use_example_data .value :
23
29
raw = mne .concatenate_raws (
24
30
[mne .io .read_raw (p , preload = True , verbose = False ) for p in eegbci .load_data (1 , [1 , 2 ])],
@@ -27,6 +33,15 @@ def stream_thread(self):
27
33
eegbci .standardize (raw )
28
34
# scale the data for better default behavior
29
35
raw .apply_function (lambda x : x * 1e4 )
36
+ elif self .params .recording .file_path .value .endswith (".csv" ):
37
+ # load data from csv file
38
+ df = pd .read_csv (self .params .recording .file_path .value , index_col = 0 )
39
+ df = df .select_dtypes (include = ["float" ])
40
+ data = df .transpose ().to_numpy ()
41
+
42
+ # TODO: make sfreq a parameter
43
+ info = mne .create_info (ch_names = df .columns .tolist (), ch_types = ["eeg" ] * data .shape [0 ], sfreq = 256 )
44
+ raw = mne .io .RawArray (data , info )
30
45
else :
31
46
# load data from file
32
47
raw = mne .io .read_raw (self .params .recording .file_path .value , preload = True )
@@ -60,9 +75,7 @@ def setup(self, init: bool = True):
60
75
# both use_example_data and file_path are set
61
76
# TODO: add proper logging
62
77
print ("Both 'use_example_data' and 'file_path' are set. Using example data." )
63
- elif self .params .recording .file_path .value == "" :
64
- # either use example data or a file path must be set
65
- raise ValueError ("File path cannot be empty if 'Use Example Data' is False." )
78
+
66
79
assert self .params .recording .stream_name .value != "" , "Stream name cannot be empty."
67
80
68
81
# start the stream
0 commit comments