mne-realtime icon indicating copy to clipboard operation
mne-realtime copied to clipboard

error with LSL

Open lucasbenoit opened this issue 3 years ago • 7 comments

Hi I would like to use the mne library to read eeg signal in real time with LSL and the OpenBCI gui. When I run the script plot_lslclient_rt.py , the terminal tells me that the LSL connection works but closes directly after , the error comes from the function client.start_receive_thread(8) . Here is my error in the terminal :

"Opening raw data file C:\Users\sc01484\mne_data\MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif... Read a total of 4 projection items: PCA-v1 (1 x 102) idle PCA-v2 (1 x 102) idle PCA-v3 (1 x 102) idle Average EEG reference (1 x 60) idle Range : 6450 ... 48149 = 42.956 ... 320.665 secs Ready. Reading 0 ... 4505 = 0.000 ... 30.003 secs... Removing projector <Projection | PCA-v1, active : False, n_channels : 102> Removing projector <Projection | PCA-v2, active : False, n_channels : 102> Removing projector <Projection | PCA-v3, active : False, n_channels : 102> Client: Waiting for server to start Looking for LSL stream openbcigui... Found stream 'obci_eeg1' via openbcigui... Client: Connected Got epoch 1/100 Exception in thread Thread-9: Traceback (most recent call last): File "C:\Users\sc01484\Anaconda3\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\Users\sc01484\Anaconda3\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\Users\sc01484\Anaconda3\lib\site-packages\mne_realtime\base_client.py", line 16, in _buffer_recv_worker for raw_buffer in client.iter_raw_buffers(): File "C:\Users\sc01484\Anaconda3\lib\site-packages\mne_realtime\lsl_client.py", line 83, in iter_raw_buffers yield np.vstack(samples).T File "<array_function internals>", line 5, in vstack File "C:\Users\sc01484\Anaconda3\lib\site-packages\numpy\core\shape_base.py", line 283, in vstack return _nx.concatenate(arrs, 0) File "<array_function internals>", line 5, in concatenate ValueError: need at least one array to concatenate Streams closed"

Does anyone have a solution to this error?

lucasbenoit avatar Mar 17 '21 13:03 lucasbenoit

Hi there @lb162215. For the plt_lslclient_rt.py example, it is using the MockLSLClient for the example. I can help point out what you might need to modify it to work with your hardware. How are you currently creating the LSL stream for your openbci?

teonbrooks avatar Mar 17 '21 14:03 teonbrooks

@teonbrooks I deleted the part concerning the MockLSLclient, I changed the host variable to "openbcigui". Concerning Openbci I do it from the Gui ( v5.0.3) with the networking - LSL function , with a TimeSeries send.

lucasbenoit avatar Mar 17 '21 15:03 lucasbenoit

Hey @lb162215, the hostname would be in this case the "Stream ID" and not the Name.

I could use the command line with python openbci_lsl.py --stream to create a stream that I could then read using this code:

import mne
from mne.io import read_raw_fif
from mne_realtime import LSLClient

# this is the max wait time in seconds until client connection
wait_max = 5

info = mne.create_info(ch_names = ['Fp1', 'Fp2', 'C3', 'C4', 'T5', 'T6', 'O1', 'O2'], \
                      sfreq=250, ch_types="eeg")

with LSLClient(host="openbci_eeg_id203", info=info, wait_max=wait_max) as client:
    client_info = client.get_measurement_info()
    sfreq = int(client_info['sfreq'])
    print(client_info)
    
    epoch = client.get_data_as_epoch(n_samples=sfreq)

So here you replace the host, channel names and frequency as displayed by openbci_lsl: grafik

I am happy to help furtheron if this should not work :)

timonmerk avatar Mar 17 '21 20:03 timonmerk

@timonmerk Hello, unfortunately I can't use this technique to find out the host name. I don't have the hardware at the moment, I use the playback function of the GUI and I launch the LSL of this one.

lucasbenoit avatar Mar 22 '21 15:03 lucasbenoit

@lb162215 is there an option in the OpenBCI GUI to specify the device id for playback mode?

teonbrooks avatar Mar 22 '21 15:03 teonbrooks

Looks like the Stream ID can be changed (from https://docs.openbci.com/docs/06Software/02-CompatibleThirdPartySoftware/LSL and https://github.com/openbci-archive/OpenBCI_LSL/blob/master/lib/gui.py)

timonmerk avatar Mar 22 '21 16:03 timonmerk

@teonbrooks @timonmerk Yes there is one . I use this id since the beginning , that's called 'obci_eeg1' in my error message . I tried with others ID and it's still doesn't work .

lucasbenoit avatar Mar 24 '21 14:03 lucasbenoit