{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Extracting the time series of activations in a label\n\n\nWe first apply a dSPM inverse operator to get signed activations in a label\n(with positive and negative values) and we then compare different strategies\nto average the times series in a label. We compare a simple average, with an\naveraging using the dipoles normal (flip mode) and then a PCA,\nalso using a sign flip.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "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)\nmodes = ('mean', 'mean_flip', 'pca_flip')\ntcs = dict()\nfor mode in modes:\n tcs[mode] = stc.extract_label_time_course(label, src, mode=mode)\nprint(\"Number of vertices : %d\" % len(stc_label.data))\n\n# View source activations\nfig, ax = plt.subplots(1)\nt = 1e3 * stc_label.times\nax.plot(t, stc_label.data.T, 'k', linewidth=0.5)\nfor mode, tc in tcs.items():\n ax.plot(t, tc[0], linewidth=3, label=str(mode))\nax.legend(loc='upper right')\nax.set(xlabel='Time (ms)', ylabel='Source amplitude',\n title='Activations in Label : %s' % label)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 0 }