Exemple #1
0
    def __init__(
        self,
        network=None,
        parcellation=None,
        centroids=None,
    ):
        # ============== Create graph ================
        nx.classes.graph.Graph.__init__(self)
        if network is not None:
            if isinstance(network, nx.classes.graph.Graph):
                # Copy graph
                self.__dict__.update(network.__dict__)

            else:
                # Create weighted graph from a dataframe or
                # numpy array
                if isinstance(network, pd.DataFrame):
                    M = network.values
                elif isinstance(network, np.ndarray):
                    M = network
                network = weighted_graph_from_matrix(M, create_using=self)

        # ===== Give anatomical labels to nodes ======
        if parcellation is not None:
            # assign parcellation names to nodes
            self.set_parcellation(parcellation)
        if centroids is not None:
            # assign centroids to nodes
            self.set_centroids(centroids)
        # Tell BrainNetwork class which attributes to consider "anatomical"
        # and therefore preserve when copying or creating new graphs
        self.anatomical_node_attributes = anatomical_node_attributes()
        self.anatomical_graph_attributes = anatomical_graph_attributes()
        # intialise global measures as an empty dict
        self.graph['global_measures'] = {}
def test_scale_weights():
    G1 = mkg.scale_weights(simple_weighted_graph())
    G2 = mkg.weighted_graph_from_matrix(symmetric_matrix_1() * -1)
    assert nx.is_isomorphic(G1, G2, edge_match=em())