Esempio n. 1
0
    def anatomical_matches(self,
                           nodal_keys=anatomical_node_attributes(),
                           graph_keys=anatomical_graph_attributes()):
        '''
        Checks that all graphs in GraphBundle are pairwise anatomical matches
        as defined in :func:`is_anatomical_match`.

        Parameters
        ----------
        nodal_keys : list of str, optional
        graph_keys : list of str, optional

        Returns
        -------
        bool
            `True` if all graphs are anatomically matched, `False` otherwise.

        See Also
        --------
        :func:`is_anatomical_match`
        :func:`BrainNetwork.is_nodal_match`
        '''
        H = list(self.values())[0]
        return (False not in [
            is_anatomical_match(H,
                                G,
                                nodal_keys=nodal_keys,
                                graph_keys=graph_keys) for G in self.values()
        ])
Esempio n. 2
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'] = {}