Skip to content

Commit

Permalink
Added ability to anonymize coordinates using graphviz (using networkx)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklise committed Aug 26, 2024
1 parent c640914 commit 84d5888
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions wntr/stormwater/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,17 @@ def add_composite_patterns(self, data, pattern_suffix="_composite",
return composite


def anonymize_coordinates(self, seed=None, update_model=True):
def anonymize_coordinates(self, seed=None, dot_graphviz=False, update_model=True):
"""
Anonymize coordinates using a spring layout
Anonymize coordinates using a networkX spring layout or graphviz dot layout
Parameters
----------
seed : int
Random seed used to set the spring layout
dot_graphviz : Bool (optional, default = False)
Flag indicating if dot_graphviz is used to anonymize coordinates.
If False, spring layout is used.
update_model : Bool (optional, default = True)
Flag indicating if the model coordinates are updated and vertices
and polygons are removed. If False, the coordinates are returned,
Expand All @@ -714,7 +717,10 @@ def anonymize_coordinates(self, seed=None, update_model=True):
"""
G = self.to_graph()

pos = nx.spring_layout(G, seed=seed)
if dot_graphviz:
pos = nx.nx_agraph.pygraphviz_layout(G, prog="dot", args="-Gmclimit=100")
else:
pos = nx.spring_layout(G, seed=seed)
coordinates = pd.DataFrame(pos).T
coordinates.rename(columns={0: 'X', 1: 'Y'}, inplace=True)

Expand Down

0 comments on commit 84d5888

Please sign in to comment.