本文整理汇总了Python中mne.io.proj.make_projector函数的典型用法代码示例。如果您正苦于以下问题:Python make_projector函数的具体用法?Python make_projector怎么用?Python make_projector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_projector函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_compute_proj_epochs
def test_compute_proj_epochs():
"""Test SSP computation on epochs"""
event_id, tmin, tmax = 1, -0.2, 0.3
raw = Raw(raw_fname, preload=True)
events = read_events(event_fname)
bad_ch = 'MEG 2443'
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False,
exclude=[])
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=None, proj=False)
evoked = epochs.average()
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=1)
write_proj(op.join(tempdir, 'proj.fif.gz'), projs)
for p_fname in [proj_fname, proj_gz_fname,
op.join(tempdir, 'proj.fif.gz')]:
projs2 = read_proj(p_fname)
assert_true(len(projs) == len(projs2))
for p1, p2 in zip(projs, projs2):
assert_true(p1['desc'] == p2['desc'])
assert_true(p1['data']['col_names'] == p2['data']['col_names'])
assert_true(p1['active'] == p2['active'])
# compare with sign invariance
p1_data = p1['data']['data'] * np.sign(p1['data']['data'][0, 0])
p2_data = p2['data']['data'] * np.sign(p2['data']['data'][0, 0])
if bad_ch in p1['data']['col_names']:
bad = p1['data']['col_names'].index('MEG 2443')
mask = np.ones(p1_data.size, dtype=np.bool)
mask[bad] = False
p1_data = p1_data[:, mask]
p2_data = p2_data[:, mask]
corr = np.corrcoef(p1_data, p2_data)[0, 1]
assert_array_almost_equal(corr, 1.0, 5)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, epochs.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
epochs.info['projs'] += projs
evoked = epochs.average()
evoked.save(op.join(tempdir, 'foo.fif'))
projs = read_proj(proj_fname)
projs_evoked = compute_proj_evoked(evoked, n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(projs_evoked) == 2)
# XXX : test something
# test parallelization
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=2)
projs = activate_proj(projs)
proj_par, _, _ = make_projector(projs, epochs.ch_names, bads=[])
assert_allclose(proj, proj_par, rtol=1e-8, atol=1e-16)
开发者ID:anywave,项目名称:aw-export-fif,代码行数:60,代码来源:test_proj.py
示例2: test_compute_proj_raw
def test_compute_proj_raw():
"""Test SSP computation on raw"""
# Test that the raw projectors work
raw_time = 2.5 # Do shorter amount for speed
raw = Raw(raw_fname, preload=True).crop(0, raw_time, False)
for ii in (0.25, 0.5, 1, 2):
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw, duration=ii - 0.1, stop=raw_time,
n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(w) == 1)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, raw.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
raw.info['projs'] += projs
raw.save(op.join(tempdir, 'foo_%d_raw.fif' % ii), overwrite=True)
# Test that purely continuous (no duration) raw projection works
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw, duration=None, stop=raw_time,
n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(w) == 1)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, raw.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
raw.info['projs'] += projs
raw.save(op.join(tempdir, 'foo_rawproj_continuous_raw.fif'))
# test resampled-data projector, upsampling instead of downsampling
# here to save an extra filtering (raw would have to be LP'ed to be equiv)
raw_resamp = cp.deepcopy(raw)
raw_resamp.resample(raw.info['sfreq'] * 2, n_jobs=2)
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw_resamp, duration=None, stop=raw_time,
n_grad=1, n_mag=1, n_eeg=0)
projs = activate_proj(projs)
proj_new, _, _ = make_projector(projs, raw.ch_names, bads=[])
assert_array_almost_equal(proj_new, proj, 4)
# test with bads
raw.load_bad_channels(bads_fname) # adds 2 bad mag channels
with warnings.catch_warnings(record=True) as w:
projs = compute_proj_raw(raw, n_grad=0, n_mag=0, n_eeg=1)
# test that bad channels can be excluded
proj, nproj, U = make_projector(projs, raw.ch_names,
bads=raw.ch_names)
assert_array_almost_equal(proj, np.eye(len(raw.ch_names)))
开发者ID:anywave,项目名称:aw-export-fif,代码行数:59,代码来源:test_proj.py
示例3: test_compute_proj_parallel
def test_compute_proj_parallel():
"""Test computation of ExG projectors using parallelization"""
raw_0 = Raw(raw_fname).crop(0, 10, copy=False)
raw_0.load_data()
raw = raw_0.copy()
projs, _ = compute_proj_eog(raw, n_mag=2, n_grad=2, n_eeg=2,
bads=['MEG 2443'], average=False,
avg_ref=True, no_proj=False, n_jobs=1,
l_freq=None, h_freq=None, reject=None,
tmax=dur_use)
raw_2 = raw_0.copy()
projs_2, _ = compute_proj_eog(raw_2, n_mag=2, n_grad=2, n_eeg=2,
bads=['MEG 2443'], average=False,
avg_ref=True, no_proj=False, n_jobs=2,
l_freq=None, h_freq=None, reject=None,
tmax=dur_use)
projs = activate_proj(projs)
projs_2 = activate_proj(projs_2)
projs, _, _ = make_projector(projs, raw_2.info['ch_names'],
bads=['MEG 2443'])
projs_2, _, _ = make_projector(projs_2, raw_2.info['ch_names'],
bads=['MEG 2443'])
assert_array_almost_equal(projs, projs_2, 10)
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:23,代码来源:test_ssp.py
示例4: test_inverse_residual
def test_inverse_residual():
"""Test MNE inverse application."""
# use fname_inv as it will be faster than fname_full (fewer verts and chs)
evoked = _get_evoked().pick_types()
inv = read_inverse_operator(fname_inv_fixed_depth)
fwd = read_forward_solution(fname_fwd)
fwd = convert_forward_solution(fwd, force_fixed=True, surf_ori=True)
fwd = pick_channels_forward(fwd, evoked.ch_names)
matcher = re.compile(r'.* ([0-9]?[0-9]?[0-9]?\.[0-9])% variance.*')
for method in ('MNE', 'dSPM', 'sLORETA'):
with catch_logging() as log:
stc, residual = apply_inverse(
evoked, inv, method=method, return_residual=True, verbose=True)
log = log.getvalue()
match = matcher.match(log.replace('\n', ' '))
assert match is not None
match = float(match.group(1))
assert 45 < match < 50
if method == 'MNE': # must be first!
recon = apply_forward(fwd, stc, evoked.info)
proj_op = make_projector(evoked.info['projs'], evoked.ch_names)[0]
recon.data[:] = np.dot(proj_op, recon.data)
residual_fwd = evoked.copy()
residual_fwd.data -= recon.data
corr = np.corrcoef(residual_fwd.data.ravel(),
residual.data.ravel())[0, 1]
assert corr > 0.999
with catch_logging() as log:
_, residual = apply_inverse(
evoked, inv, 0., 'MNE', return_residual=True, verbose=True)
log = log.getvalue()
match = matcher.match(log.replace('\n', ' '))
assert match is not None
match = float(match.group(1))
assert match == 100.
assert_array_less(np.abs(residual.data), 1e-15)
# Degenerate: we don't have the right representation for eLORETA for this
with pytest.raises(ValueError, match='eLORETA does not .* support .*'):
apply_inverse(evoked, inv, method="eLORETA", return_residual=True)
开发者ID:vibhaviswana,项目名称:mne-python,代码行数:40,代码来源:test_inverse.py
示例5: test_compute_proj_epochs
def test_compute_proj_epochs():
"""Test SSP computation on epochs."""
tempdir = _TempDir()
event_id, tmin, tmax = 1, -0.2, 0.3
raw = read_raw_fif(raw_fname, preload=True)
events = read_events(event_fname)
bad_ch = "MEG 2443"
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False, exclude=[])
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks, baseline=None, proj=False)
evoked = epochs.average()
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=1)
write_proj(op.join(tempdir, "test-proj.fif.gz"), projs)
for p_fname in [proj_fname, proj_gz_fname, op.join(tempdir, "test-proj.fif.gz")]:
projs2 = read_proj(p_fname)
assert_true(len(projs) == len(projs2))
for p1, p2 in zip(projs, projs2):
assert_true(p1["desc"] == p2["desc"])
assert_true(p1["data"]["col_names"] == p2["data"]["col_names"])
assert_true(p1["active"] == p2["active"])
# compare with sign invariance
p1_data = p1["data"]["data"] * np.sign(p1["data"]["data"][0, 0])
p2_data = p2["data"]["data"] * np.sign(p2["data"]["data"][0, 0])
if bad_ch in p1["data"]["col_names"]:
bad = p1["data"]["col_names"].index("MEG 2443")
mask = np.ones(p1_data.size, dtype=np.bool)
mask[bad] = False
p1_data = p1_data[:, mask]
p2_data = p2_data[:, mask]
corr = np.corrcoef(p1_data, p2_data)[0, 1]
assert_array_almost_equal(corr, 1.0, 5)
if p2["explained_var"]:
assert_array_almost_equal(p1["explained_var"], p2["explained_var"])
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, epochs.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
epochs.info["projs"] += projs
evoked = epochs.average()
evoked.save(op.join(tempdir, "foo-ave.fif"))
projs = read_proj(proj_fname)
projs_evoked = compute_proj_evoked(evoked, n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(projs_evoked) == 2)
# XXX : test something
# test parallelization
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=2, desc_prefix="foobar")
assert_true(all("foobar" in x["desc"] for x in projs))
projs = activate_proj(projs)
proj_par, _, _ = make_projector(projs, epochs.ch_names, bads=[])
assert_allclose(proj, proj_par, rtol=1e-8, atol=1e-16)
# test warnings on bad filenames
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
proj_badname = op.join(tempdir, "test-bad-name.fif.gz")
write_proj(proj_badname, projs)
read_proj(proj_badname)
assert_naming(w, "test_proj.py", 2)
开发者ID:nwilming,项目名称:mne-python,代码行数:69,代码来源:test_proj.py
示例6: test_compute_proj_epochs
def test_compute_proj_epochs():
"""Test SSP computation on epochs."""
tempdir = _TempDir()
event_id, tmin, tmax = 1, -0.2, 0.3
raw = read_raw_fif(raw_fname, preload=True)
events = read_events(event_fname)
bad_ch = 'MEG 2443'
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False,
exclude=[])
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=None, proj=False)
evoked = epochs.average()
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=1)
write_proj(op.join(tempdir, 'test-proj.fif.gz'), projs)
for p_fname in [proj_fname, proj_gz_fname,
op.join(tempdir, 'test-proj.fif.gz')]:
projs2 = read_proj(p_fname)
assert len(projs) == len(projs2)
for p1, p2 in zip(projs, projs2):
assert p1['desc'] == p2['desc']
assert p1['data']['col_names'] == p2['data']['col_names']
assert p1['active'] == p2['active']
# compare with sign invariance
p1_data = p1['data']['data'] * np.sign(p1['data']['data'][0, 0])
p2_data = p2['data']['data'] * np.sign(p2['data']['data'][0, 0])
if bad_ch in p1['data']['col_names']:
bad = p1['data']['col_names'].index('MEG 2443')
mask = np.ones(p1_data.size, dtype=np.bool)
mask[bad] = False
p1_data = p1_data[:, mask]
p2_data = p2_data[:, mask]
corr = np.corrcoef(p1_data, p2_data)[0, 1]
assert_array_almost_equal(corr, 1.0, 5)
if p2['explained_var']:
assert_array_almost_equal(p1['explained_var'],
p2['explained_var'])
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, epochs.ch_names, bads=[])
assert nproj == 2
assert U.shape[1] == 2
# test that you can save them
epochs.info['projs'] += projs
evoked = epochs.average()
evoked.save(op.join(tempdir, 'foo-ave.fif'))
projs = read_proj(proj_fname)
projs_evoked = compute_proj_evoked(evoked, n_grad=1, n_mag=1, n_eeg=0)
assert len(projs_evoked) == 2
# XXX : test something
# test parallelization
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=1,
desc_prefix='foobar')
assert all('foobar' in x['desc'] for x in projs)
projs = activate_proj(projs)
proj_par, _, _ = make_projector(projs, epochs.ch_names, bads=[])
assert_allclose(proj, proj_par, rtol=1e-8, atol=1e-16)
# test warnings on bad filenames
proj_badname = op.join(tempdir, 'test-bad-name.fif.gz')
with pytest.warns(RuntimeWarning, match='-proj.fif'):
write_proj(proj_badname, projs)
with pytest.warns(RuntimeWarning, match='-proj.fif'):
read_proj(proj_badname)
开发者ID:jhouck,项目名称:mne-python,代码行数:73,代码来源:test_proj.py
注:本文中的mne.io.proj.make_projector函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论