Neurotheque Resources is a comprehensive, modular toolkit for EEG data processing and analysis. Built on state‐of‐the‐art libraries such as MNE-Python, autoreject it enables:
- Preprocessing & Channel Setup: Automatic bad channel detection and re-referencing with standardized electrode montages.
- Artifact Rejection: Advanced methods like ICA and auto-rejection for high-quality EEG data.
- Task & Trigger Parsing: Flexible logic to merge triggers for tasks like Go/No-Go, finger tapping, or mental imagery.
- Epoching & Analysis: Efficient epoch slicing, ROI averaging, time–frequency transforms, and ERP analyses.
- Report Generation: Automated HTML reporting (via MNE's
Report) for visual inspection and documentation of analysis results.
This repository is designed for both single-subject and multi-subject pipelines, ensuring reproducibility and scalability.
- Repository Structure
- Installation & Quick Start
- Usage Examples
- Direct Step Usage
- Testing
- Contributors & Acknowledgments
- Contributing
- License
- Contact
-
notebooks/
- tutorials/ – Step-by-step Jupyter notebooks illustrating basic usage and pipeline demos.
- preprocessing/ – Notebooks focusing on data cleaning (filtering, ICA, etc.).
- analysis/ – Notebooks showing advanced analysis tasks (ERP, ROI-based metrics, time–frequency transforms).
-
scr/
pipeline.py– The main pipeline driver and CLI (supports JSON or YAML configs with schema validation).steps/– Modular processing steps (e.g.,LoadData,FilterStep,AutoRejectStep,ICAStep,SplitTasksStep,TriggerParsingStep).strategies/– Strategy examples for different paradigms (e.g., finger tapping, mental imagery).utils/– Helper utilities for referencing, MNE cleaning, spectra, etc.
-
docs/ – Additional documentation, user guides, or methodology reports.
-
configs/ – JSON/YAML pipeline configs (e.g.,
gonogo_minimal_pipeline.json/.yml). JSON is the primary format; YAML remains supported. -
tests/ – Comprehensive test suite for all components of the pipeline.
- unit/ – Tests for individual steps and utility functions.
- integration/ – Tests for complete workflows and pipeline configurations.
- Processed data:
data/processed/sub-<id>/ses-<id>/*.fif(viaProjectPaths.get_derivative_path/get_checkpoint_path) - Split tasks:
data/processed/sub-<id>/ses-<id>/*_split.fif(viaget_split_task_path) - Reports:
reports/<type>/sub-<id>/ses-<id>/[...]
- Clone the repository:
git clone https://github.com/UNFmontreal/neurotheque_resources.git cd neurotheque_resources - Install dependencies:
Or install as a package for a cleaner setup:
pip install -r requirements.txt # runtime deps # optional: dev tools pip install -r requirements-dev.txt # adds pytest, black, flake8, etc.
pip install -e . # users pip install -e .[dev] # contributors (adds tests/docs tools)
- Supported Python:
- We test on Python 3.10–3.12 (recommended with MNE 1.5+).
-
Run a Pipeline (JSON or YAML)
# JSON (preferred) python -m scr.pipeline --config configs/gonogo_minimal_pipeline.json # YAML (backward compatible) python -m scr.pipeline --config configs/pilot_preprocessing_strategy.yml
Notes:
- The CLI auto-detects JSON vs YAML by extension and validates against
scr/config_schema.json. - Use
--no-validateto skip schema checks if iterating quickly. - Use
--dry-runto print the step plan (and resolved files in multi-file mode) without executing.
- The CLI auto-detects JSON vs YAML by extension and validates against
-
Use a Strategy Script
# Example: Using the finger tapping strategy from scr.strategies.finger_tapping_strategy import run_finger_tapping_pipeline input_path = "data/raw/sub-01_ses-001_eeg.edf" output_path = "data/processed/sub-01_ses-001_preprocessed.fif" run_finger_tapping_pipeline(input_path, output_path)
-
Explore the Jupyter Notebooks
Each processing step in the Neurotheque pipeline can be used independently on MNE data objects, allowing for flexible integration into your custom workflows.
from scr.steps.filter import FilterStep
# Configure parameters
filter_params = {
"l_freq": 1.0, # High-pass frequency (Hz)
"h_freq": 40.0, # Low-pass frequency (Hz)
"notch_freqs": [50] # Optional notch filter frequencies (Hz)
}
# Initialize the step
filter_step = FilterStep(filter_params)
# Run it on your MNE data
filtered_data = filter_step.run(your_mne_raw_data)Here's a simplified workflow example directly using the processing steps:
import mne
from scr.steps.load import LoadData
from scr.steps.filter import FilterStep
from scr.steps.autoreject import AutoRejectStep
from scr.steps.epoching import EpochingStep
# Load data
load_step = LoadData({"input_file": "your_data.fif"})
raw_data = load_step.run(None)
# Apply filters
filter_step = FilterStep({"l_freq": 1.0, "h_freq": 40.0})
filtered_data = filter_step.run(raw_data)
# Apply AutoReject for artifact detection
ar_step = AutoRejectStep({"mode": "fit", "plot_results": True})
ar_data = ar_step.run(filtered_data)
# Create epochs
events = mne.find_events(ar_data)
epoch_step = EpochingStep({
"tmin": -0.2, "tmax": 0.5,
"baseline": (None, 0),
"event_id": {"1": 1}
})
epochs = epoch_step.run(ar_data)
print(f"Created {len(epochs)} clean epochs")For detailed examples of direct step usage, see:
- Direct Step Usage Guide (examples directory forthcoming)
- Minimal config:
configs/gonogo_minimal_pipeline.json(DSI‑24 → Go/NoGo). - Run:
python -m scr.pipeline --config configs/gonogo_minimal_pipeline.json. - Outputs: processed FIF and checkpoints under
data/processed/sub-<id>/ses-<id>/, and reports underreports/as defined byProjectPathsand your configdirectory.
Notes:
- The runner passes
subject_id/session_id/task_id/run_idand apathshelper to each step. In multi‑file mode these are parsed from filenames; in single‑subject mode they default to the values in your config (default_subject,default_session,default_run). - AutoSave (enabled by
auto_save: true) writes checkpoints after each step using the conventionafter_<step>. SaveCheckpoint does the same using the explicitcheckpoint_key. The resume logic recognizes both patterns.
Some examples (e.g., spectral modeling/FOOOF, mixed-effects) require additional packages that are not needed for core preprocessing:
- fooof (spectral parameterization)
- statsmodels (mixed-effects models)
Install on demand, for example: pip install fooof statsmodels.
- Example config:
configs/task_splitting_pipeline.yml - Preview segments (no execution):
python -m scr.pipeline --dry-run --config configs/task_splitting_pipeline.yml
The Neurotheque pipeline includes a comprehensive test suite to ensure reliability and robustness. The tests are organized into unit tests (for individual components) and integration tests (for workflows and complete pipelines).
To run tests, first install the development dependencies:
pip install -r requirements-dev.txtUse pytest directly or the bundled test runner:
# Run all tests (pytest)
pytest -q
# Or use the project test runner
python tests/run_tests.py # all
python tests/run_tests.py --unit # unit only
python tests/run_tests.py --integration # integration onlyFor detailed information about the test suite, including how to add new tests, see the tests/README.md file.
This repository now ships a BIDS‑native preprocessing flow for DSI‑24 EDF recordings:
- BIDSify your raw
.edffolder (entity inference + event mapping via JSON) - Preprocess from BIDS using the same JSON (filters/notch/reref/ICA/optional autoreject/epoching)
- Outputs are saved under BIDS derivatives with a comprehensive MNE HTML report
python dsi_bids.py \
--config configs/examples/gonogo.json \
--source /path/to/source_edfs \
--bids-root /path/to/bids_rootNotes:
- If your filenames are non‑standard, the tool applies documented regex patterns + fallbacks from the config to infer
subject,session,task,run. - Events are discovered from the Trigger channel and mapped purely from JSON (no per‑task if/elif).
- A per‑file JSON log is written to
derivatives/neurotheque-preproc/logs/.
python preprocess_single.py \
--config configs/examples/gonogo.json \
--bids-root /path/to/bids_root \
--sub 01 --ses 001 --task gonogo --run 01This writes cleaned FIF/epochs/evokeds/figures and a Report to:
derivatives/neurotheque-preproc/<version>/... and
derivatives/neurotheque-preproc/reports/....
python preprocess_batch.py \
--config configs/examples/gonogo.json \
--bids-root /path/to/bids_root \
--task gonogo --n-jobs 1See configs/examples/ for Go/No‑Go and Five‑Point examples.
Schemas:
- BIDS‑first examples:
bidsfirst_config_schema.json - Modular pipeline:
scr/config_schema.json
