How to use the pynets.stats.netstats.prune_disconnected function in pynets

To help you get started, we’ve selected a few pynets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dPys / PyNets / tests / test_netstats.py View on Github external
def test_raw_mets():
    """
    Test raw_mets extraction functionality
    """
    from pynets.stats.netstats import global_efficiency, average_local_efficiency
    from networkx.algorithms import degree_assortativity_coefficient, average_clustering, average_shortest_path_length, degree_pearson_correlation_coefficient, graph_number_of_cliques, transitivity, sigma
    base_dir = str(Path(__file__).parent/"examples")
    est_path = base_dir + '/002/fmri/DesikanKlein2012/graphs/0021001_Default_est_sps_0.19densparc_mm.npy'
    in_mat = np.load(est_path)
    G = nx.from_numpy_array(in_mat)
    [G, _] = netstats.prune_disconnected(G)
    metric_list_glob = [global_efficiency, average_local_efficiency, degree_assortativity_coefficient,
                        average_clustering, average_shortest_path_length, degree_pearson_correlation_coefficient,
                        graph_number_of_cliques, transitivity]
    for i in metric_list_glob:
        net_met_val = netstats.raw_mets(G, i)
        print(i)
        print(net_met_val)
        assert net_met_val is not np.nan
github dPys / PyNets / tests / test_netstats.py View on Github external
def test_prune_disconnected():
    """
    Test pruning functionality
    """
    base_dir = str(Path(__file__).parent/"examples")
    in_mat = np.load(base_dir + '/002/fmri/graphs/002_Default_est_cov_0.95prop_TESTmm_3nb_2fwhm_0.1Hz_func.npy')
    G = nx.from_numpy_array(in_mat)

    start_time = time.time()
    [G, pruned_nodes] = netstats.prune_disconnected(G)
    print("%s%s%s" % ('thresh_and_fit (Functional, proportional thresholding) --> finished: ',
                      str(np.round(time.time() - start_time, 1)), 's'))

    assert G is not None
    assert pruned_nodes is not None
github dPys / PyNets / pynets / plotting / plot_gen.py View on Github external
import cPickle as pickle
    except ImportError:
        import _pickle as pickle

    ch2better_loc = pkg_resources.resource_filename("pynets", "templates/ch2better.nii.gz")

    coords = list(coords)
    labels = list(labels)
    if len(coords) > 0:
        dpi_resolution = 500
        if '\'b' in atlas:
            atlas = atlas.decode('utf-8')
        if (prune == 1 or prune == 2) and len(coords) == conn_matrix.shape[0]:
            G_pre = nx.from_numpy_matrix(np.abs(conn_matrix))
            if prune == 1:
                [G, pruned_nodes] = prune_disconnected(G_pre)
            elif prune == 2:
                [G, pruned_nodes] = most_important(G_pre)
            else:
                G = G_pre
                pruned_nodes = []
            pruned_nodes.sort(reverse=True)
            print('(Display)')
            coords_pre = list(coords)
            labels_pre = list(labels)
            if len(pruned_nodes) > 0:
                for j in pruned_nodes:
                    labels_pre.pop(j)
                    coords_pre.pop(j)
                conn_matrix = nx.to_numpy_array(G)
                labels = labels_pre
                coords = coords_pre
github dPys / PyNets / pynets / core / thresholding.py View on Github external
thr : float
        A proportional threshold, between 0 and 1, to achieve through local thresholding.

    Returns
    -------
    conn_matrix_thr : array
        Weighted, MST local-thresholded, NxN matrix.
    """
    from pynets.core import thresholding
    from pynets.stats import netstats

    fail_tol = 10
    conn_matrix = np.nan_to_num(conn_matrix)
    G = nx.from_numpy_matrix(conn_matrix)
    if not nx.is_connected(G):
        [G, pruned_nodes] = netstats.prune_disconnected(G)
        pruned_nodes.sort(reverse=True)
        coords_pre = list(coords)
        labels_pre = list(labels)
        if len(pruned_nodes) > 0:
            for j in pruned_nodes:
                labels_pre.pop(j)
                coords_pre.pop(j)
            conn_matrix = nx.to_numpy_array(G)
            labels = labels_pre
            coords = coords_pre

    maximum_edges = G.number_of_edges()
    G = thresholding.weight_to_distance(G)
    min_t = nx.minimum_spanning_tree(G, weight="distance")
    len_edges = min_t.number_of_edges()
    upper_values = np.triu_indices(np.shape(conn_matrix)[0], k=1)
github dPys / PyNets / pynets / plotting / plot_gen.py View on Github external
import cPickle as pickle
    except ImportError:
        import _pickle as pickle

    ch2better_loc = pkg_resources.resource_filename("pynets", "templates/ch2better.nii.gz")

    coords = list(coords)
    labels = list(labels)
    if len(coords) > 0:
        dpi_resolution = 500
        if '\'b' in atlas:
            atlas = atlas.decode('utf-8')
        if (prune == 1 or prune == 2) and len(coords) == conn_matrix.shape[0]:
            G_pre = nx.from_numpy_matrix(np.abs(conn_matrix))
            if prune == 1:
                [G, pruned_nodes] = prune_disconnected(G_pre)
            elif prune == 2:
                [G, pruned_nodes] = most_important(G_pre)
            else:
                G = G_pre
                pruned_nodes = []
            pruned_nodes.sort(reverse=True)
            coords_pre = list(coords)
            labels_pre = list(labels)
            if len(pruned_nodes) > 0:
                for j in pruned_nodes:
                    labels_pre.pop(j)
                    coords_pre.pop(j)
                conn_matrix = nx.to_numpy_array(G)
                labels = labels_pre
                coords = coords_pre
            else: