本文整理汇总了Python中mne.read_cov函数的典型用法代码示例。如果您正苦于以下问题:Python read_cov函数的具体用法?Python read_cov怎么用?Python read_cov使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_cov函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_cov_estimation_on_raw_segment
def test_cov_estimation_on_raw_segment():
"""Test estimation from raw on continuous recordings (typically empty room)
"""
tempdir = _TempDir()
raw = Raw(raw_fname, preload=False)
cov = compute_raw_data_covariance(raw)
cov_mne = read_cov(erm_cov_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
assert_true(linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro') < 1e-4)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
cov = compute_raw_data_covariance(raw, picks=picks)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_true(linalg.norm(cov.data - cov_mne.data[picks][:, picks],
ord='fro') / linalg.norm(cov.data, ord='fro') < 1e-4)
# make sure we get a warning with too short a segment
raw_2 = raw.crop(0, 1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov = compute_raw_data_covariance(raw_2)
assert_true(len(w) == 1)
开发者ID:LizetteH,项目名称:mne-python,代码行数:30,代码来源:test_cov.py
示例2: test_cov_estimation_with_triggers
def test_cov_estimation_with_triggers():
"""Test estimation from raw with triggers
"""
events = find_events(raw)
event_ids = [1, 2, 3, 4]
reject = dict(grad=10000e-13, mag=4e-12, eeg=80e-6, eog=150e-6)
# cov with merged events and keep_sample_mean=True
events_merged = merge_events(events, event_ids, 1234)
epochs = Epochs(raw, events_merged, 1234, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True,
reject=reject, preload=True)
cov = compute_covariance(epochs, keep_sample_mean=True)
cov_mne = read_cov(cov_km_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
assert_true((linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 0.005)
# Test with tmin and tmax (different but not too much)
cov_tmin_tmax = compute_covariance(epochs, tmin=-0.19, tmax=-0.01)
assert_true(np.all(cov.data != cov_tmin_tmax.data))
assert_true((linalg.norm(cov.data - cov_tmin_tmax.data, ord='fro')
/ linalg.norm(cov_tmin_tmax.data, ord='fro')) < 0.05)
# cov using a list of epochs and keep_sample_mean=True
epochs = [Epochs(raw, events, ev_id, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True, reject=reject)
for ev_id in event_ids]
cov2 = compute_covariance(epochs, keep_sample_mean=True)
assert_array_almost_equal(cov.data, cov2.data)
assert_true(cov.ch_names == cov2.ch_names)
# cov with keep_sample_mean=False using a list of epochs
cov = compute_covariance(epochs, keep_sample_mean=False)
cov_mne = read_cov(cov_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
assert_true((linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 0.005)
# test IO when computation done in Python
cov.save('test-cov.fif') # test saving
cov_read = read_cov('test-cov.fif')
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_true((linalg.norm(cov.data - cov_read.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 1e-5)
# cov with list of epochs with different projectors
epochs = [Epochs(raw, events[:4], event_ids[0], tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True, reject=reject),
Epochs(raw, events[:4], event_ids[0], tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=False, reject=reject)]
# these should fail
assert_raises(ValueError, compute_covariance, epochs)
assert_raises(ValueError, compute_covariance, epochs, projs=None)
# these should work, but won't be equal to above
cov = compute_covariance(epochs, projs=epochs[0].info['projs'])
cov = compute_covariance(epochs, projs=[])
开发者ID:starzynski,项目名称:mne-python,代码行数:60,代码来源:test_cov.py
示例3: test_cov_estimation_on_raw
def test_cov_estimation_on_raw():
"""Test estimation from raw (typically empty room)"""
tempdir = _TempDir()
raw = Raw(raw_fname, preload=False)
cov_mne = read_cov(erm_cov_fname)
cov = compute_raw_covariance(raw, tstep=None)
assert_equal(cov.ch_names, cov_mne.ch_names)
assert_equal(cov.nfree, cov_mne.nfree)
assert_snr(cov.data, cov_mne.data, 1e4)
cov = compute_raw_covariance(raw) # tstep=0.2 (default)
assert_equal(cov.nfree, cov_mne.nfree - 119) # cutoff some samples
assert_snr(cov.data, cov_mne.data, 1e2)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
cov = compute_raw_covariance(raw, picks=picks, tstep=None)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 1e4)
cov = compute_raw_covariance(raw, picks=picks)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 90) # cutoff samps
# make sure we get a warning with too short a segment
raw_2 = raw.crop(0, 1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov = compute_raw_covariance(raw_2)
assert_true(any('Too few samples' in str(ww.message) for ww in w))
开发者ID:GrantRVD,项目名称:mne-python,代码行数:35,代码来源:test_cov.py
示例4: test_cov_estimation_on_raw_segment
def test_cov_estimation_on_raw_segment():
"""Estimate raw on continuous recordings (typically empty room)
"""
raw = Raw(raw_fname)
cov = compute_raw_data_covariance(raw)
cov_mne = read_cov(erm_cov_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
print (linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro'))
assert_true(linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 1e-6
# test IO when computation done in Python
cov.save('test-cov.fif') # test saving
cov_read = read_cov('test-cov.fif')
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_true((linalg.norm(cov.data - cov_read.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 1e-5)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
cov = compute_raw_data_covariance(raw, picks=picks)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_true(linalg.norm(cov.data - cov_mne.data[picks][:, picks],
ord='fro') / linalg.norm(cov.data, ord='fro')) < 1e-6
开发者ID:sudo-nim,项目名称:mne-python,代码行数:26,代码来源:test_cov.py
示例5: test_cov_scaling
def test_cov_scaling():
"""Test rescaling covs"""
evoked = read_evokeds(ave_fname, condition=0, baseline=(None, 0),
proj=True)
cov = read_cov(cov_fname)['data']
cov2 = read_cov(cov_fname)['data']
assert_array_equal(cov, cov2)
evoked.pick_channels([evoked.ch_names[k] for k in pick_types(
evoked.info, meg=True, eeg=True
)])
picks_list = _picks_by_type(evoked.info)
scalings = dict(mag=1e15, grad=1e13, eeg=1e6)
_apply_scaling_cov(cov2, picks_list, scalings=scalings)
_apply_scaling_cov(cov, picks_list, scalings=scalings)
assert_array_equal(cov, cov2)
assert_true(cov.max() > 1)
_undo_scaling_cov(cov2, picks_list, scalings=scalings)
_undo_scaling_cov(cov, picks_list, scalings=scalings)
assert_array_equal(cov, cov2)
assert_true(cov.max() < 1)
data = evoked.data.copy()
_apply_scaling_array(data, picks_list, scalings=scalings)
_undo_scaling_array(data, picks_list, scalings=scalings)
assert_allclose(data, evoked.data, atol=1e-20)
开发者ID:jdammers,项目名称:mne-python,代码行数:28,代码来源:test_cov.py
示例6: test_inverse_operator_channel_ordering
def test_inverse_operator_channel_ordering():
"""Test MNE inverse computation is immune to channel reorderings
"""
# These are with original ordering
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
fwd_orig = make_forward_solution(evoked.info, fname_trans, src_fname,
fname_bem, eeg=True, mindist=5.0)
fwd_orig = convert_forward_solution(fwd_orig, surf_ori=True)
inv_orig = make_inverse_operator(evoked.info, fwd_orig, noise_cov,
loose=0.2, depth=0.8,
limit_depth_chs=False)
stc_1 = apply_inverse(evoked, inv_orig, lambda2, "dSPM")
# Assume that a raw reordering applies to both evoked and noise_cov,
# so we don't need to create those from scratch. Just reorder them,
# then try to apply the original inverse operator
new_order = np.arange(len(evoked.info['ch_names']))
randomiser = np.random.RandomState(42)
randomiser.shuffle(new_order)
evoked.data = evoked.data[new_order]
evoked.info['chs'] = [evoked.info['chs'][n] for n in new_order]
evoked.info._update_redundant()
evoked.info._check_consistency()
cov_ch_reorder = [c for c in evoked.info['ch_names']
if (c in noise_cov.ch_names)]
new_order_cov = [noise_cov.ch_names.index(name) for name in cov_ch_reorder]
noise_cov['data'] = noise_cov.data[np.ix_(new_order_cov, new_order_cov)]
noise_cov['names'] = [noise_cov['names'][idx] for idx in new_order_cov]
fwd_reorder = make_forward_solution(evoked.info, fname_trans, src_fname,
fname_bem, eeg=True, mindist=5.0)
fwd_reorder = convert_forward_solution(fwd_reorder, surf_ori=True)
inv_reorder = make_inverse_operator(evoked.info, fwd_reorder, noise_cov,
loose=0.2, depth=0.8,
limit_depth_chs=False)
stc_2 = apply_inverse(evoked, inv_reorder, lambda2, "dSPM")
assert_equal(stc_1.subject, stc_2.subject)
assert_array_equal(stc_1.times, stc_2.times)
assert_allclose(stc_1.data, stc_2.data, rtol=1e-5, atol=1e-5)
assert_true(inv_orig['units'] == inv_reorder['units'])
# Reload with original ordering & apply reordered inverse
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
stc_3 = apply_inverse(evoked, inv_reorder, lambda2, "dSPM")
assert_allclose(stc_1.data, stc_3.data, rtol=1e-5, atol=1e-5)
开发者ID:hoechenberger,项目名称:mne-python,代码行数:53,代码来源:test_inverse.py
示例7: test_io_cov
def test_io_cov():
"""Test IO for noise covariance matrices
"""
cov = read_cov(cov_fname)
cov.save('cov.fif')
cov2 = read_cov('cov.fif')
assert_array_almost_equal(cov.data, cov2.data)
cov['bads'] = ['EEG 039']
cov_sel = pick_channels_cov(cov, exclude=cov['bads'])
assert_true(cov_sel['dim'] == (len(cov['data']) - len(cov['bads'])))
assert_true(cov_sel['data'].shape == (cov_sel['dim'], cov_sel['dim']))
cov_sel.save('cov.fif')
开发者ID:sudo-nim,项目名称:mne-python,代码行数:13,代码来源:test_cov.py
示例8: test_cov_estimation_on_raw
def test_cov_estimation_on_raw():
"""Test estimation from raw (typically empty room)"""
tempdir = _TempDir()
raw = read_raw_fif(raw_fname, preload=True)
cov_mne = read_cov(erm_cov_fname)
# The pure-string uses the more efficient numpy-based method, the
# the list gets triaged to compute_covariance (should be equivalent
# but use more memory)
for method in (None, ['empirical']): # None is cast to 'empirical'
cov = compute_raw_covariance(raw, tstep=None, method=method)
assert_equal(cov.ch_names, cov_mne.ch_names)
assert_equal(cov.nfree, cov_mne.nfree)
assert_snr(cov.data, cov_mne.data, 1e4)
cov = compute_raw_covariance(raw, method=method) # tstep=0.2 (default)
assert_equal(cov.nfree, cov_mne.nfree - 119) # cutoff some samples
assert_snr(cov.data, cov_mne.data, 1e2)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
raw_pick = raw.copy().pick_channels(
[raw.ch_names[pick] for pick in picks])
raw_pick.info.normalize_proj()
cov = compute_raw_covariance(raw_pick, picks=picks, tstep=None,
method=method)
assert_true(cov_mne.ch_names[:5] == cov.ch_names)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 1e4)
cov = compute_raw_covariance(raw_pick, picks=picks, method=method)
assert_snr(cov.data, cov_mne.data[picks][:, picks], 90) # cutoff samps
# make sure we get a warning with too short a segment
raw_2 = read_raw_fif(raw_fname).crop(0, 1, copy=False)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov = compute_raw_covariance(raw_2, method=method)
assert_true(any('Too few samples' in str(ww.message) for ww in w))
# no epochs found due to rejection
assert_raises(ValueError, compute_raw_covariance, raw, tstep=None,
method='empirical', reject=dict(eog=200e-6))
# but this should work
cov = compute_raw_covariance(raw.copy().crop(0, 10., copy=False),
tstep=None, method=method,
reject=dict(eog=1000e-6))
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:50,代码来源:test_cov.py
示例9: test_io_cov
def test_io_cov():
"""Test IO for noise covariance matrices
"""
tempdir = _TempDir()
cov = read_cov(cov_fname)
cov.save(op.join(tempdir, 'test-cov.fif'))
cov2 = read_cov(op.join(tempdir, 'test-cov.fif'))
assert_array_almost_equal(cov.data, cov2.data)
cov2 = read_cov(cov_gz_fname)
assert_array_almost_equal(cov.data, cov2.data)
cov2.save(op.join(tempdir, 'test-cov.fif.gz'))
cov2 = read_cov(op.join(tempdir, 'test-cov.fif.gz'))
assert_array_almost_equal(cov.data, cov2.data)
cov['bads'] = ['EEG 039']
cov_sel = pick_channels_cov(cov, exclude=cov['bads'])
assert_true(cov_sel['dim'] == (len(cov['data']) - len(cov['bads'])))
assert_true(cov_sel['data'].shape == (cov_sel['dim'], cov_sel['dim']))
cov_sel.save(op.join(tempdir, 'test-cov.fif'))
cov2 = read_cov(cov_gz_fname)
assert_array_almost_equal(cov.data, cov2.data)
cov2.save(op.join(tempdir, 'test-cov.fif.gz'))
cov2 = read_cov(op.join(tempdir, 'test-cov.fif.gz'))
assert_array_almost_equal(cov.data, cov2.data)
# test warnings on bad filenames
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
cov_badname = op.join(tempdir, 'test-bad-name.fif.gz')
write_cov(cov_badname, cov)
read_cov(cov_badname)
assert_true(len(w) == 2)
开发者ID:LizetteH,项目名称:mne-python,代码行数:34,代码来源:test_cov.py
示例10: test_io_cov
def test_io_cov():
"""Test IO for noise covariance matrices
"""
cov = read_cov(cov_fname)
cov.save(op.join(tempdir, "test-cov.fif"))
cov2 = read_cov(op.join(tempdir, "test-cov.fif"))
assert_array_almost_equal(cov.data, cov2.data)
cov2 = read_cov(cov_gz_fname)
assert_array_almost_equal(cov.data, cov2.data)
cov2.save(op.join(tempdir, "test-cov.fif.gz"))
cov2 = read_cov(op.join(tempdir, "test-cov.fif.gz"))
assert_array_almost_equal(cov.data, cov2.data)
cov["bads"] = ["EEG 039"]
cov_sel = pick_channels_cov(cov, exclude=cov["bads"])
assert_true(cov_sel["dim"] == (len(cov["data"]) - len(cov["bads"])))
assert_true(cov_sel["data"].shape == (cov_sel["dim"], cov_sel["dim"]))
cov_sel.save(op.join(tempdir, "test-cov.fif"))
cov2 = read_cov(cov_gz_fname)
assert_array_almost_equal(cov.data, cov2.data)
cov2.save(op.join(tempdir, "test-cov.fif.gz"))
cov2 = read_cov(op.join(tempdir, "test-cov.fif.gz"))
assert_array_almost_equal(cov.data, cov2.data)
# test warnings on bad filenames
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
cov_badname = op.join(tempdir, "test-bad-name.fif.gz")
write_cov(cov_badname, cov)
read_cov(cov_badname)
assert_true(len(w) == 2)
开发者ID:rgoj,项目名称:mne-python,代码行数:33,代码来源:test_cov.py
示例11: test_cov_estimation_on_raw
def test_cov_estimation_on_raw(method, tmpdir):
"""Test estimation from raw (typically empty room)."""
tempdir = str(tmpdir)
raw = read_raw_fif(raw_fname, preload=True)
cov_mne = read_cov(erm_cov_fname)
# The pure-string uses the more efficient numpy-based method, the
# the list gets triaged to compute_covariance (should be equivalent
# but use more memory)
with pytest.warns(None): # can warn about EEG ref
cov = compute_raw_covariance(raw, tstep=None, method=method,
rank='full')
assert_equal(cov.ch_names, cov_mne.ch_names)
assert_equal(cov.nfree, cov_mne.nfree)
assert_snr(cov.data, cov_mne.data, 1e4)
# tstep=0.2 (default)
with pytest.warns(None): # can warn about EEG ref
cov = compute_raw_covariance(raw, method=method, rank='full')
assert_equal(cov.nfree, cov_mne.nfree - 119) # cutoff some samples
assert_snr(cov.data, cov_mne.data, 1e2)
# test IO when computation done in Python
cov.save(op.join(tempdir, 'test-cov.fif')) # test saving
cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
assert cov_read.ch_names == cov.ch_names
assert cov_read.nfree == cov.nfree
assert_array_almost_equal(cov.data, cov_read.data)
# test with a subset of channels
raw_pick = raw.copy().pick_channels(raw.ch_names[:5])
raw_pick.info.normalize_proj()
cov = compute_raw_covariance(raw_pick, tstep=None, method=method,
rank='full')
assert cov_mne.ch_names[:5] == cov.ch_names
assert_snr(cov.data, cov_mne.data[:5, :5], 1e4)
cov = compute_raw_covariance(raw_pick, method=method, rank='full')
assert_snr(cov.data, cov_mne.data[:5, :5], 90) # cutoff samps
# make sure we get a warning with too short a segment
raw_2 = read_raw_fif(raw_fname).crop(0, 1)
with pytest.warns(RuntimeWarning, match='Too few samples'):
cov = compute_raw_covariance(raw_2, method=method)
# no epochs found due to rejection
pytest.raises(ValueError, compute_raw_covariance, raw, tstep=None,
method='empirical', reject=dict(eog=200e-6))
# but this should work
cov = compute_raw_covariance(raw.copy().crop(0, 10.),
tstep=None, method=method,
reject=dict(eog=1000e-6),
verbose='error')
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:50,代码来源:test_cov.py
示例12: test_cov_estimation_with_triggers
def test_cov_estimation_with_triggers():
"""Estimate raw with triggers
"""
raw = Raw(raw_fname)
events = find_events(raw)
event_ids = [1, 2, 3, 4]
reject = dict(grad=10000e-13, mag=4e-12, eeg=80e-6, eog=150e-6)
# cov with merged events and keep_sample_mean=True
events_merged = merge_events(events, event_ids, 1234)
epochs = Epochs(raw, events_merged, 1234, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True,
reject=reject, preload=True)
cov = compute_covariance(epochs, keep_sample_mean=True)
cov_mne = read_cov(cov_km_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
assert_true((linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 0.005)
# Test with tmin and tmax (different but not too much)
cov_tmin_tmax = compute_covariance(epochs, tmin=-0.19, tmax=-0.01)
assert_true(np.all(cov.data != cov_tmin_tmax.data))
assert_true((linalg.norm(cov.data - cov_tmin_tmax.data, ord='fro')
/ linalg.norm(cov_tmin_tmax.data, ord='fro')) < 0.05)
# cov using a list of epochs and keep_sample_mean=True
epochs = [Epochs(raw, events, ev_id, tmin=-0.2, tmax=0,
baseline=(-0.2, -0.1), proj=True, reject=reject)
for ev_id in event_ids]
cov2 = compute_covariance(epochs, keep_sample_mean=True)
assert_array_almost_equal(cov.data, cov2.data)
assert_true(cov.ch_names == cov2.ch_names)
# cov with keep_sample_mean=False using a list of epochs
cov = compute_covariance(epochs, keep_sample_mean=False)
cov_mne = read_cov(cov_fname)
assert_true(cov_mne.ch_names == cov.ch_names)
assert_true((linalg.norm(cov.data - cov_mne.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 0.005)
# test IO when computation done in Python
cov.save('test-cov.fif') # test saving
cov_read = read_cov('test-cov.fif')
assert_true(cov_read.ch_names == cov.ch_names)
assert_true(cov_read.nfree == cov.nfree)
assert_true((linalg.norm(cov.data - cov_read.data, ord='fro')
/ linalg.norm(cov.data, ord='fro')) < 1e-5)
开发者ID:sudo-nim,项目名称:mne-python,代码行数:49,代码来源:test_cov.py
示例13: test_io_cov
def test_io_cov():
"""Test IO for noise covariance matrices
"""
fid, tree, _ = fiff_open(fname)
cov_type = 1
cov = mne.read_cov(fid, tree, cov_type)
fid.close()
mne.write_cov_file('cov.fif', cov)
fid, tree, _ = fiff_open('cov.fif')
cov2 = mne.read_cov(fid, tree, cov_type)
fid.close()
print assert_array_almost_equal(cov['data'], cov2['data'])
开发者ID:arokem,项目名称:mne-python,代码行数:15,代码来源:test_cov.py
示例14: test_ad_hoc_cov
def test_ad_hoc_cov(tmpdir):
"""Test ad hoc cov creation and I/O."""
out_fname = op.join(str(tmpdir), 'test-cov.fif')
evoked = read_evokeds(ave_fname)[0]
cov = make_ad_hoc_cov(evoked.info)
cov.save(out_fname)
assert 'Covariance' in repr(cov)
cov2 = read_cov(out_fname)
assert_array_almost_equal(cov['data'], cov2['data'])
std = dict(grad=2e-13, mag=10e-15, eeg=0.1e-6)
cov = make_ad_hoc_cov(evoked.info, std)
cov.save(out_fname)
assert 'Covariance' in repr(cov)
cov2 = read_cov(out_fname)
assert_array_almost_equal(cov['data'], cov2['data'])
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:15,代码来源:test_cov.py
示例15: test_gamma_map_vol_sphere
def test_gamma_map_vol_sphere():
"""Gamma MAP with a sphere forward and volumic source space"""
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0),
proj=False)
evoked.resample(50, npad=100)
evoked.crop(tmin=0.1, tmax=0.16) # crop to window around peak
cov = read_cov(fname_cov)
cov = regularize(cov, evoked.info)
info = evoked.info
sphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=0.080)
src = mne.setup_volume_source_space(subject=None, pos=15., mri=None,
sphere=(0.0, 0.0, 0.0, 80.0),
bem=None, mindist=5.0,
exclude=2.0)
fwd = mne.make_forward_solution(info, trans=None, src=src, bem=sphere,
eeg=False, meg=True)
alpha = 0.5
assert_raises(ValueError, gamma_map, evoked, fwd, cov, alpha,
loose=0, return_residual=False)
assert_raises(ValueError, gamma_map, evoked, fwd, cov, alpha,
loose=0.2, return_residual=False)
stc = gamma_map(evoked, fwd, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=2,
return_residual=False)
assert_array_almost_equal(stc.times, evoked.times, 5)
开发者ID:nfoti,项目名称:mne-python,代码行数:31,代码来源:test_gamma_map.py
示例16: test_plot_ica_overlay
def test_plot_ica_overlay():
"""Test plotting of ICA cleaning."""
import matplotlib.pyplot as plt
raw = _get_raw(preload=True)
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
# can't use info.normalize_proj here because of how and when ICA and Epochs
# objects do picking of Raw data
with pytest.warns(RuntimeWarning, match='projection'):
ica.fit(raw, picks=picks)
# don't test raw, needs preload ...
with pytest.warns(RuntimeWarning, match='projection'):
ecg_epochs = create_ecg_epochs(raw, picks=picks)
ica.plot_overlay(ecg_epochs.average())
with pytest.warns(RuntimeWarning, match='projection'):
eog_epochs = create_eog_epochs(raw, picks=picks)
ica.plot_overlay(eog_epochs.average())
pytest.raises(TypeError, ica.plot_overlay, raw[:2, :3][0])
ica.plot_overlay(raw)
plt.close('all')
# smoke test for CTF
raw = read_raw_fif(raw_ctf_fname)
raw.apply_gradient_compensation(3)
picks = pick_types(raw.info, meg=True, ref_meg=False)
ica = ICA(n_components=2, max_pca_components=3, n_pca_components=3)
ica.fit(raw, picks=picks)
with pytest.warns(RuntimeWarning, match='longer than'):
ecg_epochs = create_ecg_epochs(raw)
ica.plot_overlay(ecg_epochs.average())
plt.close('all')
开发者ID:SherazKhan,项目名称:mne-python,代码行数:32,代码来源:test_ica.py
示例17: test_plot_instance_components
def test_plot_instance_components():
"""Test plotting of components as instances of raw and epochs."""
import matplotlib.pyplot as plt
raw = _get_raw()
picks = _get_picks(raw)
ica = ICA(noise_cov=read_cov(cov_fname), n_components=2,
max_pca_components=3, n_pca_components=3)
with pytest.warns(RuntimeWarning, match='projection'):
ica.fit(raw, picks=picks)
fig = ica.plot_sources(raw, exclude=[0], title='Components')
for key in ['down', 'up', 'right', 'left', 'o', '-', '+', '=', 'pageup',
'pagedown', 'home', 'end', 'f11', 'b']:
fig.canvas.key_press_event(key)
ax = fig.get_axes()[0]
line = ax.lines[0]
_fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]],
'data')
_fake_click(fig, ax, [-0.1, 0.9]) # click on y-label
fig.canvas.key_press_event('escape')
plt.close('all')
epochs = _get_epochs()
fig = ica.plot_sources(epochs, exclude=[0], title='Components')
for key in ['down', 'up', 'right', 'left', 'o', '-', '+', '=', 'pageup',
'pagedown', 'home', 'end', 'f11', 'b']:
fig.canvas.key_press_event(key)
# Test a click
ax = fig.get_axes()[0]
line = ax.lines[0]
_fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], 'data')
_fake_click(fig, ax, [-0.1, 0.9]) # click on y-label
fig.canvas.key_press_event('escape')
plt.close('all')
开发者ID:SherazKhan,项目名称:mne-python,代码行数:32,代码来源:test_ica.py
示例18: test_gamma_map
def test_gamma_map():
"""Test Gamma MAP inverse"""
forward = read_forward_solution(fname_fwd, force_fixed=False,
surf_ori=True)
forward = pick_types_forward(forward, meg=False, eeg=True)
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0))
evoked.resample(50)
evoked.crop(tmin=0, tmax=0.3)
cov = read_cov(fname_cov)
cov = regularize(cov, evoked.info)
alpha = 0.2
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-5,
xyz_same_gamma=True, update_mode=1, verbose=False)
idx = np.argmax(np.sum(stc.data ** 2, axis=1))
assert_true(np.concatenate(stc.vertices)[idx] == 96397)
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-5,
xyz_same_gamma=False, update_mode=1, verbose=False)
idx = np.argmax(np.sum(stc.data ** 2, axis=1))
assert_true(np.concatenate(stc.vertices)[idx] == 82010)
# force fixed orientation
stc, res = gamma_map(evoked, forward, cov, alpha, tol=1e-5,
xyz_same_gamma=False, update_mode=2,
loose=None, return_residual=True, verbose=False)
idx = np.argmax(np.sum(stc.data ** 2, axis=1))
# assert_true(np.concatenate(stc.vertices)[idx] == 83398) # XXX FIX
assert_array_almost_equal(evoked.times, res.times)
开发者ID:pombreda,项目名称:mne-python,代码行数:30,代码来源:test_gamma_map.py
示例19: run_inverse
def run_inverse(subject_id):
subject = "sub%03d" % subject_id
print("processing subject: %s" % subject)
data_path = op.join(meg_dir, subject)
fname_ave = op.join(data_path, '%s-ave.fif' % subject)
fname_cov = op.join(data_path, '%s-cov.fif' % subject)
fname_fwd = op.join(data_path, '%s-meg-%s-fwd.fif' % (subject, spacing))
fname_inv = op.join(data_path, '%s-meg-%s-inv.fif' % (subject, spacing))
evokeds = mne.read_evokeds(fname_ave, condition=[0, 1, 2, 3, 4, 5])
cov = mne.read_cov(fname_cov)
# cov = mne.cov.regularize(cov, evokeds[0].info,
# mag=0.05, grad=0.05, eeg=0.1, proj=True)
forward = mne.read_forward_solution(fname_fwd, surf_ori=True)
# forward = mne.pick_types_forward(forward, meg=True, eeg=False)
# make an M/EEG, MEG-only, and EEG-only inverse operators
info = evokeds[0].info
inverse_operator = make_inverse_operator(info, forward, cov,
loose=0.2, depth=0.8)
write_inverse_operator(fname_inv, inverse_operator)
# Compute inverse solution
snr = 3.0
lambda2 = 1.0 / snr ** 2
for evoked in evokeds:
stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM",
pick_ori=None)
stc.save(op.join(data_path, 'mne_dSPM_inverse-%s' % evoked.comment))
开发者ID:dengemann,项目名称:mne-biomag-group-demo,代码行数:34,代码来源:06-make_inverse.py
示例20: test_make_inverse_operator_free
def test_make_inverse_operator_free():
"""Test MNE inverse computation (free orientation)
"""
fwd_op = read_forward_solution_meg(fname_fwd, surf_ori=True)
fwd_1 = read_forward_solution_meg(fname_fwd, surf_ori=False,
force_fixed=False)
fwd_2 = read_forward_solution_meg(fname_fwd, surf_ori=False,
force_fixed=True)
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
# can't make free inv with fixed fwd
assert_raises(ValueError, make_inverse_operator, evoked.info, fwd_2,
noise_cov, depth=None)
# for free ori inv, loose=None and loose=1 should be equivalent
inv_1 = make_inverse_operator(evoked.info, fwd_op, noise_cov, loose=None)
inv_2 = make_inverse_operator(evoked.info, fwd_op, noise_cov, loose=1)
_compare_inverses_approx(inv_1, inv_2, evoked, 0, 1e-2)
# for depth=None, surf_ori of the fwd should not matter
inv_3 = make_inverse_operator(evoked.info, fwd_op, noise_cov, depth=None,
loose=None)
inv_4 = make_inverse_operator(evoked.info, fwd_1, noise_cov, depth=None,
loose=None)
_compare_inverses_approx(inv_3, inv_4, evoked, 0, 1e-2)
开发者ID:cmoutard,项目名称:mne-python,代码行数:26,代码来源:test_inverse.py
注:本文中的mne.read_cov函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论