{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute source power using DICS beamfomer\n\n\nCompute a Dynamic Imaging of Coherent Sources (DICS) [1]_ filter from\nsingle-trial activity to estimate source power for two frequencies of\ninterest.\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# Denis Engemann \n#\n# License: BSD (3-clause)\n\nimport mne\nfrom mne.datasets import sample\nfrom mne.time_frequency import csd_epochs\nfrom mne.beamformer import dics_source_power\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'\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'] # 1 bad MEG channel\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\n# As fsum is False csd_epochs returns a list of CrossSpectralDensity\n# instances than can then be passed to dics_source_power\ndata_csds = csd_epochs(epochs, mode='multitaper', tmin=0.04, tmax=0.15,\n fmin=15, fmax=30, fsum=False)\nnoise_csds = csd_epochs(epochs, mode='multitaper', tmin=-0.11,\n tmax=-0.001, fmin=15, fmax=30, fsum=False)\n\n# Compute DICS spatial filter and estimate source power\nstc = dics_source_power(epochs.info, forward, noise_csds, data_csds)\n\nfor i, csd in enumerate(data_csds):\n message = 'DICS source power at %0.1f Hz' % csd.frequencies[0]\n brain = stc.plot(surface='inflated', hemi='rh', subjects_dir=subjects_dir,\n time_label=message, figure=i)\n brain.set_data_time_index(i)\n brain.show_view('lateral')\n # Uncomment line below to save images\n # brain.save_image('DICS_source_power_freq_%d.png' % csd.frequencies[0])" ], "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" } } } }