Beispiel #1
0
    def setUpClass(cls):
        cls.G = simple_weighted_graph()

        cls.Gname = simple_weighted_graph()
        nx.set_node_attributes(cls.Gname, {
            0: 'a',
            1: 'b',
            2: 'c'
        },
                               name='name')

        cls.Gcentroids = simple_weighted_graph()
        nx.set_node_attributes(cls.Gcentroids, {
            0: (1, 0, 0),
            1: (0, 1, 0),
            2: (0, 0, 1)
        },
                               name='centroids')
        nx.set_node_attributes(cls.Gcentroids, {0: 1, 1: 0, 2: 0}, name='x')
        nx.set_node_attributes(cls.Gcentroids, {0: 0, 1: 1, 2: 0}, name='y')
        nx.set_node_attributes(cls.Gcentroids, {0: 0, 1: 0, 2: 1}, name='z')

        cls.H = simple_anatomical_graph()

        cls.J = nx.Graph()
        cls.J.add_nodes_from(cls.H.nodes)
        mkg.copy_anatomical_data(cls.J, cls.H)
        cls.K = simple_anatomical_graph()
        cls.K.remove_edges_from(cls.H.edges)
        cls.L = mkg.anatomical_copy(cls.H)
        cls.R = mkg.anatomical_copy(cls.H)
        nx.set_node_attributes(cls.R, 'stetson', name='hats')
Beispiel #2
0
 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())
Beispiel #3
0
    def anatomical_copy(self):
        '''
        Create a new graph from G preserving:
        * nodes
        * edges
        * any nodal attributes specified in G.anatomical_node_attributes
        * any graph attributes specified in G.anatomical_graph_attributes
        * ``G.anatomical_node_attributes``
        * ``G.anatomical_graph_attributes``

        Returns
        -------
        :class:`networkx.Graph`
            A new graph with the same nodes and edges as G and identical
            anatomical data.

        See Also
        --------
        :func:`BrainNetwork.anatomical_copy`
        :func:`anatomical_data`
        :func:`set_anatomical_node_attributes`
        :func:`set_anatomical_graph_attributes`
        '''
        H = anatomical_copy(self,
                            nodal_keys=self.anatomical_node_attributes,
                            graph_keys=self.anatomical_graph_attributes)
        H.set_anatomical_node_attributes(self.anatomical_node_attributes)
        H.set_anatomical_graph_attributes(self.anatomical_graph_attributes)
        return H