本文整理汇总了Python中mne.read_forward_solution函数的典型用法代码示例。如果您正苦于以下问题:Python read_forward_solution函数的具体用法?Python read_forward_solution怎么用?Python read_forward_solution使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_forward_solution函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_convert_forward
def test_convert_forward():
"""Test converting forward solution between different representations
"""
fwd = read_forward_solution(fname_meeg)
print(fwd) # __repr__
assert_true(isinstance(fwd, Forward))
# look at surface orientation
fwd_surf = convert_forward_solution(fwd, surf_ori=True)
fwd_surf_io = read_forward_solution(fname_meeg, surf_ori=True)
compare_forwards(fwd_surf, fwd_surf_io)
# go back
fwd_new = convert_forward_solution(fwd_surf, surf_ori=False)
print(fwd_new)
assert_true(isinstance(fwd, Forward))
compare_forwards(fwd, fwd_new)
# now go to fixed
fwd_fixed = convert_forward_solution(fwd_surf, surf_ori=False,
force_fixed=True)
print(fwd_fixed)
assert_true(isinstance(fwd_fixed, Forward))
fwd_fixed_io = read_forward_solution(fname_meeg, surf_ori=False,
force_fixed=True)
compare_forwards(fwd_fixed, fwd_fixed_io)
# now go back to cartesian (original condition)
fwd_new = convert_forward_solution(fwd_fixed)
print(fwd_new)
assert_true(isinstance(fwd_new, Forward))
compare_forwards(fwd, fwd_new)
开发者ID:dengemann,项目名称:mne-python,代码行数:28,代码来源:test_forward.py
示例2: test_make_inverse_operator_fixed
def test_make_inverse_operator_fixed():
"""Test MNE inverse computation w/ fixed orientation (& no depth weighting)
"""
fwd_op = read_forward_solution(fname_fwd, surf_ori=True)
fwd_1 = read_forward_solution(fname_fwd, surf_ori=False, force_fixed=False)
fwd_2 = read_forward_solution(fname_fwd, surf_ori=False, force_fixed=True)
# can't make fixed inv without surf ori fwd
assert_raises(ValueError, make_inverse_operator, evoked.info, fwd_1,
noise_cov, depth=0.8, loose=None, fixed=True)
# can't make fixed inv with depth weighting without free ori fwd
assert_raises(ValueError, make_inverse_operator, evoked.info, fwd_2,
noise_cov, depth=0.8, loose=None, fixed=True)
inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov, depth=0.8,
loose=None, fixed=True)
_compare_io(inv_op)
inverse_operator_fixed = read_inverse_operator(fname_inv_fixed)
_compare_inverses_approx(inverse_operator_fixed, inv_op, evoked, 2)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator_fixed) == 302)
# Now without depth weighting, these should be equivalent
inv_op = make_inverse_operator(evoked.info, fwd_2, noise_cov, depth=None,
loose=None, fixed=True)
inv_2 = make_inverse_operator(evoked.info, fwd_op, noise_cov, depth=None,
loose=None, fixed=True)
_compare_inverses_approx(inv_op, inv_2, evoked, 2)
_compare_io(inv_op)
# now compare to C solution
inverse_operator_nodepth = read_inverse_operator(fname_inv_nodepth)
_compare_inverses_approx(inverse_operator_nodepth, inv_op, evoked, 2)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator_fixed) == 302)
开发者ID:simonster,项目名称:mne-python,代码行数:33,代码来源:test_inverse.py
示例3: test_make_inverse_operator_fixed
def test_make_inverse_operator_fixed():
"""Test MNE inverse computation (fixed orientation)
"""
fwd_op = read_forward_solution(fname_fwd, surf_ori=True)
fwd_1 = read_forward_solution(fname_fwd, surf_ori=False, force_fixed=False)
fwd_2 = read_forward_solution(fname_fwd, surf_ori=False, force_fixed=True)
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
# can't make depth-weighted fixed inv without surf ori fwd
assert_raises(ValueError, make_inverse_operator, evoked.info, fwd_1,
noise_cov, depth=0.8, loose=None, fixed=True)
# can't make fixed inv with depth weighting without free ori fwd
assert_raises(ValueError, make_inverse_operator, evoked.info, fwd_2,
noise_cov, depth=0.8, loose=None, fixed=True)
# compare to C solution w/fixed
inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov, depth=0.8,
loose=None, fixed=True)
_compare_io(inv_op)
inverse_operator_fixed = read_inverse_operator(fname_inv_fixed)
_compare_inverses_approx(inverse_operator_fixed, inv_op, evoked, 2)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator_fixed) == 302)
# now compare to C solution
# note that the forward solution must not be surface-oriented
# to get equivalency (surf_ori=True changes the normals)
inv_op = make_inverse_operator(evoked.info, fwd_2, noise_cov, depth=None,
loose=None, fixed=True)
inverse_operator_nodepth = read_inverse_operator(fname_inv_nodepth)
_compare_inverses_approx(inverse_operator_nodepth, inv_op, evoked, 2)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator_fixed) == 302)
开发者ID:Anevar,项目名称:mne-python,代码行数:34,代码来源:test_inverse.py
示例4: test_io_forward
def test_io_forward():
"""Test IO for forward solutions
"""
fwd = mne.read_forward_solution(fname)
fwd = mne.read_forward_solution(fname, force_fixed=True)
fwd = mne.read_forward_solution(fname, surf_ori=True)
leadfield = fwd['sol']['data']
开发者ID:emilyruzich,项目名称:mne-python,代码行数:7,代码来源:test_forward.py
示例5: test_psf_ctf
def test_psf_ctf():
"""Test computation of PSFs and CTFs for linear estimators
"""
inverse_operator = read_inverse_operator(fname_inv)
forward = read_forward_solution(fname_fwd, force_fixed=False,
surf_ori=True)
forward = pick_types_forward(forward, meg=True, eeg=False)
labels = [mne.read_label(ss) for ss in fname_label]
method = 'MNE'
n_svd_comp = 2
# Test PSFs (then CTFs)
for mode in ('sum', 'svd'):
stc_psf, psf_ev = point_spread_function(inverse_operator,
forward,
method=method,
labels=labels,
lambda2=lambda2,
pick_ori='normal',
mode=mode,
n_svd_comp=n_svd_comp)
n_vert, n_samples = stc_psf.shape
should_n_vert = (inverse_operator['src'][1]['vertno'].shape[0] +
inverse_operator['src'][0]['vertno'].shape[0])
if mode == 'svd':
should_n_samples = len(labels) * n_svd_comp + 1
else:
should_n_samples = len(labels) + 1
assert_true(n_vert == should_n_vert)
assert_true(n_samples == should_n_samples)
n_chan, n_samples = psf_ev.data.shape
assert_true(n_chan == forward['nchan'])
forward = read_forward_solution(fname_fwd, force_fixed=True, surf_ori=True)
forward = pick_types_forward(forward, meg=True, eeg=False)
# Test CTFs
for mode in ('sum', 'svd'):
stc_ctf = cross_talk_function(inverse_operator, forward,
labels, method=method,
lambda2=lambda2,
signed=False, mode=mode,
n_svd_comp=n_svd_comp)
n_vert, n_samples = stc_ctf.shape
should_n_vert = (inverse_operator['src'][1]['vertno'].shape[0] +
inverse_operator['src'][0]['vertno'].shape[0])
if mode == 'svd':
should_n_samples = len(labels) * n_svd_comp + 1
else:
should_n_samples = len(labels) + 1
assert_true(n_vert == should_n_vert)
assert_true(n_samples == should_n_samples)
开发者ID:LizetteH,项目名称:mne-python,代码行数:59,代码来源:test_psf_ctf.py
示例6: _get_data
def _get_data(tmin=-0.1, tmax=0.15, all_forward=True, epochs=True,
epochs_preload=True, data_cov=True):
"""Read in data used in tests
"""
label = mne.read_label(fname_label)
events = mne.read_events(fname_event)
raw = mne.fiff.Raw(fname_raw, preload=True)
forward = mne.read_forward_solution(fname_fwd)
if all_forward:
forward_surf_ori = mne.read_forward_solution(fname_fwd, surf_ori=True)
forward_fixed = mne.read_forward_solution(fname_fwd, force_fixed=True,
surf_ori=True)
forward_vol = mne.read_forward_solution(fname_fwd_vol, surf_ori=True)
else:
forward_surf_ori = None
forward_fixed = None
forward_vol = None
event_id, tmin, tmax = 1, tmin, tmax
# Setup for reading the raw data
raw.info['bads'] = ['MEG 2443', 'EEG 053'] # 2 bads channels
if epochs:
# Set up pick list: MEG - bad channels
left_temporal_channels = mne.read_selection('Left-temporal')
picks = mne.fiff.pick_types(raw.info, meg=True, eeg=False,
stim=True, eog=True, ref_meg=False,
exclude='bads',
selection=left_temporal_channels)
# Read epochs
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=picks, baseline=(None, 0),
preload=epochs_preload,
reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))
if epochs_preload:
epochs.resample(200, npad=0, n_jobs=2)
evoked = epochs.average()
info = evoked.info
else:
epochs = None
evoked = None
info = raw.info
noise_cov = mne.read_cov(fname_cov)
noise_cov = mne.cov.regularize(noise_cov, info,
mag=0.05, grad=0.05, eeg=0.1, proj=True)
if data_cov:
data_cov = mne.compute_covariance(epochs, tmin=0.04, tmax=0.15)
else:
data_cov = None
return raw, epochs, evoked, data_cov, noise_cov, label, forward,\
forward_surf_ori, forward_fixed, forward_vol
开发者ID:Anevar,项目名称:mne-python,代码行数:55,代码来源:test_lcmv.py
示例7: test_restrict_forward_to_label
def test_restrict_forward_to_label():
"""Test restriction of source space to label
"""
fwd = read_forward_solution(fname_meeg, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)
label_path = op.join(data_path, 'MEG', 'sample', 'labels')
labels = ['Aud-lh', 'Vis-rh']
label_lh = read_label(op.join(label_path, labels[0] + '.label'))
label_rh = read_label(op.join(label_path, labels[1] + '.label'))
fwd_out = restrict_forward_to_label(fwd, [label_lh, label_rh])
src_sel_lh = np.intersect1d(fwd['src'][0]['vertno'], label_lh.vertices)
src_sel_lh = np.searchsorted(fwd['src'][0]['vertno'], src_sel_lh)
vertno_lh = fwd['src'][0]['vertno'][src_sel_lh]
nuse_lh = fwd['src'][0]['nuse']
src_sel_rh = np.intersect1d(fwd['src'][1]['vertno'], label_rh.vertices)
src_sel_rh = np.searchsorted(fwd['src'][1]['vertno'], src_sel_rh)
vertno_rh = fwd['src'][1]['vertno'][src_sel_rh]
src_sel_rh += nuse_lh
assert_equal(fwd_out['sol']['ncol'], len(src_sel_lh) + len(src_sel_rh))
assert_equal(fwd_out['src'][0]['nuse'], len(src_sel_lh))
assert_equal(fwd_out['src'][1]['nuse'], len(src_sel_rh))
assert_equal(fwd_out['src'][0]['vertno'], vertno_lh)
assert_equal(fwd_out['src'][1]['vertno'], vertno_rh)
fwd = read_forward_solution(fname_meeg, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)
label_path = op.join(data_path, 'MEG', 'sample', 'labels')
labels = ['Aud-lh', 'Vis-rh']
label_lh = read_label(op.join(label_path, labels[0] + '.label'))
label_rh = read_label(op.join(label_path, labels[1] + '.label'))
fwd_out = restrict_forward_to_label(fwd, [label_lh, label_rh])
src_sel_lh = np.intersect1d(fwd['src'][0]['vertno'], label_lh.vertices)
src_sel_lh = np.searchsorted(fwd['src'][0]['vertno'], src_sel_lh)
vertno_lh = fwd['src'][0]['vertno'][src_sel_lh]
nuse_lh = fwd['src'][0]['nuse']
src_sel_rh = np.intersect1d(fwd['src'][1]['vertno'], label_rh.vertices)
src_sel_rh = np.searchsorted(fwd['src'][1]['vertno'], src_sel_rh)
vertno_rh = fwd['src'][1]['vertno'][src_sel_rh]
src_sel_rh += nuse_lh
assert_equal(fwd_out['sol']['ncol'],
3 * (len(src_sel_lh) + len(src_sel_rh)))
assert_equal(fwd_out['src'][0]['nuse'], len(src_sel_lh))
assert_equal(fwd_out['src'][1]['nuse'], len(src_sel_rh))
assert_equal(fwd_out['src'][0]['vertno'], vertno_lh)
assert_equal(fwd_out['src'][1]['vertno'], vertno_rh)
开发者ID:GrantRVD,项目名称:mne-python,代码行数:55,代码来源:test_forward.py
示例8: test_restrict_forward_to_stc
def test_restrict_forward_to_stc():
"""Test restriction of source space to source SourceEstimate
"""
start = 0
stop = 5
n_times = stop - start - 1
sfreq = 10.0
t_start = 0.123
fwd = read_forward_solution(fname_meeg)
fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=True,
use_cps=True)
fwd = pick_types_forward(fwd, meg=True)
vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
fwd_out = restrict_forward_to_stc(fwd, stc)
assert_true(isinstance(fwd_out, Forward))
assert_equal(fwd_out['sol']['ncol'], 20)
assert_equal(fwd_out['src'][0]['nuse'], 15)
assert_equal(fwd_out['src'][1]['nuse'], 5)
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])
fwd = read_forward_solution(fname_meeg)
fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)
vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
fwd_out = restrict_forward_to_stc(fwd, stc)
assert_equal(fwd_out['sol']['ncol'], 60)
assert_equal(fwd_out['src'][0]['nuse'], 15)
assert_equal(fwd_out['src'][1]['nuse'], 5)
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])
# Test saving the restricted forward object. This only works if all fields
# are properly accounted for.
temp_dir = _TempDir()
fname_copy = op.join(temp_dir, 'copy-fwd.fif')
with warnings.catch_warnings(record=True):
warnings.simplefilter('always')
write_forward_solution(fname_copy, fwd_out, overwrite=True)
fwd_out_read = read_forward_solution(fname_copy)
fwd_out_read = convert_forward_solution(fwd_out_read, surf_ori=True,
force_fixed=False)
compare_forwards(fwd_out, fwd_out_read)
开发者ID:HSMin,项目名称:mne-python,代码行数:54,代码来源:test_forward.py
示例9: test_convert_forward
def test_convert_forward():
"""Test converting forward solution between different representations
"""
fwd = read_forward_solution(fname_meeg_grad)
fwd_repr = repr(fwd)
assert_true('306' in fwd_repr)
assert_true('60' in fwd_repr)
assert_true(fwd_repr)
assert_true(isinstance(fwd, Forward))
# look at surface orientation
fwd_surf = convert_forward_solution(fwd, surf_ori=True)
# The following test can be removed in 0.16
fwd_surf_io = read_forward_solution(fname_meeg_grad, surf_ori=True)
compare_forwards(fwd_surf, fwd_surf_io)
del fwd_surf_io
gc.collect()
# go back
fwd_new = convert_forward_solution(fwd_surf, surf_ori=False)
assert_true(repr(fwd_new))
assert_true(isinstance(fwd_new, Forward))
compare_forwards(fwd, fwd_new)
del fwd_new
gc.collect()
# now go to fixed
fwd_fixed = convert_forward_solution(fwd_surf, surf_ori=True,
force_fixed=True, use_cps=False)
del fwd_surf
gc.collect()
assert_true(repr(fwd_fixed))
assert_true(isinstance(fwd_fixed, Forward))
assert_true(is_fixed_orient(fwd_fixed))
# The following test can be removed in 0.16
fwd_fixed_io = read_forward_solution(fname_meeg_grad, force_fixed=True)
assert_true(repr(fwd_fixed_io))
assert_true(isinstance(fwd_fixed_io, Forward))
assert_true(is_fixed_orient(fwd_fixed_io))
compare_forwards(fwd_fixed, fwd_fixed_io)
del fwd_fixed_io
gc.collect()
# now go back to cartesian (original condition)
fwd_new = convert_forward_solution(fwd_fixed, surf_ori=False,
force_fixed=False)
assert_true(repr(fwd_new))
assert_true(isinstance(fwd_new, Forward))
compare_forwards(fwd, fwd_new)
del fwd, fwd_new, fwd_fixed
gc.collect()
开发者ID:nfoti,项目名称:mne-python,代码行数:52,代码来源:test_forward.py
示例10: _load_forward
def _load_forward():
"""Load forward models."""
fwd_free = mne.read_forward_solution(fname_fwd)
fwd_free = mne.pick_types_forward(fwd_free, meg=True, eeg=False)
fwd_free = mne.convert_forward_solution(fwd_free, surf_ori=False)
fwd_surf = mne.convert_forward_solution(fwd_free, surf_ori=True,
use_cps=False)
fwd_fixed = mne.convert_forward_solution(fwd_free, force_fixed=True,
use_cps=False)
fwd_vol = mne.read_forward_solution(fname_fwd_vol)
label = mne.read_label(fname_label)
return fwd_free, fwd_surf, fwd_fixed, fwd_vol, label
开发者ID:jhouck,项目名称:mne-python,代码行数:13,代码来源:test_dics.py
示例11: _get_data
def _get_data(tmin=-0.11, tmax=0.15, read_all_forward=True, compute_csds=True):
"""Read in data used in tests."""
label = mne.read_label(fname_label)
events = mne.read_events(fname_event)[:10]
raw = mne.io.read_raw_fif(fname_raw, preload=False)
raw.add_proj([], remove_existing=True) # we'll subselect so remove proj
forward = mne.read_forward_solution(fname_fwd)
if read_all_forward:
forward_surf_ori = _read_forward_solution_meg(
fname_fwd, surf_ori=True)
forward_fixed = _read_forward_solution_meg(
fname_fwd, force_fixed=True, use_cps=False)
forward_vol = mne.read_forward_solution(fname_fwd_vol)
forward_vol = mne.convert_forward_solution(forward_vol, surf_ori=True)
else:
forward_surf_ori = None
forward_fixed = None
forward_vol = None
event_id, tmin, tmax = 1, tmin, tmax
# Setup for reading the raw data
raw.info['bads'] = ['MEG 2443', 'EEG 053'] # 2 bads channels
# Set up pick list: MEG - bad channels
left_temporal_channels = mne.read_selection('Left-temporal')
picks = mne.pick_types(raw.info, meg=True, eeg=False,
stim=True, eog=True, exclude='bads',
selection=left_temporal_channels)
# Read epochs
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=picks, baseline=(None, 0), preload=True,
reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))
epochs.resample(200, npad=0, n_jobs=2)
evoked = epochs.average().crop(0, None)
# Computing the data and noise cross-spectral density matrices
if compute_csds:
data_csd = csd_epochs(epochs, mode='multitaper', tmin=0.045,
tmax=None, fmin=8, fmax=12,
mt_bandwidth=72.72)
noise_csd = csd_epochs(epochs, mode='multitaper', tmin=None,
tmax=0.0, fmin=8, fmax=12,
mt_bandwidth=72.72)
else:
data_csd, noise_csd = None, None
return raw, epochs, evoked, data_csd, noise_csd, label, forward,\
forward_surf_ori, forward_fixed, forward_vol
开发者ID:HSMin,项目名称:mne-python,代码行数:50,代码来源:test_dics.py
示例12: test_sensitivity_maps
def test_sensitivity_maps():
"""Test sensitivity map computation."""
fwd = mne.read_forward_solution(fwd_fname)
fwd = mne.convert_forward_solution(fwd, surf_ori=True)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
projs = read_proj(eog_fname)
projs.extend(read_proj(ecg_fname))
decim = 6
for ch_type in ['eeg', 'grad', 'mag']:
w = read_source_estimate(sensmap_fname % (ch_type, 'lh')).data
stc = sensitivity_map(fwd, projs=None, ch_type=ch_type,
mode='free', exclude='bads')
assert_array_almost_equal(stc.data, w, decim)
assert_true(stc.subject == 'sample')
# let's just make sure the others run
if ch_type == 'grad':
# fixed (2)
w = read_source_estimate(sensmap_fname % (ch_type, '2-lh')).data
stc = sensitivity_map(fwd, projs=None, mode='fixed',
ch_type=ch_type, exclude='bads')
assert_array_almost_equal(stc.data, w, decim)
if ch_type == 'mag':
# ratio (3)
w = read_source_estimate(sensmap_fname % (ch_type, '3-lh')).data
stc = sensitivity_map(fwd, projs=None, mode='ratio',
ch_type=ch_type, exclude='bads')
assert_array_almost_equal(stc.data, w, decim)
if ch_type == 'eeg':
# radiality (4), angle (5), remaining (6), and dampening (7)
modes = ['radiality', 'angle', 'remaining', 'dampening']
ends = ['4-lh', '5-lh', '6-lh', '7-lh']
for mode, end in zip(modes, ends):
w = read_source_estimate(sensmap_fname % (ch_type, end)).data
stc = sensitivity_map(fwd, projs=projs, mode=mode,
ch_type=ch_type, exclude='bads')
assert_array_almost_equal(stc.data, w, decim)
# test corner case for EEG
stc = sensitivity_map(fwd, projs=[make_eeg_average_ref_proj(fwd['info'])],
ch_type='eeg', exclude='bads')
# test corner case for projs being passed but no valid ones (#3135)
assert_raises(ValueError, sensitivity_map, fwd, projs=None, mode='angle')
assert_raises(RuntimeError, sensitivity_map, fwd, projs=[], mode='angle')
# test volume source space
fname = op.join(sample_path, 'sample_audvis_trunc-meg-vol-7-fwd.fif')
fwd = mne.read_forward_solution(fname)
sensitivity_map(fwd)
开发者ID:HSMin,项目名称:mne-python,代码行数:48,代码来源:test_proj.py
示例13: 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
示例14: _get_data
def _get_data():
"""Read in data used in tests."""
# read forward model
forward = mne.read_forward_solution(fname_fwd)
# read data
raw = mne.io.read_raw_fif(fname_raw, preload=True)
events = mne.read_events(fname_event)
event_id, tmin, tmax = 1, -0.1, 0.15
# decimate for speed
left_temporal_channels = mne.read_selection('Left-temporal')
picks = mne.pick_types(raw.info, selection=left_temporal_channels)
picks = picks[::2]
raw.pick_channels([raw.ch_names[ii] for ii in picks])
del picks
raw.info.normalize_proj() # avoid projection warnings
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
baseline=(None, 0.), preload=True, reject=reject)
noise_cov = mne.compute_covariance(epochs, tmin=None, tmax=0.)
data_cov = mne.compute_covariance(epochs, tmin=0.01, tmax=0.15)
return epochs, data_cov, noise_cov, forward
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:26,代码来源:test_check.py
示例15: test_pick_forward_seeg
def test_pick_forward_seeg():
"""Test picking forward with SEEG
"""
fwd = read_forward_solution(test_forward.fname_meeg)
counts = channel_indices_by_type(fwd["info"])
for key in counts.keys():
counts[key] = len(counts[key])
counts["meg"] = counts["mag"] + counts["grad"]
fwd_ = pick_types_forward(fwd, meg=True, eeg=False, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts["meg"])
fwd_ = pick_types_forward(fwd, meg=False, eeg=True, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts["eeg"])
# should raise exception related to emptiness
assert_raises(ValueError, pick_types_forward, fwd, meg=False, eeg=False, seeg=True)
# change last chan from EEG to sEEG
seeg_name = "OTp1"
rename_channels(fwd["info"], {"EEG 060": seeg_name})
for ch in fwd["info"]["chs"]:
if ch["ch_name"] == seeg_name:
ch["kind"] = FIFF.FIFFV_SEEG_CH
ch["coil_type"] = FIFF.FIFFV_COIL_EEG
fwd["sol"]["row_names"][-1] = fwd["info"]["chs"][-1]["ch_name"]
counts["eeg"] -= 1
counts["seeg"] += 1
# repick & check
fwd_seeg = pick_types_forward(fwd, meg=False, eeg=False, seeg=True)
assert_equal(fwd_seeg["sol"]["row_names"], [seeg_name])
assert_equal(fwd_seeg["info"]["ch_names"], [seeg_name])
# should work fine
fwd_ = pick_types_forward(fwd, meg=True, eeg=False, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts["meg"])
fwd_ = pick_types_forward(fwd, meg=False, eeg=True, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts["eeg"])
fwd_ = pick_types_forward(fwd, meg=False, eeg=False, seeg=True)
_check_fwd_n_chan_consistent(fwd_, counts["seeg"])
开发者ID:YoheiOseki,项目名称:mne-python,代码行数:35,代码来源:test_pick.py
示例16: test_pick_forward_seeg
def test_pick_forward_seeg():
fwd = read_forward_solution(test_forward.fname_meeg)
counts = channel_indices_by_type(fwd['info'])
for key in counts.keys():
counts[key] = len(counts[key])
counts['meg'] = counts['mag'] + counts['grad']
fwd_ = pick_types_forward(fwd, meg=True, eeg=False, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts['meg'])
fwd_ = pick_types_forward(fwd, meg=False, eeg=True, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts['eeg'])
# should raise exception related to emptiness
assert_raises(ValueError, pick_types_forward, fwd, meg=False, eeg=False,
seeg=True)
# change last chan from EEG to sEEG
seeg_name = 'OTp1'
rename_channels(fwd['info'], {'EEG 060': (seeg_name, 'seeg')})
fwd['sol']['row_names'][-1] = fwd['info']['chs'][-1]['ch_name']
counts['eeg'] -= 1
counts['seeg'] += 1
# repick & check
fwd_seeg = pick_types_forward(fwd, meg=False, eeg=False, seeg=True)
assert_equal(fwd_seeg['sol']['row_names'], [seeg_name])
assert_equal(fwd_seeg['info']['ch_names'], [seeg_name])
# should work fine
fwd_ = pick_types_forward(fwd, meg=True, eeg=False, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts['meg'])
fwd_ = pick_types_forward(fwd, meg=False, eeg=True, seeg=False)
_check_fwd_n_chan_consistent(fwd_, counts['eeg'])
fwd_ = pick_types_forward(fwd, meg=False, eeg=False, seeg=True)
_check_fwd_n_chan_consistent(fwd_, counts['seeg'])
开发者ID:MadsJensen,项目名称:mne-python,代码行数:30,代码来源:test_pick.py
示例17: 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
示例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),
proj=False)
evoked.resample(50, npad=100)
evoked.crop(tmin=0.1, tmax=0.16) # crop to nice window near samp border
cov = read_cov(fname_cov)
cov = regularize(cov, evoked.info)
alpha = 0.5
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=True, update_mode=1)
_check_stc(stc, evoked, 68477)
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=1)
_check_stc(stc, evoked, 82010)
# force fixed orientation
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=2,
loose=None, return_residual=False)
_check_stc(stc, evoked, 85739, 20)
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:27,代码来源:test_gamma_map.py
示例19: test_apply_mne_inverse_fixed_raw
def test_apply_mne_inverse_fixed_raw():
"""Test MNE with fixed-orientation inverse operator on Raw
"""
raw = fiff.Raw(fname_raw)
start = 3
stop = 10
_, times = raw[0, start:stop]
label_lh = read_label(fname_label % 'Aud-lh')
# create a fixed-orientation inverse operator
fwd = read_forward_solution(fname_fwd, force_fixed=False, surf_ori=True)
noise_cov = read_cov(fname_cov)
inv_op = make_inverse_operator(raw.info, fwd, noise_cov,
loose=None, depth=0.8, fixed=True)
stc = apply_inverse_raw(raw, inv_op, lambda2, "dSPM",
label=label_lh, start=start, stop=stop, nave=1,
pick_ori=None, buffer_size=None)
stc2 = apply_inverse_raw(raw, inv_op, lambda2, "dSPM",
label=label_lh, start=start, stop=stop, nave=1,
pick_ori=None, buffer_size=3)
assert_true(stc.subject == 'sample')
assert_true(stc2.subject == 'sample')
assert_array_almost_equal(stc.times, times)
assert_array_almost_equal(stc2.times, times)
assert_array_almost_equal(stc.data, stc2.data)
开发者ID:Anevar,项目名称:mne-python,代码行数:28,代码来源:test_inverse.py
示例20: test_gamma_map
def test_gamma_map():
"""Test Gamma MAP inverse"""
forward = read_forward_solution(fname_fwd)
forward = convert_forward_solution(forward, surf_ori=True)
forward = pick_types_forward(forward, meg=False, eeg=True)
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)
alpha = 0.5
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=True, update_mode=1)
_check_stc(stc, evoked, 68477)
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=1)
_check_stc(stc, evoked, 82010)
dips = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=1,
return_as_dipoles=True)
assert_true(isinstance(dips[0], Dipole))
stc_dip = make_stc_from_dipoles(dips, forward['src'])
_check_stcs(stc, stc_dip)
# force fixed orientation
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=2,
loose=0, return_residual=False)
_check_stc(stc, evoked, 85739, 20)
开发者ID:nfoti,项目名称:mne-python,代码行数:35,代码来源:test_gamma_map.py
注:本文中的mne.read_forward_solution函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论