{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Extracting time course from source_estimate object\n\n\nLoad a SourceEstimate object from stc files and\nextract the time course of activation in\nindividual labels, as well as in a complex label\nformed through merging two labels.\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Author: Christian Brodbeck \n#\n# License: BSD (3-clause)\n\nimport os\n\nimport mne\nfrom mne.datasets import sample\nimport matplotlib.pyplot as plt\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nos.environ['SUBJECTS_DIR'] = data_path + '/subjects'\nmeg_path = data_path + '/MEG/sample'\n\n# load the stc\nstc = mne.read_source_estimate(meg_path + '/sample_audvis-meg')\n\n# load the labels\naud_lh = mne.read_label(meg_path + '/labels/Aud-lh.label')\naud_rh = mne.read_label(meg_path + '/labels/Aud-rh.label')\n\n# extract the time course for different labels from the stc\nstc_lh = stc.in_label(aud_lh)\nstc_rh = stc.in_label(aud_rh)\nstc_bh = stc.in_label(aud_lh + aud_rh)\n\n# calculate center of mass and transform to mni coordinates\nvtx, _, t_lh = stc_lh.center_of_mass('sample')\nmni_lh = mne.vertex_to_mni(vtx, 0, 'sample')[0]\nvtx, _, t_rh = stc_rh.center_of_mass('sample')\nmni_rh = mne.vertex_to_mni(vtx, 1, 'sample')[0]\n\n# plot the activation\nplt.figure()\nplt.axes([.1, .275, .85, .625])\nhl = plt.plot(stc.times, stc_lh.data.mean(0), 'b')[0]\nhr = plt.plot(stc.times, stc_rh.data.mean(0), 'g')[0]\nhb = plt.plot(stc.times, stc_bh.data.mean(0), 'r')[0]\nplt.xlabel('Time (s)')\nplt.ylabel('Source amplitude (dSPM)')\nplt.xlim(stc.times[0], stc.times[-1])\n\n# add a legend including center-of-mass mni coordinates to the plot\nlabels = ['LH: center of mass = %s' % mni_lh.round(2),\n 'RH: center of mass = %s' % mni_rh.round(2),\n 'Combined LH & RH']\nplt.figlegend([hl, hr, hb], labels, 'lower center')\nplt.suptitle('Average activation in auditory cortex labels', fontsize=20)\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" } } } }