本文整理汇总了Python中mne.minimum_norm.inverse.prepare_inverse_operator函数的典型用法代码示例。如果您正苦于以下问题:Python prepare_inverse_operator函数的具体用法?Python prepare_inverse_operator怎么用?Python prepare_inverse_operator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prepare_inverse_operator函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_io_inverse_operator
def test_io_inverse_operator():
"""Test IO of inverse_operator."""
tempdir = _TempDir()
inverse_operator = read_inverse_operator(fname_inv)
x = repr(inverse_operator)
assert (x)
assert (isinstance(inverse_operator['noise_cov'], Covariance))
# just do one example for .gz, as it should generalize
_compare_io(inverse_operator, '.gz')
# test warnings on bad filenames
inv_badname = op.join(tempdir, 'test-bad-name.fif.gz')
with pytest.warns(RuntimeWarning, match='-inv.fif'):
write_inverse_operator(inv_badname, inverse_operator)
with pytest.warns(RuntimeWarning, match='-inv.fif'):
read_inverse_operator(inv_badname)
# make sure we can write and read
inv_fname = op.join(tempdir, 'test-inv.fif')
args = (10, 1. / 9., 'dSPM')
inv_prep = prepare_inverse_operator(inverse_operator, *args)
write_inverse_operator(inv_fname, inv_prep)
inv_read = read_inverse_operator(inv_fname)
_compare(inverse_operator, inv_read)
inv_read_prep = prepare_inverse_operator(inv_read, *args)
_compare(inv_prep, inv_read_prep)
inv_prep_prep = prepare_inverse_operator(inv_prep, *args)
_compare(inv_prep, inv_prep_prep)
开发者ID:teonbrooks,项目名称:mne-python,代码行数:28,代码来源:test_inverse.py
示例2: test_io_inverse_operator
def test_io_inverse_operator():
"""Test IO of inverse_operator
"""
tempdir = _TempDir()
inverse_operator = read_inverse_operator(fname_inv)
x = repr(inverse_operator)
assert_true(x)
assert_true(isinstance(inverse_operator['noise_cov'], Covariance))
# just do one example for .gz, as it should generalize
_compare_io(inverse_operator, '.gz')
# test warnings on bad filenames
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
inv_badname = op.join(tempdir, 'test-bad-name.fif.gz')
write_inverse_operator(inv_badname, inverse_operator)
read_inverse_operator(inv_badname)
assert_naming(w, 'test_inverse.py', 2)
# make sure we can write and read
inv_fname = op.join(tempdir, 'test-inv.fif')
args = (10, 1. / 9., 'dSPM')
inv_prep = prepare_inverse_operator(inverse_operator, *args)
write_inverse_operator(inv_fname, inv_prep)
inv_read = read_inverse_operator(inv_fname)
_compare(inverse_operator, inv_read)
inv_read_prep = prepare_inverse_operator(inv_read, *args)
_compare(inv_prep, inv_read_prep)
inv_prep_prep = prepare_inverse_operator(inv_prep, *args)
_compare(inv_prep, inv_prep_prep)
开发者ID:claire-braboszcz,项目名称:mne-python,代码行数:30,代码来源:test_inverse.py
示例3: test_apply_mne_inverse_raw
def test_apply_mne_inverse_raw():
"""Test MNE with precomputed inverse operator on Raw."""
start = 3
stop = 10
raw = read_raw_fif(fname_raw)
label_lh = read_label(fname_label % 'Aud-lh')
_, times = raw[0, start:stop]
inverse_operator = read_inverse_operator(fname_full)
inverse_operator = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=lambda2, method="dSPM")
for pick_ori in [None, "normal", "vector"]:
stc = apply_inverse_raw(raw, inverse_operator, lambda2, "dSPM",
label=label_lh, start=start, stop=stop, nave=1,
pick_ori=pick_ori, buffer_size=None,
prepared=True)
stc2 = apply_inverse_raw(raw, inverse_operator, lambda2, "dSPM",
label=label_lh, start=start, stop=stop,
nave=1, pick_ori=pick_ori,
buffer_size=3, prepared=True)
if pick_ori is None:
assert_true(np.all(stc.data > 0))
assert_true(np.all(stc2.data > 0))
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:claire-braboszcz,项目名称:mne-python,代码行数:30,代码来源:test_inverse.py
示例4: test_tfr_with_inverse_operator
def test_tfr_with_inverse_operator():
"""Test time freq with MNE inverse computation"""
tmin, tmax, event_id = -0.2, 0.5, 1
# Setup for reading the raw data
raw = io.Raw(fname_data)
events = find_events(raw, stim_channel='STI 014')
inverse_operator = read_inverse_operator(fname_inv)
inv = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=1. / 9., method="dSPM")
raw.info['bads'] += ['MEG 2443', 'EEG 053'] # bads + 2 more
# picks MEG gradiometers
picks = pick_types(raw.info, meg=True, eeg=False, eog=True,
stim=False, exclude='bads')
# Load condition 1
event_id = 1
events3 = events[:3] # take 3 events to keep the computation time low
epochs = Epochs(raw, events3, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6),
preload=True)
# Compute a source estimate per frequency band
bands = dict(alpha=[10, 10])
label = read_label(fname_label)
stcs = source_band_induced_power(epochs, inv, bands,
n_cycles=2, use_fft=False, pca=True,
label=label, prepared=True)
stc = stcs['alpha']
assert_true(len(stcs) == len(list(bands.keys())))
assert_true(np.all(stc.data > 0))
assert_array_almost_equal(stc.times, epochs.times)
stcs_no_pca = source_band_induced_power(epochs, inv, bands,
n_cycles=2, use_fft=False,
pca=False, label=label,
prepared=True)
assert_array_almost_equal(stcs['alpha'].data, stcs_no_pca['alpha'].data)
# Compute a source estimate per frequency band
epochs = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6),
preload=True)
frequencies = np.arange(7, 30, 2) # define frequencies of interest
power, phase_lock = source_induced_power(epochs, inv,
frequencies, label,
baseline=(-0.1, 0),
baseline_mode='percent',
n_cycles=2, n_jobs=1,
prepared=True)
assert_true(np.all(phase_lock > 0))
assert_true(np.all(phase_lock <= 1))
assert_true(np.max(power) > 10)
开发者ID:BushraR,项目名称:mne-python,代码行数:60,代码来源:test_time_frequency.py
示例5: test_apply_inverse_operator
def test_apply_inverse_operator():
"""Test MNE inverse application
"""
inverse_operator = read_inverse_operator(fname_full)
evoked = _get_evoked()
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
stc = apply_inverse(evoked, inverse_operator, lambda2, "MNE")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10e-9)
assert_true(stc.data.mean() > 1e-11)
# test if using prepared and not prepared inverse operator give the same
# result
inv_op = prepare_inverse_operator(inverse_operator, nave=evoked.nave,
lambda2=lambda2, method="MNE")
stc2 = apply_inverse(evoked, inv_op, lambda2, "MNE")
assert_array_almost_equal(stc.data, stc2.data)
assert_array_almost_equal(stc.times, stc2.times)
stc = apply_inverse(evoked, inverse_operator, lambda2, "sLORETA")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10.0)
assert_true(stc.data.mean() > 0.1)
stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 35)
assert_true(stc.data.mean() > 0.1)
# test without using a label (so delayed computation is used)
label = read_label(fname_label % 'Aud-lh')
stc = apply_inverse(evoked, inv_op, lambda2, "MNE")
stc_label = apply_inverse(evoked, inv_op, lambda2, "MNE",
label=label)
assert_equal(stc_label.subject, 'sample')
label_stc = stc.in_label(label)
assert_true(label_stc.subject == 'sample')
assert_array_almost_equal(stc_label.data, label_stc.data)
# Test we get errors when using custom ref or no average proj is present
evoked.info['custom_ref_applied'] = True
assert_raises(ValueError, apply_inverse, evoked, inv_op, lambda2, "MNE")
evoked.info['custom_ref_applied'] = False
evoked.info['projs'] = [] # remove EEG proj
assert_raises(ValueError, apply_inverse, evoked, inv_op, lambda2, "MNE")
开发者ID:cmoutard,项目名称:mne-python,代码行数:54,代码来源:test_inverse.py
示例6: _apply_inverse_evoked_list
def _apply_inverse_evoked_list(evoked_list, inverse_operator, lambda2, method="MNE",
labels=None, nave=1, pick_ori=None,
verbose=None, pick_normal=None):
""" Utility function for applying the inverse solution to a list of evoked object
Assume that the info for each evoked object in the list is the same
Input:
evoked_list,
inverse_operator,
lambda2,
method,
labels, list of label objects
nave = 1,
pick_ori = None,
verbos = none,
pick_normal = None
Output: stc_Data, [n_sources_labels, n_times, n_trials]
"""
info = evoked_list[0].info
method = _check_method(method)
pick_ori = _check_ori(pick_ori, pick_normal)
_check_ch_names(inverse_operator, info)
inv = prepare_inverse_operator(inverse_operator, nave, lambda2, method)
sel = _pick_channels_inverse_operator(info['ch_names'], inv)
labels_union = None
if labels is not None:
labels_union = labels[0]
if len(labels) > 1:
for i in range(1,len(labels)):
labels_union += labels[i]
K, noise_norm, vertno = _assemble_kernel(inv, labels_union, method, pick_ori)
is_free_ori = (inverse_operator['source_ori'] == FIFF.FIFFV_MNE_FREE_ORI
and pick_ori is None)
if not is_free_ori and noise_norm is not None:
# premultiply kernel with noise normalization
K *= noise_norm
n_channels = len(sel)
n_times = len(evoked_list[0].times)
n_trials = len(evoked_list)
n_sources = K.shape[0]
stc_Data = np.zeros([n_sources,n_times, n_trials])
for i in range(n_trials):
if is_free_ori:
# Compute solution and combine current components (non-linear)
sol = np.dot(K, evoked_list[i].data) # apply imaging kernel
if is_free_ori:
sol = combine_xyz(sol)
if noise_norm is not None:
sol *= noise_norm
else:
# Linear inverse: do computation here or delayed
sol = np.dot(K, evoked_list[i].data)
stc_Data[:,:,i] = sol
return stc_Data
开发者ID:YingYang,项目名称:STFT_R_git_repo,代码行数:53,代码来源:mne_stft_regression.py
示例7: test_apply_mne_inverse_fixed_raw
def test_apply_mne_inverse_fixed_raw():
"""Test MNE with fixed-orientation inverse operator on Raw."""
raw = read_raw_fif(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_meg(fname_fwd, force_fixed=False,
surf_ori=True)
noise_cov = read_cov(fname_cov)
assert_raises(ValueError, make_inverse_operator,
raw.info, fwd, noise_cov, loose=1., fixed=True)
inv_op = make_inverse_operator(raw.info, fwd, noise_cov,
fixed=True, use_cps=True)
inv_op2 = prepare_inverse_operator(inv_op, nave=1,
lambda2=lambda2, method="dSPM")
stc = apply_inverse_raw(raw, inv_op2, lambda2, "dSPM",
label=label_lh, start=start, stop=stop, nave=1,
pick_ori=None, buffer_size=None, prepared=True)
stc2 = apply_inverse_raw(raw, inv_op2, lambda2, "dSPM",
label=label_lh, start=start, stop=stop, nave=1,
pick_ori=None, buffer_size=3, prepared=True)
stc3 = apply_inverse_raw(raw, inv_op, lambda2, "dSPM",
label=label_lh, start=start, stop=stop, nave=1,
pick_ori=None, buffer_size=None)
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(stc3.times, times)
assert_array_almost_equal(stc.data, stc2.data)
assert_array_almost_equal(stc.data, stc3.data)
开发者ID:claire-braboszcz,项目名称:mne-python,代码行数:38,代码来源:test_inverse.py
示例8: test_apply_inverse_operator
def test_apply_inverse_operator():
"""Test MNE inverse application
"""
inverse_operator = read_inverse_operator(fname_full)
evoked = _get_evoked()
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
stc = apply_inverse(evoked, inverse_operator, lambda2, "MNE")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10e-9)
assert_true(stc.data.mean() > 1e-11)
# test if using prepared and not prepared inverse operator give the same
# result
inv_op = prepare_inverse_operator(inverse_operator, nave=evoked.nave,
lambda2=lambda2, method="MNE")
stc2 = apply_inverse(evoked, inv_op, lambda2, "MNE")
assert_array_almost_equal(stc.data, stc2.data)
assert_array_almost_equal(stc.times, stc2.times)
stc = apply_inverse(evoked, inverse_operator, lambda2, "sLORETA")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10.0)
assert_true(stc.data.mean() > 0.1)
stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 35)
assert_true(stc.data.mean() > 0.1)
开发者ID:LizetteH,项目名称:mne-python,代码行数:37,代码来源:test_inverse.py
示例9: test_apply_mne_inverse_epochs
def test_apply_mne_inverse_epochs():
"""Test MNE with precomputed inverse operator on Epochs."""
inverse_operator = read_inverse_operator(fname_full)
label_lh = read_label(fname_label % 'Aud-lh')
label_rh = read_label(fname_label % 'Aud-rh')
event_id, tmin, tmax = 1, -0.2, 0.5
raw = read_raw_fif(fname_raw)
picks = pick_types(raw.info, meg=True, eeg=False, stim=True, ecg=True,
eog=True, include=['STI 014'], exclude='bads')
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
flat = dict(grad=1e-15, mag=1e-15)
events = read_events(fname_event)[:15]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject, flat=flat)
inverse_operator = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=lambda2,
method="dSPM")
for pick_ori in [None, "normal", "vector"]:
stcs = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
label=label_lh, pick_ori=pick_ori)
stcs2 = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
label=label_lh, pick_ori=pick_ori,
prepared=True)
# test if using prepared and not prepared inverse operator give the
# same result
assert_array_almost_equal(stcs[0].data, stcs2[0].data)
assert_array_almost_equal(stcs[0].times, stcs2[0].times)
assert_true(len(stcs) == 2)
assert_true(3 < stcs[0].data.max() < 10)
assert_true(stcs[0].subject == 'sample')
inverse_operator = read_inverse_operator(fname_full)
stcs = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
label=label_lh, pick_ori='normal')
data = sum(stc.data for stc in stcs) / len(stcs)
flip = label_sign_flip(label_lh, inverse_operator['src'])
label_mean = np.mean(data, axis=0)
label_mean_flip = np.mean(flip[:, np.newaxis] * data, axis=0)
assert_true(label_mean.max() < label_mean_flip.max())
# test extracting a BiHemiLabel
inverse_operator = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=lambda2,
method="dSPM")
stcs_rh = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
label=label_rh, pick_ori="normal",
prepared=True)
stcs_bh = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
label=label_lh + label_rh,
pick_ori="normal",
prepared=True)
n_lh = len(stcs[0].data)
assert_array_almost_equal(stcs[0].data, stcs_bh[0].data[:n_lh])
assert_array_almost_equal(stcs_rh[0].data, stcs_bh[0].data[n_lh:])
# test without using a label (so delayed computation is used)
stcs = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
pick_ori="normal", prepared=True)
assert_true(stcs[0].subject == 'sample')
label_stc = stcs[0].in_label(label_rh)
assert_true(label_stc.subject == 'sample')
assert_array_almost_equal(stcs_rh[0].data, label_stc.data)
开发者ID:claire-braboszcz,项目名称:mne-python,代码行数:69,代码来源:test_inverse.py
示例10: test_apply_inverse_operator
def test_apply_inverse_operator():
"""Test MNE inverse application."""
inverse_operator = read_inverse_operator(fname_full)
evoked = _get_evoked()
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
stc = apply_inverse(evoked, inverse_operator, lambda2, "MNE")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10e-9)
assert_true(stc.data.mean() > 1e-11)
# test if using prepared and not prepared inverse operator give the same
# result
inv_op = prepare_inverse_operator(inverse_operator, nave=evoked.nave,
lambda2=lambda2, method="MNE")
stc2 = apply_inverse(evoked, inv_op, lambda2, "MNE")
assert_array_almost_equal(stc.data, stc2.data)
assert_array_almost_equal(stc.times, stc2.times)
stc = apply_inverse(evoked, inverse_operator, lambda2, "sLORETA")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10.0)
assert_true(stc.data.mean() > 0.1)
stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 35)
assert_true(stc.data.mean() > 0.1)
# test without using a label (so delayed computation is used)
label = read_label(fname_label % 'Aud-lh')
stc = apply_inverse(evoked, inv_op, lambda2, "MNE")
stc_label = apply_inverse(evoked, inv_op, lambda2, "MNE",
label=label)
assert_equal(stc_label.subject, 'sample')
label_stc = stc.in_label(label)
assert_true(label_stc.subject == 'sample')
assert_allclose(stc_label.data, label_stc.data)
# Test that no errors are raised with loose inverse ops and picking normals
noise_cov = read_cov(fname_cov)
fwd = read_forward_solution_meg(fname_fwd)
inv_op2 = make_inverse_operator(evoked.info, fwd, noise_cov, loose=1,
fixed='auto', depth=None)
apply_inverse(evoked, inv_op2, 1 / 9., method='MNE',
pick_ori='normal')
# Test we get errors when using custom ref or no average proj is present
evoked.info['custom_ref_applied'] = True
assert_raises(ValueError, apply_inverse, evoked, inv_op, lambda2, "MNE")
evoked.info['custom_ref_applied'] = False
evoked.info['projs'] = [] # remove EEG proj
assert_raises(ValueError, apply_inverse, evoked, inv_op, lambda2, "MNE")
开发者ID:claire-braboszcz,项目名称:mne-python,代码行数:61,代码来源:test_inverse.py
示例11: test_source_psd_epochs
def test_source_psd_epochs():
"""Test multi-taper source PSD computation in label from epochs."""
raw = read_raw_fif(fname_data)
inverse_operator = read_inverse_operator(fname_inv)
label = read_label(fname_label)
event_id, tmin, tmax = 1, -0.2, 0.5
lambda2, method = 1. / 9., 'dSPM'
bandwidth = 8.
fmin, fmax = 0, 100
picks = pick_types(raw.info, meg=True, eeg=False, stim=True,
ecg=True, eog=True, include=['STI 014'],
exclude='bads')
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
events = find_events(raw, stim_channel='STI 014')
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject)
# only look at one epoch
epochs.drop_bad()
one_epochs = epochs[:1]
inv = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=1. / 9., method="dSPM")
# return list
stc_psd = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
prepared=True)[0]
# return generator
stcs = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
return_generator=True,
prepared=True)
for stc in stcs:
stc_psd_gen = stc
assert_array_almost_equal(stc_psd.data, stc_psd_gen.data)
# compare with direct computation
stc = apply_inverse_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
prepared=True)[0]
sfreq = epochs.info['sfreq']
psd, freqs = _psd_multitaper(stc.data, sfreq=sfreq, bandwidth=bandwidth,
fmin=fmin, fmax=fmax)
assert_array_almost_equal(psd, stc_psd.data)
assert_array_almost_equal(freqs, stc_psd.times)
# Check corner cases caused by tiny bandwidth
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=0.01, low_bias=True,
fmin=fmin, fmax=fmax,
return_generator=False,
prepared=True)
compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=0.01, low_bias=False,
fmin=fmin, fmax=fmax,
return_generator=False,
prepared=True)
assert_true(len(w) >= 2)
assert_true(any('not properly use' in str(ww.message) for ww in w))
assert_true(any('Bandwidth too small' in str(ww.message) for ww in w))
开发者ID:deep-introspection,项目名称:mne-python,代码行数:81,代码来源:test_time_frequency.py
示例12: test_apply_inverse_operator
def test_apply_inverse_operator():
"""Test MNE inverse application."""
# use fname_inv as it will be faster than fname_full (fewer verts and chs)
inverse_operator = read_inverse_operator(fname_inv)
evoked = _get_evoked()
# Inverse has 306 channels - 4 proj = 302
assert (compute_rank_inverse(inverse_operator) == 302)
# Inverse has 306 channels - 4 proj = 302
assert (compute_rank_inverse(inverse_operator) == 302)
stc = apply_inverse(evoked, inverse_operator, lambda2, "MNE")
assert stc.subject == 'sample'
assert stc.data.min() > 0
assert stc.data.max() < 13e-9
assert stc.data.mean() > 1e-11
# test if using prepared and not prepared inverse operator give the same
# result
inv_op = prepare_inverse_operator(inverse_operator, nave=evoked.nave,
lambda2=lambda2, method="MNE")
stc2 = apply_inverse(evoked, inv_op, lambda2, "MNE")
assert_array_almost_equal(stc.data, stc2.data)
assert_array_almost_equal(stc.times, stc2.times)
# This is little more than a smoke test...
stc = apply_inverse(evoked, inverse_operator, lambda2, "sLORETA")
assert stc.subject == 'sample'
assert stc.data.min() > 0
assert stc.data.max() < 10.0
assert stc.data.mean() > 0.1
stc = apply_inverse(evoked, inverse_operator, lambda2, "eLORETA")
assert stc.subject == 'sample'
assert stc.data.min() > 0
assert stc.data.max() < 3.0
assert stc.data.mean() > 0.1
stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM")
assert stc.subject == 'sample'
assert stc.data.min() > 0
assert stc.data.max() < 35
assert stc.data.mean() > 0.1
# test without using a label (so delayed computation is used)
label = read_label(fname_label % 'Aud-lh')
stc = apply_inverse(evoked, inv_op, lambda2, "MNE")
stc_label = apply_inverse(evoked, inv_op, lambda2, "MNE",
label=label)
assert_equal(stc_label.subject, 'sample')
label_stc = stc.in_label(label)
assert label_stc.subject == 'sample'
assert_allclose(stc_label.data, label_stc.data)
# Test that no errors are raised with loose inverse ops and picking normals
noise_cov = read_cov(fname_cov)
fwd = read_forward_solution_meg(fname_fwd)
inv_op_meg = make_inverse_operator(evoked.info, fwd, noise_cov, loose=1,
fixed='auto', depth=None)
apply_inverse(evoked, inv_op_meg, 1 / 9., method='MNE', pick_ori='normal')
# Test we get errors when using custom ref or no average proj is present
evoked.info['custom_ref_applied'] = True
pytest.raises(ValueError, apply_inverse, evoked, inv_op, lambda2, "MNE")
evoked.info['custom_ref_applied'] = False
evoked.info['projs'] = [] # remove EEG proj
pytest.raises(ValueError, apply_inverse, evoked, inv_op, lambda2, "MNE")
# But test that we do not get EEG-related errors on MEG-only inv (gh-4650)
apply_inverse(evoked, inv_op_meg, 1. / 9.)
开发者ID:teonbrooks,项目名称:mne-python,代码行数:71,代码来源:test_inverse.py
示例13: test_apply_inverse_operator
def test_apply_inverse_operator():
"""Test MNE inverse computation (precomputed and non-precomputed)
"""
inverse_operator = read_inverse_operator(fname_inv)
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
# Test old version of inverse computation starting from forward operator
fwd_op = read_forward_solution(fname_fwd, surf_ori=True)
my_inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov,
loose=0.2, depth=0.8,
limit_depth_chs=False)
_compare_io(my_inv_op)
assert_true(inverse_operator['units'] == 'Am')
_compare_inverses_approx(my_inv_op, inverse_operator, evoked, 2,
check_depth=False)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
# Test MNE inverse computation starting from forward operator
my_inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov,
loose=0.2, depth=0.8)
_compare_io(my_inv_op)
_compare_inverses_approx(my_inv_op, inverse_operator, evoked, 2)
# Inverse has 306 channels - 4 proj = 302
assert_true(compute_rank_inverse(inverse_operator) == 302)
stc = apply_inverse(evoked, inverse_operator, lambda2, "MNE")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10e-10)
assert_true(stc.data.mean() > 1e-11)
# test if using prepared and not prepared inverse operator give the same
# result
inv_op = prepare_inverse_operator(inverse_operator, nave=evoked.nave,
lambda2=lambda2, method="MNE")
stc2 = apply_inverse(evoked, inv_op, lambda2, "MNE")
assert_array_almost_equal(stc.data, stc2.data)
assert_array_almost_equal(stc.times, stc2.times)
stc = apply_inverse(evoked, inverse_operator, lambda2, "sLORETA")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 10.0)
assert_true(stc.data.mean() > 0.1)
stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM")
assert_true(stc.subject == 'sample')
assert_true(stc.data.min() > 0)
assert_true(stc.data.max() < 35)
assert_true(stc.data.mean() > 0.1)
my_stc = apply_inverse(evoked, my_inv_op, lambda2, "dSPM")
assert_true('dev_head_t' in my_inv_op['info'])
assert_true('mri_head_t' in my_inv_op)
assert_true(my_stc.subject == 'sample')
assert_equal(stc.times, my_stc.times)
assert_array_almost_equal(stc.data, my_stc.data, 2)
开发者ID:dengemann,项目名称:mne-python,代码行数:61,代码来源:test_inverse.py
示例14: test_source_psd_epochs
def test_source_psd_epochs():
"""Test multi-taper source PSD computation in label from epochs."""
raw = read_raw_fif(fname_data)
inverse_operator = read_inverse_operator(fname_inv)
label = read_label(fname_label)
event_id, tmin, tmax = 1, -0.2, 0.5
lambda2, method = 1. / 9., 'dSPM'
bandwidth = 8.
fmin, fmax = 0, 100
picks = pick_types(raw.info, meg=True, eeg=False, stim=True,
ecg=True, eog=True, include=['STI 014'],
exclude='bads')
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
events = find_events(raw, stim_channel='STI 014')
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject)
# only look at one epoch
epochs.drop_bad()
one_epochs = epochs[:1]
inv = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=1. / 9., method="dSPM")
# return list
stc_psd = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
prepared=True)[0]
# return generator
stcs = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
return_generator=True,
prepared=True)
for stc in stcs:
stc_psd_gen = stc
assert_allclose(stc_psd.data, stc_psd_gen.data, atol=1e-7)
# compare with direct computation
stc = apply_inverse_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
prepared=True)[0]
sfreq = epochs.info['sfreq']
psd, freqs = psd_array_multitaper(stc.data, sfreq=sfreq,
bandwidth=bandwidth, fmin=fmin,
fmax=fmax)
assert_allclose(psd, stc_psd.data, atol=1e-7)
assert_allclose(freqs, stc_psd.times)
# Check corner cases caused by tiny bandwidth
with pytest.raises(ValueError, match='use a value of at least'):
compute_source_psd_epochs(
one_epochs, inv, lambda2=lambda2, method=method,
pick_ori="normal", label=label, bandwidth=0.01, low_bias=True,
fmin=fmin, fmax=fmax, return_generator=False, prepared=True)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:68,代码来源:test_time_frequency.py
注:本文中的mne.minimum_norm.inverse.prepare_inverse_operator函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论