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 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() ])
def test_anatomical_copy_hats(self): # check hats not copied to P P = mkg.anatomical_copy(self.R) assert nx.is_isomorphic(self.H, P, edge_match=em(), node_match=nm()) # check otherwise the same assert nx.is_isomorphic(self.R, P, edge_match=em(), node_match=nm(exclude=['hats'])) # check hats copied if specified as an additional key new_keys = mkg.anatomical_node_attributes() new_keys.append('hats') Q = mkg.anatomical_copy(self.R, nodal_keys=new_keys) assert nx.is_isomorphic(self.R, Q, edge_match=em(), node_match=nm())