Getting Started with lslconv: A Beginner’s Guide—
Introduction
lslconv is a lightweight command-line tool for converting, packaging, and preparing data recorded with the Lab Streaming Layer (LSL) and related formats. Whether you’re a researcher collecting EEG/MEG/physiology signals, a developer building a data pipeline, or a student learning to handle time-series physiological data, lslconv helps you turn raw LSL recordings into well-structured, analysis-ready files.
What lslconv does
- Converts LSL recordings into common file formats (e.g., BIDS-compatible FIF/EDF/CSV/TSV, XDF, or other lab-specific formats).
- Merges and splits streams recorded in a single session (e.g., EEG + markers + motion).
- Ensures consistent timestamps across streams by applying clock synchronization and resampling.
- Validates and packages outputs to match standards like BIDS or custom lab conventions.
- Automates batch processing via scripts and configuration files.
Why use lslconv?
- Reproducibility: standardized outputs reduce ambiguity and help ensure analyses can be replicated.
- Interoperability: converts proprietary or uncommon formats into widely supported ones.
- Time alignment: synchronizes multiple physiological and behavioral streams for accurate multimodal analysis.
- Ease of automation: command-line options and config files let you process many sessions unattended.
Installation
Prerequisites
- A POSIX-compatible environment (Linux or macOS recommended; Windows WSL works).
- Python 3.8+ (if lslconv is distributed as a Python package) or prebuilt binaries for your OS.
- Common scientific packages (NumPy, MNE, pyEDFlib) depending on target output formats.
Typical installation methods:
- pip:
pip install lslconv
- GitHub (if you prefer the latest development version):
git clone https://github.com/example/lslconv.git cd lslconv pip install -e .
- Prebuilt binaries: download from releases and place in a folder on your PATH.
Basic workflow and common commands
Note: exact CLI flags depend on the lslconv release—run lslconv --help
to view available options.
-
Inspect an XDF/LSL recording
lslconv inspect session.xdf
This lists streams, channels, sampling rates, and marker channels.
-
Convert to CSV (per-stream files)
lslconv convert session.xdf --format csv --outdir ./converted
-
Convert and resample to 250 Hz
lslconv convert session.xdf --format fif --resample 250 --outdir ./converted
-
Merge EEG + markers into a BIDS-compatible structure
lslconv convert session.xdf --format bids --bids-subject 01 --task resting --outdir ./bids_dataset
-
Batch convert multiple files using a config file (YAML/JSON)
lslconv batch --config batch_config.yml
Timestamps, synchronization, and resampling
LSL records timestamps based on source clocks and the receiver clock; discrepancies can occur. lslconv typically offers:
- Clock offset estimation using LSL’s built-in synchronization metadata.
- Inter-stream alignment using marker channels or cross-correlation.
- Resampling with anti-alias filtering to match analysis requirements.
Example: align streams then resample to 250 Hz:
lslconv convert session.xdf --align --resample 250
Output formats and options
Common outputs:
- CSV/TSV: simple, human-readable, good for quick checks.
- XDF: preserves multi-stream structure.
- EDF: widely used in sleep and polysomnography.
- FIF: MNE-compatible format for EEG/MEG.
- BIDS: organization standard for neuroimaging and electrophysiology datasets.
Options to consider:
- Channel selection (–channels)
- Time windows (–start, –end)
- Annotation/marker export (–export-markers)
- Metadata inclusion (–include-meta)
Example pipelines
- Single-session EEG preprocessing
- Convert XDF -> FIF
- Resample to 250 Hz
- Save a marker channel as events.tsv for BIDS Commands:
lslconv convert session.xdf --format fif --resample 250 --export-markers events.tsv --outdir ./preproc
- Overnight sleep study (many files)
- Batch convert all .xdf files in folder to EDF, include subject IDs from filenames
- Validate EDF headers Example batch config (YAML):
input_dir: ./raw file_pattern: "*.xdf" output_format: edf outdir: ./edf n_jobs: 8
Common pitfalls and troubleshooting
- Missing streams: ensure the recording device wrote all streams; inspect with
lslconv inspect
. - Time drift between streams: enable alignment flags and use marker-based synchronization if possible.
- Unsupported vendor formats: install additional converters or export from vendor software to XDF.
- Large files: use chunked conversion or increase available memory; consider streaming conversion if supported.
- BIDS validation failures: check required metadata fields (subject, task, sampling_rate) and use lslconv’s –bids-validate option.
Best practices
- Record a synchronization marker at start/end of sessions.
- Keep device clocks synchronized when possible.
- Store raw XDF copies before conversion.
- Use descriptive subject/task names to populate BIDS fields automatically.
- Create and reuse batch config files for consistent processing.
Further resources
- lslconv CLI help:
lslconv --help
- Lab Streaming Layer (LSL) documentation
- BIDS specification for EEG/physio
- MNE-Python documentation for working with FIF files
Conclusion
lslconv bridges raw LSL recordings and analysis-ready datasets by converting formats, aligning timestamps, and packaging outputs for standards like BIDS. With basic commands and a few best practices (synchronization markers, consistent filenames, and batch configs), you can make your physiological data reproducible and analysis-ready.
Leave a Reply