{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute MNE-dSPM inverse solution on evoked data in volume source space\n\n\nCompute dSPM inverse solution on MNE evoked dataset in a volume source\nspace and stores the solution in a nifti file for visualisation.\n\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\nfrom nilearn.plotting import plot_stat_map\nfrom nilearn.image import index_img\n\nfrom mne.datasets import sample\nfrom mne import read_evokeds\nfrom mne.minimum_norm import apply_inverse, read_inverse_operator\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nfname_inv = data_path + '/MEG/sample/sample_audvis-meg-vol-7-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 = 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\nstc = apply_inverse(evoked, inverse_operator, lambda2, method)\nstc.crop(0.0, 0.2)\n\n# Export result as a 4D nifti object\nimg = stc.as_volume(src,\n mri_resolution=False) # set True for full MRI resolution\n\n# Save it as a nifti file\n# nib.save(img, 'mne_%s_inverse.nii.gz' % method)\n\nt1_fname = data_path + '/subjects/sample/mri/T1.mgz'\n\n# Plotting with nilearn ######################################################\nplot_stat_map(index_img(img, 61), t1_fname, threshold=8.,\n title='%s (t=%.1f s.)' % (method, stc.times[61]))\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" } } } }