VBIndex / py_vb_toolbox

Vogt-Bailey index toolbox in Python
GNU General Public License v3.0
12 stars 12 forks source link

Working With Different Eigenvalues #62

Open eylulkup opened 1 month ago

eylulkup commented 1 month ago

This pull request introduces the ability to select which eigenvalue to work with in app.py, with a default of second eigenvalue. This change gives flexibility to the application while maintaining the existing functionality of the vb_index code. Also it helps users to have control over which eigenvalue they work with, enhancing the capacity of the application of VB index.

Chnages that are made in the code:

APP.PY

parser.add_argument('-e', '--eigenvalue-index', metavar='INDEX', type=int, nargs=1, default=1, help="""Index of the eigenvalue to use. Default is the second smallest eigenvalue (index 1).""")

eigenvalue_index = args.eigenvalue_index

vb_index.compute_vb_metrics(internal_loop_func="vb_vol", n_cpus=n_cpus, data=data, affine=affine, header=header, norm=L_norm, cort_index=cort_index, brain_mask=brain_mask, residual_tolerance=args.tol[0], max_num_iter=args.maxiter[0], eigenvalue_index=eigenvalue_index, output_name=args.output[0] + "." + L_norm, reho=args.reho)

VB_INDEX.PY

def compute_vb_metrics(internal_loop_func, n_cpus, data, norm, residual_tolerance, max_num_iter, eigenvalue_index, header=None, brain_mask=None, surf_vertices=None, surf_faces=None, output_name=None, nib_surf=None, k=None, cluster_index=None, cort_index=None, affine=None, reho=False, full_brain=False, debug=False):

results = run_multiprocessing(pool, internal_loop_func, n_items, dn, surf_vertices, surf_faces, data, norm, residual_tolerance, max_num_iter, eigenvalue_index, cluster_index, cort_index, affine, k, reho, full_brain, brain_mask, debug)

def run_multiprocessing(pool, internal_loop_func, n_items, dn, surf_vertices, surf_faces, data, norm, residual_tolerance, max_num_iter, eigenvalue_index, cluster_index, cort_index, affine, k, reho, full_brain, brain_mask, debug):

threads = np.append(threads, (pool.apply_async(vb_vol_internal_loop, (i0, iN, data, norm, brain_mask, residual_tolerance, max_num_iter, eigenvalue_index, reho, debug), error_callback=pool_callback)))

def vb_vol_internal_loop(i0, iN, data, norm, brain_mask, residual_tolerance, max_num_iter, eigenvalue_index, reho, debug=False):

compute_vol(neighborhood, i, idx, loc_result, affinity, vox_coords, residual_tolerance, max_num_iter, eigenvalue_index, norm)

def compute_vol(neighborhood, i, idx, loc_result, affinity, vox_coords, residual_tolerance, max_num_iter, eigenvalue_index, norm):

, , eigenvalue, _ = spectral_reorder(False, affinity, residual_tolerance, max_num_iter, eigenvalue_index, norm)

def get_fiedler_eigenpair(eigenvalue_index, method, full_brain, Q, D=None, is_symmetric=True, tol='def_tol', maxiter=50):

def spectral_reorder(full_brain, B, residual_tolerance, max_num_iter, eigenvalue_index, method='unnorm'):

vbi_value, eigenvector = get_fiedler_eigenpair(eigenvalue_index, method, full_brain, Q, tol=residual_tolerance, maxiter=max_num_iter)