Adding new attributes to nodes in a pickeled graph

685 views
Skip to first unread message

MJ

unread,
Nov 6, 2013, 10:16:57 AM11/6/13
to networkx...@googlegroups.com
Hi,

I created a graph few months ago using networkx where every node is a graph in itself. I pickled this graph.

Now I need to do some processing on this graph so I unpickled it as self.graph
For every node of this graph (which is a graph in itself), I want do some  processing on the attribute 'street-wayid' of edges of this node(graph). I also need to call some functions from a different python file whose object has been created as OSM_data_obj. Here is what I am doing:


def process_node(self):
        for n, d in self.graph.nodes_iter(data=True):
            self.tempgraph=n
            self.neighbour_IDs=[]
            for u,v,p in self.tempgraph.edges_iter(data=True):
                temp_way_ID= p['street-wayid']
                temp_neighbour_IDs=[]
                temp_coord_IDs = self.OSM_data_obj.way_dict[temp_way_ID][1] # Get the coord ID's contained in this way
                temp_neighbour_IDs = self.OSM_data_obj.neighbouring_coord_IDs(temp_coord_IDs,50)
                self.neighbour_IDs.extend(temp_neighbour_IDs)


This gives me 'self.neighbour_IDs' for every node n. I want to add this as  a new attribute to every node for which this has been calculated in the existing graph. However, I am unable to do so. Do I have to create a new graph for this purpose?Or is there some way that I can add this information in the same for loop[for n,d in self.graph.nodes_iter]?

Many Thanks,

Moritz Emanuel Beber

unread,
Nov 11, 2013, 3:34:42 PM11/11/13
to networkx...@googlegroups.com
Hello,
You can access node attributes through the Graph's .node dictionary. You
could also set it as an attribute of the individual graph objects
through the .graph dictionary. Take a look here:
http://networkx.github.io/documentation/latest/tutorial/tutorial.html#adding-attributes-to-graphs-nodes-and-edges
>
> Many Thanks,
> --
> You received this message because you are subscribed to the Google
> Groups "networkx-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to networkx-discu...@googlegroups.com.
> To post to this group, send email to networkx...@googlegroups.com.
> Visit this group at http://groups.google.com/group/networkx-discuss.
> For more options, visit https://groups.google.com/groups/opt_out.
Cheers,
Moritz

MJ

unread,
Nov 15, 2013, 11:35:28 AM11/15/13
to networkx...@googlegroups.com
Hi,
That was helpful. Thanks :)
Reply all
Reply to author
Forward
0 new messages