Skip to content

Commit 2ae28e4

Browse files
1 parent e3f68b9 commit 2ae28e4

329 files changed

Lines changed: 57686 additions & 2354 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Binary file not shown.

dev/_downloads/0f763ae384277e558103757157e170fb/plot_data_augmentation_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from braindecode.datasets import MOABBDataset
5454

5555
subject_id = 3
56-
dataset = MOABBDataset(dataset_name="BNCI2014001", subject_ids=[subject_id])
56+
dataset = MOABBDataset(dataset_name="BNCI2014_001", subject_ids=[subject_id])
5757

5858
######################################################################
5959
# Preprocessing

dev/_downloads/1d879df548fa18be8c23d9ca0dc008d4/plot_data_augmentation.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"outputs": [],
3535
"source": [
36-
"from skorch.callbacks import LRScheduler\nfrom skorch.helper import predefined_split\n\nfrom braindecode import EEGClassifier\nfrom braindecode.datasets import MOABBDataset\n\nsubject_id = 3\ndataset = MOABBDataset(dataset_name=\"BNCI2014001\", subject_ids=[subject_id])"
36+
"from skorch.callbacks import LRScheduler\nfrom skorch.helper import predefined_split\n\nfrom braindecode import EEGClassifier\nfrom braindecode.datasets import MOABBDataset\n\nsubject_id = 3\ndataset = MOABBDataset(dataset_name=\"BNCI2014_001\", subject_ids=[subject_id])"
3737
]
3838
},
3939
{

dev/_downloads/2466f8ec5c733d0bd65e187b45d875cc/plot_data_augmentation_search.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"outputs": [],
3535
"source": [
36-
"from skorch.callbacks import LRScheduler\n\nfrom braindecode import EEGClassifier\nfrom braindecode.datasets import MOABBDataset\n\nsubject_id = 3\ndataset = MOABBDataset(dataset_name=\"BNCI2014001\", subject_ids=[subject_id])"
36+
"from skorch.callbacks import LRScheduler\n\nfrom braindecode import EEGClassifier\nfrom braindecode.datasets import MOABBDataset\n\nsubject_id = 3\ndataset = MOABBDataset(dataset_name=\"BNCI2014_001\", subject_ids=[subject_id])"
3737
]
3838
},
3939
{

dev/_downloads/263464a28477cf8decb861ae6e2e9be7/plot_how_train_test_and_tune.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"outputs": [],
4545
"source": [
46-
"from braindecode.datasets import MOABBDataset\n\nsubject_id = 3\ndataset = MOABBDataset(dataset_name=\"BNCI2014001\", subject_ids=[subject_id])"
46+
"from braindecode.datasets import MOABBDataset\n\nsubject_id = 3\ndataset = MOABBDataset(dataset_name=\"BNCI2014_001\", subject_ids=[subject_id])"
4747
]
4848
},
4949
{
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
""".. _preprocessing-classes:
2+
3+
Comprehensive Preprocessing with MNE-based Classes
4+
===================================================
5+
6+
This example demonstrates the various preprocessing classes available in
7+
Braindecode that wrap MNE-Python functionality. These classes provide a
8+
convenient and type-safe way to preprocess EEG data.
9+
"""
10+
11+
# Authors: Bruno Aristimunha <b.aristimunha@gmail.com>
12+
#
13+
# License: BSD (3-clause)
14+
15+
import mne
16+
17+
from braindecode.datasets import MOABBDataset
18+
from braindecode.preprocessing import (
19+
Anonymize,
20+
ApplyHilbert,
21+
Crop,
22+
Filter,
23+
Pick,
24+
Resample,
25+
SetEEGReference,
26+
SetMontage,
27+
preprocess,
28+
)
29+
30+
###############################################################################
31+
# Load a sample dataset
32+
# ---------------------
33+
# We'll use a small MOABB dataset for demonstration
34+
35+
dataset = MOABBDataset(dataset_name="BNCI2014001", subject_ids=[1])
36+
37+
###############################################################################
38+
# Signal Processing
39+
# -----------------
40+
# Apply common signal processing operations
41+
42+
# 1. Resample to reduce computational load
43+
print(f"Original sampling frequency: {dataset.datasets[0].raw.info['sfreq']} Hz")
44+
preprocessors_signal = [
45+
Resample(sfreq=100), # Downsample to 100 Hz
46+
]
47+
preprocess(dataset, preprocessors_signal)
48+
print(f"After resampling: {dataset.datasets[0].raw.info['sfreq']} Hz")
49+
50+
# 2. Remove power line noise and apply bandpass filter
51+
preprocessors_filtering = [
52+
Filter(l_freq=4, h_freq=30), # Bandpass filter 4-30 Hz
53+
]
54+
preprocess(dataset, preprocessors_filtering)
55+
print("Applied bandpass filter 4-30 Hz")
56+
57+
###############################################################################
58+
# Channel Management
59+
# ------------------
60+
# Select and manipulate channels
61+
62+
# 3. Pick only EEG channels
63+
preprocessors_channels = [
64+
Pick(picks="eeg"), # Select only EEG channels
65+
]
66+
print(f"Channels before pick: {len(dataset.datasets[0].raw.ch_names)}")
67+
preprocess(dataset, preprocessors_channels)
68+
print(f"Channels after pick: {len(dataset.datasets[0].raw.ch_names)}")
69+
70+
# 4. Rename channels (example - just for demonstration)
71+
original_names = dataset.datasets[0].raw.ch_names[:3]
72+
print(f"Original channel names (first 3): {original_names}")
73+
# Note: We won't actually rename to avoid breaking the example,
74+
# but this is how you would do it:
75+
# preprocessors_rename = [
76+
# RenameChannels(mapping={'C3': 'C3_renamed', 'C4': 'C4_renamed'}),
77+
# ]
78+
# preprocess(dataset, preprocessors_rename)
79+
80+
###############################################################################
81+
# Reference & Montage
82+
# -------------------
83+
# Set reference and channel positions
84+
85+
# 5. Set EEG reference to average
86+
preprocessors_reference = [
87+
SetEEGReference(ref_channels="average"),
88+
]
89+
preprocess(dataset, preprocessors_reference)
90+
print("Set EEG reference to average")
91+
92+
# 6. Set montage for proper channel positions
93+
montage = mne.channels.make_standard_montage("standard_1020")
94+
preprocessors_montage = [
95+
SetMontage(montage=montage, match_case=False, on_missing="ignore"),
96+
]
97+
preprocess(dataset, preprocessors_montage)
98+
print(
99+
f"Set montage, number of positions: {len(dataset.datasets[0].raw.get_montage().get_positions()['ch_pos'])}"
100+
)
101+
102+
###############################################################################
103+
# Data Transformation
104+
# -------------------
105+
# Apply transformations to the data
106+
107+
# 7. Crop data to specific time range
108+
preprocessors_crop = [
109+
Crop(tmin=0, tmax=60), # Keep only first 60 seconds
110+
]
111+
print(f"Data duration before crop: {dataset.datasets[0].raw.times[-1]:.1f} s")
112+
preprocess(dataset, preprocessors_crop)
113+
print(f"Data duration after crop: {dataset.datasets[0].raw.times[-1]:.1f} s")
114+
115+
###############################################################################
116+
# Metadata & Configuration
117+
# -------------------------
118+
# Modify metadata and configuration
119+
120+
# 8. Anonymize measurement information
121+
preprocessors_anonymize = [
122+
Anonymize(),
123+
]
124+
preprocess(dataset, preprocessors_anonymize)
125+
print("Anonymized measurement information")
126+
127+
###############################################################################
128+
# Advanced: Envelope Extraction
129+
# ------------------------------
130+
# Extract signal envelope using Hilbert transform
131+
132+
# 9. Compute envelope (useful for some analyses)
133+
# Note: This modifies the data, so use carefully
134+
preprocessors_envelope = [
135+
ApplyHilbert(envelope=True),
136+
]
137+
preprocess(dataset, preprocessors_envelope)
138+
print("Computed signal envelope")
139+
140+
###############################################################################
141+
# Combining Multiple Preprocessing Steps
142+
# ---------------------------------------
143+
# You can combine multiple preprocessing steps in a single pipeline
144+
145+
print("\n" + "=" * 60)
146+
print("Complete Preprocessing Pipeline Example")
147+
print("=" * 60)
148+
149+
# Reload dataset for complete pipeline demonstration
150+
dataset_complete = MOABBDataset(dataset_name="BNCI2014001", subject_ids=[1])
151+
152+
# Set montage first (needed for interpolation)
153+
montage = mne.channels.make_standard_montage("standard_1020")
154+
155+
complete_pipeline = [
156+
# 1. Set montage
157+
SetMontage(montage=montage, match_case=False, on_missing="ignore"),
158+
# 2. Set reference
159+
SetEEGReference(ref_channels="average"),
160+
# 3. Bandpass filter
161+
Filter(l_freq=4, h_freq=30),
162+
# 4. Downsample
163+
Resample(sfreq=100),
164+
# 5. Select only EEG channels
165+
Pick(picks="eeg"),
166+
# 6. Crop to region of interest
167+
Crop(tmin=0, tmax=60),
168+
# 7. Anonymize
169+
Anonymize(),
170+
]
171+
172+
print(
173+
f"Original: {dataset_complete.datasets[0].raw.info['sfreq']} Hz, "
174+
f"{dataset_complete.datasets[0].raw.times[-1]:.1f} s, "
175+
f"{len(dataset_complete.datasets[0].raw.ch_names)} channels"
176+
)
177+
178+
preprocess(dataset_complete, complete_pipeline)
179+
180+
print(
181+
f"After preprocessing: {dataset_complete.datasets[0].raw.info['sfreq']} Hz, "
182+
f"{dataset_complete.datasets[0].raw.times[-1]:.1f} s, "
183+
f"{len(dataset_complete.datasets[0].raw.ch_names)} channels"
184+
)
185+
186+
print("\nPreprocessing complete!")
187+
188+
###############################################################################
189+
# Summary
190+
# -------
191+
# Braindecode provides 45 preprocessing classes that wrap MNE-Python
192+
# functionality:
193+
#
194+
# **Signal Processing**: Resample, Filter, NotchFilter, SavgolFilter,
195+
# ApplyHilbert, Rescale, OversampledTemporalProjection
196+
#
197+
# **Channel Management**: Pick, PickChannels, PickTypes, DropChannels,
198+
# AddChannels, CombineChannels, RenameChannels, ReorderChannels,
199+
# SetChannelTypes, InterpolateBads, InterpolateTo, InterpolateBridgedElectrodes,
200+
# ComputeBridgedElectrodes, EqualizeChannels
201+
#
202+
# **Reference & Montage**: SetEEGReference, AddReferenceChannels, SetMontage
203+
#
204+
# **SSP Projections**: AddProj, ApplyProj, DelProj
205+
#
206+
# **Data Transformation**: Crop, CropByAnnotations, ComputeCurrentSourceDensity,
207+
# FixStimArtifact, MaxwellFilter, RealignRaw, RegressArtifact
208+
#
209+
# **Artifact Detection & Annotation**: AnnotateAmplitude, AnnotateBreak,
210+
# AnnotateMovement, AnnotateMuscleZscore, AnnotateNan
211+
#
212+
# **Metadata & Configuration**: Anonymize, SetAnnotations, SetMeasDate,
213+
# AddEvents, FixMagCoilTypes, ApplyGradientCompensation
214+
#
215+
# See the API documentation for details on each class and their parameters.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)