bsl.StreamReceiver#

class bsl.StreamReceiver(bufsize=1, winsize=1, stream_name=None)#

Class for data acquisition from LSL streams.

It supports the streams of:
  • EEG

  • Markers

Parameters
  • bufsize (int | float) – Buffer’s size [secs]. MAX_BUF_SIZE (def: 1-day) is the maximum size. Large buffer may lead to a delay if not pulled frequently.

  • winsize (int | float) – Window’s size [secs]. Must be smaller than the buffer’s size.

  • stream_name (list | str | None) – Servers’ name or list of servers’ name to connect to. If None, connects to all the available streams.

Attributes
bufsize

Buffer’s size [sec].

connected

Connected status.

mne_infos

Dictionary containing the Info for the compatible streams.

stream_name

Connected stream’s name.

streams

Connected streams dictionary {stream_name: _Stream}.

winsize

Window’s size [sec].

Methods

acquire()

Read data from the streams and fill their buffer using threading.

connect([stream_name, timeout, force])

Search for the available streams on the LSL network and connect to the appropriate ones.

disconnect([stream_name])

Disconnects the stream stream_name from the StreamReceiver.

get_buffer([stream_name, return_raw])

Get the entire buffer of a stream.

get_window([stream_name, return_raw])

Get the latest window from a stream's buffer.

reset_buffer([stream_name])

Clear the stream's buffer.

show_info()

Display the information about the connected streams.

acquire()#

Read data from the streams and fill their buffer using threading.

property bufsize#

Buffer’s size [sec].

Type

int | float

connect(stream_name=None, timeout=5, force=False)#

Search for the available streams on the LSL network and connect to the appropriate ones. If a LSL stream fulfills the requirements (name…), a connection is established.

This function is called while instantiated a StreamReceiver and can be recall to reconnect to the LSL streams.

Parameters
  • stream_name (list | str | None) – Servers’ name or list of servers’ name to connect to. If None, connects to all the available streams.

  • timeout (int | float) – Timeout duration in seconds after which the search is abandoned.

  • force (bool) – If True, force reconnect if the StreamReceiver was already connected.

property connected#

Connected status.

Type

bool

disconnect(stream_name=None)#

Disconnects the stream stream_name from the StreamReceiver.

If stream_name is a list, disconnects all streams in the list. If stream_name is None, disconnects all streams.

Parameters

stream_name (str | list | None) – Servers’ name or list of servers’ name to disconnect from. If None, disconnect from all streams.

get_buffer(stream_name=None, return_raw=False)#

Get the entire buffer of a stream.

If several streams are connected, specify the name.

Parameters
  • stream_name (str | None) – Name of the stream from which data is retrieved. Can be set to None (default) if the StreamReceiver is connected to a single stream.

  • return_raw (bool) – By default (False), data is returned as a array of shape (samples, channels). If set to True, the StreamReceiver will attempt to return data as a MNE Raw instances.

Returns

  • data (array) – Data (samples, channels).

  • timestamps (array) – Data’s timestamps (samples, ).

Notes

Returns a raw data array in the unit streamed by the LSL outlet. For conversion the corresponding scaling factor must be set for each stream, with e.g. for a stream in uV to convert to V:

sr.streams['stream_to_convert'].scaling_factor = 1e-6
get_window(stream_name=None, return_raw=False)#

Get the latest window from a stream’s buffer.

If several streams are connected, specify the name.

Parameters
  • stream_name (str | None) – Name of the stream from which data is retrieved. Can be set to None (default) if the StreamReceiver is connected to a single stream.

  • return_raw (bool) – By default (False), data is returned as a array of shape (samples, channels). If set to True, the StreamReceiver will attempt to return data as a MNE Raw instances.

Returns

  • data (array) – Data (samples, channels).

  • timestamps (array) – Data’s timestamps (samples, ).

Notes

Returns a raw data array in the unit streamed by the LSL outlet. For conversion the corresponding scaling factor must be set for each stream, with e.g. for a stream in uV to convert to V:

sr.streams['stream_to_convert'].scaling_factor = 1e-6
property mne_infos#

Dictionary containing the Info for the compatible streams.

Type

dict

reset_buffer(stream_name=None)#

Clear the stream’s buffer.

Parameters

stream_name (str | list | None) – Name of the stream(s) to reset its buffer. If None, reset all stream’s buffer.

show_info()#

Display the information about the connected streams.

property stream_name#

Connected stream’s name.

Type

None | list

property streams#

Connected streams dictionary {stream_name: _Stream}.

Type

dict

property winsize#

Window’s size [sec].

Type

int | float