pred_brain.exp.lsl#

Create LSL markers and control LabRecorder recordings.

pred_brain.exp.lsl.create_markers_outlet(name: str = 'ExperimentMarkers', source_id: str | None = None, channel_label='ExperimentMarker') → pylsl.StreamOutlet#

Create an LSL outlet for string-valued experiment markers.

Parameters:
namestr, default=”ExperimentMarkers”

Name of the LSL stream.

source_idstr or None, default=None

Source ID for the LSL stream. If None, an ID based on the hostname is used.

channel_labelstr, default=”ExperimentMarker”

Label for the single channel in the LSL stream.

Returns:
pylsl.StreamOutlet

The created LSL outlet for sending experiment markers.

pred_brain.exp.lsl.start_audio_capture(cli_path, device=None, name=None, api=None, config=None, rate=None, channels=None, format=None, ts_offset_us=None)#

Start audio capture and return the process handle.

Omitted options are left to the configuration file or the CLI defaults.

Parameters:
cli_pathstr

Path to the AudioCaptureCLI executable.

devicestr or int, optional

Device index (see --list) or ID. If omitted, the configuration or CLI default is used.

namestr, optional

LSL stream name. If omitted, the configuration or CLI default is used.

apistr, optional

Capture API (see --list). The CLI default is the first API with available devices.

configstr or Path, optional

Path to a GUI .cfg file. Other options override its settings.

rateint, optional

Sample rate in Hz. The CLI default is device preferred.

channelsint, optional

Channel count. The CLI default is device preferred.

formatstr, optional

Audio format: “Int16”, “Int32”, or “Float”. The CLI default is device preferred.

ts_offset_usint, optional

Number of microseconds to subtract from every timestamp to account for the device’s measured input latency.

Returns:
subprocess.Popen

Process handle for the audio capture.

pred_brain.exp.lsl.stop_audio_capture(process, timeout=5)#

Stop audio capture and wait for the process to exit.

If the process does not exit within timeout seconds after termination is requested, it is killed.

Parameters:
processsubprocess.Popen

Audio-capture process returned by start_audio_capture().

timeoutfloat, default=5

Maximum number of seconds to wait for graceful termination.

pred_brain.exp.lsl.check_lsl_streams(stream_criteria: dict[str, str] | list[dict[str, str]], wait_time: float = 3.0)#

Check whether the specified LSL streams are available within the wait time.

Parameters:
stream_criteriadict or list of dict

One or more sets of stream attributes. All attributes in a dictionary must match the same stream. Values without regular-expression syntax are compared exactly; other values are searched as regular expressions against string-valued attributes.

wait_timefloat, default=3.0

Maximum number of seconds to wait for the stream(s) to become available.

Returns:
all_activebool

True only if every criteria dictionary matches at least one stream; otherwise False.

active_streamslist of StreamInfo

List of currently active LSL streams as returned by pylsl.resolve_streams.

Examples

# Check for a stream with an exact name and type >>> check_lsl_streams({“name”: “MyEvents”, “type”: “Markers”}) # Check for a stream with an exact type >>> check_lsl_streams({“type”: “Gaze”}) # Check for a stream whose name ends with “Neon Gaze” >>> check_lsl_streams({“name”: r”Neon Gaze$”}) True

pred_brain.exp.lsl.launch_lab_recorder(lab_recorder_path: Path | str, config_path: Path | str | None = None, port: int = 22345, timeout: float = 60.0) → None#

Launch LabRecorder and wait for its remote-control server.

If a remote-control server is already available on localhost:port, this function does not launch another instance.

LabRecorder is considered ready once its remote-control TCP server accepts a connection on localhost:port.

Parameters:
lab_recorder_pathpathlib.Path or str

Path to the LabRecorder executable.

config_pathpathlib.Path or str, optional

Path to a LabRecorder configuration file. When provided, it is passed to the executable with the -c option.

portint, default=22345

TCP port configured for LabRecorder’s remote-control server.

timeoutfloat, default=60.0

Maximum number of seconds to wait for LabRecorder to become available.

Raises:
RuntimeError

If LabRecorder exits before its remote-control server becomes available.

TimeoutError

If LabRecorder does not become available within timeout seconds.

Notes

The LabRecorder configuration must enable the remote-control server on the specified port. Otherwise this function will time out.

pred_brain.exp.lsl.set_lab_recorder_filename(port: int = 22345, root: str | Path | None = None, filename: str | None = None)#

Configure LabRecorder’s filename template through remote control.

Parameters:
portint, default=22345

TCP port of the LabRecorder remote-control server on localhost.

rootstr or pathlib.Path, optional

Root directory for the recording files.

filenamestr, optional

Filename or filename template. If None, the default BIDS template is unchanged.

pred_brain.exp.lsl.start_recording_lab_recorder(port: int = 22345, select_all_streams: bool = True)#

Start an LSL recording through LabRecorder’s remote-control server.

When select_all_streams is true, the function first sends update and select_all commands so that all available streams are selected.

Parameters:
portint, default=22345

TCP port of the LabRecorder remote-control server on localhost.

select_all_streamsbool, default=True

Whether to refresh the stream list and select every available stream before starting the recording.

Raises:
OSError

If a connection to the server cannot be established or a command cannot be sent.

pred_brain.exp.lsl.update_lab_recorder(port: int = 22345)#

Refresh LabRecorder’s list of available LSL streams.

Parameters:
portint, default=22345

TCP port of the LabRecorder remote-control server on localhost.

Raises:
OSError

If a connection to the server cannot be established or the command cannot be sent.

pred_brain.exp.lsl.stop_recording_lab_recorder(port: int = 22345)#

Stop the active LSL recording through LabRecorder’s remote-control server.

Parameters:
portint, default=22345

TCP port of the LabRecorder remote-control server on localhost.

Raises:
OSError

If a connection to the server cannot be established or the command cannot be sent.