Skip to content
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

Migrating to networkx 2.0 #84

Merged
merged 12 commits into from
Sep 23, 2017
Merged

Migrating to networkx 2.0 #84

merged 12 commits into from
Sep 23, 2017

Conversation

gboeing
Copy link
Owner

@gboeing gboeing commented Aug 22, 2017

Migrating OSMnx from networkx 1.x to networkx 2.0's new API.

@gboeing
Copy link
Owner Author

gboeing commented Aug 22, 2017

@coveralls
Copy link

coveralls commented Aug 22, 2017

Coverage Status

Coverage decreased (-0.004%) to 94.185% when pulling 54d8e5e on nx2 into b863781 on master.

@coveralls
Copy link

coveralls commented Aug 22, 2017

Coverage Status

Coverage decreased (-0.004%) to 94.185% when pulling 7cd3b31 on nx2 into b863781 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.004%) to 94.185% when pulling e04660b on nx2 into b863781 on master.

1 similar comment
@coveralls
Copy link

coveralls commented Aug 23, 2017

Coverage Status

Coverage decreased (-0.004%) to 94.185% when pulling e04660b on nx2 into b863781 on master.

@coveralls
Copy link

coveralls commented Aug 23, 2017

Coverage Status

Coverage decreased (-0.06%) to 94.128% when pulling 4fd2d27 on nx2 into b863781 on master.

@@ -554,7 +554,7 @@ def plot_graph_route(G, route, bbox=None, fig_height=6, fig_width=None,
lines = []
for u, v in edge_nodes:
# if there are parallel edges, select the shortest in length
data = min([data for data in G.edge[u][v].values()], key=lambda x: x['length'])
data = min(G.get_edge_data(u, v).values(), key=lambda x: x['length'])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be G[u][v].values() or G.adj[u][v].values() or G.get_edge_data(u, v).values(). They are equivalent.

edge_types = [list(edge.values())[0]['highway'] for edge in G_undir.edge[node].values()]
# first, identify all the highway types of this node's incident edges
incident_edges_data = [G_undir.get_edge_data(node, neighbor) for neighbor in G_undir.neighbors(node)]
edge_types = [data[0]['highway'] for data in incident_edges_data]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could stick with what you had replacing G_undir.edge[node] with G_undir.adj[node] or G_undir[node]

# look at this first edge's parallel edges one at a time
for key_other in H.edge[u][v]:
# look at every other edge between u and v, one at a time
for key_other in dict(H[u][v]).keys():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code H[u][v] creates a dict. So you don't need the dict/keys parts. Replace G.edge[u][v] with either G[u][v] or G.adj[u][v] (they are equivalent)

@@ -71,13 +71,13 @@ def is_endpoint(G, node, strict=True):

# add all the edge OSM IDs for incoming edges
for u in G.predecessors(node):
for key in G.edge[u][node]:
osmids.append(G.edge[u][node][key]['osmid'])
for key in dict(G[u][node]).keys():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: could replace G.edge with G.adj everywhere in the old code. You can also use G[u][node] in place of G.edge[u][node] if you prefer.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dschult thanks Dan, very helpful.

@@ -243,14 +243,13 @@ def simplify_graph(G_, strict=True):
for u, v in zip(path[:-1], path[1:]):

# there shouldn't be multiple edges between interstitial nodes
edges = G.edge[u][v]
if not len(edges) == 1:
if not G.number_of_edges(u=u, v=v) == 1:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be: if len(G[u][v]) != 1: but maybe G.number_of_edges is clearer.

@@ -509,7 +509,7 @@ def get_route_edge_attributes(G, route, attribute, minimize_key='length'):
for u, v in zip(route[:-1], route[1:]):
# if there are parallel edges between two nodes, select the one with the
# lowest value of minimize_key
data = min([data for data in G.edge[u][v].values()], key=lambda x: x[minimize_key])
data = min(G.get_edge_data(u, v).values(), key=lambda x: x[minimize_key])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same options as above: G.edge could be replaced by G, G.adj or by using G.get_edge_data. They are equivalent.

@coveralls
Copy link

coveralls commented Aug 25, 2017

Coverage Status

Coverage increased (+0.4%) to 94.552% when pulling 0ed2063 on nx2 into b863781 on master.

@gboeing gboeing merged commit cddf8ac into master Sep 23, 2017
@gboeing gboeing deleted the nx2 branch September 23, 2017 04:47
@coveralls
Copy link

coveralls commented Sep 23, 2017

Coverage Status

Coverage decreased (-0.5%) to 94.128% when pulling 8f70c0b on nx2 into 7c11684 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants