LslReceiver

class gpype.backend.sources.lsl_receiver.LslReceiver[source]

Bases: Source

Reads a Lab Streaming Layer stream into a pipeline.

The mirror of LSLSender, and the way another vendor’s amplifier, MATLAB, a stimulus program or a second g.Pype process gets its data in. Channel names, types and units are read from the stream description, so a g.Pype stream read back keeps what it was published with. Types and units are kept even where the channels are not all named; the names only where every channel has one.

What arrives this way is somebody else’s data: LSL carries no per-sample authentication, so a stream says what it is and cannot prove it.

RESOLVE_TIMEOUT_S = 5.0

How long to wait for the stream to appear, in seconds.

class Configuration[source]

Bases: Configuration

Configuration class for LslReceiver parameters.

class Keys[source]

Bases: Keys

Configuration keys for LslReceiver settings.

class OptionalKeys[source]

Bases: OptionalKeys

Optional configuration keys.

STREAM_NAME = 'stream_name'

Stream name to resolve

STREAM_TYPE = 'stream_type'

Stream type to resolve, when no name is given

__init__(stream_name=None, stream_type=None, channel_count=None, sampling_rate=None, edge_id=None, **kwargs)[source]

Initialize the receiver.

Parameters:
  • stream_name (Optional[str]) – Name of the stream to resolve.

  • stream_type (Optional[str]) – Type to resolve, when no name is given.

  • channel_count (Optional[int]) – Expected channel count. Read from the stream when not given.

  • sampling_rate (Optional[float]) – Expected rate. Read from the stream when not given.

  • edge_id (Optional[str]) – Which edge runs this node, matched against the edge process’s –edge-id. None, the default, is every edge; ignored when the pipeline is not distributed.

  • **kwargs – Additional arguments for the parent Source.

Raises:
  • ValueError – If neither a name nor a type is given, or if the stream shape is missing on a server.

  • RuntimeError – If the shape has to be read from a stream that does not appear.

setup(data, port_context_in)[source]

Publish what the stream said about its channels.

Parameters:
Return type:

dict[str, dict]

Returns:

Output port contexts.

start()[source]

Resolve the stream, open the inlet, and begin pulling.

This is where the publisher has to exist. Resolving here rather than in the constructor is what allows a saved pipeline to be rebuilt while the stream is offline.

Raises:

RuntimeError – If no matching stream appears in time.

stop()[source]

Stop pulling and close the inlet.

step(data)[source]

Emit the sample the pulling thread handed over.

Return type:

dict[str, ndarray]

Returns:

One sample, or None when nothing is waiting.