Sources¶
A Source wraps a device, file, or transport behind a uniform interface. Built-in sources live here; custom sources implement the Source protocol below. See Add a custom source for the recipe.
The protocol¶
Source ¶
Bases: Protocol
Protocol every data source must implement.
Three methods, no inheritance: connect opens the device or file
and returns a :class:StreamInfo describing the data, read
polls non-blockingly for the next chunk, disconnect releases
the device. The framework's :class:Stream wraps any object
matching this Protocol and runs it on a daemon acquisition thread.
See Add a custom source for worked examples and the full contract.
connect ¶
connect() -> StreamInfo
read ¶
Return (data, ts) where data is sample-major
(n_samples, n_channels) and ts is (n_samples,)
float64 LSL clock timestamps. Return (None, None) if no
new data is available.
Source code in myogestic/stream.py
Built-in sources¶
LSLSource ¶
LSLSource(stream_name: str)
Pull samples from a Lab Streaming Layer outlet by name.
The default real-time source for MyoGestic: name the outlet you want
on your local LSL network, drop the source into a :class:Stream,
and the framework's acquisition thread handles the rest. Uses
mne_lsl under the hood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_name
|
str
|
LSL outlet name to subscribe to (e.g. |
required |
Example
from myogestic import Stream from myogestic.sources import LSLSource stream = Stream("emg", source=LSLSource("TestEMG1"), ... window_seconds=1.0)
The source is non-blocking: :meth:read pulls whatever is
immediately available from the inlet and returns (None, None)
when the outlet has produced nothing new since the last call. The
acquisition thread paces itself by waiting for the inlet to fill,
so a fast spin loop is harmless.
Source code in myogestic/sources/lsl.py
connect ¶
connect() -> StreamInfo
Resolve the outlet by name and open an inlet.
Returns a :class:StreamInfo whose channel count, sample rate,
and dtype come from the outlet's metadata. Blocks up to 10 s
waiting for the outlet to appear on the network.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if no outlet with |
Source code in myogestic/sources/lsl.py
read ¶
Pull whatever samples are immediately available.
Non-blocking. Returns (data, timestamps) where data is
(n_samples, n_channels) float32 and timestamps is a 1-D
float64 array of LSL clock seconds. Returns (None, None) if
the inlet hasn't been opened or no new samples are pending.
Source code in myogestic/sources/lsl.py
disconnect ¶
discover ¶
Scan for available LSL streams on the network.
reconnect ¶
reconnect(target: str | None = None) -> StreamInfo
Reconnect to the same or a different LSL stream.
ReplaySource ¶
Replays a recorded session as if it were a live stream.
Accepts either a folder-format session or a .session.zip archive —
delegates to open_session_store so both layouts work transparently.
Source code in myogestic/sources/replay.py
SerialSource¶
Opt-in: lives at myogestic.sources.serial_source.SerialSource. Direct import only (requires the serial extra for pyserial).
SerialSource ¶
Reads fixed-width binary frames from a serial port.
Each frame is n_channels float32 values (little-endian). The source self-paces via serial blocking reads; timestamps are stamped on arrival with mne_lsl.lsl.local_clock().
Source code in myogestic/sources/serial_source.py
discover ¶
List available serial ports.
Source code in myogestic/sources/serial_source.py
reconnect ¶
reconnect(target: str | None = None) -> StreamInfo
Reconnect to the same or a different serial port.