mne group analysis presentation @ biomag 2016 conf

67
How to perform MEG group analysis with MNE MNE software for processing MEG and EEG data, A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier, C. Brodbeck, L. Parkkonen, M. Hämäläinen, Neuroimage, 2014 MEG and EEG data analysis with MNE-Python, A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier, C. Brodbeck, R. Goj, M. Jas, T. Brooks, L. Parkkonen, M. Hämäläinen, Frontiers in Neuroscience, 2013 Biomag 2016 http://www.biomag2016.org/satellite_meetings2.php http://martinos.org/mne

Upload: agramfort

Post on 23-Jan-2018

1.295 views

Category:

Science


0 download

TRANSCRIPT

Page 1: MNE group analysis presentation @ Biomag 2016 conf

How to perform MEG group analysis with MNE

MNE software for processing MEG and EEG data, A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier, C. Brodbeck, L. Parkkonen, M. Hämäläinen, Neuroimage, 2014MEG and EEG data analysis with MNE-Python, A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier, C. Brodbeck, R. Goj, M. Jas, T. Brooks, L. Parkkonen, M. Hämäläinen, Frontiers in Neuroscience, 2013

Biomag 2016http://www.biomag2016.org/satellite_meetings2.php

http://martinos.org/mne

Page 2: MNE group analysis presentation @ Biomag 2016 conf

• MNE based on C code developed for ~15 years by MSH• MNE-Python started ~6 years ago at MGH, Boston

About the project

Source: https://www.ohloh.net/p/MNE

Page 3: MNE group analysis presentation @ Biomag 2016 conf

http://martinos.org/mne/

Page 4: MNE group analysis presentation @ Biomag 2016 conf

http://mne-tools.github.io/mne-biomag-group-demo/

Page 5: MNE group analysis presentation @ Biomag 2016 conf

People behind this work

@agramfort @dengemann

@jasmainak

http://martinos.org/mne/stable/whats_new.html@jaeilepp

@Eric89GXL

Page 7: MNE group analysis presentation @ Biomag 2016 conf

MNE People

https://github.com/mne-tools/mne-python/graphs/contributors

Alan Leggitt, Alexander Rudiuk, Alexandre Barachant, Alexandre Gramfort, Andrew Dykstra, Asish Panda, Basile Pinsard, Brad Buran, Camilo Lamus, Cathy Nangini, Chris Holdgraf, Christian Brodbeck, Christoph Dinh, Christopher J. Bailey, Christopher Mullins, Clemens Brunner, Clément Moutard, Dan G. Wakeman, Daniel McCloy, Daniel Strohmeier, Denis A. Engemann, Emanuele Olivetti, Emily Ruzich, Emily Stephen, Eric Larson, Fede Raimondo, Federico Raimondo, Félix Raimundo, Guillaume Dumas, Hafeza Anevar, Hari Bharadwaj, Ingoo Lee, Jaakko Leppakangas, Jair Montoya, Jean-Remi King, Johannes Niediek, Jona Sassenhagen, Jussi Nurminen, Kambiz Tavabi, Keith Doelling, Lorenzo De Santis, Louis Thibault, Luke Bloy, Mads Jensen, Mainak Jas, Manfred Kitzbichler, Manoj Kumar, Marian Dovgialo, Marijn van Vliet, Mark Wronkiewicz, Marmaduke Woodman, Martin Billinger, Martin Luessi, Matt Tucker, Matti Hamalainen, Michael Krause, Mikolaj Magnuski, Natalie Klein, Nick Foti, Nick Ward, Niklas Wilming, Olaf Hauk, Phillip Alday, Praveen Sripad, Richard Höchenberger, Roan LaPlante, Romain Trachel, Roman Goj, Ross Maddox, Sagun Pai, Saket Choudhary, Simon Kornblith, Simon-Shlomo Poil, Sourav Singh, Tal Linzen, Tanay, Teon Brooks, Tom Dupré la Tour, Yaroslav Halchenko, Yousra Bekhti, Ellen Lau, Mads Jensen !

Page 8: MNE group analysis presentation @ Biomag 2016 conf

https://github.com/mne-tools/mne-biomag-group-demo/

Get the code to replicate

Page 9: MNE group analysis presentation @ Biomag 2016 conf

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/index.html

Analysis Scripts

Page 10: MNE group analysis presentation @ Biomag 2016 conf

One script

Page 11: MNE group analysis presentation @ Biomag 2016 conf
Page 12: MNE group analysis presentation @ Biomag 2016 conf

.../mne-biomag-group-demo/tree/master/scripts/processing

Fetch data from OpenfMRI

Sensor space analysis

Source space analysis

Anatomical pipeline

Page 13: MNE group analysis presentation @ Biomag 2016 conf

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/index.html

Results at group level

Page 14: MNE group analysis presentation @ Biomag 2016 conf

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/index.html

Demos and results for each

subject

Page 15: MNE group analysis presentation @ Biomag 2016 conf

Installing MNE-Python

$ pip install --upgrade --user mne

Install Scientific Python environment, e.g., Anaconda at

http://martinos.org/mne/stable/install_mne_python.html

https://www.continuum.io/downloads

Install MNE-Python:

Page 16: MNE group analysis presentation @ Biomag 2016 conf

.../mne-biomag-group-demo/tree/master/scripts/processing

Fetch data from OpenfMRI

Sensor space analysis

Source space analysis

Anatomical pipeline

Page 17: MNE group analysis presentation @ Biomag 2016 conf

Built on top of FreeSurfer$ recon-all -s ${SUBJECT} -i xy000000.nii -all

http://surfer.nmr.mgh.harvard.edu/

Page 18: MNE group analysis presentation @ Biomag 2016 conf

Anatomy workflow

MRI data

MRI data reconstructedrecon-all (Freesurfer 5.1)

BEM meshmne watershed_bemor mne flash_bem

BEM model

MEG/EEG data

Forward solutionor gain matrix

not automatic

needs freesurfer

Coregistrationmne_analyze/mrilab/Python

Page 19: MNE group analysis presentation @ Biomag 2016 conf

BEM meshes

http://martinos.org/mne/stable/auto_tutorials/plot_forward.html

Page 20: MNE group analysis presentation @ Biomag 2016 conf

BEM meshes

>>> for subject_id in range(1, 20):>>> subject = "sub%03d" % subject_id>>> mne.bem.make_watershed_bem(subject, >>> subjects_dir=subjects_dir,>>> overwrite=True)

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/11-make_watershed.html

Page 21: MNE group analysis presentation @ Biomag 2016 conf

Preprocessing: From raw to ERP/ERFdrifts blinks

line noise

cardiac

10 seconds filtered data clean data using SSPs

Preprocessingto get cleanevoked data(ERF/ERP)

or ICA

Page 22: MNE group analysis presentation @ Biomag 2016 conf

Maxwell filtering

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_maxfilter.html

MNE implements maxfilter (TM)

Page 23: MNE group analysis presentation @ Biomag 2016 conf

Maxwell filtering

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_maxfilter.html

MNE implements maxfilter (TM)

Page 24: MNE group analysis presentation @ Biomag 2016 conf

Maxwell filtering

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_maxfilter.html

MNE implements maxfilter (TM)

Page 25: MNE group analysis presentation @ Biomag 2016 conf

.../mne-biomag-group-demo/tree/master/scripts/processing

Fetch data from OpenfMRI

Sensor space analysis

Source space analysis

Page 26: MNE group analysis presentation @ Biomag 2016 conf

Filtering

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_analysis_1.html

Page 27: MNE group analysis presentation @ Biomag 2016 conf

Filtering

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_analysis_1.html

Page 28: MNE group analysis presentation @ Biomag 2016 conf

Code for filtering

>>> for subject_id in range(1, 20):>>> subject = "sub%03d" % subject_id>>> for run in range(1, 7):>>> raw_in = ...>>> raw = mne.io.read_raw_fif(raw_in, preload=True, add_eeg_ref=False)>>> raw.filter(1, 40, l_trans_bandwidth=0.5, h_trans_bandwidth='auto',>>> filter_length='auto', phase='zero', fir_window='hann')

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/02-python_filtering.html

Page 29: MNE group analysis presentation @ Biomag 2016 conf

Filter design

http://martinos.org/mne/stable/auto_tutorials/plot_background_filtering.html

Page 30: MNE group analysis presentation @ Biomag 2016 conf

Filter design

High pass filtering removes slow drifts and can make baselining unnecessary… yet the story is not that simple

http://martinos.org/mne/stable/auto_tutorials/plot_background_filtering.html

Page 31: MNE group analysis presentation @ Biomag 2016 conf

Paradigm

Presentation Screen

Famous

Unfamiliar

Scrambled

Page 32: MNE group analysis presentation @ Biomag 2016 conf

Paradigm on trigger channel

>>> mask = 4096 + 256 # mask for excluding high order bits>>> events = mne.find_events(raw, stim_channel='STI101',>>> consecutive='increasing', mask=mask,>>> mask_type='not_and', min_duration=0.003)>>> fig = mne.viz.plot_events(events)

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/03-run_extract_events.html

Page 33: MNE group analysis presentation @ Biomag 2016 conf

Paradigm in code

>>> events_id = {>>> 'face/famous/first': 5,>>> 'face/famous/immediate': 6,>>> 'face/famous/long': 7,>>> 'face/unfamiliar/first': 13,>>> 'face/unfamiliar/immediate': 14,>>> 'face/unfamiliar/long': 15,>>> 'scrambled/first': 17,>>> 'scrambled/immediate': 18,>>> 'scrambled/long': 19,>>> }

Use “tags” to describe events

Page 34: MNE group analysis presentation @ Biomag 2016 conf

From Epochs to Evoked

>>> tmin, tmax = -0.2, 0.8>>> reject = dict(grad=4000e-13, mag=4e-12, eog=180e-6)>>> baseline = None>>>>>> epochs = mne.Epochs(raw, events, events_id, tmin, tmax,

proj=True, picks=picks, baseline=baseline, preload=True, decim=2, reject=reject, add_eeg_ref=False)

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/05-make_epochs.html

…reject the ones with blinks

Page 35: MNE group analysis presentation @ Biomag 2016 conf

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_analysis_1.html

why did we drop epochs?Example of “drop log” for subject 1:

Page 36: MNE group analysis presentation @ Biomag 2016 conf

Use ICA on Epochs to remove ECG>>> ica_name = op.join(meg_dir, subject, 'run_%02d-ica.fif' % run)>>> ica = read_ica(ica_name)>>> n_max_ecg = 3 # use max 3 components>>> ecg_epochs = create_ecg_epochs(raw, tmin=-.5, tmax=.5)>>> ecg_inds, scores_ecg = ica.find_bads_ecg(ecg_epochs, method='ctps',

threshold=0.8)>>> ica.exclude += ecg_inds[:n_max_ecg]>>> ica.apply(epochs)

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_ica.html

Page 37: MNE group analysis presentation @ Biomag 2016 conf

Use ICA on Epochs to remove ECG

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_ica.html

Page 38: MNE group analysis presentation @ Biomag 2016 conf

Fit and apply ICA on Epochs

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_ica.html

Page 39: MNE group analysis presentation @ Biomag 2016 conf

From Epochs to Evoked

>>> evoked_faces = epochs['face'].average()>>> evoked_famous = epochs['face/famous'].average()>>> evoked_scrambled = epochs['scrambled'].average()>>> evoked_unfamiliar = epochs[‘face/unfamiliar'].average()>>> contrast = mne.combine_evoked([evoked_famous, >>> evoked_unfamiliar,>>> evoked_scrambled], >>> weights=[0.5, 0.5, -1.])>>> mne.evoked.write_evokeds('%s-ave.fif' % subject, [evoked_famous, evoked_scrambled, evoked_unfamiliar, contrast,

faces])

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/06-make_evoked.html

Index Epochs with tags

Page 40: MNE group analysis presentation @ Biomag 2016 conf

EEG Evoked for 3 first subjects

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_compare.html

Page 41: MNE group analysis presentation @ Biomag 2016 conf

EEG Evoked topographies (6 subjects)

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_compare.html

Page 42: MNE group analysis presentation @ Biomag 2016 conf

MEG Evoked for 3 first subjects

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_compare.html

Page 43: MNE group analysis presentation @ Biomag 2016 conf

MEG Evoked for 3 first subjects

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_compare.html

Page 44: MNE group analysis presentation @ Biomag 2016 conf

Back to filtering…

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_fanning.html

>>> raw.filter(None, 40, fir_window='hann', phase='zero', h_trans_bandwidth=‘auto’, filter_length='auto')

Page 45: MNE group analysis presentation @ Biomag 2016 conf

Back to filtering…

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_fanning.html

>>> raw.filter(None, 40, fir_window='hann', phase='zero', h_trans_bandwidth=‘auto’, filter_length='auto')

Fanningproblem

Page 46: MNE group analysis presentation @ Biomag 2016 conf

Much lessfanning

Back to filtering…

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_fanning.html

>>> raw.filter(1, None, l_trans_bandwidth=0.5, fir_window='hann', phase='zero',

h_trans_bandwidth=‘auto’, filter_length='auto')

Page 47: MNE group analysis presentation @ Biomag 2016 conf

Covariance est. and whitening

Engemann, D.A., Gramfort, A., Automated model selection in covariance estimation and spatial whitening of MEG and EEG signals., Neuroimage 2015

>>> cov = mne.compute_covariance(epochs, tmax=0, method='shrunk')

Page 48: MNE group analysis presentation @ Biomag 2016 conf

Covariance est. and whitening

>>> cov = mne.compute_covariance(epochs, tmax=0, method='shrunk')

whitened Global Field Power

whitened ERF

whitened ERP

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_analysis_1.html

Page 49: MNE group analysis presentation @ Biomag 2016 conf

Grand averaging

>>> for idx, evokeds in enumerate(all_evokeds):>>> # Combine subjects:>>> grand_avg[idx] = mne.combine_evoked(evokeds, 'equal')

>>> mapping = {'Famous': evokeds[0], 'Scrambled': evokeds[1], 'Unfamiliar': evokeds[2]}>>> mne.viz.plot_compare_evokeds(mapping, [idx])

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_group.html

Page 50: MNE group analysis presentation @ Biomag 2016 conf

Grand averaging

>>> for idx, evokeds in enumerate(all_evokeds):>>> # Combine subjects:>>> grand_avg[idx] = mne.combine_evoked(evokeds, 'equal')

>>> mapping = {'Famous': evokeds[0], 'Scrambled': evokeds[1], 'Unfamiliar': evokeds[2]}>>> mne.viz.plot_compare_evokeds(mapping, [idx])

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_group.html

From baseline to baseline !

Page 51: MNE group analysis presentation @ Biomag 2016 conf

MNE vs. Wakeman et al.

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_group.html

Page 52: MNE group analysis presentation @ Biomag 2016 conf

MNE vs. Wakeman et al.

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_group.html

Real?

Page 53: MNE group analysis presentation @ Biomag 2016 conf

Sensors stats (cluster level)

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_sensor_cluster_stats_eeg_channel.html

Page 54: MNE group analysis presentation @ Biomag 2016 conf

Sensors stats (cluster level)

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_sensor_spatio_temporal_cluster_stats.html

p = 0.01 (corrected)

Page 55: MNE group analysis presentation @ Biomag 2016 conf

Decoding

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_time_decoding.html

>>> td = TimeDecoding(predict_mode='cross-validation', times=times, scorer='roc_auc')>>> td.fit(epochs, y)

http://mne-tools.github.io/mne-biomag-group-demo/auto_scripts/08-run_time_decoding.html

Page 56: MNE group analysis presentation @ Biomag 2016 conf

Source space analysis

• 3 Layers BEM forward modeling

• dSPM source localization on cortical surface

• loose orientation (0.2) & depth (0.8) & SNR = 3

• RMS across orientations

• morphing to fsaverage:subject fsaveragemorphing

… the MNE (default) way

Page 57: MNE group analysis presentation @ Biomag 2016 conf

Source space analysis

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_analysis_2.html

Subject 2Contrast

localization (faces vs.

scrambled

Page 58: MNE group analysis presentation @ Biomag 2016 conf

Source space group analysis

http://mne-tools.github.io/mne-biomag-group-demo/auto_examples/plot_group.html

16 subjectsaverage ofContrast (faces vs.

scrambled

Page 59: MNE group analysis presentation @ Biomag 2016 conf

MNE web report

http://perso.telecom-paristech.fr/~mjas/biomag_demo/report_sub002.html

Page 60: MNE group analysis presentation @ Biomag 2016 conf

MNE web report

http://perso.telecom-paristech.fr/~mjas/biomag_demo/report_sub002.html

Command line:$ mne report --path MEG/sub002 --info MEG/sub002/run_01_filt_sss-epo.fif --subject sub002 --subjects-dir subjects/ --verbose --jobs 6

Page 61: MNE group analysis presentation @ Biomag 2016 conf

Getting help http://martinos.org/mne/

http://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysisMailing list:

Page 62: MNE group analysis presentation @ Biomag 2016 conf

Getting inspired...http://martinos.org/mne/auto_examples/index.html

Page 63: MNE group analysis presentation @ Biomag 2016 conf

Sending feedbackhttps://github.com/mne-tools/mne-python

Page 64: MNE group analysis presentation @ Biomag 2016 conf

Some links• Documentation:

• http://martinos.org/mne/ (general doc)

• http://martinos.org/mne/stable/manual/index.html (manual)

• http://martinos.org/mne/stable/tutorials.html (tutorials with code)

• http://martinos.org/mne/auto_examples/index.html (python examples)

• Code:

• https://github.com/mne-tools/mne-python (mne-python code)

• https://github.com/mne-tools/mne-matlab (mne matlab toolbox)

• https://github.com/mne-tools/mne-scripts (mne shell scripts)

Page 65: MNE group analysis presentation @ Biomag 2016 conf

Access HCP-MEG data as MNE-Python data structures

https:/mne-tools.github.io/mne-hcp

Page 66: MNE group analysis presentation @ Biomag 2016 conf

Seamlessly plug HCP MEG data into the Python ecosystem

…/mne-hcp/auto_tutorials/index.html

Poster

[Mo-P008]

Engemann et al.

Page 67: MNE group analysis presentation @ Biomag 2016 conf

Alexandre Gramforthttp://alexandre.gramfort.netContact:

GitHub : @agramfort Twitter : @agramfort

If you want a sticker come to the

MNE poster !

OpenScience!