def _gen_lcmv(active_cov, baseline_cov, common_cov):
    filters = make_lcmv(epochs.info, fwd, common_cov, reg=0.05,
                        noise_cov=None, pick_ori='max-power')
    stc_base = apply_lcmv_cov(baseline_cov, filters)
    stc_act = apply_lcmv_cov(active_cov, filters)
    stc_act /= stc_base
    return stc_act
Esempio n. 2
0
def test_lcmv_cov(weight_norm, pick_ori):
    """Test LCMV source power computation."""
    raw, epochs, evoked, data_cov, noise_cov, label, forward,\
        forward_surf_ori, forward_fixed, forward_vol = _get_data()
    convert_forward_solution(forward, surf_ori=True, copy=False)
    filters = make_lcmv(evoked.info,
                        forward,
                        data_cov,
                        noise_cov=noise_cov,
                        weight_norm=weight_norm,
                        pick_ori=pick_ori)
    for cov in (data_cov, noise_cov):
        this_cov = pick_channels_cov(cov, evoked.ch_names)
        this_evoked = evoked.copy().pick_channels(this_cov['names'])
        this_cov['projs'] = this_evoked.info['projs']
        assert this_evoked.ch_names == this_cov['names']
        stc = apply_lcmv_cov(this_cov, filters)
        assert stc.data.min() > 0
        assert stc.shape == (498, 1)
        ev = EvokedArray(this_cov.data, this_evoked.info)
        stc_1 = apply_lcmv(ev, filters)
        assert stc_1.data.min() < 0
        ev = EvokedArray(stc_1.data.T, this_evoked.info)
        stc_2 = apply_lcmv(ev, filters)
        assert stc_2.data.shape == (498, 498)
        data = np.diag(stc_2.data)[:, np.newaxis]
        assert data.min() > 0
        assert_allclose(data, stc.data, rtol=1e-12)
Esempio n. 3
0
def test_lcmv_fieldtrip(_get_bf_data, bf_type, weight_norm, pick_ori, pwr):
    """Test LCMV vs fieldtrip output."""
    evoked, data_cov, fwd = _get_bf_data

    # run the MNE-Python beamformer
    filters = make_lcmv(evoked.info,
                        fwd,
                        data_cov=data_cov,
                        noise_cov=None,
                        pick_ori=pick_ori,
                        reg=0.05,
                        weight_norm=weight_norm)
    if pwr:
        stc_mne = apply_lcmv_cov(data_cov, filters)
    else:
        stc_mne = apply_lcmv(evoked, filters)

    # load the FieldTrip output
    ft_fname = op.join(ft_data_path, 'ft_source_' + bf_type + '-vol.mat')
    stc_ft_data = read_mat(ft_fname)['stc']
    if stc_ft_data.ndim == 1:
        stc_ft_data.shape = (stc_ft_data.size, 1)

    if stc_mne.data.ndim == 2:
        signs = np.sign((stc_mne.data * stc_ft_data).sum(-1, keepdims=True))
        if pwr:
            assert_array_equal(signs, 1.)
        stc_mne.data *= signs
    assert stc_ft_data.shape == stc_mne.data.shape
    if pick_ori == 'vector':
        # compare norms first
        assert_allclose(np.linalg.norm(stc_mne.data, axis=1),
                        np.linalg.norm(stc_ft_data, axis=1),
                        rtol=1e-6)
    assert_allclose(stc_mne.data, stc_ft_data, rtol=1e-6)
Esempio n. 4
0
def test_lcmv_fieldtrip(_get_bf_data, bf_type, weight_norm, pick_ori, pwr):
    """Test LCMV vs fieldtrip output."""
    evoked, data_cov, fwd = _get_bf_data

    # run the MNE-Python beamformer
    filters = make_lcmv(evoked.info,
                        fwd,
                        data_cov=data_cov,
                        noise_cov=None,
                        pick_ori=pick_ori,
                        reg=0.05,
                        weight_norm=weight_norm)
    if pwr is True:
        stc_mne = apply_lcmv_cov(data_cov, filters)
    else:
        stc_mne = apply_lcmv(evoked, filters)
        # take the absolute value, since orientation can be flipped
        stc_mne.data[:, :] = np.abs(stc_mne.data)

    # load the FieldTrip output
    ft_fname = op.join(ft_data_path, 'ft_source_' + bf_type + '-vol.stc')
    stc_ft = mne.read_source_estimate(ft_fname)

    # calculate the Pearson correlation between the source solutions:
    pearson = np.corrcoef(stc_mne.data.ravel(), stc_ft.data.ravel())[0, 1]
    assert pearson >= 0.99
Esempio n. 5
0
def test_lcmv_fieldtrip(_get_bf_data, bf_type, weight_norm, pick_ori, pwr):
    """Test LCMV vs fieldtrip output."""
    evoked, data_cov, fwd = _get_bf_data

    # run the MNE-Python beamformer
    filters = make_lcmv(evoked.info, fwd, data_cov=data_cov,
                        noise_cov=None, pick_ori=pick_ori, reg=0.05,
                        weight_norm=weight_norm)
    if pwr is True:
        stc_mne = apply_lcmv_cov(data_cov, filters)
    else:
        stc_mne = apply_lcmv(evoked, filters)
        # take the absolute value, since orientation can be flipped
        stc_mne.data[:, :] = np.abs(stc_mne.data)

    # load the FieldTrip output
    ft_fname = op.join(ft_data_path, 'ft_source_' + bf_type + '-vol.stc')
    stc_ft = mne.read_source_estimate(ft_fname)

    # calculate the Pearson correlation between the source solutions:
    pearson = np.corrcoef(stc_mne.data.ravel(), stc_ft.data.ravel())[0, 1]
    assert pearson >= 0.99