本文整理汇总了Python中mne.preprocessing.ICA.sources_as_raw方法的典型用法代码示例。如果您正苦于以下问题:Python ICA.sources_as_raw方法的具体用法?Python ICA.sources_as_raw怎么用?Python ICA.sources_as_raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.preprocessing.ICA
的用法示例。
在下文中一共展示了ICA.sources_as_raw方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ica_additional
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_raw [as 别名]
def test_ica_additional():
"""Test additional ICA functionality
"""
stop2 = 500
raw = io.Raw(raw_fname, preload=True).crop(0, stop, False).crop(1.5)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
test_cov = read_cov(test_cov_name)
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)
# for testing eog functionality
picks2 = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=True, exclude='bads')
epochs_eog = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks2,
baseline=(None, 0), preload=True)
test_cov2 = deepcopy(test_cov)
ica = ICA(noise_cov=test_cov2, n_components=3, max_pca_components=4,
n_pca_components=4)
assert_true(ica.info is None)
ica.decompose_raw(raw, picks[:5])
assert_true(isinstance(ica.info, Info))
assert_true(ica.n_components_ < 5)
ica = ICA(n_components=3, max_pca_components=4,
n_pca_components=4)
assert_raises(RuntimeError, ica.save, '')
ica.decompose_raw(raw, picks=None, start=start, stop=stop2)
# test warnings on bad filenames
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
ica_badname = op.join(op.dirname(tempdir), 'test-bad-name.fif.gz')
ica.save(ica_badname)
read_ica(ica_badname)
assert_true(len(w) == 2)
# test decim
ica = ICA(n_components=3, max_pca_components=4,
n_pca_components=4)
raw_ = raw.copy()
for _ in range(3):
raw_.append(raw_)
n_samples = raw_._data.shape[1]
ica.decompose_raw(raw, picks=None, decim=3)
assert_true(raw_._data.shape[1], n_samples)
# test expl var
ica = ICA(n_components=1.0, max_pca_components=4,
n_pca_components=4)
ica.decompose_raw(raw, picks=None, decim=3)
assert_true(ica.n_components_ == 4)
# epochs extraction from raw fit
assert_raises(RuntimeError, ica.get_sources_epochs, epochs)
# test reading and writing
test_ica_fname = op.join(op.dirname(tempdir), 'test-ica.fif')
for cov in (None, test_cov):
ica = ICA(noise_cov=cov, n_components=2, max_pca_components=4,
n_pca_components=4)
with warnings.catch_warnings(record=True): # ICA does not converge
ica.decompose_raw(raw, picks=picks, start=start, stop=stop2)
sources = ica.get_sources_epochs(epochs)
assert_true(ica.mixing_matrix_.shape == (2, 2))
assert_true(ica.unmixing_matrix_.shape == (2, 2))
assert_true(ica.pca_components_.shape == (4, len(picks)))
assert_true(sources.shape[1] == ica.n_components_)
for exclude in [[], [0]]:
ica.exclude = [0]
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.exclude == ica_read.exclude)
# test pick merge -- add components
ica.pick_sources_raw(raw, exclude=[1])
assert_true(ica.exclude == [0, 1])
# -- only as arg
ica.exclude = []
ica.pick_sources_raw(raw, exclude=[0, 1])
assert_true(ica.exclude == [0, 1])
# -- remove duplicates
ica.exclude += [1]
ica.pick_sources_raw(raw, exclude=[0, 1])
assert_true(ica.exclude == [0, 1])
# test basic include
ica.exclude = []
ica.pick_sources_raw(raw, include=[1])
ica_raw = ica.sources_as_raw(raw)
assert_true(ica.exclude == [ica_raw.ch_names.index(e) for e in
ica_raw.info['bads']])
# test filtering
d1 = ica_raw._data[0].copy()
with warnings.catch_warnings(record=True): # dB warning
ica_raw.filter(4, 20)
#.........这里部分代码省略.........
示例2: Raw
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_raw [as 别名]
n_pca_components=1.0
max_pca_components=None
subjects_dir = '/home/qdong/data/'
subject_path = subjects_dir + subject#Set the data path of the subject
#raw_fname = subject_path + '/MEG/ssp_cleaned_%s_audi_cued-raw_cle.fif' %subject
raw_fname = subject_path + '/MEG/%s_audi_cued-raw_cle.fif' %subject
raw_basename = os.path.splitext(os.path.basename(raw_fname))[0]
raw = Raw(raw_fname, preload=True)
picks = mne.fiff.pick_types(raw.info, meg=True, eeg=False, eog=False,
stim=False, exclude='bads')
ica = ICA(n_components=n_components, n_pca_components=n_pca_components, max_pca_components=max_pca_components, random_state=0)
ica.decompose_raw(raw, picks=picks, decim=3)
if trigger == 'resp':
add_from_raw = mne.fiff.pick_types(raw.info, meg=False, resp=True, exclude='bads')
sources_add = ica.sources_as_raw(raw, picks=add_from_raw)
events = mne.find_events(sources_add, stim_channel=res_ch_name)
raw_basename += '_resp'
elif trigger == 'stim':
add_from_raw = mne.fiff.pick_types(raw.info, meg=False, stim=True, exclude='bads')
sources_add = ica.sources_as_raw(raw, picks=add_from_raw)
events = mne.find_events(sources_add, stim_channel=sti_ch_name)
raw_basename += '_stim'
else:
print "Incorrect trigger."
sys.exit()
# drop non-data channels (ICA sources are type misc)
#ica.n_pca_components=None
picks = mne.fiff.pick_types(sources_add.info, meg=False, misc=True, exclude='bads')
#Compare different bandwith of ICA components: 2-4, 4-8, 8-12, 12-16, 16-20Hz
示例3: Raw
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_raw [as 别名]
n_pca_components=1.0
max_pca_components=None
subjects_dir = '/home/qdong/freesurfer/subjects/'
subject_path = subjects_dir + subject#Set the data path of the subject
#raw_fname = subject_path + '/MEG/ssp_cleaned_%s_audi_cued-raw_cle.fif' %subject
raw_fname = subject_path + '/MEG/%s_audi_cued-raw_cle.fif' %subject
raw_basename = os.path.splitext(os.path.basename(raw_fname))[0]
raw = Raw(raw_fname, preload=True)
picks = mne.fiff.pick_types(raw.info, meg=True, eeg=False, eog=False,
stim=False, exclude='bads')
ica = ICA(n_components=n_components, n_pca_components=n_pca_components, max_pca_components=max_pca_components, random_state=0)
ica.decompose_raw(raw, picks=picks, decim=3)
add_resp_raw = mne.fiff.pick_types(raw.info, meg=False, resp=True, exclude='bads')
sources_resp_add = ica.sources_as_raw(raw, picks=add_resp_raw)
resp_events = mne.find_events(sources_resp_add, stim_channel=res_ch_name)
add_stim_raw = mne.fiff.pick_types(raw.info, meg=False, stim=True, exclude='bads')
sources_stim_add = ica.sources_as_raw(raw, picks=add_stim_raw)
stim_events = mne.find_events(sources_stim_add, stim_channel=sti_ch_name)
stim_picks = mne.fiff.pick_types(sources_stim_add.info, meg=False, misc=True, exclude='bads')
resp_picks = mne.fiff.pick_types(sources_resp_add.info, meg=False, misc=True, exclude='bads')
#Compare different bandwith of ICA components: 2-4, 4-8, 8-12, 12-16, 16-20Hz
l_f=2
Brain_idx=[]#The index of ICA related with trigger channels
for i in [4, 8, 12, 16]:
h_f = i
if l_f != 2:
sources_stim_add = ica.sources_as_raw(raw, picks=add_stim_raw)
示例4: test_ica_additional
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_raw [as 别名]
def test_ica_additional():
"""Test additional functionality
"""
stop2 = 500
test_cov2 = deepcopy(test_cov)
ica = ICA(noise_cov=test_cov2, n_components=3, max_pca_components=4,
n_pca_components=4)
ica.decompose_raw(raw, picks[:5])
assert_true(ica.n_components_ < 5)
ica = ICA(n_components=3, max_pca_components=4,
n_pca_components=4)
assert_raises(RuntimeError, ica.save, '')
ica.decompose_raw(raw, picks=None, start=start, stop=stop2)
# epochs extraction from raw fit
assert_raises(RuntimeError, ica.get_sources_epochs, epochs)
# test reading and writing
test_ica_fname = op.join(op.dirname(tempdir), 'ica_test.fif')
for cov in (None, test_cov):
ica = ICA(noise_cov=cov, n_components=3, max_pca_components=4,
n_pca_components=4)
ica.decompose_raw(raw, picks=picks, start=start, stop=stop2)
sources = ica.get_sources_epochs(epochs)
assert_true(sources.shape[1] == ica.n_components_)
for exclude in [[], [0]]:
ica.exclude = [0]
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.exclude == ica_read.exclude)
# test pick merge -- add components
ica.pick_sources_raw(raw, exclude=[1])
assert_true(ica.exclude == [0, 1])
# -- only as arg
ica.exclude = []
ica.pick_sources_raw(raw, exclude=[0, 1])
assert_true(ica.exclude == [0, 1])
# -- remove duplicates
ica.exclude += [1]
ica.pick_sources_raw(raw, exclude=[0, 1])
assert_true(ica.exclude == [0, 1])
ica_raw = ica.sources_as_raw(raw)
assert_true(ica.exclude == [ica.ch_names.index(e) for e in
ica_raw.info['bads']])
ica.n_pca_components = 2
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.n_pca_components ==
ica_read.n_pca_components)
ica.n_pca_components = 4
ica_read.n_pca_components = 4
ica.exclude = []
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.ch_names == ica_read.ch_names)
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)
# score funcs raw, with catch since "ties preclude exact" warning
# XXX this should be fixed by a future PR...
with warnings.catch_warnings(True) as w:
sfunc_test = [ica.find_sources_raw(raw, target='EOG 061',
score_func=n, start=0, stop=10)
for n, f in score_funcs.items()]
# score funcs raw
# check lenght of scores
[assert_true(ica.n_components_ == len(scores)) for scores in sfunc_test]
# 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))
## score funcs epochs ##
#.........这里部分代码省略.........
示例5: test_ica_additional
# 需要导入模块: from mne.preprocessing import ICA [as 别名]
# 或者: from mne.preprocessing.ICA import sources_as_raw [as 别名]
def test_ica_additional():
"""Test additional functionality
"""
stop2 = 500
test_cov2 = deepcopy(test_cov)
ica = ICA(noise_cov=test_cov2, n_components=3, max_pca_components=4,
n_pca_components=4)
assert_true(ica.info is None)
ica.decompose_raw(raw, picks[:5])
assert_true(isinstance(ica.info, Info))
assert_true(ica.n_components_ < 5)
ica = ICA(n_components=3, max_pca_components=4,
n_pca_components=4)
assert_raises(RuntimeError, ica.save, '')
ica.decompose_raw(raw, picks=None, start=start, stop=stop2)
# epochs extraction from raw fit
assert_raises(RuntimeError, ica.get_sources_epochs, epochs)
# test reading and writing
test_ica_fname = op.join(op.dirname(tempdir), 'ica_test.fif')
for cov in (None, test_cov):
ica = ICA(noise_cov=cov, n_components=3, max_pca_components=4,
n_pca_components=4)
ica.decompose_raw(raw, picks=picks, start=start, stop=stop2)
sources = ica.get_sources_epochs(epochs)
assert_true(sources.shape[1] == ica.n_components_)
for exclude in [[], [0]]:
ica.exclude = [0]
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.exclude == ica_read.exclude)
# test pick merge -- add components
ica.pick_sources_raw(raw, exclude=[1])
assert_true(ica.exclude == [0, 1])
# -- only as arg
ica.exclude = []
ica.pick_sources_raw(raw, exclude=[0, 1])
assert_true(ica.exclude == [0, 1])
# -- remove duplicates
ica.exclude += [1]
ica.pick_sources_raw(raw, exclude=[0, 1])
assert_true(ica.exclude == [0, 1])
ica_raw = ica.sources_as_raw(raw)
assert_true(ica.exclude == [ica_raw.ch_names.index(e) for e in
ica_raw.info['bads']])
ica.n_pca_components = 2
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.n_pca_components ==
ica_read.n_pca_components)
ica.n_pca_components = 4
ica_read.n_pca_components = 4
ica.exclude = []
ica.save(test_ica_fname)
ica_read = read_ica(test_ica_fname)
assert_true(ica.ch_names == ica_read.ch_names)
assert_true(isinstance(ica_read.info, Info)) # XXX improve later
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
#.........这里部分代码省略.........