本文整理汇总了Python中mne.preprocessing.ICA.pick_sources_epochs方法的典型用法代码示例。如果您正苦于以下问题:Python ICA.pick_sources_epochs方法的具体用法?Python ICA.pick_sources_epochs怎么用?Python ICA.pick_sources_epochs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.preprocessing.ICA
的用法示例。
在下文中一共展示了ICA.pick_sources_epochs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ica_full_data_recovery
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import pick_sources_epochs [as 别名]
def test_ica_full_data_recovery():
"""Test recovery of full data when no source is rejected"""
# Most basic recovery
raw = io.Raw(raw_fname, preload=True).crop(0, stop, False).crop(1.5)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
n_channels = 5
data = raw._data[:n_channels].copy()
data_epochs = epochs.get_data()
for n_components, n_pca_components, ok in [(2, n_channels, True),
(2, n_channels // 2, False)]:
ica = ICA(n_components=n_components,
max_pca_components=n_pca_components,
n_pca_components=n_pca_components)
ica.decompose_raw(raw, picks=list(range(n_channels)))
raw2 = ica.pick_sources_raw(raw, exclude=[])
if ok:
assert_allclose(data[:n_channels], raw2._data[:n_channels],
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(data[:n_channels] - raw2._data[:n_channels])
assert_true(np.max(diff) > 1e-14)
ica = ICA(n_components=n_components,
max_pca_components=n_pca_components,
n_pca_components=n_pca_components)
ica.decompose_epochs(epochs, picks=list(range(n_channels)))
epochs2 = ica.pick_sources_epochs(epochs, exclude=[])
data2 = epochs2.get_data()[:, :n_channels]
if ok:
assert_allclose(data_epochs[:, :n_channels], data2,
rtol=1e-10, atol=1e-15)
else:
diff = np.abs(data_epochs[:, :n_channels] - data2)
assert_true(np.max(diff) > 1e-14)
示例2: components
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import pick_sources_epochs [as 别名]
score_func='pearsonr')
# get the source most correlated with the ECG.
ecg_source_idx = np.argsort(np.abs(ecg_scores))[-1]
ica.exclude += [ecg_source_idx]
# Restore sensor space data
# plot spatial sensitivities of a few ICA components
# title = 'Spatial patterns of ICA components (Magnetometers)'
# source_idx = range(0, ica.n_components_)
# ica.plot_topomap(source_idx, ch_type='mag')
# plt.suptitle(title, fontsize=12)
epochs_ica = ica.pick_sources_epochs(epochs)
# epochs_ica.save("sef_bilat-tsss-mc-autobad-epochs.fif")
print epochs_ica
epochs_ica.info
#### Evoked data
evoked_left = epochs_ica["Left"].average()
evoked_right = epochs_ica["Right"].average()
print "plot evoked for Left"
evoked_left.plot()
print "plot evoked for Right"
示例3: ICA
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import pick_sources_epochs [as 别名]
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(None, 50).decompose_epochs(epochs, decim=2)
for ch_name in ["MRT51-2908", "MLF14-2908"]: # ECG, EOG contaminated chs
scores = ica.find_sources_epochs(epochs, ch_name, "pearsonr")
ica.exclude += list(np.argsort(np.abs(scores))[-2:])
ica.plot_topomap(np.unique(ica.exclude)) # plot components found
# select ICA sources and reconstruct MEG signals, compute clean ERFs
epochs = ica.pick_sources_epochs(epochs)
evoked = [epochs[k].average() for k in event_ids]
contrast = evoked[1] - evoked[0]
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.crop(None, 0, copy=True))
示例4: test_ica_core
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import pick_sources_epochs [as 别名]
def test_ica_core():
"""Test ICA on raw and epochs
"""
# setup parameter
# XXX. The None cases helped revealing bugs but are time consuming.
noise_cov = [None, test_cov]
# removed None cases to speed up...
n_components = [3, 1.0] # for future dbg add cases
max_pca_components = [4]
picks_ = [picks]
iter_ica_params = product(noise_cov, n_components, max_pca_components,
picks_)
# # test init catchers
assert_raises(ValueError, ICA, n_components=3, max_pca_components=2)
assert_raises(ValueError, ICA, n_components=1.3, max_pca_components=2)
# test essential core functionality
for n_cov, n_comp, max_n, pcks in iter_ica_params:
# Test ICA raw
ica = ICA(noise_cov=n_cov, n_components=n_comp,
max_pca_components=max_n, n_pca_components=max_n,
random_state=0)
print ica # to test repr
# test fit checker
assert_raises(RuntimeError, ica.get_sources_raw, raw)
assert_raises(RuntimeError, ica.get_sources_epochs, epochs)
# test decomposition
ica.decompose_raw(raw, picks=pcks, start=start, stop=stop)
print ica # to test repr
# test re-init exception
assert_raises(RuntimeError, ica.decompose_raw, raw, picks=picks)
sources = ica.get_sources_raw(raw)
assert_true(sources.shape[0] == ica.n_components_)
# test preload filter
raw3 = raw.copy()
raw3._preloaded = False
assert_raises(ValueError, ica.pick_sources_raw, raw3,
include=[1, 2])
for excl, incl in (([], []), ([], [1, 2]), ([1, 2], [])):
raw2 = ica.pick_sources_raw(raw, exclude=excl, include=incl,
copy=True)
assert_array_almost_equal(raw2[:, :][1], raw[:, :][1])
#######################################################################
# test epochs decomposition
# test re-init exception
assert_raises(RuntimeError, ica.decompose_epochs, epochs, picks=picks)
ica = ICA(noise_cov=n_cov, n_components=n_comp,
max_pca_components=max_n, n_pca_components=max_n,
random_state=0)
ica.decompose_epochs(epochs, picks=picks)
print ica # to test repr
# test pick block after epochs fit
assert_raises(ValueError, ica.pick_sources_raw, raw)
sources = ica.get_sources_epochs(epochs)
assert_true(sources.shape[1] == ica.n_components_)
assert_raises(ValueError, ica.find_sources_epochs, epochs,
target=np.arange(1))
# test preload filter
epochs3 = epochs.copy()
epochs3.preload = False
assert_raises(ValueError, ica.pick_sources_epochs, epochs3,
include=[1, 2])
# test source picking
for excl, incl in (([], []), ([], [1, 2]), ([1, 2], [])):
epochs2 = ica.pick_sources_epochs(epochs, exclude=excl,
include=incl, copy=True)
assert_array_almost_equal(epochs2.get_data(),
epochs.get_data())