{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Maxwell filter data with movement compensation\n\n\nDemonstrate movement compensation on simulated data. The simulated data\ncontains bilateral activation of auditory cortices, repeated over 14\ndifferent head rotations (head center held fixed). See the following for\ndetails:\n\n https://github.com/mne-tools/mne-misc-data/blob/master/movement/simulate.py\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Eric Larson \n#\n# License: BSD (3-clause)\n\nfrom os import path as op\n\nimport mne\nfrom mne.preprocessing import maxwell_filter\n\nprint(__doc__)\n\ndata_path = op.join(mne.datasets.misc.data_path(verbose=True), 'movement')\n\npos = mne.chpi.read_head_pos(op.join(data_path, 'simulated_quats.pos'))\nraw = mne.io.read_raw_fif(op.join(data_path, 'simulated_movement_raw.fif'))\nraw_stat = mne.io.read_raw_fif(op.join(data_path,\n 'simulated_stationary_raw.fif'))" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Visualize the \"subject\" head movements (traces)\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "mne.viz.plot_head_positions(pos, mode='traces')" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Process our simulated raw data (taking into account head movements)\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# extract our resulting events\nevents = mne.find_events(raw, stim_channel='STI 014')\nevents[:, 2] = 1\nraw.plot(events=events)\n\ntopo_kwargs = dict(times=[0, 0.1, 0.2], ch_type='mag', vmin=-500, vmax=500)\n\n# 0. Take average of stationary data (bilateral auditory patterns)\nevoked_stat = mne.Epochs(raw_stat, events, 1, -0.2, 0.8).average()\nevoked_stat.plot_topomap(title='Stationary', **topo_kwargs)\n\n# 1. Take a naive average (smears activity)\nevoked = mne.Epochs(raw, events, 1, -0.2, 0.8).average()\nevoked.plot_topomap(title='Moving: naive average', **topo_kwargs)\n\n# 2. Use raw movement compensation (restores pattern)\nraw_sss = maxwell_filter(raw, head_pos=pos)\nevoked_raw_mc = mne.Epochs(raw_sss, events, 1, -0.2, 0.8).average()\nevoked_raw_mc.plot_topomap(title='Moving: movement compensated', **topo_kwargs)" ], "outputs": [], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 2", "name": "python2", "language": "python" }, "language_info": { "mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "file_extension": ".py", "version": "2.7.13", "pygments_lexer": "ipython2", "codemirror_mode": { "version": 2, "name": "ipython" } } } }