Using Muse with MNE realtime

Hi,

I am following this tutorial:
https://mne.tools/mne-realtime/auto_examples/lslclient_rt_.html#sphx-glr-auto-examples-lslclient-rt-py

I have Muse S and I am using BlueMuse.
I removed from the code the 2 parts “Load a file to stream raw data” and “For this example, let’s use the mock LSL stream.”

I also had to remove info=raw.info from the arguments of LSLClient since I don’t have the variable raw.

Now my code looks like this:

# this is the host id that identifies your stream on LSL
host = 'F009-34BL-2521'
# this is the max wait time in seconds until client connection
wait_max = 5


_, ax = plt.subplots(1)
n_epochs = 5

with LSLClient(host=host, wait_max=wait_max) as client:
    client_info = client.get_measurement_info()
    sfreq = int(client_info['sfreq'])

    # let's observe ten seconds of data
    for ii in range(n_epochs):
        print('Got epoch %d/%d' % (ii + 1, n_epochs))
        plt.cla()
        epoch = client.get_data_as_epoch(n_samples=sfreq)
        epoch.average().plot(axes=ax)
        plt.pause(1.)
    plt.draw()
print('Streams closed')

The issue is the ‘host’ variable. below is all the information from BlueMuse:

{
“hn”: “MuseS-4F46”,
“sn”: “5008-YMH9-4F46”,
“ma”: “00-55-da-b9-4f-46”,
“id”: “0039002d 47525015 20393755”,
“bp”: 20,
“ts”: 0,
“ps”: 81,
“hs”: “F009-34BL-2521”,
“rc”: 0
}

I used all of these values and none of them worked. I get this message looping:

looking for LSL stream 0039002d 47525015 20393755…
0039002d 47525015 20393755 not found in streams: [‘LSLBridge’, ‘LSLBridge’, ‘LSLBridge’, ‘LSLBridge’]

And this error:
Traceback (most recent call last):
File “D:/Program/EEG_Analysis/Test.py”, line 19, in
with LSLClient(host=host, wait_max=wait_max) as client:
File “D:\3_Tools\anaconda3\lib\site-packages\mne_realtime\base_client.py”, line 76, in enter
self._connection_error()
File “D:\3_Tools\anaconda3\lib\site-packages\mne_realtime\lsl_client.py”, line 110, in _connection_error
super()._connection_error(extra)
File “D:\3_Tools\anaconda3\lib\site-packages\mne_realtime\base_client.py”, line 85, in _connection_error
raise RuntimeError(f’Could not connect to Client.{extra}’)
RuntimeError: Could not connect to Client. Available streams on 0039002d 47525015 20393755 from resolve_streams():
[<pylsl.pylsl.StreamInfo object at 0x000001C3731A8700>, <pylsl.pylsl.StreamInfo object at 0x000001C377D4F160>, <pylsl.pylsl.StreamInfo object at 0x000001C377D4F280>, <pylsl.pylsl.StreamInfo object at 0x000001C377D4F1C0>]

I am a beginner, any help would be appreciated.

Thanks!

Hello, could you start the LSL stream from the Muse device and try:

import pylsl

streamInfos = pylsl.resolve_streams()
streams = [(si.name(), si.type(), si.source_id()) for si in streamInfos]
print (streams)

Also, you could look into BSL which focuses only on LSL communication.

For mne-realtime, the host should be the .source_id() corresponding to the stream you want to connect to.

Hi Mathieu,
Thanks for the answer. I tried it but Muse device has no source id:

[(‘MuseS (mac address) Gyroscope’, ‘Gyroscope’, ‘LSLBridge’), (‘MuseS ((mac address) Accelerometer’, ‘Accelerometer’, ‘LSLBridge’), (‘MuseS ((mac address) EEG’, ‘EEG’, ‘LSLBridge’)]
‘tuple’ object has no attribute ‘source_id’

I already use muselsl and pylsl to read and plot the data and it is working but it is not my final goal.

I am trying to use MNE Real-time because I need to clean the signal (remove EOG and other artefacts) compute the PSD, extract some signal features, classify, and finally send an output to a game engine.

I am still exploring the existing tools. Someone suggested to use Brainflow. I am not sure what is the best way to go, knowing that everything needs to be real-time so the user gets a feedback from the video game real-time too.

Arf… I never used mne-realtime, but I think it does rely on the source_id to identify the device/LSL stream… And yet some devices don’t have a source_id and will return None. If you could, creating an issue about this on the GitHub tracker would be nice for the developers: Issues · mne-tools/mne-realtime · GitHub

Meanwhile, I do recommend you give a shot to BSL. It relies on the stream .name() to identify a device. As for the .source_id(), it’s not perfect but it should work for you. You could connect with a StreamReceiver and then retrieve the window as a mne.io.Raw instance on which you can apply any MNE post-processing (I’m actually doing something similar in a current neurofeedback study feeding alpha and delta band power to a visual feedback).

Pseudo-code:

sr = StreamReceiver(bufsize=1, winsize=1, stream_name=...)

# main loop
while True:
    sr.acquire()
    raw, _ = sr.get_window(stream_name=..., return_raw=True)

    # apply post-processing
    raw.set_eeg_reference(ref_channels='average')
    raw.filter(...)
    [...]

    # compute psds
    psds, _ = mne.time_frequency.psd_multitaper(raw, ...)

    # feed to the game engine
    feed_psd2game_enngine(psds)

You have to be very careful about the latency you introduce in the system and on keeping the processing steps light-weighted. In this regard, it might be better to return the window as a numpy array and process directly with scipy. You should definitely time your processing steps with e.g. timeit.

Now that I read again your response… isn’t the source_idLSLBridge and you just got the error because you called .source_id() on the wrong object?