Demonstrate movement compensation on simulated data. The simulated data contains bilateral activation of auditory cortices, repeated over 14 different head rotations (head center held fixed). See the following for details:
# Authors: Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD (3-clause)
from os import path as op
import mne
from mne.preprocessing import maxwell_filter
print(__doc__)
data_path = op.join(mne.datasets.misc.data_path(verbose=True), 'movement')
pos = mne.chpi.read_head_pos(op.join(data_path, 'simulated_quats.pos'))
raw = mne.io.read_raw_fif(op.join(data_path, 'simulated_movement_raw.fif'))
raw_stat = mne.io.read_raw_fif(op.join(data_path,
'simulated_stationary_raw.fif'))
Out:
Overwriting existing file.
Opening raw data file /home/ubuntu/mne_data/MNE-misc-data/movement/simulated_movement_raw.fif...
Current compensation grade : 0
Range : 25800 ... 34208 = 42.956 ... 56.955 secs
Ready.
Opening raw data file /home/ubuntu/mne_data/MNE-misc-data/movement/simulated_stationary_raw.fif...
Current compensation grade : 0
Range : 25800 ... 34208 = 42.956 ... 56.955 secs
Ready.
Process our simulated raw data (taking into account head movements)
# extract our resulting events
events = mne.find_events(raw, stim_channel='STI 014')
events[:, 2] = 1
raw.plot(events=events)
topo_kwargs = dict(times=[0, 0.1, 0.2], ch_type='mag', vmin=-500, vmax=500)
# 0. Take average of stationary data (bilateral auditory patterns)
evoked_stat = mne.Epochs(raw_stat, events, 1, -0.2, 0.8).average()
evoked_stat.plot_topomap(title='Stationary', **topo_kwargs)
# 1. Take a naive average (smears activity)
evoked = mne.Epochs(raw, events, 1, -0.2, 0.8).average()
evoked.plot_topomap(title='Moving: naive average', **topo_kwargs)
# 2. Use raw movement compensation (restores pattern)
raw_sss = maxwell_filter(raw, head_pos=pos)
evoked_raw_mc = mne.Epochs(raw_sss, events, 1, -0.2, 0.8).average()
evoked_raw_mc.plot_topomap(title='Moving: movement compensated', **topo_kwargs)
Out:
14 events found
Events id: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
14 matching events found
Applying baseline correction (mode: mean)
0 projection items activated
14 matching events found
Applying baseline correction (mode: mean)
0 projection items activated
Maxwell filtering raw data
Appending head position result channels and loading raw data from disk
No bad MEG channels
Processing 203 gradiometers and 102 magnetometers
Automatic origin fit: head of radius 91.0 mm
Using origin -4.1, 16.0, 51.7 mm in the head frame
Computing regularization
Resulting information: 462.4 bits/sample (98.3% of peak 470.1)
Using 75/80 inside and 15/15 outside harmonic components
Processing 1 data chunk of (at least) 10.0 sec
Used 14 head positions for 0.00 - 14.00 sec
[done]
14 matching events found
Applying baseline correction (mode: mean)
0 projection items activated
Total running time of the script: (0 minutes 9.175 seconds)
plot_movement_compensation.py
plot_movement_compensation.ipynb