本文整理汇总了Python中mne.preprocessing.ICA.plot_overlay方法的典型用法代码示例。如果您正苦于以下问题:Python ICA.plot_overlay方法的具体用法?Python ICA.plot_overlay怎么用?Python ICA.plot_overlay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.preprocessing.ICA
的用法示例。
在下文中一共展示了ICA.plot_overlay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_plot_ica_overlay
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
def test_plot_ica_overlay():
"""Test plotting of ICA cleaning."""
import matplotlib.pyplot as plt
raw = _get_raw(preload=True)
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
# can't use info.normalize_proj here because of how and when ICA and Epochs
# objects do picking of Raw data
with pytest.warns(RuntimeWarning, match='projection'):
ica.fit(raw, picks=picks)
# don't test raw, needs preload ...
with pytest.warns(RuntimeWarning, match='projection'):
ecg_epochs = create_ecg_epochs(raw, picks=picks)
ica.plot_overlay(ecg_epochs.average())
with pytest.warns(RuntimeWarning, match='projection'):
eog_epochs = create_eog_epochs(raw, picks=picks)
ica.plot_overlay(eog_epochs.average())
pytest.raises(TypeError, ica.plot_overlay, raw[:2, :3][0])
ica.plot_overlay(raw)
plt.close('all')
# smoke test for CTF
raw = read_raw_fif(raw_ctf_fname)
raw.apply_gradient_compensation(3)
picks = pick_types(raw.info, meg=True, ref_meg=False)
ica = ICA(n_components=2, max_pca_components=3, n_pca_components=3)
ica.fit(raw, picks=picks)
with pytest.warns(RuntimeWarning, match='longer than'):
ecg_epochs = create_ecg_epochs(raw)
ica.plot_overlay(ecg_epochs.average())
plt.close('all')
示例2: test_plot_ica_overlay
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
def test_plot_ica_overlay():
"""Test plotting of ICA cleaning
"""
raw = _get_raw()
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
ica.fit(raw, picks=picks)
# don't test raw, needs preload ...
ecg_epochs = create_ecg_epochs(raw, picks=picks)
ica.plot_overlay(ecg_epochs.average())
eog_epochs = create_eog_epochs(raw, picks=picks)
ica.plot_overlay(eog_epochs.average())
assert_raises(ValueError, ica.plot_overlay, raw[:2, :3][0])
plt.close('all')
示例3: test_plot_ica_overlay
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
def test_plot_ica_overlay():
"""Test plotting of ICA cleaning
"""
raw = _get_raw()
picks = _get_picks(raw)
ica_picks = pick_types(raw.info, meg=True, eeg=False, stim=False, ecg=False, eog=False, exclude="bads")
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2, max_pca_components=3, n_pca_components=3)
ica.fit(raw, picks=ica_picks)
# don't test raw, needs preload ...
ecg_epochs = create_ecg_epochs(raw, picks=picks)
ica.plot_overlay(ecg_epochs.average())
eog_epochs = create_eog_epochs(raw, picks=picks)
ica.plot_overlay(eog_epochs.average())
assert_raises(ValueError, ica.plot_overlay, raw[:2, :3][0])
plt.close("all")
示例4: test_plot_ica_overlay
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
def test_plot_ica_overlay():
"""Test plotting of ICA cleaning."""
import matplotlib.pyplot as plt
raw = _get_raw(preload=True)
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
# can't use info.normalize_proj here because of how and when ICA and Epochs
# objects do picking of Raw data
with warnings.catch_warnings(record=True): # bad proj
ica.fit(raw, picks=picks)
# don't test raw, needs preload ...
with warnings.catch_warnings(record=True): # bad proj
ecg_epochs = create_ecg_epochs(raw, picks=picks)
ica.plot_overlay(ecg_epochs.average())
with warnings.catch_warnings(record=True): # bad proj
eog_epochs = create_eog_epochs(raw, picks=picks)
ica.plot_overlay(eog_epochs.average())
assert_raises(ValueError, ica.plot_overlay, raw[:2, :3][0])
ica.plot_overlay(raw)
plt.close('all')
示例5: dict
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
baseline = None # no baseline as high-pass is applied
reject = dict(mag=5e-12)
epochs = mne.Epochs(raw, events, event_ids, tmin, tmax, picks=picks,
baseline=baseline, preload=True, reject=reject)
# Fit ICA, find and remove major artifacts
ica = ICA(n_components=0.95, random_state=0).fit(raw, decim=1, reject=reject)
# compute correlation scores, get bad indices sorted by score
eog_epochs = create_eog_epochs(raw, ch_name='MRT31-2908', reject=reject)
eog_inds, eog_scores = ica.find_bads_eog(eog_epochs, ch_name='MRT31-2908')
ica.plot_scores(eog_scores, eog_inds) # see scores the selection is based on
ica.plot_components(eog_inds) # view topographic sensitivity of components
ica.exclude += eog_inds[:1] # we saw the 2nd ECG component looked too dipolar
ica.plot_overlay(eog_epochs.average()) # inspect artifact removal
ica.apply(epochs) # clean data, default in place
evoked = [epochs[k].average() for k in event_ids]
contrast = combine_evoked(evoked, weights=[-1, 1]) # Faces - scrambled
evoked.append(contrast)
for e in evoked:
e.plot(ylim=dict(mag=[-400, 400]))
plt.show()
# estimate noise covarariance
noise_cov = mne.compute_covariance(epochs, tmax=0, method='shrunk',
示例6: red
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
show_picks = np.abs(scores).argsort()[::-1][:5] # indices of top five scores
# detected artifacts drawn in red (via exclude)
ica.plot_sources(raw, show_picks, exclude=eog_inds, start=0., stop=3.0)
ica.plot_components(eog_inds, colorbar=False) # show component sensitivites
ica.exclude += eog_inds[:1] # mark first for exclusion
###############################################################################
# 3) check detection and visualize artifact rejection
# estimate average artifact
eog_evoked = eog_epochs.average()
ica.plot_sources(eog_evoked) # latent EOG sources + selction
ica.plot_overlay(eog_evoked) # overlay raw and clean EOG artifacts
# check the amplitudes do not change
ica.plot_overlay(raw) # EOG artifacts remain
###############################################################################
# To save an ICA solution you can say:
# >>> ica.save('my_ica.fif')
#
# You can later restore the session by saying:
# >>> from mne.preprocessing import read_ica
# >>> read_ica('my_ica.fif')
#
# Apply the solution to Raw, Epochs or Evoked like this:
# >>> ica.apply(epochs, copy=False)
示例7: ica_method
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
def ica_method(raw, picks, plot='n', save ='n'):
###############################################################################
# 1) Fit ICA model using the FastICA algorithm
# Other available choices are `infomax` or `extended-infomax`
# We pass a float value between 0 and 1 to select n_components based on the
# percentage of variance explained by the PCA components.
ica = ICA(n_components=0.95, method='fastica')
picks = mne.pick_types(raw.info, meg=False, eeg=True, eog=False,
stim=False, exclude='bads')
ica.fit(raw, picks=picks, decim=3)
# maximum number of components to reject
n_max_eog = 1 # here we don't expect horizontal EOG components
###############################################################################
# 2) identify bad components by analyzing latent sources.
# detect EOG by correlation
eog_inds, scores = ica.find_bads_eog(raw, threshold=2.5)
show_picks = np.abs(scores).argsort()[::-1][:5]
eog_inds = eog_inds[:n_max_eog]
ica.exclude += eog_inds
###############################################################################
# 3) Assess component selection and unmixing quality
eog_evoked = create_eog_epochs(raw, tmin=-.5, tmax=.5, picks=picks).average()
if plot=='y':
title = 'Sources related to %s artifacts (red)'
ica.plot_scores(scores, exclude=eog_inds, title=title % 'eog', labels='eog')
if save=='y':
pylab.savefig('2.png')
ica.plot_sources(raw, show_picks, exclude=eog_inds, title=title % 'eog')
if save=='y':
pylab.savefig('3.png')
ica.plot_components(eog_inds, title=title % 'eog', colorbar=True)
if save=='y':
pylab.savefig('4.png')
ica.plot_overlay(raw) # EOG artifacts remain
if save=='y':
pylab.savefig('5.png')
ica.plot_sources(eog_evoked, exclude=eog_inds) # plot EOG sources + selection
if save=='y':
pylab.savefig('6.png')
ica.plot_overlay(eog_evoked, exclude=eog_inds) # plot EOG cleaning
if save=='y':
pylab.savefig('7.png')
ica.apply(raw, exclude=eog_inds)
eeg_only_after=raw.pick_types(meg=False, eeg=True)
return eeg_only_after
示例8:
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
fig = ica.plot_scores(scores, exclude=eog_inds,
title=title % ('eog', subject))
fig.savefig(save_folder + "pics/%s_%s_eog_scores.png" % (subject,
condition))
fig = ica.plot_sources(eog_average, exclude=None)
fig.savefig(save_folder + "pics/%s_%s_eog_source.png" % (subject,
condition))
fig = ica.plot_components(ica.exclude, title=title % ('eog', subject),
colorbar=True)
fig.savefig(save_folder + "pics/%s_%s_eog_component.png" % (subject,
condition))
fig = ica.plot_overlay(eog_average, exclude=None, show=False)
fig.savefig(save_folder + "pics/%s_%s_eog_excluded.png" % (subject,
condition))
# del eog_epochs, eog_average
##########################################################################
# Apply the solution to Raw, Epochs or Evoked like this:
raw_ica = ica.apply(raw)
ica.save(save_folder + "%s_%s-ica.fif" % (subject, condition)) # save ICA
# componenets
# Save raw with ICA removed
raw_ica.save(save_folder + "%s_%s_filtered_ica_mc_tsss-raw.fif" % (
subject, condition),
overwrite=True)
示例9: list
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
show_picks = mscores.argsort()[::-1][:5]
eog_inds = list(show_picks[:n_max_eog])
ica.exclude += eog_inds
fig = ica.plot_scores(scores, exclude=eog_inds, title=title % 'eog')
fig.savefig(img_folder + '/ica_eog_scores.png')
fig = ica.plot_sources(epochs, show_picks, exclude=eog_inds, title=title % 'eog')
fig.savefig(img_folder + '/ica_eog_sources.png')
fig = ica.plot_components(show_picks, title=title % 'eog', colorbar=True)
fig.set_size_inches(12.,8.)
fig.savefig(img_folder + '/ica_eog_components.png')
# Now exclude what we find
# epochs_ica = ica.apply(epochs, copy=True)
#evo_ica = epochs_ica.average()
evo= epochs.average()
#megp = pick_types(epochs.info, meg=True, eog=False)
#eogp = pick_types(epochs.info, meg=False, eog=True)
#fig = ica.plot_overlay(evo, picks=megp) #
fig = ica.plot_overlay(evo) #
fig.savefig(img_folder + '/ica_evo_overlay_meg.png')
#fig = ica.plot_overlay(evo, picks=eogp) #
#fig.savefig(img_folder + '/ica_evo_overlay_eog.png')
#fig = evo.plot()
#fig.savefig(img_folder + '/epevo.png')
#fig = evo_ica.plot()
#fig.savefig(img_folder + '/epevo_ica.png')
示例10: create_eog_epochs
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
fig.savefig(img_folder + '/ica_heog_sources.png')
fig = ica.plot_components(show_picks_h, title=title % 'heog', colorbar=True)
fig.set_size_inches(12.,8.)
fig.savefig(img_folder + '/ica_heog_components.png')
heog_inds = heog_inds[:2] # manually determined, take only first two ICs
ica.exclude += heog_inds
###############################################################################
# 3) Assess component selection and unmixing quality
# estimate average artifact
ecg_evoked = ecg_epochs.average()
fig = ica.plot_sources(ecg_evoked, exclude=ecg_inds) # plot ECG sources + selection
fig.savefig(img_folder + '/ica_ecg_evoked_sources.png')
fig = ica.plot_overlay(ecg_evoked, exclude=ecg_inds) # plot ECG cleaning
fig.savefig(img_folder + '/ica_ecg_evoked_overlay.png')
#eog_evoked = create_eog_epochs(raw, tmin=-.5, tmax=.5, picks=picks).average()
#fig = ica.plot_sources(eog_evoked, exclude=eog_inds) # plot EOG sources + selection
#fig.savefig(img_folder + '/ica_eog_evoked_sources.png')
#fig = ica.plot_overlay(eog_evoked, exclude=eog_inds) # plot EOG cleaning
#fig.savefig(img_folder + '/ica_eog_evoked_overlay.png')
tmp=ica.exclude
ica.exclude = []
veog_evoked = create_eog_epochs(raw, ch_name='EOG001', tmin=-.5, tmax=.5, picks=picks).average()
fig = ica.plot_sources(veog_evoked, exclude=veog_inds) # plot EOG sources + selection
fig.savefig(img_folder + '/ica_veog_evoked_sources_veog_inds.png')
fig = ica.plot_overlay(veog_evoked, exclude=veog_inds) # plot EOG cleaning
fig.savefig(img_folder + '/ica_veog_evoked_overlay_veog_inds.png')
示例11: ICA
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
ica = ICA(n_components=0.95).fit(epochs)
###############################################################################
# 2) Find ECG Artifacts
# generate ECG epochs to improve detection by correlation
ecg_epochs = create_ecg_epochs(raw, tmin=-.5, tmax=.5, picks=picks)
ecg_inds, scores = ica.find_bads_ecg(ecg_epochs)
ica.plot_scores(scores, exclude=ecg_inds)
title = 'Sources related to %s artifacts (red)'
show_picks = np.abs(scores).argsort()[::-1][:5]
ica.plot_sources(epochs, show_picks, exclude=ecg_inds, title=title % 'ecg')
ica.plot_components(ecg_inds, title=title % 'ecg')
ica.exclude += ecg_inds[:3] # whatever happens, we take 3
###############################################################################
# 3) Assess component selection and unmixing quality
# estimate average artifact
ecg_evoked = ecg_epochs.average()
ica.plot_sources(ecg_evoked) # plot ECG sources + selection
ica.plot_overlay(ecg_evoked) # plot ECG cleaning
# check effect on ERF of interest
epochs.crop(-.2, None) # crop to baseline of interest
ica.plot_overlay(epochs['aud_l'].average()) # plot remaining left auditory ERF
示例12: runICA
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
#.........这里部分代码省略.........
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg_none' + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 1:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg' + map(str, ecg_exclude)[0] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 2:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 3:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '_' + map(str, ecg_exclude)[2] + '.pdf', format = 'pdf')
elif len(eog_exclude) == 2:
if len(ecg_exclude) == 0:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg_none' + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 1:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg' + map(str, ecg_exclude)[0] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 2:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 3:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '_' + map(str, ecg_exclude)[2] + '.pdf', format = 'pdf')
# plot the scores for the different components highlighting in red that/those related to ECG
scores_plots_ecg=ica.plot_scores(ecg_scores, exclude=ecg_source_idx, title=title % 'ecg')
scores_plots_ecg.savefig(saveRoot + name + '_ecg_scores.pdf', format = 'pdf')
scores_plots_eog=ica.plot_scores(eog_scores, exclude=eog_source_idx, title=title % 'eog')
scores_plots_eog.savefig(saveRoot + name + '_eog_scores.pdf', format = 'pdf')
source_source_ecg=ica.plot_sources(ecg_evoked, exclude=ecg_source_idx)
source_source_ecg.savefig(saveRoot + name + '_ecg_source.pdf', format = 'pdf')
#ax = plt.subplot(2,1,2)
source_clean_ecg=ica.plot_overlay(ecg_evoked, exclude=ecg_source_idx)
source_clean_ecg.savefig(saveRoot + name + '_ecg_clean.pdf', format = 'pdf')
#clean_plot.savefig(saveRoot + name + '_ecg_clean.pdf', format = 'pdf')
#if len(eog_exclude) > 0:
source_source_eog=ica.plot_sources(eog_evoked, exclude=eog_source_idx)
source_source_eog.savefig(saveRoot + name + '_eog_source.pdf', format = 'pdf')
source_clean_eog=ica.plot_overlay(eog_evoked, exclude=eog_source_idx)
source_clean_eog.savefig(saveRoot + name + '_eog_clean.pdf', format = 'pdf')
overl_plot = ica.plot_overlay(raw)
overl_plot.savefig(saveRoot + name + '_overl.pdf', format = 'pdf')
event_id = 999
ecg_events, _, _ = mne.preprocessing.find_ecg_events(raw, event_id,
ch_name=raw.ch_names[ecg_picks].encode('UTF8'))
picks = mne.pick_types(raw.info, meg=False, eeg=False, stim=False, ecg=True)
tmin, tmax = -0.1, 0.1
epochs_ecg = mne.Epochs(raw, ecg_events, event_id, tmin, tmax,picks=picks)
data_ecg = epochs_ecg.get_data()
event_id = 998
eog_events = mne.preprocessing.find_eog_events(raw, event_id,
ch_name=raw.ch_names[eog_picks].encode('UTF8'))
picks = mne.pick_types(raw.info, meg=False, eeg=False, stim=False, eog=True,
exclude='bads')
tmin, tmax = -0.5, 0.5
epochs_eog = mne.Epochs(raw, eog_events, event_id, tmin, tmax,picks=[picks[0]])#,
data_eog = epochs_eog.get_data()
plSize = 1
示例13: runICA
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
#.........这里部分代码省略.........
#ica_plot = ica.plot_components(source_idx)
# select ICA sources and reconstruct MEG signals, compute clean ERFs
# Add detected artefact sources to exclusion list
# We now add the eog artefacts to the ica.exclusion list
if not ecg_source_idx:
print("No ECG components above threshold were identified for subject " + name +
" - selecting the component with the highest score under threshold")
ecg_exclude = [np.absolute(ecg_scores).argmax()]
ecg_source_idx=[np.absolute(ecg_scores).argmax()]
elif ecg_source_idx:
ecg_exclude += ecg_source_idx[:n_max_ecg]
ica.exclude += ecg_exclude
if not eog_source_idx:
if np.absolute(eog_scores).any>0.3:
eog_exclude=[np.absolute(eog_scores).argmax()]
eog_source_idx=[np.absolute(eog_scores).argmax()]
print("No EOG components above threshold were identified " + name +
" - selecting the component with the highest score under threshold above 0.3")
elif not np.absolute(eog_scores).any>0.3:
eog_exclude=[]
print("No EOG components above threshold were identified" + name)
elif eog_source_idx:
eog_exclude += eog_source_idx
ica.exclude += eog_exclude
print('########## saving')
if len(eog_exclude) == 0:
if len(ecg_exclude) == 0:
ica_plot.savefig(saveRoot + name + '_comps_eog_none-ecg_none' + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 1:
ica_plot.savefig(saveRoot + name + '_comps_eog_none-ecg' + map(str, ecg_exclude)[0] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 2:
ica_plot.savefig(saveRoot + name + '_comps_eog_none-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 3:
ica_plot.savefig(saveRoot + name + '_comps_eog_none-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '_' + map(str, ecg_exclude)[2] + '.pdf', format = 'pdf')
elif len(eog_exclude) == 1:
if len(ecg_exclude) == 0:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg_none' + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 1:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg' + map(str, ecg_exclude)[0] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 2:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 3:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '_' + map(str, ecg_exclude)[2] + '.pdf', format = 'pdf')
elif len(eog_exclude) == 2:
if len(ecg_exclude) == 0:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg_none' + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 1:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg' + map(str, ecg_exclude)[0] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 2:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '.pdf', format = 'pdf')
elif len(ecg_exclude) == 3:
ica_plot.savefig(saveRoot + name + '_comps_eog' + map(str, eog_exclude)[0] + '_' + map(str, eog_exclude)[1] +
'-ecg' + map(str, ecg_exclude)[0] + '_' + map(str, ecg_exclude)[1] + '_' + map(str, ecg_exclude)[2] + '.pdf', format = 'pdf')
# plot the scores for the different components highlighting in red that/those related to ECG
#scores_plots=plt.figure()
#ax = plt.subplot(2,1,1)
scores_plots_ecg=ica.plot_scores(ecg_scores, exclude=ecg_source_idx, title=title % 'ecg')
scores_plots_ecg.savefig(saveRoot + name + '_ecg_scores.pdf', format = 'pdf')
#ax = plt.subplot(2,1,2)
scores_plots_eog=ica.plot_scores(eog_scores, exclude=eog_source_idx, title=title % 'eog')
scores_plots_eog.savefig(saveRoot + name + '_eog_scores.pdf', format = 'pdf')
#if len(ecg_exclude) > 0:
# estimate average artifact
#source_clean_ecg=plt.figure()
#ax = plt.subplot(2,1,1)
source_source_ecg=ica.plot_sources(ecg_evoked, exclude=ecg_source_idx)
source_source_ecg.savefig(saveRoot + name + '_ecg_source.pdf', format = 'pdf')
#ax = plt.subplot(2,1,2)
source_clean_ecg=ica.plot_overlay(ecg_evoked, exclude=ecg_source_idx)
source_clean_ecg.savefig(saveRoot + name + '_ecg_clean.pdf', format = 'pdf')
#clean_plot.savefig(saveRoot + name + '_ecg_clean.pdf', format = 'pdf')
#if len(eog_exclude) > 0:
source_source_eog=ica.plot_sources(eog_evoked, exclude=eog_source_idx)
source_source_eog.savefig(saveRoot + name + '_eog_source.pdf', format = 'pdf')
source_clean_eog=ica.plot_overlay(eog_evoked, exclude=eog_source_idx)
source_clean_eog.savefig(saveRoot + name + '_eog_clean.pdf', format = 'pdf')
overl_plot = ica.plot_overlay(raw)
overl_plot.savefig(saveRoot + name + '_overl.pdf', format = 'pdf')
plt.close('all')
## restore sensor space data
icaList = ica.apply(raw)
return(icaList, ica)
示例14: compute_ica
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
def compute_ica(subject):
"""Function will compute ICA on raw and apply the ICA.
params:
subject : str
the subject id to be loaded
"""
raw = Raw(save_folder + "%s_filtered_data_mc_raw_tsss.fif" % subject,
preload=True)
# ICA Part
ica = ICA(n_components=0.95, method='fastica', max_iter=256)
picks = mne.pick_types(raw.info, meg=True, eeg=True,
stim=False, exclude='bads')
ica.fit(raw, picks=picks, decim=decim, reject=reject)
# maximum number of components to reject
n_max_ecg, n_max_eog = 3, 1
##########################################################################
# 2) identify bad components by analyzing latent sources.
title = 'Sources related to %s artifacts (red) for sub: %s'
# generate ECG epochs use detection via phase statistics
ecg_epochs = create_ecg_epochs(raw, ch_name="ECG002",
tmin=-.5, tmax=.5, picks=picks)
n_ecg_epochs_found = len(ecg_epochs.events)
sel_ecg_epochs = np.arange(0, n_ecg_epochs_found, 10)
ecg_epochs = ecg_epochs[sel_ecg_epochs]
ecg_inds, scores = ica.find_bads_ecg(ecg_epochs, method='ctps')
fig = ica.plot_scores(scores, exclude=ecg_inds,
title=title % ('ecg', subject))
fig.savefig(save_folder + "pics/%s_ecg_scores.png" % subject)
if ecg_inds:
show_picks = np.abs(scores).argsort()[::-1][:5]
fig = ica.plot_sources(raw, show_picks, exclude=ecg_inds,
title=title % ('ecg', subject), show=False)
fig.savefig(save_folder + "pics/%s_ecg_sources.png" % subject)
fig = ica.plot_components(ecg_inds, title=title % ('ecg', subject),
colorbar=True)
fig.savefig(save_folder + "pics/%s_ecg_component.png" % subject)
ecg_inds = ecg_inds[:n_max_ecg]
ica.exclude += ecg_inds
# estimate average artifact
ecg_evoked = ecg_epochs.average()
del ecg_epochs
# plot ECG sources + selection
fig = ica.plot_sources(ecg_evoked, exclude=ecg_inds)
fig.savefig(save_folder + "pics/%s_ecg_sources_ave.png" % subject)
# plot ECG cleaning
ica.plot_overlay(ecg_evoked, exclude=ecg_inds)
fig.savefig(save_folder + "pics/%s_ecg_sources_clean_ave.png" % subject)
# DETECT EOG BY CORRELATION
# HORIZONTAL EOG
eog_epochs = create_eog_epochs(raw, ch_name="EOG001")
eog_inds, scores = ica.find_bads_eog(raw)
fig = ica.plot_scores(scores, exclude=eog_inds,
title=title % ('eog', subject))
fig.savefig(save_folder + "pics/%s_eog_scores.png" % subject)
fig = ica.plot_components(eog_inds, title=title % ('eog', subject),
colorbar=True)
fig.savefig(save_folder + "pics/%s_eog_component.png" % subject)
eog_inds = eog_inds[:n_max_eog]
ica.exclude += eog_inds
del eog_epochs
##########################################################################
# Apply the solution to Raw, Epochs or Evoked like this:
raw_ica = ica.apply(raw, copy=False)
ica.save(save_folder + "%s-ica.fif" % subject) # save ICA componenets
# Save raw with ICA removed
raw_ica.save(save_folder + "%s_filtered_ica_mc_raw_tsss.fif" % subject,
overwrite=True)
plt.close("all")
示例15:
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import plot_overlay [as 别名]
ica.exclude += eog_inds
if eog_inds:
fig = ica.plot_scores(
scores, exclude=eog_inds, title=title % ('eog', subject))
fig.savefig(ica_folder + "plots/%s_%s_eog_scores_2.png" % (subject,
condition))
fig = ica.plot_sources(eog_average, exclude=eog_inds)
fig.savefig(ica_folder + "plots/%s_%s_eog_source_2.png" % (subject,
condition))
fig = ica.plot_components(
eog_inds, title=title % ('eog', subject), colorbar=True)
fig.savefig(ica_folder + "plots/%s_%s_eog_component_2.png" % (
subject, condition))
fig = ica.plot_overlay(eog_average, exclude=eog_inds, show=False)
fig.savefig(ica_folder + "plots/%s_%s_eog_excluded_2.png" % (
subject, condition))
del eog_epochs, eog_average
# ECG
ecg_epochs = create_ecg_epochs(raw, tmin=-.5, tmax=.5)
ecg_inds, scores = ica.find_bads_ecg(ecg_epochs)
ecg_inds = ecg_inds[:n_max_ecg]
ica.exclude.extend(ecg_inds)
if ecg_inds:
fig = ica.plot_components(
ecg_inds, title=title % ('ecg', subject), colorbar=True)
fig.savefig(ica_folder + "plots/%s_%s_ecg_component_2.png" % (