mne_lsl.lsl.StreamInletπ
- class mne_lsl.lsl.StreamInlet(sinfo, chunk_size=0, max_buffered=360, recover=True, processing_flags=None)[source]π
An inlet to retrieve data and metadata on the network.
- Parameters:
- sinfo
StreamInfo
Description of the stream to connect to.
- chunk_size
int
β₯ 1
|0
The desired chunk granularity in samples. By default, the
chunk_size
defined by the sender (outlet) is used.- max_buffered
int
β₯ 0
The maximum amount of data to buffer in the Outlet. The number of samples buffered is
max_buffered * 100
if the sampling rate is irregular, else itβsmax_buffered
seconds.- recover
bool
Attempt to silently recover lost streams that are recoverable (requires a
source_id
to be specified in theStreamInfo
).- processing_flagssequence of
str
|'all'
|None
Set the post-processing options. By default, post-processing is disabled. Any combination of the processing flags is valid. The available flags are:
'clocksync'
: Automatic clock synchronization, equivalent to manually adding the estimatedtime_correction()
.'dejitter'
: Remove jitter on the received timestamps with a smoothing algorithm.'monotize'
: Force the timestamps to be monotically ascending. This option should not be enable if'dejitter'
is not enabled.'threadsafe'
: Post-processing is thread-safe, thus the same inlet can be read from multiple threads.
- sinfo
Attributes
Channel format of a stream.
Number of channels.
Name of the stream.
Number of available samples on the
StreamOutlet
.Sampling rate of the stream, according to the source (in Hz).
Type of the stream.
True if the clock was potentially reset since the last call.
Methods
Drop the current data stream.
flush
()Drop all queued and not-yet pulled samples.
get_sinfo
([timeout])StreamInfo
corresponding to this Inlet.open_stream
([timeout])Subscribe to a data stream.
pull_chunk
([timeout, max_samples])Pull a chunk of samples from the inlet.
pull_sample
([timeout])Pull a single sample from the inlet.
time_correction
([timeout])Retrieve an estimated time correction offset for the given stream.
- close_stream()[source]π
Drop the current data stream.
All samples that are still buffered or in flight will be dropped and transmission and buffering of data for this inlet will be stopped. This method is used if an application stops being interested in data from a source (temporarily or not) but keeps the outlet alive, to not waste unnecessary system and network resources.
Warning
At the moment,
liblsl
is released in version 1.16. Closing and re-opening a stream does not work and new samples pushed to the outlet do not arrive at the inlet. c.f. this github issue.
- flush()[source]π
Drop all queued and not-yet pulled samples.
- Returns:
- n_dropped
int
Number of dropped samples.
- n_dropped
- get_sinfo(timeout=None)[source]π
StreamInfo
corresponding to this Inlet.- Parameters:
- Returns:
- sinfo
StreamInfo
Description of the stream connected to the inlet.
- sinfo
- open_stream(timeout=None)[source]π
Subscribe to a data stream.
All samples pushed in at the other end from this moment onwards will be queued and eventually be delivered in response to
pull_sample()
orpull_chunk()
calls. Pulling a sample without subscribing to the stream with this method is permitted (the stream will be opened implicitly).- Parameters:
Notes
Opening a stream is a non-blocking operation. Thus, samples pushed on an outlet while the stream is not yet open will be missed.
- pull_chunk(timeout=0.0, max_samples=1024)[source]π
Pull a chunk of samples from the inlet.
- Parameters:
- timeout
float
|None
Optional timeout (in seconds) of the operation. None correspond to a very large value, effectively disabling the timeout.
0.
makes this function non-blocking even if no sample is available. See notes for additional details.- max_samples
int
Maximum number of samples to return. The function is blocking until this number of samples is available or until
timeout
is reached. See notes for additional details.
- timeout
- Returns:
- samples
list
oflist
ofstr
|array
of shape (n_samples, n_channels) If the channel format is
'string'
, returns a list of list of values for each channel and sample. Each sublist represents an entire channel. Else, returns a numpy array of shape(n_samples, n_channels)
.- timestamps
array
of shape (n_samples,) Acquisition timestamp on the remote machine. To map the timestamp to the local clock of the client machine, add the estimated time correction return by
time_correction()
.
- samples
Notes
The argument
timeout
andmax_samples
control the blocking behavior of the pull operation. If the number of available sample is inferior ton_samples
, the pull operation is blocking untiltimeout
is reached. Thus, to return all the available samples at a given time, regardless of the number of samples requested,timeout
must be set to0
.Note that if
timeout
is reached and no sample is available, emptysamples
andtimestamps
arrays are returned.
- pull_sample(timeout=0.0)[source]π
Pull a single sample from the inlet.
- Parameters:
- Returns:
- sample
list
ofstr
|array
of shape (n_channels,) If the channel format is
'string
, returns a list of values for each channel. Else, returns a numpy array of shape(n_channels,)
.- timestamp
float
|None
Acquisition timestamp on the remote machine. To map the timestamp to the local clock of the client machine, add the estimated time correction return by
time_correction()
. None if no sample was retrieved.
- sample
Notes
Note that if
timeout
is reached and no sample is available, an emptysample
is returned andtimestamp
is set to None.
- time_correction(timeout=None)[source]π
Retrieve an estimated time correction offset for the given stream.
The first call to this function takes several milliseconds until a reliable first estimate is obtained. Subsequent calls are instantaneous (and rely on periodic background updates). The precision of these estimates should be below 1 ms (empirically within +/-0.2 ms).
- Parameters:
- Returns:
- time_correction
float
Current estimate of the time correction. This number needs to be added to a timestamp that was remotely generated via
local_clock()
to map it into thelocal_clock()
domain of the client machine.
- time_correction
- property dtypeπ
Channel format of a stream.
All channels in a stream have the same format.
- Type:
dtype
|"string"
- property n_channelsπ
Number of channels.
A stream must have at least one channel. The number of channels remains constant for all samples.
- Type:
- property nameπ
Name of the stream.
The name of the stream is defined by the application creating the LSL outlet. Streams with identical names can coexist, at the cost of ambiguity for the recording application and/or the experimenter.
- Type:
- property samples_availableπ
Number of available samples on the
StreamOutlet
.- Type:
- property sfreqπ
Sampling rate of the stream, according to the source (in Hz).
If a stream is irregularly sampled, the sampling rate is set to
0
.- Type:
- property stypeπ
Type of the stream.
The content type is a short string, such as
"EEG"
,"Gaze"
, β¦ which describes the content carried by the channel. If a stream contains mixed content, this value should be an empty string and the type should be stored in the description of individual channels.- Type:
Examples using mne_lsl.lsl.StreamInlet
π
Introduction to real-time LSL streams