Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions doc/tutorials/0-1_meg_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This tutorial walks through the full MEG processing pipeline step by step:

1. Preprocessing — Downsample, filter, detect bad segments/channels.
1. Preprocessing — Downsample, filter, detect bad segments/channels, ICA artefact rejection.
2. Surface Extraction — Extract skull/scalp surfaces from a structural MRI.
3. Coregistration — Align MEG sensor space to MRI space.
4. Forward Model — Compute the lead field matrix.
Expand Down Expand Up @@ -161,11 +161,36 @@
# raw = preproc.detect_bad_channels(raw, picks="grad")

#%%
# Save preprocessing QC plots (PSD, sum-of-squares time series, channel standard deviations). Check that bad segments and channels are being correctly identified.
# ICA artefact rejection
# **********************
#
# Automatic ICA artefact rejection to remove ECG and EOG artefacts.
# Two approaches are available:
#
# **Option A: ECG/EOG correlation** — Uses MNE-Python's built-in
# correlation-based detection.
#
# .. code-block:: python
#
# raw, ica, ic_labels = preproc.ica_ecg_eog_correlation(raw, picks="meg")
#
# **Option B: MEGNet automatic labelling** — Uses ``mne-icalabel`` (included
# in the osl-dynamics conda environments) to classify components with a
# pre-trained deep learning model. Note, MEGNet was trained on ``'mag'``
# sensor topographies.
#
# .. code-block:: python
#
# raw, ica, ic_labels = preproc.ica_label(raw, picks="mag", method="megnet")

#%%
# Save preprocessing QC plots (PSD, sum-of-squares time series, channel
# standard deviations, ICA component topographies). Check that bad segments,
# channels, and ICA components are being correctly identified.
#
# .. code-block:: python
#
# preproc.save_qc_plots(raw, plots_dir / id, show=True)
# preproc.save_qc_plots(raw, plots_dir / id, show=True, ica=ica, ic_labels=ic_labels)

#%%
# Save preprocessed data
Expand Down
61 changes: 32 additions & 29 deletions envs/bmrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ dependencies:
- aiohttp=3.13.3=py312h5d8c7f2_0
- aiosignal=1.4.0=pyhd8ed1ab_0
- alsa-lib=1.2.15.3=hb03c661_0
- anyio=4.12.1=pyhcf101f3_0
- anyio=4.13.0=pyhcf101f3_0
- aom=3.9.1=hac33072_0
- argon2-cffi=25.1.0=pyhd8ed1ab_0
- argon2-cffi-bindings=25.1.0=py312h4c3975b_2
- arrow=1.4.0=pyhcf101f3_0
- asttokens=3.0.1=pyhd8ed1ab_0
- async-lru=2.2.0=pyhcf101f3_0
- attr=2.5.2=h39aace5_0
- attrs=25.4.0=pyhcf101f3_1
- async-lru=2.3.0=pyhcf101f3_0
- attrs=26.1.0=pyhcf101f3_0
- babel=2.18.0=pyhcf101f3_1
- backports.zstd=1.3.0=py312h90b7ffd_0
- beautifulsoup4=4.14.3=pyha770c72_0
Expand All @@ -38,12 +37,12 @@ dependencies:
- certifi=2026.2.25=pyhd8ed1ab_0
- cffi=2.0.0=py312h460c074_1
- charls=2.4.3=hecca717_0
- charset-normalizer=3.4.5=pyhd8ed1ab_0
- charset-normalizer=3.4.6=pyhd8ed1ab_0
- comm=0.2.3=pyhe01879c_0
- contourpy=1.3.3=py312h0a2e395_4
- cpython=3.12.13=py312hd8ed1ab_0
- cycler=0.12.1=pyhcf101f3_2
- cyclopts=4.7.0=pyhcf101f3_0
- cyclopts=4.10.1=pyhcf101f3_0
- cyrus-sasl=2.1.28=hd9c7081_0
- dav1d=1.2.1=hd590300_0
- dbus=1.16.2=h24cb091_1
Expand All @@ -67,19 +66,19 @@ dependencies:
- fonts-conda-forge=1=hc364b38_1
- fonttools=4.62.0=py312h8a5da7c_0
- fqdn=1.5.1=pyhd8ed1ab_1
- freetype=2.14.2=ha770c72_0
- freetype=2.14.3=ha770c72_0
- fribidi=1.0.16=hb03c661_0
- frozenlist=1.7.0=py312h447239a_0
- fslpy=3.27.0=pyhd8ed1ab_0
- gdk-pixbuf=2.44.4=h2b0a6b4_0
- giflib=5.2.2=hd590300_0
- gl2ps=1.4.2=hae5d5c5_1
- gl2ps=1.4.2=h36e74d4_2
- gmp=6.3.0=hac33072_2
- gnutls=3.8.11=h18acefa_1
- graphite2=1.3.14=hecca717_2
- h11=0.16.0=pyhcf101f3_1
- h2=4.3.0=pyhcf101f3_0
- h5io=0.2.5=pyhecae5ae_0
- h5io=0.2.5=pyhc455866_0
- h5py=3.13.0=nompi_py312hedeef09_100
- harfbuzz=12.2.0=h15599e2_0
- hdf4=4.2.15=h2a13503_7
Expand All @@ -92,9 +91,9 @@ dependencies:
- idna=3.11=pyhd8ed1ab_0
- imagecodecs=2026.1.14=py312h40df4bb_1
- imageio=2.37.0=pyhfb79c49_0
- importlib-metadata=8.7.0=pyhe01879c_1
- importlib-metadata=8.8.0=pyhcf101f3_0
- importlib_resources=6.5.2=pyhd8ed1ab_0
- intel-gmmlib=22.9.0=hb700be7_0
- intel-gmmlib=22.10.0=hb700be7_0
- intel-media-driver=25.3.4=hecca717_0
- ipyevents=2.0.4=pyhbbac1ac_0
- ipykernel=7.2.0=pyha191276_1
Expand All @@ -107,7 +106,7 @@ dependencies:
- joblib=1.5.3=pyhd8ed1ab_0
- json5=0.13.0=pyhd8ed1ab_0
- jsoncpp=1.9.6=hf42df4d_1
- jsonpointer=3.0.0=pyhcf101f3_3
- jsonpointer=3.1.1=pyhcf101f3_0
- jsonschema=4.26.0=pyhcf101f3_0
- jsonschema-specifications=2025.9.1=pyhcf101f3_0
- jsonschema-with-format-nongpl=4.26.0=hcf101f3_0
Expand All @@ -132,7 +131,7 @@ dependencies:
- lazy-loader=0.5=pyhd8ed1ab_0
- lazy_loader=0.5=pyhd8ed1ab_0
- lcms2=2.18=h0c24ade_0
- ld_impl_linux-64=2.45.1=default_hbd61a6d_101
- ld_impl_linux-64=2.45.1=default_hbd61a6d_102
- lerc=4.1.0=hdb68285_0
- level-zero=1.28.2=hb700be7_0
- libabseil=20250512.1=cxx17_hba17884_0
Expand All @@ -144,7 +143,7 @@ dependencies:
- libbrotlicommon=1.2.0=hb03c661_1
- libbrotlidec=1.2.0=hb03c661_1
- libbrotlienc=1.2.0=hb03c661_1
- libcap=2.77=h3ff7636_0
- libcap=2.77=hd0affe5_1
- libcblas=3.11.0=5_h0358290_openblas
- libclang-cpp21.1=21.1.0=default_h99862b1_1
- libclang13=21.1.0=default_h746c552_1
Expand All @@ -158,8 +157,8 @@ dependencies:
- libexpat=2.7.4=hecca717_0
- libffi=3.5.2=h3435931_0
- libflac=1.5.0=he200343_1
- libfreetype=2.14.2=ha770c72_0
- libfreetype6=2.14.2=h73754d4_0
- libfreetype=2.14.3=ha770c72_0
- libfreetype6=2.14.3=h73754d4_0
- libgcc=15.2.0=he0feb66_18
- libgcc-ng=15.2.0=h69a702a_18
- libgfortran=15.2.0=h69a702a_18
Expand All @@ -181,7 +180,7 @@ dependencies:
- liblzma=5.8.2=hb03c661_0
- libmicrohttpd=1.0.2=hc2fc477_0
- libnetcdf=4.9.2=nompi_h00e09a9_116
- libnghttp2=1.67.0=had1ee68_0
- libnghttp2=1.68.1=h877daf1_0
- libnsl=2.0.1=hb9d3cd8_1
- libntlm=1.8=hb9d3cd8_0
- libogg=1.3.5=hd0c01bc_1
Expand Down Expand Up @@ -212,11 +211,11 @@ dependencies:
- libssh2=1.11.1=hcf80075_0
- libstdcxx=15.2.0=h934c35e_18
- libstdcxx-ng=15.2.0=hdf11a46_18
- libsystemd0=257.10=hd0affe5_4
- libsystemd0=257.13=hd0affe5_0
- libtasn1=4.21.0=hb03c661_0
- libtheora=1.1.1=h4ab18f5_1006
- libtiff=4.7.1=h9d88235_1
- libudev1=257.10=hd0affe5_4
- libudev1=257.13=hd0affe5_0
- libunistring=0.9.10=h7f98852_0
- libunwind=1.8.3=h65a8314_0
- liburing=2.12=hb700be7_0
Expand All @@ -234,7 +233,7 @@ dependencies:
- libxml2=2.13.9=h04c0eec_0
- libxslt=1.1.43=h7a3aeb2_0
- libzip=1.11.2=h6991a6a_0
- libzlib=1.3.1=hb9d3cd8_2
- libzlib=1.3.2=h25fd6f3_2
- libzopfli=1.0.3=h9c3ff4c_0
- llvmlite=0.46.0=py312h7424e68_0
- loguru=0.7.3=pyh707e725_0
Expand Down Expand Up @@ -270,7 +269,7 @@ dependencies:
- notebook-shim=0.2.4=pyhd8ed1ab_1
- numba=0.64.0=py312hd1dde6f_0
- ocl-icd=2.3.3=hb9d3cd8_0
- opencl-headers=2025.06.13=h5888daf_0
- opencl-headers=2025.06.13=hecca717_0
- openh264=2.6.0=hc22cd8d_0
- openjpeg=2.5.4=h55fea9a_0
- openjph=0.26.3=h8d634f6_0
Expand Down Expand Up @@ -326,7 +325,7 @@ dependencies:
- rav1e=0.7.1=h8fae777_3
- readline=8.3=h853b02a_0
- referencing=0.37.0=pyhcf101f3_0
- requests=2.32.5=pyhcf101f3_1
- requests=2.33.0=pyhcf101f3_0
- rfc3339-validator=0.1.4=pyhd8ed1ab_1
- rfc3986-validator=0.1.1=pyh9f0ad1d_0
- rfc3987-syntax=1.1.0=pyhe01879c_1
Expand Down Expand Up @@ -358,14 +357,14 @@ dependencies:
- tinycss2=1.4.0=pyhd8ed1ab_0
- tk=8.6.13=noxft_h366c992_103
- tomli=2.4.0=pyhcf101f3_0
- tornado=6.5.3=py312h4c3975b_0
- tornado=6.5.5=py312h4c3975b_0
- tqdm=4.67.3=pyh8f84b5b_0
- traitlets=5.14.3=pyhd8ed1ab_1
- trame=3.12.0=pyhd8ed1ab_0
- trame-client=3.11.3=pyhd8ed1ab_0
- trame-common=1.1.2=pyhd8ed1ab_0
- trame-client=3.11.4=pyhd8ed1ab_0
- trame-common=1.1.3=pyhd8ed1ab_0
- trame-server=3.10.0=pyhd8ed1ab_0
- trame-vtk=2.11.1=pyh932262d_0
- trame-vtk=2.11.5=pyh3504b2d_0
- trame-vuetify=3.2.1=pyhd8ed1ab_0
- typing-extensions=4.15.0=h396c80c_0
- typing_extensions=4.15.0=pyhcf101f3_0
Expand All @@ -378,7 +377,7 @@ dependencies:
- vtk=9.3.1=osmesa_py312hf4758c4_116
- vtk-base=9.3.1=osmesa_py312hc9bc066_116
- vtk-io-ffmpeg=9.3.1=osmesa_py312hf4758c4_116
- wayland=1.24.0=hd6090a7_1
- wayland=1.25.0=hd6090a7_0
- wayland-protocols=1.47=hd8ed1ab_0
- wcwidth=0.6.0=pyhd8ed1ab_0
- webcolors=25.10.0=pyhd8ed1ab_0
Expand Down Expand Up @@ -419,7 +418,7 @@ dependencies:
- zeromq=4.3.5=h387f397_9
- zfp=1.0.1=h909a3a2_5
- zipp=3.23.0=pyhcf101f3_1
- zlib=1.3.1=hb9d3cd8_2
- zlib=1.3.2=h25fd6f3_2
- zlib-ng=2.3.3=hceb46e0_1
- zstd=1.5.7=hb78ec9c_6
- pip:
Expand All @@ -435,6 +434,8 @@ dependencies:
- libclang==18.1.1
- markdown==3.10.2
- ml-dtypes==0.5.4
- mne-icalabel==0.8.1
- mpmath==1.3.0
- namex==0.1.0
- numpy==2.1.3
- nvidia-cublas-cu12==12.5.3.2
Expand All @@ -449,15 +450,17 @@ dependencies:
- nvidia-cusparse-cu12==12.5.1.3
- nvidia-nccl-cu12==2.23.4
- nvidia-nvjitlink-cu12==12.5.82
- onnxruntime==1.24.4
- opt-einsum==3.4.0
- optree==0.19.0
- protobuf==5.29.6
- sympy==1.14.0
- tensorboard==2.19.0
- tensorboard-data-server==0.7.2
- tensorflow==2.19.0
- tensorflow-probability==0.25.0
- termcolor==3.3.0
- tf-keras==2.19.0
- werkzeug==3.1.6
- werkzeug==3.1.7
- wrapt==2.1.2
- osl-dynamics
1 change: 1 addition & 0 deletions envs/fsl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ dependencies:
- trame-vtk
- trame-vuetify
- pip:
- mne-icalabel[onnx]
- tensorflow==2.19
- tensorflow-probability[tf]==0.25
Loading
Loading