

@slow_test
@testing.requires_testing_data
def test_apply_inverse_operator():
    'Test MNE inverse application\n    '
    inverse_operator = read_inverse_operator(fname_full)
    evoked = _get_evoked()
    assert_true((compute_rank_inverse(inverse_operator) == 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() < 1e-08))
    assert_true((stc.data.mean() > 1e-11))
    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))
    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)
    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'] = []
    assert_raises(ValueError, apply_inverse, evoked, inv_op, lambda2, 'MNE')

dataset/ETHPy150Open mne-tools/mne-python/mne/minimum_norm/tests/test_inverse.py test_apply_inverse_operator/original