

def label_sign_flip(label, src):
    'Compute sign for label averaging\n\n    Parameters\n    ----------\n    label : Label\n        A label.\n    src : list of dict\n        The source space over which the label is defined.\n\n    Returns\n    -------\n    flip : array\n        Sign flip vector (contains 1 or -1)\n    '
    if (len(src) != 2):
        raise ValueError('Only source spaces with 2 hemisphers are accepted')
    lh_vertno = src[0]['vertno']
    rh_vertno = src[1]['vertno']
    if (label.hemi == 'lh'):
        vertno_sel = np.intersect1d(lh_vertno, label.vertices)
        if (len(vertno_sel) == 0):
            return np.array([], int)
        ori = src[0]['nn'][vertno_sel]
    elif (label.hemi == 'rh'):
        vertno_sel = np.intersect1d(rh_vertno, label.vertices)
        if (len(vertno_sel) == 0):
            return np.array([], int)
        ori = src[1]['nn'][vertno_sel]
    else:
        raise Exception('Unknown hemisphere type')
    (_, _, Vh) = linalg.svd(ori, full_matrices=False)
    flip = np.sign(np.dot(ori, Vh[0]))
    return flip

dataset/ETHPy150Open mne-tools/mne-python/mne/label.py label_sign_flip/original