{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Working with ECoG data\n\n\nMNE supports working with more than just MEG and EEG data. Here we show some\nof the functions that can be used to facilitate working with\nelectrocorticography (ECoG) data.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Eric Larson \n# Chris Holdgraf \n#\n# License: BSD (3-clause)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.io import loadmat\nfrom mayavi import mlab\n\nimport mne\nfrom mne.viz import plot_trans, snapshot_brain_montage\n\nprint(__doc__)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Let's load some ECoG electrode locations and names, and turn them into\na :class:`mne.channels.DigMontage` class.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "mat = loadmat(mne.datasets.misc.data_path() + '/ecog/sample_ecog.mat')\nch_names = mat['ch_names'].tolist()\nelec = mat['elec']\ndig_ch_pos = dict(zip(ch_names, elec))\nmon = mne.channels.DigMontage(dig_ch_pos=dig_ch_pos)\nprint('Created %s channel positions' % len(ch_names))" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Now that we have our electrode positions in MRI coordinates, we can create\nour measurement info structure.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "info = mne.create_info(ch_names, 1000., 'ecog', montage=mon)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "We can then plot the locations of our electrodes on our subject's brain.\n\n

Note

These are not real electrodes for this subject, so they\n do not align to the cortical surface perfectly.

\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "subjects_dir = mne.datasets.sample.data_path() + '/subjects'\nfig = plot_trans(info, trans=None, subject='sample', subjects_dir=subjects_dir)\nmlab.view(200, 70)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Sometimes it is useful to make a scatterplot for the current figure view.\nThis is best accomplished with matplotlib. We can capture an image of the\ncurrent mayavi view, along with the xy position of each electrode, with the\n`snapshot_brain_montage` function.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# We'll once again plot the surface, then take a snapshot.\nfig = plot_trans(info, trans=None, subject='sample', subjects_dir=subjects_dir)\nmlab.view(200, 70)\nxy, im = snapshot_brain_montage(fig, mon)\n\n# Convert from a dictionary to array to plot\nxy_pts = np.vstack(xy[ch] for ch in info['ch_names'])\n\n# Define an arbitrary \"activity\" pattern for viz\nactivity = np.linspace(100, 200, xy_pts.shape[0])\n\n# This allows us to use matplotlib to create arbitrary 2d scatterplots\n_, ax = plt.subplots(figsize=(10, 10))\nax.imshow(im)\nax.scatter(*xy_pts.T, c=activity, s=200, cmap='coolwarm')\nax.set_axis_off()\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" } } } }