本文整理汇总了Python中mne.fiff.Raw.add_proj方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.add_proj方法的具体用法?Python Raw.add_proj怎么用?Python Raw.add_proj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.fiff.Raw
的用法示例。
在下文中一共展示了Raw.add_proj方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_proj
# 需要导入模块: from mne.fiff import Raw [as 别名]
# 或者: from mne.fiff.Raw import add_proj [as 别名]
def test_proj():
"""Test SSP proj operations
"""
for proj_active in [True, False]:
raw = Raw(fif_fname, preload=False, proj_active=proj_active)
assert_true(all(p['active'] == proj_active for p in raw.info['projs']))
data, times = raw[0:2, :]
data1, times1 = raw[0:2]
assert_array_equal(data, data1)
assert_array_equal(times, times1)
# test adding / deleting proj
if proj_active:
assert_raises(ValueError, raw.add_proj, [],
{'remove_existing': True})
assert_raises(ValueError, raw.del_proj, 0)
else:
projs = deepcopy(raw.info['projs'])
n_proj = len(raw.info['projs'])
raw.del_proj(0)
assert_true(len(raw.info['projs']) == n_proj - 1)
raw.add_proj(projs, remove_existing=False)
assert_true(len(raw.info['projs']) == 2 * n_proj - 1)
raw.add_proj(projs, remove_existing=True)
assert_true(len(raw.info['projs']) == n_proj)
# test apply_proj() with and without preload
for preload in [True, False]:
raw = Raw(fif_fname, preload=preload, proj_active=False)
data, times = raw[:, 0:2]
raw.apply_projector()
data_proj_1 = np.dot(raw._projector, data)
# load the file again without proj
raw = Raw(fif_fname, preload=preload, proj_active=False)
# write the file with proj. activated, make sure proj has been applied
raw.save(op.join(tempdir, 'raw.fif'), proj_active=True)
raw2 = Raw(op.join(tempdir, 'raw.fif'), proj_active=False)
data_proj_2, _ = raw2[:, 0:2]
assert_array_almost_equal(data_proj_1, data_proj_2)
assert_true(all(p['active'] for p in raw2.info['projs']))
# read orig file with proj. active
raw2 = Raw(fif_fname, preload=preload, proj_active=True)
data_proj_2, _ = raw2[:, 0:2]
assert_array_almost_equal(data_proj_1, data_proj_2)
assert_true(all(p['active'] for p in raw2.info['projs']))
# test that apply_projector works
raw.apply_projector()
data_proj_2, _ = raw[:, 0:2]
assert_array_almost_equal(data_proj_1, data_proj_2)
assert_array_almost_equal(data_proj_2,
np.dot(raw._projector, data_proj_2))
示例2: test_multiple_files
# 需要导入模块: from mne.fiff import Raw [as 别名]
# 或者: from mne.fiff.Raw import add_proj [as 别名]
def test_multiple_files():
"""Test loading multiple files simultaneously
"""
# split file
raw = Raw(fif_fname, preload=True)
split_size = 10. # in seconds
sfreq = raw.info['sfreq']
nsamp = (raw.last_samp - raw.first_samp)
tmins = np.round(np.arange(0., nsamp, split_size * sfreq))
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp]))
tmaxs /= sfreq
tmins /= sfreq
# going in reverse order so the last fname is the first file (need later)
raws = [None] * len(tmins)
for ri in range(len(tmins) - 1, -1, -1):
fname = op.join(tempdir, 'test_raw_split-%d_raw.fif' % ri)
raw.save(fname, tmin=tmins[ri], tmax=tmaxs[ri])
raws[ri] = Raw(fname)
events = [find_events(r) for r in raws]
last_samps = [r.last_samp for r in raws]
first_samps = [r.first_samp for r in raws]
# test concatenation of split file
all_raw_1 = concatenate_raws(raws, preload=False)
assert_true(raw.first_samp == all_raw_1.first_samp)
assert_true(raw.last_samp == all_raw_1.last_samp)
assert_array_almost_equal(raw[:, :][0], all_raw_1[:, :][0])
raws[0] = Raw(fname)
all_raw_2 = concatenate_raws(raws, preload=True)
assert_array_almost_equal(raw[:, :][0], all_raw_2[:, :][0])
# test proper event treatment for split files
events = concatenate_events(events, first_samps, last_samps)
events2 = find_events(all_raw_2)
assert_array_equal(events, events2)
# test various methods of combining files
n_combos = 9
raw_combos = [None] * n_combos
raw = Raw(fif_fname, preload=True)
raw_combos[0] = Raw([fif_fname, fif_fname], preload=True)
raw_combos[1] = Raw([fif_fname, fif_fname], preload=False)
raw_combos[2] = Raw([fif_fname, fif_fname], preload='memmap8.dat')
assert_raises(ValueError, Raw, [fif_fname, ctf_fname])
assert_raises(ValueError, Raw, [fif_fname, fif_bad_marked_fname])
n_times = len(raw._times)
assert_true(raw[:, :][0].shape[1] * 2 == raw_combos[0][:, :][0].shape[1])
assert_true(raw_combos[0][:, :][0].shape[1] == len(raw_combos[0]._times))
# with all data preloaded, result should be preloaded
raw_combos[3] = Raw(fif_fname, preload=True)
raw_combos[3].append(Raw(fif_fname, preload=True))
assert_true(raw_combos[0]._preloaded == True)
# with any data not preloaded, don't set result as preloaded
raw_combos[4] = concatenate_raws([Raw(fif_fname, preload=True),
Raw(fif_fname, preload=False)])
assert_true(raw_combos[1]._preloaded == False)
assert_array_equal(find_events(raw_combos[4]), find_events(raw_combos[0]))
# user should be able to force data to be preloaded upon concat
raw_combos[5] = concatenate_raws([Raw(fif_fname, preload=False),
Raw(fif_fname, preload=True)],
preload=True)
assert_true(raw_combos[2]._preloaded == True)
raw_combos[6] = concatenate_raws([Raw(fif_fname, preload=False),
Raw(fif_fname, preload=True)],
preload='memmap3.dat')
raw_combos[7] = concatenate_raws([Raw(fif_fname, preload=True),
Raw(fif_fname, preload=True)],
preload='memmap4.dat')
raw_combos[8] = concatenate_raws([Raw(fif_fname, preload=False),
Raw(fif_fname, preload=False)],
preload='memmap5.dat')
# make sure that all our data match
times = range(0, 2 * n_times, 999)
# add potentially problematic points
times.extend([n_times - 1, n_times, 2 * n_times - 1])
for ti in times: # let's do a subset of points for speed
orig = raw[:, ti % n_times][0]
for raw_combo in raw_combos:
# these are almost_equals because of possible dtype differences
assert_array_almost_equal(orig, raw_combo[:, ti][0])
# verify that combining raws with different projectors throws an exception
raw.add_proj([], remove_existing=True)
assert_raises(ValueError, raw.append, Raw(fif_fname, preload=True))
# now test event treatment for concatenated raw files
events = [find_events(raw), find_events(raw)]
last_samps = [raw.last_samp, raw.last_samp]
first_samps = [raw.first_samp, raw.first_samp]
events = concatenate_events(events, first_samps, last_samps)
events2 = find_events(raw_combos[0])
#.........这里部分代码省略.........
示例3: test_multiple_files
# 需要导入模块: from mne.fiff import Raw [as 别名]
# 或者: from mne.fiff.Raw import add_proj [as 别名]
def test_multiple_files():
"""Test loading multiple files simultaneously
"""
# split file
raw = Raw(fif_fname, preload=True).crop(0, 10)
split_size = 3. # in seconds
sfreq = raw.info['sfreq']
nsamp = (raw.last_samp - raw.first_samp)
tmins = np.round(np.arange(0., nsamp, split_size * sfreq))
tmaxs = np.concatenate((tmins[1:] - 1, [nsamp]))
tmaxs /= sfreq
tmins /= sfreq
assert_equal(raw.n_times, len(raw._times))
# going in reverse order so the last fname is the first file (need later)
raws = [None] * len(tmins)
for ri in range(len(tmins) - 1, -1, -1):
fname = op.join(tempdir, 'test_raw_split-%d_raw.fif' % ri)
raw.save(fname, tmin=tmins[ri], tmax=tmaxs[ri])
raws[ri] = Raw(fname)
events = [find_events(r, stim_channel='STI 014') for r in raws]
last_samps = [r.last_samp for r in raws]
first_samps = [r.first_samp for r in raws]
# test concatenation of split file
all_raw_1 = concatenate_raws(raws, preload=False)
assert_true(raw.first_samp == all_raw_1.first_samp)
assert_true(raw.last_samp == all_raw_1.last_samp)
assert_allclose(raw[:, :][0], all_raw_1[:, :][0])
raws[0] = Raw(fname)
all_raw_2 = concatenate_raws(raws, preload=True)
assert_allclose(raw[:, :][0], all_raw_2[:, :][0])
# test proper event treatment for split files
events = concatenate_events(events, first_samps, last_samps)
events2 = find_events(all_raw_2, stim_channel='STI 014')
assert_array_equal(events, events2)
# test various methods of combining files
raw = Raw(fif_fname, preload=True)
n_times = len(raw._times)
# make sure that all our data match
times = list(range(0, 2 * n_times, 999))
# add potentially problematic points
times.extend([n_times - 1, n_times, 2 * n_times - 1])
raw_combo0 = Raw([fif_fname, fif_fname], preload=True)
_compare_combo(raw, raw_combo0, times, n_times)
raw_combo = Raw([fif_fname, fif_fname], preload=False)
_compare_combo(raw, raw_combo, times, n_times)
raw_combo = Raw([fif_fname, fif_fname], preload='memmap8.dat')
_compare_combo(raw, raw_combo, times, n_times)
assert_raises(ValueError, Raw, [fif_fname, ctf_fname])
assert_raises(ValueError, Raw, [fif_fname, fif_bad_marked_fname])
assert_true(raw[:, :][0].shape[1] * 2 == raw_combo0[:, :][0].shape[1])
assert_true(raw_combo0[:, :][0].shape[1] == len(raw_combo0._times))
# with all data preloaded, result should be preloaded
raw_combo = Raw(fif_fname, preload=True)
raw_combo.append(Raw(fif_fname, preload=True))
assert_true(raw_combo._preloaded is True)
assert_true(len(raw_combo._times) == raw_combo._data.shape[1])
_compare_combo(raw, raw_combo, times, n_times)
# with any data not preloaded, don't set result as preloaded
raw_combo = concatenate_raws([Raw(fif_fname, preload=True),
Raw(fif_fname, preload=False)])
assert_true(raw_combo._preloaded is False)
assert_array_equal(find_events(raw_combo, stim_channel='STI 014'),
find_events(raw_combo0, stim_channel='STI 014'))
_compare_combo(raw, raw_combo, times, n_times)
# user should be able to force data to be preloaded upon concat
raw_combo = concatenate_raws([Raw(fif_fname, preload=False),
Raw(fif_fname, preload=True)],
preload=True)
assert_true(raw_combo._preloaded is True)
_compare_combo(raw, raw_combo, times, n_times)
raw_combo = concatenate_raws([Raw(fif_fname, preload=False),
Raw(fif_fname, preload=True)],
preload='memmap3.dat')
_compare_combo(raw, raw_combo, times, n_times)
raw_combo = concatenate_raws([Raw(fif_fname, preload=True),
Raw(fif_fname, preload=True)],
preload='memmap4.dat')
_compare_combo(raw, raw_combo, times, n_times)
raw_combo = concatenate_raws([Raw(fif_fname, preload=False),
Raw(fif_fname, preload=False)],
preload='memmap5.dat')
_compare_combo(raw, raw_combo, times, n_times)
# verify that combining raws with different projectors throws an exception
raw.add_proj([], remove_existing=True)
assert_raises(ValueError, raw.append, Raw(fif_fname, preload=True))
# now test event treatment for concatenated raw files
events = [find_events(raw, stim_channel='STI 014'),
#.........这里部分代码省略.........