Open apollner opened 3 years ago
Right now, vertices are stored as an attributes on links (pipes, pumps, valves) and can be read in and written to INP files, but they are not used for visualization in WNTR. We’ve talked about updating graphics options in WNTR, but I’m not sure how quickly we’ll get to this.
To use vertices in functions like plot_network
, I think we would need to create a temporary NetworkX graph from the water network model that includes the additional vertices as “hidden nodes” and keep the ability to plot node attributes only on actual nodes (junctions, tanks, reservoirs). If this is something you’d like to work on, please let us know.
Right now, vertices are stored as an attributes on links (pipes, pumps, valves) and can be read in and written to INP files, but they are not used for visualization in WNTR. We’ve talked about updating graphics options in WNTR, but I’m not sure how quickly we’ll get to this.
To use vertices in functions like
plot_network
, I think we would need to create a temporary NetworkX graph from the water network model that includes the additional vertices as “hidden nodes” and keep the ability to plot node attributes only on actual nodes (junctions, tanks, reservoirs). If this is something you’d like to work on, please let us know.
@kaklise thanks for the response. It sounds like an interesting feature to work on, just out of my scope at the moment. For now I managed using QGISRed.
@kaklise Not the prettiest code, but something like the code below should work. I didn't implement the "zip" approach that WNTR uses, but should be easy enough to do. The key is to create a third list for "vertices" and add them to the 'pos' list, but add them with zero size. I didn't change the core WNTR code, just created a quick script to see if it works. But the vertex list should be able to be created within the current link loop within plot_network.
--- code snippet --- G = wn.get_graph() pos = wntr.graphics.network.nx.get_node_attributes(G, 'pos')
G = nx.MultiDiGraph() nodes_list = wn.node_name_list vertex_list = []
for node in pos.keys(): G.add_node(node, size=10)
for link in wn.link_name_list: link_prop = wn.get_link(link) len_vertices = len(link_prop.vertices) st_node = link_prop.start_node.name en_node = link_prop.end_node.name
if len_vertices>0: # do something if there are vertices
base_name = link+"_v"
for vertex in range(len_vertices):
val = vertex + 1
name = base_name+str(val)
vertex_list += [name]
G.add_node(name, size=0)
G.add_edge(st_node, name)
if val == len_vertices:
G.add_edge(name, en_node)
st_node = name
pos[name] = link_prop.vertices[vertex]
else:
G.add_edge(st_node, en_node)
nx.draw_networkx_nodes(G, pos, nodelist=nodes_list, node_size=20) # real nodes nx.draw_networkx_nodes(G, pos, nodelist=vertex_list, node_size=0) ## vertices nx.draw_networkx_edges(G, pos, arrowstyle='-', arrowsize=0, node_size=0) #all links
Wouldn't this approach break the link_labels
option? Because the original edges are now gone, and we have new, smaller edges away from where the original was.
I'm interested in working on this issue. I have some questions, though:
wntr.graphics.plot_network(wn, vertices=True)
)vertices
? link_vertices
?Thanks!
vertices
is a good parameter nameThere might be additional graphics functions that could make use of this update.
The Vertices disappear when I make a plot, how can I plot with Vertices? Thanks