{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Extracting the time series of activations in a label\n\n\nWe first apply a dSPM inverse operator to get signed activations\nin a label (with positive and negative values) and we then\ncompare different strategies to average the times series\nin a label. We compare a simple average, with an averaging\nusing the dipoles normal (flip mode) and then a PCA,\nalso using a sign flip.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Author: Alexandre Gramfort \n#\n# License: BSD (3-clause)\n\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne.datasets import sample\nfrom mne.minimum_norm import read_inverse_operator, apply_inverse\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nlabel = 'Aud-lh'\nlabel_fname = data_path + '/MEG/sample/labels/%s.label' % label\nfname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'\nfname_evoked = data_path + '/MEG/sample/sample_audvis-ave.fif'\n\nsnr = 3.0\nlambda2 = 1.0 / snr ** 2\nmethod = \"dSPM\" # use dSPM method (could also be MNE or sLORETA)\n\n# Load data\nevoked = mne.read_evokeds(fname_evoked, condition=0, baseline=(None, 0))\ninverse_operator = read_inverse_operator(fname_inv)\nsrc = inverse_operator['src']\n\n# Compute inverse solution\npick_ori = \"normal\" # Get signed values to see the effect of sign filp\nstc = apply_inverse(evoked, inverse_operator, lambda2, method,\n pick_ori=pick_ori)\n\nlabel = mne.read_label(label_fname)\n\nstc_label = stc.in_label(label)\nmean = stc.extract_label_time_course(label, src, mode='mean')\nmean_flip = stc.extract_label_time_course(label, src, mode='mean_flip')\npca = stc.extract_label_time_course(label, src, mode='pca_flip')\n\nprint(\"Number of vertices : %d\" % len(stc_label.data))\n\n# View source activations\nplt.figure()\nplt.plot(1e3 * stc_label.times, stc_label.data.T, 'k', linewidth=0.5)\nh0, = plt.plot(1e3 * stc_label.times, mean.T, 'r', linewidth=3)\nh1, = plt.plot(1e3 * stc_label.times, mean_flip.T, 'g', linewidth=3)\nh2, = plt.plot(1e3 * stc_label.times, pca.T, 'b', linewidth=3)\nplt.legend([h0, h1, h2], ['mean', 'mean flip', 'PCA flip'])\nplt.xlabel('Time (ms)')\nplt.ylabel('Source amplitude')\nplt.title('Activations in Label : %s' % label)\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" } } } }