Esempio n. 1
0
def test_resolution_matrix_lcmv():
    """Test computation of resolution matrix for LCMV beamformers."""
    # read forward solution
    forward = mne.read_forward_solution(fname_fwd)

    # remove bad channels
    forward = mne.pick_channels_forward(forward, exclude='bads')

    # forward operator with fixed source orientations
    forward_fxd = mne.convert_forward_solution(forward, surf_ori=True,
                                               force_fixed=True)

    # evoked info
    info = mne.io.read_info(fname_evoked)
    mne.pick_info(info, mne.pick_types(info), copy=False)  # good MEG channels

    # noise covariance matrix
    # ad-hoc to avoid discrepancies due to regularisation of real noise
    # covariance matrix
    noise_cov = mne.make_ad_hoc_cov(info)

    # Resolution matrix for Beamformer
    data_cov = noise_cov.copy()  # to test a property of LCMV

    # compute beamformer filters
    # reg=0. to make sure noise_cov and data_cov are as similar as possible
    filters = make_lcmv(info, forward_fxd, data_cov, reg=0.,
                        noise_cov=noise_cov,
                        pick_ori=None, rank=None,
                        weight_norm=None,
                        reduce_rank=False,
                        verbose=False)

    # Compute resolution matrix for beamformer
    resmat_lcmv = make_lcmv_resolution_matrix(filters, forward_fxd, info)

    # for noise_cov==data_cov and whitening, the filter weights should be the
    # transpose of leadfield

    # create filters with transposed whitened leadfield as weights
    forward_fxd = mne.pick_channels_forward(forward_fxd, info['ch_names'])
    filters_lfd = deepcopy(filters)
    filters_lfd['weights'][:] = forward_fxd['sol']['data'].T

    # compute resolution matrix for filters with transposed leadfield
    resmat_fwd = make_lcmv_resolution_matrix(filters_lfd, forward_fxd, info)

    # pairwise correlation for rows (CTFs) of resolution matrices for whitened
    # LCMV beamformer and transposed leadfield should be 1
    # Some rows are off by about 0.1 - not yet clear why
    corr = []

    for (f, l) in zip(resmat_fwd, resmat_lcmv):

        corr.append(np.corrcoef(f, l)[0, 1])

    # all row correlations should at least be above ~0.8
    assert_allclose(corr, 1., atol=0.2)

    # Maximum row correlation should at least be close to 1
    assert_allclose(np.max(corr), 1., atol=0.01)
Esempio n. 2
0
filters_post = make_lcmv(info,
                         forward,
                         cov_post,
                         reg=0.05,
                         noise_cov=noise_cov,
                         pick_ori=None,
                         rank=None,
                         weight_norm=None,
                         reduce_rank=False,
                         verbose=False)

##############################################################################
# Compute resolution matrices for the two LCMV beamformers
# --------------------------------------------------------

rm_pre = make_lcmv_resolution_matrix(filters_pre, forward, info)

rm_post = make_lcmv_resolution_matrix(filters_post, forward, info)

# compute cross-talk functions (CTFs) for one target vertex
sources = [3000]

stc_pre = get_cross_talk(rm_pre, forward['src'], sources, norm=True)

stc_post = get_cross_talk(rm_post, forward['src'], sources, norm=True)

##############################################################################
# Visualise
# ---------
vertno_lh = forward['src'][0]['vertno']  # vertex of selected source
verttrue = [vertno_lh[sources[0]]]  # pick one vertex
Esempio n. 3
0
                    bf_filts = make_lcmv(info,
                                         fwd_use,
                                         data_cov_use,
                                         reg=0.05,
                                         noise_cov=noise_cov_lcmv,
                                         pick_ori=None,
                                         rank='info',
                                         weight_norm='unit-noise-gain',
                                         reduce_rank=False,
                                         verbose=False)

                    # bf_filts = _get_matrix_from_lcmv_identity(fwd_use, info, noise_cov_use, data_cov_use)

                    # resmat = bf_filts.dot(fwd_use['sol']['data'])

                    resmat = make_lcmv_resolution_matrix(
                        bf_filts, fwd_use, info)

                    # resmat = make_resolution_matrix_lcmv(fwd_use, lcmv_filters)

                    cov_lat_str = C._lat_str(cov_dat[0], cov_dat[1])

                    meth_str = '%s_%s' % ('LCMV', cov_lat_str)

                    functions_and_metrics(resmat, fwd_use['src'], functions,
                                          metrics, subject, meth_str)

                    # Save some PSFs
                    filetext = meth_str + '_PSFs'
                    fname = fname_stc = C.fname_STC(C, C.resolution_subdir,
                                                    subject, filetext)