{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n\nThe :class:`Info ` data structure\n==============================================\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "from __future__ import print_function\n\nimport mne\nimport os.path as op" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "The :class:`Info ` data object is typically created\nwhen data is imported into MNE-Python and contains details such as:\n\n - date, subject information, and other recording details\n - the sampling rate\n - information about the data channels (name, type, position, etc.)\n - digitized points\n - sensor\u2013head coordinate transformation matrices\n\nand so forth. See the :class:`the API reference `\nfor a complete list of all data fields. Once created, this object is passed\naround throughout the data analysis pipeline.\n\nIt behaves as a nested Python dictionary:\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Read the info object from an example recording\ninfo = mne.io.read_info(\n op.join(mne.datasets.sample.data_path(), 'MEG', 'sample',\n 'sample_audvis_raw.fif'), verbose=False)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "List all the fields in the info object\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "print('Keys in info dictionary:\\n', info.keys())" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Obtain the sampling rate of the data\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "print(info['sfreq'], 'Hz')" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "List all information about the first data channel\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "print(info['chs'][0])" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\nObtaining subsets of channels\n-----------------------------\n\nThere are a number of convenience functions to obtain channel indices, given\nan :class:`mne.Info` object.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "source": [ "Get channel indices by name\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "channel_indices = mne.pick_channels(info['ch_names'], ['MEG 0312', 'EEG 005'])" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Get channel indices by regular expression\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "channel_indices = mne.pick_channels_regexp(info['ch_names'], 'MEG *')" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Get channel indices by type\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "channel_indices = mne.pick_types(info, meg=True) # MEG only\nchannel_indices = mne.pick_types(info, eeg=True) # EEG only" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "MEG gradiometers and EEG channels\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "channel_indices = mne.pick_types(info, meg='grad', eeg=True)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Get a dictionary of channel indices, grouped by channel type\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "channel_indices_by_type = mne.io.pick.channel_indices_by_type(info)\nprint('The first three magnetometers:', channel_indices_by_type['mag'][:3])" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Obtaining information about channels\n------------------------------------\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Channel type of a specific channel\nchannel_type = mne.io.pick.channel_type(info, 75)\nprint('Channel #75 is of type:', channel_type)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Channel types of a collection of channels\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "meg_channels = mne.pick_types(info, meg=True)[:10]\nchannel_types = [mne.io.pick.channel_type(info, ch) for ch in meg_channels]\nprint('First 10 MEG channels are of type:\\n', channel_types)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Dropping channels from an info structure\n----------------------------------------\n\nIt is possible to limit the info structure to only include a subset of\nchannels with the :func:`mne.pick_info` function:\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Only keep EEG channels\neeg_indices = mne.pick_types(info, meg=False, eeg=True)\nreduced_info = mne.pick_info(info, eeg_indices)\n\nprint(reduced_info)" ], "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" } } } }