{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Morph source estimates from one subject to another subject\n\n\nA source estimate from a given subject 'sample' is morphed\nto the anatomy of another subject 'fsaverage'. The output\nis a source estimate defined on the anatomy of 'fsaverage'\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Alexandre Gramfort \n# Eric Larson \n#\n# License: BSD (3-clause)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nimport mne\nfrom mne.datasets import sample\n\nprint(__doc__)\n\ndata_path = sample.data_path()\n\nsubject_from = 'sample'\nsubject_to = 'fsaverage'\nsubjects_dir = data_path + '/subjects'\n\nfname = data_path + '/MEG/sample/sample_audvis-meg'\n\n# Read input stc file\nstc_from = mne.read_source_estimate(fname)\n# Morph using one method (supplying the vertices in fsaverage's source\n# space makes it faster). Note that for any generic subject, you could do:\n# vertices_to = mne.grade_to_vertices(subject_to, grade=5)\n# But fsaverage's source space was set up so we can just do this:\nvertices_to = [np.arange(10242), np.arange(10242)]\nstc_to = mne.morph_data(subject_from, subject_to, stc_from, n_jobs=1,\n grade=vertices_to, subjects_dir=subjects_dir)\nstc_to.save('%s_audvis-meg' % subject_to)\n\n# Morph using another method -- useful if you're going to do a lot of the\n# same inter-subject morphing operations; you could save and load morph_mat\nmorph_mat = mne.compute_morph_matrix(subject_from, subject_to,\n stc_from.vertices, vertices_to,\n subjects_dir=subjects_dir)\nstc_to_2 = mne.morph_data_precomputed(subject_from, subject_to,\n stc_from, vertices_to, morph_mat)\nstc_to_2.save('%s_audvis-meg_2' % subject_to)\n\n# View source activations\nplt.plot(stc_from.times, stc_from.data.mean(axis=0), 'r', label='from')\nplt.plot(stc_to.times, stc_to.data.mean(axis=0), 'b', label='to')\nplt.plot(stc_to_2.times, stc_to.data.mean(axis=0), 'g', label='to_2')\nplt.xlabel('time (ms)')\nplt.ylabel('Mean Source amplitude')\nplt.legend()\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" } } } }