Skip to content

Instantly share code, notes, and snippets.

@pravsripad
Last active December 29, 2015 04:29
Show Gist options
  • Save pravsripad/7615675 to your computer and use it in GitHub Desktop.
Save pravsripad/7615675 to your computer and use it in GitHub Desktop.
BUG: Calculating evoked ica sources after exclusion.
#!/usr/bin/env python
import matplotlib.pylab as pl
import numpy as np
import mne
from mne.fiff import Raw
from mne.preprocessing.ica import ICA
from mne.datasets import sample
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
raw = Raw(raw_fname, preload=True)
picks = mne.fiff.pick_types(raw.info, meg=True)
tmin, tmax, event_id = -0.2, 0.5, 1
baseline = (None, 0)
reject = None
events = mne.find_events(raw, stim_channel='STI 014')
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=False, picks=picks,
baseline=baseline, preload=True, reject=reject)
ica = ICA(n_components=0.90, n_pca_components=64, max_pca_components=100,
noise_cov=None, random_state=0)
ica.decompose_epochs(epochs)
ica.exclude = [33] # Choosing random pick to exclude
sources = ica.sources_as_raw(raw)
ica_picks = mne.fiff.pick_types(sources.info, misc=True, exclude='bads')
ica_epochs = mne.Epochs(sources, events, event_id, tmin, tmax, picks=ica_picks, preload=True, proj=False)
ica_evoked = ica_epochs.average(ica_picks)
pl.figure()
ica_evoked.plot(titles=dict(misc='ICA sources'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment