本文整理汇总了Python中mne.make_sphere_model函数的典型用法代码示例。如果您正苦于以下问题:Python make_sphere_model函数的具体用法?Python make_sphere_model怎么用?Python make_sphere_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_sphere_model函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_make_sphere_model
def test_make_sphere_model():
"""Test making a sphere model."""
info = read_info(fname_raw)
pytest.raises(ValueError, make_sphere_model, 'foo', 'auto', info)
pytest.raises(ValueError, make_sphere_model, 'auto', 'auto', None)
pytest.raises(ValueError, make_sphere_model, 'auto', 'auto', info,
relative_radii=(), sigmas=())
pytest.raises(ValueError, make_sphere_model, 'auto', 'auto', info,
relative_radii=(1,)) # wrong number of radii
# here we just make sure it works -- the functionality is actually
# tested more extensively e.g. in the forward and dipole code
with catch_logging() as log:
bem = make_sphere_model('auto', 'auto', info, verbose=True)
log = log.getvalue()
assert ' RV = ' in log
for line in log.split('\n'):
if ' RV = ' in line:
val = float(line.split()[-2])
assert val < 0.01 # actually decent fitting
break
assert '3 layers' in repr(bem)
assert 'Sphere ' in repr(bem)
assert ' mm' in repr(bem)
bem = make_sphere_model('auto', None, info)
assert 'no layers' in repr(bem)
assert 'Sphere ' in repr(bem)
pytest.raises(ValueError, make_sphere_model, sigmas=(0.33,),
relative_radii=(1.0,))
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:28,代码来源:test_bem.py
示例2: test_volume_source_space
def test_volume_source_space():
"""Test setting up volume source spaces."""
tempdir = _TempDir()
src = read_source_spaces(fname_vol)
temp_name = op.join(tempdir, 'temp-src.fif')
surf = read_bem_surfaces(fname_bem, s_id=FIFF.FIFFV_BEM_SURF_ID_BRAIN)
surf['rr'] *= 1e3 # convert to mm
# The one in the testing dataset (uses bem as bounds)
for bem, surf in zip((fname_bem, None), (None, surf)):
src_new = setup_volume_source_space(
'sample', pos=7.0, bem=bem, surface=surf, mri='T1.mgz',
subjects_dir=subjects_dir)
write_source_spaces(temp_name, src_new, overwrite=True)
src[0]['subject_his_id'] = 'sample' # XXX: to make comparison pass
_compare_source_spaces(src, src_new, mode='approx')
del src_new
src_new = read_source_spaces(temp_name)
_compare_source_spaces(src, src_new, mode='approx')
pytest.raises(IOError, setup_volume_source_space, 'sample',
pos=7.0, bem=None, surface='foo', # bad surf
mri=fname_mri, subjects_dir=subjects_dir)
assert repr(src) == repr(src_new)
assert src.kind == 'volume'
# Spheres
sphere = make_sphere_model(r0=(0., 0., 0.), head_radius=0.1,
relative_radii=(0.9, 1.0), sigmas=(0.33, 1.0))
src = setup_volume_source_space(pos=10)
src_new = setup_volume_source_space(pos=10, sphere=sphere)
_compare_source_spaces(src, src_new, mode='exact')
pytest.raises(ValueError, setup_volume_source_space, sphere='foo')
# Need a radius
sphere = make_sphere_model(head_radius=None)
pytest.raises(ValueError, setup_volume_source_space, sphere=sphere)
开发者ID:teonbrooks,项目名称:mne-python,代码行数:33,代码来源:test_source_space.py
示例3: test_make_sphere_model
def test_make_sphere_model():
"""Test making a sphere model"""
info = read_info(fname_raw)
assert_raises(ValueError, make_sphere_model, 'foo', 'auto', info)
assert_raises(ValueError, make_sphere_model, 'auto', 'auto', None)
# here we just make sure it works -- the functionality is actually
# tested more extensively e.g. in the forward and dipole code
make_sphere_model('auto', 'auto', info)
开发者ID:matthew-tucker,项目名称:mne-python,代码行数:8,代码来源:test_bem.py
示例4: test_make_sphere_model
def test_make_sphere_model():
"""Test making a sphere model"""
info = read_info(fname_raw)
assert_raises(ValueError, make_sphere_model, "foo", "auto", info)
assert_raises(ValueError, make_sphere_model, "auto", "auto", None)
# here we just make sure it works -- the functionality is actually
# tested more extensively e.g. in the forward and dipole code
bem = make_sphere_model("auto", "auto", info)
assert_true("3 layers" in repr(bem))
assert_true("Sphere " in repr(bem))
assert_true(" mm" in repr(bem))
bem = make_sphere_model("auto", None, info)
assert_true("no layers" in repr(bem))
assert_true("Sphere " in repr(bem))
开发者ID:mdclarke,项目名称:mne-python,代码行数:14,代码来源:test_bem.py
示例5: test_make_forward_solution_sphere
def test_make_forward_solution_sphere():
"""Test making a forward solution with a sphere model"""
temp_dir = _TempDir()
fname_src_small = op.join(temp_dir, "sample-oct-2-src.fif")
src = setup_source_space("sample", fname_src_small, "oct2", subjects_dir=subjects_dir, add_dist=False)
out_name = op.join(temp_dir, "tmp-fwd.fif")
run_subprocess(
[
"mne_forward_solution",
"--meg",
"--eeg",
"--meas",
fname_raw,
"--src",
fname_src_small,
"--mri",
fname_trans,
"--fwd",
out_name,
]
)
fwd = read_forward_solution(out_name)
sphere = make_sphere_model(verbose=True)
fwd_py = make_forward_solution(fname_raw, fname_trans, src, sphere, meg=True, eeg=True, verbose=True)
_compare_forwards(fwd, fwd_py, 366, 108, meg_rtol=5e-1, meg_atol=1e-6, eeg_rtol=5e-1, eeg_atol=5e-1)
# Since the above is pretty lax, let's check a different way
for meg, eeg in zip([True, False], [False, True]):
fwd_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
fwd_py_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
assert_allclose(np.corrcoef(fwd_["sol"]["data"].ravel(), fwd_py_["sol"]["data"].ravel())[0, 1], 1.0, rtol=1e-3)
开发者ID:mmagnuski,项目名称:mne-python,代码行数:30,代码来源:test_make_forward.py
示例6: make_montage
def make_montage(info, kind, check=False):
from . import _reorder
assert kind in ('mgh60', 'mgh70', 'uw_70', 'uw_60')
picks = mne.pick_types(info, meg=False, eeg=True, exclude=())
if kind in ('mgh60', 'mgh70'):
ch_names = mne.utils._clean_names(
[info['ch_names'][pick] for pick in picks], remove_whitespace=True)
if kind == 'mgh60':
assert len(ch_names) in (59, 60)
else:
assert len(ch_names) in (70,)
montage = mne.channels.read_montage(kind, ch_names=ch_names)
else:
ch_names = getattr(_reorder, 'ch_names_' + kind)
ch_names = ch_names
montage = mne.channels.read_montage('standard_1020', ch_names=ch_names)
assert len(montage.ch_names) == len(ch_names)
montage.ch_names = ['EEG%03d' % ii for ii in range(1, 61)]
sphere = mne.make_sphere_model('auto', 'auto', info)
montage.pos /= np.linalg.norm(montage.pos, axis=-1, keepdims=True)
montage.pos *= sphere.radius
montage.pos += sphere['r0']
info = mne.pick_info(info, picks)
eeg_pos = np.array([ch['loc'][:3] for ch in info['chs']])
assert len(eeg_pos) == len(montage.pos), (len(eeg_pos), len(montage.pos))
if check:
from mayavi import mlab
mlab.figure(size=(800, 800))
mlab.points3d(*sphere['r0'], scale_factor=2 * sphere.radius,
color=(0., 0., 1.), opacity=0.1, mode='sphere')
mlab.points3d(*montage.pos.T, scale_factor=0.01,
color=(1, 0, 0), mode='sphere', opacity=0.5)
mlab.points3d(*eeg_pos.T, scale_factor=0.005, color=(1, 1, 1),
mode='sphere', opacity=1)
return montage, sphere
开发者ID:Eric89GXL,项目名称:mnefun,代码行数:35,代码来源:misc.py
示例7: test_volume_labels_morph
def test_volume_labels_morph(tmpdir):
"""Test generating a source space from volume label."""
# see gh-5224
evoked = mne.read_evokeds(fname_evoked)[0].crop(0, 0)
evoked.pick_channels(evoked.ch_names[:306:8])
evoked.info.normalize_proj()
n_ch = len(evoked.ch_names)
aseg_fname = op.join(subjects_dir, 'sample', 'mri', 'aseg.mgz')
label_names = get_volume_labels_from_aseg(aseg_fname)
src = setup_volume_source_space(
'sample', subjects_dir=subjects_dir, volume_label=label_names[:2],
mri=aseg_fname)
assert len(src) == 2
assert src.kind == 'volume'
n_src = sum(s['nuse'] for s in src)
sphere = make_sphere_model('auto', 'auto', evoked.info)
fwd = make_forward_solution(evoked.info, fname_trans, src, sphere)
assert fwd['sol']['data'].shape == (n_ch, n_src * 3)
inv = make_inverse_operator(evoked.info, fwd, make_ad_hoc_cov(evoked.info),
loose=1.)
stc = apply_inverse(evoked, inv)
assert stc.data.shape == (n_src, 1)
img = stc.as_volume(src, mri_resolution=True)
n_on = np.array(img.dataobj).astype(bool).sum()
assert n_on == 291 # was 291 on `master` before gh-5590
img = stc.as_volume(src, mri_resolution=False)
n_on = np.array(img.dataobj).astype(bool).sum()
assert n_on == 44 # was 20 on `master` before gh-5590
开发者ID:jhouck,项目名称:mne-python,代码行数:28,代码来源:test_morph.py
示例8: 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
示例9: test_make_forward_solution_sphere
def test_make_forward_solution_sphere():
"""Test making a forward solution with a sphere model."""
temp_dir = _TempDir()
fname_src_small = op.join(temp_dir, 'sample-oct-2-src.fif')
src = setup_source_space('sample', 'oct2', subjects_dir=subjects_dir,
add_dist=False)
write_source_spaces(fname_src_small, src) # to enable working with MNE-C
out_name = op.join(temp_dir, 'tmp-fwd.fif')
run_subprocess(['mne_forward_solution', '--meg', '--eeg',
'--meas', fname_raw, '--src', fname_src_small,
'--mri', fname_trans, '--fwd', out_name])
fwd = read_forward_solution(out_name)
sphere = make_sphere_model(verbose=True)
fwd_py = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=True, verbose=True)
_compare_forwards(fwd, fwd_py, 366, 108,
meg_rtol=5e-1, meg_atol=1e-6,
eeg_rtol=5e-1, eeg_atol=5e-1)
# Since the above is pretty lax, let's check a different way
for meg, eeg in zip([True, False], [False, True]):
fwd_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
fwd_py_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
assert_allclose(np.corrcoef(fwd_['sol']['data'].ravel(),
fwd_py_['sol']['data'].ravel())[0, 1],
1.0, rtol=1e-3)
开发者ID:olafhauk,项目名称:mne-python,代码行数:25,代码来源:test_make_forward.py
示例10: test_simulate_raw_chpi
def test_simulate_raw_chpi():
"""Test simulation of raw data with cHPI"""
with warnings.catch_warnings(record=True): # MaxShield
raw = Raw(raw_chpi_fname, allow_maxshield=True)
sphere = make_sphere_model('auto', 'auto', raw.info)
# make sparse spherical source space
sphere_vol = tuple(sphere['r0'] * 1000.) + (sphere.radius * 1000.,)
src = setup_volume_source_space('sample', sphere=sphere_vol, pos=70.)
stc = _make_stc(raw, src)
# simulate data with cHPI on
raw_sim = simulate_raw(raw, stc, None, src, sphere, cov=None, chpi=False)
raw_chpi = simulate_raw(raw, stc, None, src, sphere, cov=None, chpi=True)
# XXX we need to test that the cHPI signals are actually in the correct
# place, but that should be a subsequent enhancement (not trivial to do so)
psd_sim, freqs_sim = compute_raw_psd(raw_sim)
psd_chpi, freqs_chpi = compute_raw_psd(raw_chpi)
assert_array_equal(freqs_sim, freqs_chpi)
hpi_freqs = np.array([x['custom_ref'][0]
for x in raw.info['hpi_meas'][0]['hpi_coils']])
freq_idx = np.sort([np.argmin(np.abs(freqs_sim - f)) for f in hpi_freqs])
picks_meg = pick_types(raw.info, meg=True, eeg=False)
picks_eeg = pick_types(raw.info, meg=False, eeg=True)
assert_allclose(psd_sim[picks_eeg], psd_chpi[picks_eeg])
assert_true((psd_chpi[picks_meg][:, freq_idx] >
100 * psd_sim[picks_meg][:, freq_idx]).all())
开发者ID:leggitta,项目名称:mne-python,代码行数:25,代码来源:test_raw.py
示例11: test_apply_inverse_sphere
def test_apply_inverse_sphere():
"""Test applying an inverse with a sphere model (rank-deficient)."""
evoked = _get_evoked()
evoked.pick_channels(evoked.ch_names[:306:8])
evoked.info['projs'] = []
cov = make_ad_hoc_cov(evoked.info)
sphere = make_sphere_model('auto', 'auto', evoked.info)
fwd = read_forward_solution(fname_fwd)
vertices = [fwd['src'][0]['vertno'][::5],
fwd['src'][1]['vertno'][::5]]
stc = SourceEstimate(np.zeros((sum(len(v) for v in vertices), 1)),
vertices, 0., 1.)
fwd = restrict_forward_to_stc(fwd, stc)
fwd = make_forward_solution(evoked.info, fwd['mri_head_t'], fwd['src'],
sphere, mindist=5.)
evoked = EvokedArray(fwd['sol']['data'].copy(), evoked.info)
assert fwd['sol']['nrow'] == 39
assert fwd['nsource'] == 101
assert fwd['sol']['ncol'] == 303
tempdir = _TempDir()
temp_fname = op.join(tempdir, 'temp-inv.fif')
inv = make_inverse_operator(evoked.info, fwd, cov, loose=1.)
# This forces everything to be float32
write_inverse_operator(temp_fname, inv)
inv = read_inverse_operator(temp_fname)
stc = apply_inverse(evoked, inv, method='eLORETA',
method_params=dict(eps=1e-2))
# assert zero localization bias
assert_array_equal(np.argmax(stc.data, axis=0),
np.repeat(np.arange(101), 3))
开发者ID:teonbrooks,项目名称:mne-python,代码行数:30,代码来源:test_inverse.py
示例12: test_make_sphere_model
def test_make_sphere_model():
"""Test making a sphere model"""
info = read_info(fname_raw)
assert_raises(ValueError, make_sphere_model, 'foo', 'auto', info)
assert_raises(ValueError, make_sphere_model, 'auto', 'auto', None)
assert_raises(ValueError, make_sphere_model, 'auto', 'auto', info,
relative_radii=(), sigmas=())
assert_raises(ValueError, make_sphere_model, 'auto', 'auto', info,
relative_radii=(1,)) # wrong number of radii
# here we just make sure it works -- the functionality is actually
# tested more extensively e.g. in the forward and dipole code
bem = make_sphere_model('auto', 'auto', info)
assert_true('3 layers' in repr(bem))
assert_true('Sphere ' in repr(bem))
assert_true(' mm' in repr(bem))
bem = make_sphere_model('auto', None, info)
assert_true('no layers' in repr(bem))
assert_true('Sphere ' in repr(bem))
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:18,代码来源:test_bem.py
示例13: test_dipole_fitting_fixed
def test_dipole_fitting_fixed():
"""Test dipole fitting with a fixed position."""
import matplotlib.pyplot as plt
tpeak = 0.073
sphere = make_sphere_model(head_radius=0.1)
evoked = read_evokeds(fname_evo, baseline=(None, 0))[0]
evoked.pick_types(meg=True)
t_idx = np.argmin(np.abs(tpeak - evoked.times))
evoked_crop = evoked.copy().crop(tpeak, tpeak)
assert_equal(len(evoked_crop.times), 1)
cov = read_cov(fname_cov)
dip_seq, resid = fit_dipole(evoked_crop, cov, sphere)
assert isinstance(dip_seq, Dipole)
assert isinstance(resid, Evoked)
assert_equal(len(dip_seq.times), 1)
pos, ori, gof = dip_seq.pos[0], dip_seq.ori[0], dip_seq.gof[0]
amp = dip_seq.amplitude[0]
# Fix position, allow orientation to change
dip_free, resid_free = fit_dipole(evoked, cov, sphere, pos=pos)
assert isinstance(dip_free, Dipole)
assert isinstance(resid_free, Evoked)
assert_allclose(dip_free.times, evoked.times)
assert_allclose(np.tile(pos[np.newaxis], (len(evoked.times), 1)),
dip_free.pos)
assert_allclose(ori, dip_free.ori[t_idx]) # should find same ori
assert (np.dot(dip_free.ori, ori).mean() < 0.9) # but few the same
assert_allclose(gof, dip_free.gof[t_idx]) # ... same gof
assert_allclose(amp, dip_free.amplitude[t_idx]) # and same amp
assert_allclose(resid.data, resid_free.data[:, [t_idx]])
# Fix position and orientation
dip_fixed, resid_fixed = fit_dipole(evoked, cov, sphere, pos=pos, ori=ori)
assert (isinstance(dip_fixed, DipoleFixed))
assert_allclose(dip_fixed.times, evoked.times)
assert_allclose(dip_fixed.info['chs'][0]['loc'][:3], pos)
assert_allclose(dip_fixed.info['chs'][0]['loc'][3:6], ori)
assert_allclose(dip_fixed.data[1, t_idx], gof)
assert_allclose(resid.data, resid_fixed.data[:, [t_idx]])
_check_roundtrip_fixed(dip_fixed)
# bad resetting
evoked.info['bads'] = [evoked.ch_names[3]]
dip_fixed, resid_fixed = fit_dipole(evoked, cov, sphere, pos=pos, ori=ori)
# Degenerate conditions
evoked_nan = evoked.copy().crop(0, 0)
evoked_nan.data[0, 0] = None
pytest.raises(ValueError, fit_dipole, evoked_nan, cov, sphere)
pytest.raises(ValueError, fit_dipole, evoked, cov, sphere, ori=[1, 0, 0])
pytest.raises(ValueError, fit_dipole, evoked, cov, sphere, pos=[0, 0, 0],
ori=[2, 0, 0])
pytest.raises(ValueError, fit_dipole, evoked, cov, sphere, pos=[0.1, 0, 0])
# copying
dip_fixed_2 = dip_fixed.copy()
dip_fixed_2.data[:] = 0.
assert not np.isclose(dip_fixed.data, 0., atol=1e-20).any()
# plotting
plt.close('all')
dip_fixed.plot()
plt.close('all')
开发者ID:SherazKhan,项目名称:mne-python,代码行数:57,代码来源:test_dipole.py
示例14: test_make_forward_solution_discrete
def test_make_forward_solution_discrete():
"""Test making and converting a forward solution with discrete src."""
# smoke test for depth weighting and discrete source spaces
src = read_source_spaces(fname_src)[0]
src = SourceSpaces([src] + setup_volume_source_space(
pos=dict(rr=src['rr'][src['vertno'][:3]].copy(),
nn=src['nn'][src['vertno'][:3]].copy())))
sphere = make_sphere_model()
fwd = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=False)
convert_forward_solution(fwd, surf_ori=True)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:11,代码来源:test_make_forward.py
示例15: test_dipole_fitting_ctf
def test_dipole_fitting_ctf():
"""Test dipole fitting with CTF data."""
raw_ctf = read_raw_ctf(fname_ctf).set_eeg_reference()
events = make_fixed_length_events(raw_ctf, 1)
evoked = Epochs(raw_ctf, events, 1, 0, 0, baseline=None).average()
cov = make_ad_hoc_cov(evoked.info)
sphere = make_sphere_model((0., 0., 0.))
# XXX Eventually we should do some better checks about accuracy, but
# for now our CTF phantom fitting tutorials will have to do
# (otherwise we need to add that to the testing dataset, which is
# a bit too big)
fit_dipole(evoked, cov, sphere)
开发者ID:mvdoc,项目名称:mne-python,代码行数:12,代码来源:test_dipole.py
示例16: test_make_forward_solution_sphere
def test_make_forward_solution_sphere():
"""Test making a forward solution with a sphere model."""
temp_dir = _TempDir()
fname_src_small = op.join(temp_dir, 'sample-oct-2-src.fif')
src = setup_source_space('sample', 'oct2', subjects_dir=subjects_dir,
add_dist=False)
write_source_spaces(fname_src_small, src) # to enable working with MNE-C
out_name = op.join(temp_dir, 'tmp-fwd.fif')
run_subprocess(['mne_forward_solution', '--meg', '--eeg',
'--meas', fname_raw, '--src', fname_src_small,
'--mri', fname_trans, '--fwd', out_name])
fwd = read_forward_solution(out_name)
sphere = make_sphere_model(verbose=True)
fwd_py = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=True, verbose=True)
_compare_forwards(fwd, fwd_py, 366, 108,
meg_rtol=5e-1, meg_atol=1e-6,
eeg_rtol=5e-1, eeg_atol=5e-1)
# Since the above is pretty lax, let's check a different way
for meg, eeg in zip([True, False], [False, True]):
fwd_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
fwd_py_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
assert_allclose(np.corrcoef(fwd_['sol']['data'].ravel(),
fwd_py_['sol']['data'].ravel())[0, 1],
1.0, rtol=1e-3)
# Number of layers in the sphere model doesn't matter for MEG
# (as long as no sources are omitted due to distance)
assert len(sphere['layers']) == 4
fwd = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=False)
sphere_1 = make_sphere_model(head_radius=None)
assert len(sphere_1['layers']) == 0
assert_array_equal(sphere['r0'], sphere_1['r0'])
fwd_1 = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=False)
_compare_forwards(fwd, fwd_1, 306, 108, meg_rtol=1e-12, meg_atol=1e-12)
# Homogeneous model
sphere = make_sphere_model(head_radius=None)
with pytest.raises(RuntimeError, match='zero shells.*EEG'):
make_forward_solution(fname_raw, fname_trans, src, sphere)
开发者ID:adykstra,项目名称:mne-python,代码行数:40,代码来源:test_make_forward.py
示例17: test_inverse_ctf_comp
def test_inverse_ctf_comp():
"""Test interpolation with compensated CTF data."""
ctf_dir = op.join(testing.data_path(download=False), 'CTF')
raw_fname = op.join(ctf_dir, 'somMDYO-18av.ds')
raw = mne.io.read_raw_ctf(raw_fname)
raw.apply_gradient_compensation(1)
sphere = make_sphere_model()
cov = make_ad_hoc_cov(raw.info)
src = mne.setup_volume_source_space(
pos=dict(rr=[[0., 0., 0.01]], nn=[[0., 1., 0.]]))
fwd = make_forward_solution(raw.info, None, src, sphere, eeg=False)
inv = make_inverse_operator(raw.info, fwd, cov, loose=1.)
apply_inverse_raw(raw, inv, 1. / 9.)
开发者ID:teonbrooks,项目名称:mne-python,代码行数:13,代码来源:test_inverse.py
示例18: 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, rank=None)
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=30., 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
pytest.raises(ValueError, gamma_map, evoked, fwd, cov, alpha,
loose=0, return_residual=False)
pytest.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)
# Compare orientation obtained using fit_dipole and gamma_map
# for a simulated evoked containing a single dipole
stc = mne.VolSourceEstimate(50e-9 * np.random.RandomState(42).randn(1, 4),
vertices=stc.vertices[:1],
tmin=stc.tmin,
tstep=stc.tstep)
evoked_dip = mne.simulation.simulate_evoked(fwd, stc, info, cov, nave=1e9,
use_cps=True)
dip_gmap = gamma_map(evoked_dip, fwd, cov, 0.1, return_as_dipoles=True)
amp_max = [np.max(d.amplitude) for d in dip_gmap]
dip_gmap = dip_gmap[np.argmax(amp_max)]
assert (dip_gmap[0].pos[0] in src[0]['rr'][stc.vertices])
dip_fit = mne.fit_dipole(evoked_dip, cov, sphere)[0]
assert (np.abs(np.dot(dip_fit.ori[0], dip_gmap.ori[0])) > 0.99)
开发者ID:jhouck,项目名称:mne-python,代码行数:49,代码来源:test_gamma_map.py
示例19: compute_bias
def compute_bias(raw):
events = find_events(raw, 'STI201', verbose=False)
events = events[1:] # first one has an artifact
tmin, tmax = -0.2, 0.1
epochs = mne.Epochs(raw, events, dipole_number, tmin, tmax,
baseline=(None, -0.01), preload=True, verbose=False)
sphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=None,
verbose=False)
cov = mne.compute_covariance(epochs, tmax=0, method='oas',
rank=None, verbose=False)
idx = epochs.time_as_index(0.036)[0]
data = epochs.get_data()[:, :, idx].T
evoked = mne.EvokedArray(data, epochs.info, tmin=0.)
dip = fit_dipole(evoked, cov, sphere, n_jobs=1, verbose=False)[0]
actual_pos = mne.dipole.get_phantom_dipoles()[0][dipole_number - 1]
misses = 1000 * np.linalg.norm(dip.pos - actual_pos, axis=-1)
return misses
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:17,代码来源:plot_otp.py
示例20: test_simulate_raw_chpi
def test_simulate_raw_chpi():
"""Test simulation of raw data with cHPI."""
raw = read_raw_fif(raw_chpi_fname, allow_maxshield='yes')
picks = np.arange(len(raw.ch_names))
picks = np.setdiff1d(picks, pick_types(raw.info, meg=True, eeg=True)[::4])
raw.load_data().pick_channels([raw.ch_names[pick] for pick in picks])
raw.info.normalize_proj()
sphere = make_sphere_model('auto', 'auto', raw.info)
# make sparse spherical source space
sphere_vol = tuple(sphere['r0'] * 1000.) + (sphere.radius * 1000.,)
src = setup_volume_source_space(sphere=sphere_vol, pos=70.)
stc = _make_stc(raw, src)
# simulate data with cHPI on
with pytest.deprecated_call():
raw_sim = simulate_raw(raw, stc, None, src, sphere, cov=None,
head_pos=pos_fname, interp='zero')
# need to trim extra samples off this one
with pytest.deprecated_call():
raw_chpi = simulate_raw(raw, stc, None, src, sphere, cov=None,
chpi=True, head_pos=pos_fname, interp='zero')
# test cHPI indication
hpi_freqs, hpi_pick, hpi_ons = _get_hpi_info(raw.info)
assert_allclose(raw_sim[hpi_pick][0], 0.)
assert_allclose(raw_chpi[hpi_pick][0], hpi_ons.sum())
# test that the cHPI signals make some reasonable values
picks_meg = pick_types(raw.info, meg=True, eeg=False)
picks_eeg = pick_types(raw.info, meg=False, eeg=True)
for picks in [picks_meg[:3], picks_eeg[:3]]:
psd_sim, freqs_sim = psd_welch(raw_sim, picks=picks)
psd_chpi, freqs_chpi = psd_welch(raw_chpi, picks=picks)
assert_array_equal(freqs_sim, freqs_chpi)
freq_idx = np.sort([np.argmin(np.abs(freqs_sim - f))
for f in hpi_freqs])
if picks is picks_meg:
assert (psd_chpi[:, freq_idx] >
100 * psd_sim[:, freq_idx]).all()
else:
assert_allclose(psd_sim, psd_chpi, atol=1e-20)
# test localization based on cHPI information
quats_sim = _calculate_chpi_positions(raw_chpi, t_step_min=10.)
quats = read_head_pos(pos_fname)
_assert_quats(quats, quats_sim, dist_tol=5e-3, angle_tol=3.5)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:45,代码来源:test_raw.py
注:本文中的mne.make_sphere_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论