本文整理汇总了Python中mne.preprocessing.ICA.sources_as_epochs方法的典型用法代码示例。如果您正苦于以下问题:Python ICA.sources_as_epochs方法的具体用法?Python ICA.sources_as_epochs怎么用?Python ICA.sources_as_epochs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.preprocessing.ICA
的用法示例。
在下文中一共展示了ICA.sources_as_epochs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ica_additional
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_epochs [as 别名]
#.........这里部分代码省略.........
assert_true(isinstance(ica_read.info, Info))
assert_raises(RuntimeError, ica_read.decompose_raw, raw)
sources = ica.get_sources_raw(raw)
sources2 = ica_read.get_sources_raw(raw)
assert_array_almost_equal(sources, sources2)
_raw1 = ica.pick_sources_raw(raw, exclude=[1])
_raw2 = ica_read.pick_sources_raw(raw, exclude=[1])
assert_array_almost_equal(_raw1[:, :][0], _raw2[:, :][0])
os.remove(test_ica_fname)
# check scrore funcs
for name, func in score_funcs.items():
if name in score_funcs_unsuited:
continue
scores = ica.find_sources_raw(raw, target='EOG 061', score_func=func,
start=0, stop=10)
assert_true(ica.n_components_ == len(scores))
# check univariate stats
scores = ica.find_sources_raw(raw, score_func=stats.skew)
# check exception handling
assert_raises(ValueError, ica.find_sources_raw, raw,
target=np.arange(1))
params = []
params += [(None, -1, slice(2), [0, 1])] # varicance, kurtosis idx params
params += [(None, 'MEG 1531')] # ECG / EOG channel params
for idx, ch_name in product(*params):
ica.detect_artifacts(raw, start_find=0, stop_find=50, ecg_ch=ch_name,
eog_ch=ch_name, skew_criterion=idx,
var_criterion=idx, kurt_criterion=idx)
## score funcs epochs ##
# check score funcs
for name, func in score_funcs.items():
if name in score_funcs_unsuited:
continue
scores = ica.find_sources_epochs(epochs_eog, target='EOG 061',
score_func=func)
assert_true(ica.n_components_ == len(scores))
# check univariate stats
scores = ica.find_sources_epochs(epochs, score_func=stats.skew)
# check exception handling
assert_raises(ValueError, ica.find_sources_epochs, epochs,
target=np.arange(1))
# ecg functionality
ecg_scores = ica.find_sources_raw(raw, target='MEG 1531',
score_func='pearsonr')
with warnings.catch_warnings(record=True): # filter attenuation warning
ecg_events = ica_find_ecg_events(raw,
sources[np.abs(ecg_scores).argmax()])
assert_true(ecg_events.ndim == 2)
# eog functionality
eog_scores = ica.find_sources_raw(raw, target='EOG 061',
score_func='pearsonr')
with warnings.catch_warnings(record=True): # filter attenuation warning
eog_events = ica_find_eog_events(raw,
sources[np.abs(eog_scores).argmax()])
assert_true(eog_events.ndim == 2)
# Test ica fiff export
ica_raw = ica.sources_as_raw(raw, start=0, stop=100)
assert_true(ica_raw.last_samp - ica_raw.first_samp == 100)
assert_true(len(ica_raw._filenames) == 0) # API consistency
ica_chans = [ch for ch in ica_raw.ch_names if 'ICA' in ch]
assert_true(ica.n_components_ == len(ica_chans))
test_ica_fname = op.join(op.abspath(op.curdir), 'test-ica_raw.fif')
ica.n_components = np.int32(ica.n_components)
ica_raw.save(test_ica_fname, overwrite=True)
ica_raw2 = io.Raw(test_ica_fname, preload=True)
assert_allclose(ica_raw._data, ica_raw2._data, rtol=1e-5, atol=1e-4)
ica_raw2.close()
os.remove(test_ica_fname)
# Test ica epochs export
ica_epochs = ica.sources_as_epochs(epochs)
assert_true(ica_epochs.events.shape == epochs.events.shape)
sources_epochs = ica.get_sources_epochs(epochs)
assert_array_equal(ica_epochs.get_data(), sources_epochs)
ica_chans = [ch for ch in ica_epochs.ch_names if 'ICA' in ch]
assert_true(ica.n_components_ == len(ica_chans))
assert_true(ica.n_components_ == ica_epochs.get_data().shape[1])
assert_true(ica_epochs.raw is None)
assert_true(ica_epochs.preload is True)
# test float n pca components
ica.pca_explained_variance_ = np.array([0.2] * 5)
ica.n_components_ = 0
for ncomps, expected in [[0.3, 1], [0.9, 4], [1, 1]]:
ncomps_ = _check_n_pca_components(ica, ncomps)
assert_true(ncomps_ == expected)
示例2: test_ica_additional
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_epochs [as 别名]
#.........这里部分代码省略.........
assert_true(np.allclose(ica.mixing_matrix_, ica_read.mixing_matrix_,
rtol=1e-16, atol=1e-32))
assert_array_equal(ica.pca_components_,
ica_read.pca_components_)
assert_array_equal(ica.pca_mean_, ica_read.pca_mean_)
assert_array_equal(ica.pca_explained_variance_,
ica_read.pca_explained_variance_)
assert_array_equal(ica._pre_whitener, ica_read._pre_whitener)
# assert_raises(RuntimeError, ica_read.decompose_raw, raw)
sources = ica.get_sources_raw(raw)
sources2 = ica_read.get_sources_raw(raw)
assert_array_almost_equal(sources, sources2)
_raw1 = ica.pick_sources_raw(raw, exclude=[1])
_raw2 = ica_read.pick_sources_raw(raw, exclude=[1])
assert_array_almost_equal(_raw1[:, :][0], _raw2[:, :][0])
os.remove(test_ica_fname)
# check scrore funcs
for name, func in score_funcs.items():
if name in score_funcs_unsuited:
continue
scores = ica.find_sources_raw(raw, target='EOG 061', score_func=func,
start=0, stop=10)
assert_true(ica.n_components_ == len(scores))
# check univariate stats
scores = ica.find_sources_raw(raw, score_func=stats.skew)
# check exception handling
assert_raises(ValueError, ica.find_sources_raw, raw,
target=np.arange(1))
params = []
params += [(None, -1, slice(2), [0, 1])] # varicance, kurtosis idx params
params += [(None, 'MEG 1531')] # ECG / EOG channel params
for idx, ch_name in product(*params):
ica.detect_artifacts(raw, start_find=0, stop_find=50, ecg_ch=ch_name,
eog_ch=ch_name, skew_criterion=idx,
var_criterion=idx, kurt_criterion=idx)
## score funcs epochs ##
# check score funcs
for name, func in score_funcs.items():
if name in score_funcs_unsuited:
continue
scores = ica.find_sources_epochs(epochs_eog, target='EOG 061',
score_func=func)
assert_true(ica.n_components_ == len(scores))
# check univariate stats
scores = ica.find_sources_epochs(epochs, score_func=stats.skew)
# check exception handling
assert_raises(ValueError, ica.find_sources_epochs, epochs,
target=np.arange(1))
# ecg functionality
ecg_scores = ica.find_sources_raw(raw, target='MEG 1531',
score_func='pearsonr')
ecg_events = ica_find_ecg_events(raw, sources[np.abs(ecg_scores).argmax()])
assert_true(ecg_events.ndim == 2)
# eog functionality
eog_scores = ica.find_sources_raw(raw, target='EOG 061',
score_func='pearsonr')
eog_events = ica_find_eog_events(raw, sources[np.abs(eog_scores).argmax()])
assert_true(eog_events.ndim == 2)
# Test ica fiff export
ica_raw = ica.sources_as_raw(raw, start=0, stop=100)
assert_true(ica_raw.last_samp - ica_raw.first_samp == 100)
ica_chans = [ch for ch in ica_raw.ch_names if 'ICA' in ch]
assert_true(ica.n_components_ == len(ica_chans))
test_ica_fname = op.join(op.abspath(op.curdir), 'test_ica.fif')
ica_raw.save(test_ica_fname)
ica_raw2 = fiff.Raw(test_ica_fname, preload=True)
assert_array_almost_equal(ica_raw._data, ica_raw2._data)
ica_raw2.close()
os.remove(test_ica_fname)
# Test ica epochs export
ica_epochs = ica.sources_as_epochs(epochs)
assert_true(ica_epochs.events.shape == epochs.events.shape)
sources_epochs = ica.get_sources_epochs(epochs)
assert_array_equal(ica_epochs.get_data(), sources_epochs)
ica_chans = [ch for ch in ica_epochs.ch_names if 'ICA' in ch]
assert_true(ica.n_components_ == len(ica_chans))
assert_true(ica.n_components_ == ica_epochs.get_data().shape[1])
assert_true(ica_epochs.raw is None)
assert_true(ica_epochs.preload == True)
# regression test for plot method
assert_raises(ValueError, ica.plot_sources_raw, raw,
order=np.arange(50))
assert_raises(ValueError, ica.plot_sources_epochs, epochs,
order=np.arange(50))