#NEWLINE# @ verbose #NEWLINE# def _lcmv_source_power( info , forward , noise_cov , data_cov , reg = 0.01 , label = None , picks = None , pick_ori = None , rank = None , verbose = None ) : #NEWLINE# #INDENT# "Linearly Constrained Minimum Variance (LCMV) beamformer.\n\n    Calculate source power in a time window based on the provided data\n    covariance. Noise covariance is used to whiten the data covariance making\n    the output equivalent to the neural activity index as defined by\n    Van Veen et al. 1997.\n\n    NOTE : This implementation has not been heavily tested so please\n    report any issues or suggestions.\n\n    Parameters\n    ----------\n    info : dict\n        Measurement info, e.g. epochs.info.\n    forward : dict\n        Forward operator.\n    noise_cov : Covariance\n        The noise covariance.\n    data_cov : Covariance\n        The data covariance.\n    reg : float\n        The regularization for the whitened data covariance.\n    label : Label | None\n        Restricts the solution to a given label.\n    picks : array-like of int | None\n        Indices (in info) of data channels. If None, MEG and EEG data channels\n        (without bad channels) will be used.\n    pick_ori : None | 'normal'\n        If 'normal', rather than pooling the orientations by taking the norm,\n        only the radial component is kept.\n    rank : None | int | dict\n        Specified rank of the noise covariance matrix. If None, the rank is\n        detected automatically. If int, the rank is specified for the MEG\n        channels. A dictionary with entries 'eeg' and/or 'meg' can be used\n        to specify the rank for each modality.\n    verbose : bool, str, int, or None\n        If not None, override default verbose level (see mne.verbose).\n\n    Returns\n    -------\n    stc : SourceEstimate\n        Source power with a single time point representing the entire time\n        window for which data covariance was calculated.\n\n    Notes\n    -----\n    The original reference is:\n    Van Veen et al. Localization of brain electrical activity via linearly\n    constrained minimum variance spatial filtering.\n    Biomedical Engineering (1997) vol. 44 (9) pp. 867--880\n    " #NEWLINE# if ( picks is None ) : #NEWLINE# #INDENT# picks = pick_types ( info , meg = True , eeg = True , ref_meg = False , exclude = 'bads' ) #NEWLINE# #UNINDENT# ( is_free_ori , ch_names , proj , vertno , G ) = _prepare_beamformer_input ( info , forward , label , picks , pick_ori ) #NEWLINE# info = pick_info ( info , [ info [ 'ch_names' ] . index ( k ) for k in ch_names if ( k in info [ 'ch_names' ] ) ] ) #NEWLINE# ( whitener , _ ) = compute_whitener ( noise_cov , info , picks , rank = rank ) #NEWLINE# G = np . dot ( whitener , G ) #NEWLINE# data_cov = pick_channels_cov ( data_cov , include = ch_names ) #NEWLINE# Cm = data_cov [ 'data' ] #NEWLINE# if info [ 'projs' ] : #NEWLINE# #INDENT# Cm = np . dot ( proj , np . dot ( Cm , proj . T ) ) #NEWLINE# #UNINDENT# Cm = np . dot ( whitener , np . dot ( Cm , whitener . T ) ) #NEWLINE# Cm_inv = linalg . pinv ( Cm , reg ) #NEWLINE# W = np . dot ( G . T , Cm_inv ) #NEWLINE# n_orient = ( 3 if is_free_ori else 1 ) #NEWLINE# n_sources = ( G . shape [ 1 ] // n_orient ) #NEWLINE# source_power = np . zeros ( ( n_sources , 1 ) ) #NEWLINE# for k in range ( n_sources ) : #NEWLINE# #INDENT# Wk = W [ ( n_orient * k ) : ( ( n_orient * k ) + n_orient ) ] #NEWLINE# Gk = G [ : , ( n_orient * k ) : ( ( n_orient * k ) + n_orient ) ] #NEWLINE# Ck = np . dot ( Wk , Gk ) #NEWLINE# if is_free_ori : #NEWLINE# #INDENT# Wk [ : ] = np . dot ( linalg . pinv ( Ck , 0.1 ) , Wk ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Wk /= Ck #NEWLINE# #UNINDENT# noise_norm = np . dot ( Wk , Wk . T ) #NEWLINE# noise_norm = noise_norm . trace ( ) #NEWLINE# sp_temp = np . dot ( np . dot ( Wk , Cm ) , Wk . T ) #NEWLINE# sp_temp /= max ( noise_norm , 1e-40 ) #NEWLINE# if ( pick_ori == 'normal' ) : #NEWLINE# #INDENT# source_power [ ( k , 0 ) ] = sp_temp [ ( 2 , 2 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# source_power [ ( k , 0 ) ] = sp_temp . trace ( ) #NEWLINE# #UNINDENT# #UNINDENT# logger . info ( '[done]' ) #NEWLINE# subject = _subject_from_forward ( forward ) #NEWLINE# return SourceEstimate ( source_power , vertices = vertno , tmin = 1 , tstep = 1 , subject = subject )