def label_sign_flip(label, src):
 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

def label_sign_flip ( label , src ) : 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
compute sign for label averaging .