{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n# Compute ICA components on epochs\n\n\nICA is fit to MEG raw data.\nWe assume that the non-stationary EOG artifacts have already been removed.\nThe sources matching the ECG are automatically found and displayed.\n\nNote that this example does quite a bit of processing, so even on a\nfast machine it can take about a minute to complete.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# Authors: Denis Engemann \n#\n# License: BSD (3-clause)\n\nimport mne\nfrom mne.preprocessing import ICA, create_ecg_epochs\nfrom mne.datasets import sample\n\nprint(__doc__)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Read and preprocess the data. Preprocessing consists of:\n\n- meg channel selection\n\n- 1 - 30 Hz band-pass IIR filter\n\n- epoching -0.2 to 0.5 seconds with respect to events\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "data_path = sample.data_path()\nraw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'\n\nraw = mne.io.read_raw_fif(raw_fname, preload=True)\nraw.pick_types(meg=True, eeg=False, exclude='bads', stim=True)\nraw.filter(1, 30)\n\n# longer + more epochs for more artifact exposure\nevents = mne.find_events(raw, stim_channel='STI 014')\nepochs = mne.Epochs(raw, events, event_id=None, tmin=-0.2, tmax=0.5)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Fit ICA model using the FastICA algorithm, detect and plot components\nexplaining ECG artifacts.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "ica = ICA(n_components=0.95, method='fastica').fit(epochs)\n\necg_epochs = create_ecg_epochs(raw, tmin=-.5, tmax=.5)\necg_inds, scores = ica.find_bads_ecg(ecg_epochs)\n\nica.plot_components(ecg_inds)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Plot properties of ECG components:\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "ica.plot_properties(epochs, picks=ecg_inds)" ], "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" } } } }