-
Notifications
You must be signed in to change notification settings - Fork 193
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
Adding vertex plotting option to plot_network #390
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e324fb3
Adding vertex plotting option to plot_network
kbonney 62c38bc
adding plot_vertices option to other plotting functions when they cal…
kbonney 741ce98
adding io.inp test
kbonney f2408d9
moving vertex graph creation to to_graph() method
kbonney 7b8817c
adding node attribute to vertex graphing test for code coverage
kbonney dadf6be
trivial commit to proc workflow
kbonney 048fd1a
undoing trivial commit
kbonney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,7 +373,7 @@ def from_gis(gis_data, append=None): | |
|
||
return wn | ||
|
||
def to_graph(wn, node_weight=None, link_weight=None, modify_direction=False): | ||
def to_graph(wn, node_weight=None, link_weight=None, modify_direction=False, include_vertices=False): | ||
""" | ||
Convert a WaterNetworkModel into a networkx MultiDiGraph | ||
|
||
|
@@ -410,8 +410,31 @@ def to_graph(wn, node_weight=None, link_weight=None, modify_direction=False): | |
for name, link in wn.links(): | ||
start_node = link.start_node_name | ||
end_node = link.end_node_name | ||
G.add_edge(start_node, end_node, key=name) | ||
nx.set_edge_attributes(G, name="type", values={(start_node, end_node, name): link.link_type}) | ||
vertices = link.vertices | ||
if include_vertices and vertices: | ||
node_base_name = name + "_vertex_" | ||
link_base_name = name + "_vertexlink_" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vertexlink -> vertex |
||
for vertex_ind in range(len(vertices)): | ||
end_node = node_base_name+str(vertex_ind) | ||
link_name = link_base_name+str(vertex_ind) | ||
G.add_edge(start_node, end_node, link_name) | ||
nx.set_edge_attributes(G, name="type", values={(start_node, end_node, link_name): link.link_type}) | ||
nx.set_edge_attributes(G, name="base_link", values={(start_node, end_node, link_name): link.name}) | ||
nx.set_node_attributes(G, name="pos", values={end_node: vertices[vertex_ind]}) | ||
nx.set_node_attributes(G, name="type", values={end_node: "Vertex"}) | ||
nx.set_node_attributes(G, name="base_link", values={end_node: link.name}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. base_link -> link_name |
||
|
||
start_node = end_node | ||
end_node = link.end_node_name | ||
link_name = link_base_name+str(vertex_ind+1) | ||
G.add_edge(start_node, end_node, link_name) | ||
nx.set_edge_attributes(G, name="type", values={(start_node, end_node, link_name): link.link_type}) | ||
nx.set_edge_attributes(G, name="base_link", values={(start_node, end_node, link_name): link.name}) | ||
|
||
else: | ||
G.add_edge(start_node, end_node, key=name) | ||
nx.set_edge_attributes(G, name="type", values={(start_node, end_node, name): link.link_type}) | ||
nx.set_edge_attributes(G, name="base_link", values={(start_node, end_node, name): link.name}) | ||
|
||
if link_weight is not None: | ||
try: # weight links | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
plot_vertices -> include_vertices