bsl.StreamReceiver

class bsl.StreamReceiver(bufsize=1, winsize=1, stream_name=None)[source]

Class for data acquisition from LSL streams.

It supports the streams of:
  • EEG

  • Markers

Parameters:
bufsizeint | 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.

winsizeint | float

Window’s size [secs]. Must be smaller than the buffer’s size.

stream_namelist | 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])

Connect to the LSL streams.

disconnect([stream_name])

Disconnect 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()[source]

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

connect(stream_name=None, timeout=5, force=False)[source]

Connect to the LSL streams.

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_namelist | str | None

Servers’ name or list of servers’ name to connect to. If None, connects to all the available streams.

timeoutint | float

Timeout duration in seconds after which the search is abandoned.

forcebool

If True, force reconnect if the StreamReceiver was already connected.

Returns:
successbool

True if the connection was successful.

disconnect(stream_name=None)[source]

Disconnect 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_namestr | 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)[source]

Get the entire buffer of a stream.

If several streams are connected, specify the name.

Parameters:
stream_namestr | 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_rawbool

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:
dataarray

Data (samples, channels).

timestampsarray

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)[source]

Get the latest window from a stream’s buffer.

If several streams are connected, specify the name.

Parameters:
stream_namestr | 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_rawbool

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:
dataarray

Data (samples, channels).

timestampsarray

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
reset_buffer(stream_name=None)[source]

Clear the stream’s buffer.

Parameters:
stream_namestr | list | None

Name of the stream(s) to reset its buffer. If None, reset all stream’s buffer.

show_info()[source]

Display the information about the connected streams.

property bufsize

Buffer’s size [sec].

Type:

int | float

property connected

Connected status.

Type:

bool

property mne_infos

Dictionary containing the Info for the compatible streams.

Type:

dict

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

Examples using bsl.StreamReceiver

StreamReceiver: real-time buffer filtered with a causal filter

StreamReceiver: real-time buffer filtered with a causal filter

StreamReceiver: real-time alpha band power

StreamReceiver: real-time alpha band power