{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute LCMV beamformer on evoked data\n\n\nCompute LCMV beamformer solutions on an evoked dataset for three different\nchoices of source orientation and store the solutions in stc files for\nvisualisation.\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\nimport numpy as np\n\nimport mne\nfrom mne.datasets import sample\nfrom mne.beamformer import lcmv\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nraw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'\nevent_fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'\nfname_fwd = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif'\nlabel_name = 'Aud-lh'\nfname_label = data_path + '/MEG/sample/labels/%s.label' % label_name\nsubjects_dir = data_path + '/subjects'" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Get epochs\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "event_id, tmin, tmax = 1, -0.2, 0.5\n\n# Setup for reading the raw data\nraw = mne.io.read_raw_fif(raw_fname, preload=True)\nraw.info['bads'] = ['MEG 2443', 'EEG 053'] # 2 bads channels\nevents = mne.read_events(event_fname)\n\n# Set up pick list: EEG + MEG - bad channels (modify to your needs)\nleft_temporal_channels = mne.read_selection('Left-temporal')\npicks = mne.pick_types(raw.info, meg=True, eeg=False, stim=True, eog=True,\n exclude='bads', selection=left_temporal_channels)\n\n# Pick the channels of interest\nraw.pick_channels([raw.ch_names[pick] for pick in picks])\n# Re-normalize our empty-room projectors, so they are fine after subselection\nraw.info.normalize_proj()\n\n# Read epochs\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax,\n baseline=(None, 0), preload=True, proj=True,\n reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))\nevoked = epochs.average()\n\nforward = mne.read_forward_solution(fname_fwd, surf_ori=True)\n\n# Compute regularized noise and data covariances\nnoise_cov = mne.compute_covariance(epochs, tmin=tmin, tmax=0, method='shrunk')\ndata_cov = mne.compute_covariance(epochs, tmin=0.04, tmax=0.15,\n method='shrunk')\n\nplt.close('all')\n\npick_oris = [None, 'normal', 'max-power']\nnames = ['free', 'normal', 'max-power']\ndescriptions = ['Free orientation', 'Normal orientation', 'Max-power '\n 'orientation']\ncolors = ['b', 'k', 'r']\n\nfor pick_ori, name, desc, color in zip(pick_oris, names, descriptions, colors):\n stc = lcmv(evoked, forward, noise_cov, data_cov, reg=0.05,\n pick_ori=pick_ori)\n\n # View activation time-series\n label = mne.read_label(fname_label)\n stc_label = stc.in_label(label)\n plt.plot(1e3 * stc_label.times, np.mean(stc_label.data, axis=0), color,\n hold=True, label=desc)\n\nplt.xlabel('Time (ms)')\nplt.ylabel('LCMV value')\nplt.ylim(-0.8, 2.2)\nplt.title('LCMV in %s' % label_name)\nplt.legend()\nplt.show()\n\n# Plot last stc in the brain in 3D with PySurfer if available\nbrain = stc.plot(hemi='lh', subjects_dir=subjects_dir,\n initial_time=0.1, time_unit='s')\nbrain.show_view('lateral')" ], "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" } } } }