{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute DICS beamfomer on evoked data\n\n\nCompute a Dynamic Imaging of Coherent Sources (DICS) [1]_ beamformer from\nsingle-trial activity in a time-frequency window to estimate source time\ncourses based on evoked data.\n\nReferences\n----------\n.. [1] Gross et al. Dynamic imaging of coherent sources: Studying neural\n interactions in the human brain. PNAS (2001) vol. 98 (2) pp. 694-699\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Author: Roman Goj \n#\n# License: BSD (3-clause)\n\nimport mne\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom mne.datasets import sample\nfrom mne.time_frequency import csd_epochs\nfrom mne.beamformer import dics\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": [ "Read raw data\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "raw = mne.io.read_raw_fif(raw_fname)\nraw.info['bads'] = ['MEG 2443', 'EEG 053'] # 2 bads channels\n\n# Set picks\npicks = mne.pick_types(raw.info, meg=True, eeg=False, eog=False,\n stim=False, exclude='bads')\n\n# Read epochs\nevent_id, tmin, tmax = 1, -0.2, 0.5\nevents = mne.read_events(event_fname)\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,\n picks=picks, baseline=(None, 0), preload=True,\n reject=dict(grad=4000e-13, mag=4e-12))\nevoked = epochs.average()\n\n# Read forward operator\nforward = mne.read_forward_solution(fname_fwd, surf_ori=True)\n\n# Computing the data and noise cross-spectral density matrices\n# The time-frequency window was chosen on the basis of spectrograms from\n# example time_frequency/plot_time_frequency.py\ndata_csd = csd_epochs(epochs, mode='multitaper', tmin=0.04, tmax=0.15,\n fmin=6, fmax=10)\nnoise_csd = csd_epochs(epochs, mode='multitaper', tmin=-0.11, tmax=0.0,\n fmin=6, fmax=10)\n\nevoked = epochs.average()\n\n# Compute DICS spatial filter and estimate source time courses on evoked data\nstc = dics(evoked, forward, noise_csd, data_csd, reg=0.05)\n\nplt.figure()\nts_show = -30 # show the 40 largest responses\nplt.plot(1e3 * stc.times,\n stc.data[np.argsort(stc.data.max(axis=1))[ts_show:]].T)\nplt.xlabel('Time (ms)')\nplt.ylabel('DICS value')\nplt.title('DICS time course of the 30 largest sources.')\nplt.show()\n\n# Plot brain in 3D with PySurfer if available\nbrain = stc.plot(hemi='rh', subjects_dir=subjects_dir,\n initial_time=0.1, time_unit='s')\nbrain.show_view('lateral')\n\n# Uncomment to save image\n# brain.save_image('DICS_map.png')" ], "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" } } } }