-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return networkx graph #41
Conversation
Potential solution to tomalrussell#39
Added blank line at the end
Potential solution for tomalrussell#40, but relies on my solution to tomalrussell#39
Co-authored-by: Tom Russell <[email protected]>
Thanks for working on this @amanmajid 😊 .. will be super useful Apart from the notes above, could you:
What do you reckon about @czor847's suggestion of a |
No worries! I've just made some changes to the code as requested. In terms of the additional bullets:
|
Great 😊 I wonder if we should create the networkx graph as a MultiDiGraph - that way it can handle multiple edges between pairs of nodes, and will retain the direction of edges, both of which are okay within the GeoDataFrame representation. It should also keep snkit in line with osmnx and momepy in terms of exchanging networkx graphs. In terms of recording requirements - yes, I’d put it on a line in “extras” so that pip will only install networkx if you do something like ‘pip install snkit[nx]’ and in dev-requirements so we can test the optional functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some detail-oriented comments! But also a suggested change to how we construct the networkx graph that would make a reasonably large difference to the API.
# get edges from network data | ||
edges_as_list = list(zip(network.edges.from_id,network.edges.to_id)) | ||
# add edges to graph | ||
G.add_weighted_edges_from(edges_as_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we pass in a column to use as weight here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking about this - it would be generally useful to add all the edge attributes here, including geometry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this part to extract nodal positions and edge weights (https://github.com/amanmajid/snkit/blob/e55bc44c4aa848fb9f1724f8db504a3c6a7ad114/src/snkit/network.py#L613-L639). I'm not sure how to go about efficiently adding all edge attributes when defining the graph?
# init graph | ||
G = nx.Graph() | ||
# get nodes from network data | ||
G.add_nodes_from(network.nodes.id.to_list()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to edges, can we add node attributes to the graph here?
Added functionality to add node and edge attributes. Also added a test for to_networkx function.
Thanks for this, @amanmajid - closes #39 and #40, potential follow-up in #42 |
Potential solution to #39