{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute induced power in the source space with dSPM\n\n\nReturns STC files ie source estimates of induced power\nfor different bands in the source space. The inverse method\nis linear based on dSPM inverse operator.\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Alexandre Gramfort \n#\n# License: BSD (3-clause)\n\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne import io\nfrom mne.datasets import sample\nfrom mne.minimum_norm import read_inverse_operator, source_band_induced_power\n\nprint(__doc__)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Set parameters\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "data_path = sample.data_path()\nraw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'\nfname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'\ntmin, tmax, event_id = -0.2, 0.5, 1\n\n# Setup for reading the raw data\nraw = io.read_raw_fif(raw_fname)\nevents = mne.find_events(raw, stim_channel='STI 014')\ninverse_operator = read_inverse_operator(fname_inv)\n\ninclude = []\nraw.info['bads'] += ['MEG 2443', 'EEG 053'] # bads + 2 more\n\n# picks MEG gradiometers\npicks = mne.pick_types(raw.info, meg=True, eeg=False, eog=True,\n stim=False, include=include, exclude='bads')\n\n# Load condition 1\nevent_id = 1\nevents = events[:10] # take 10 events to keep the computation time low\n# Use linear detrend to reduce any edge artifacts\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,\n baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6),\n preload=True, detrend=1)\n\n# Compute a source estimate per frequency band\nbands = dict(alpha=[9, 11], beta=[18, 22])\n\nstcs = source_band_induced_power(epochs, inverse_operator, bands, n_cycles=2,\n use_fft=False, n_jobs=1)\n\nfor b, stc in stcs.items():\n stc.save('induced_power_%s' % b)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "plot mean power\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "plt.plot(stcs['alpha'].times, stcs['alpha'].data.mean(axis=0), label='Alpha')\nplt.plot(stcs['beta'].times, stcs['beta'].data.mean(axis=0), label='Beta')\nplt.xlabel('Time (ms)')\nplt.ylabel('Power')\nplt.legend()\nplt.title('Mean source induced power')\nplt.show()" ], "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" } } } }