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

What to do when no variance in weight bounds #218

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions swmmanywhere/graph_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,12 @@ def __call__(self, G: nx.Graph,
bounds[w][0] = min(bounds[w][0], d.get(w, np.Inf))
bounds[w][1] = max(bounds[w][1], d.get(w, -np.Inf))

# Avoid division by zero
for w, bnd in bounds.items():
if bnd[0] == bnd[1]:
# I guess this shouldn't make a difference what the value is
bounds[w][1] += 1e-10
barneydobson marked this conversation as resolved.
Show resolved Hide resolved

G = G.copy()
eps = np.finfo(float).eps
for u, v, d in G.edges(data=True):
Expand Down
15 changes: 14 additions & 1 deletion tests/test_graph_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,20 @@ def test_calculate_weights():
for u, v, data in G.edges(data=True):
assert 'weight' in data.keys()
assert math.isfinite(data['weight'])


def test_calculate_weights_novar():
"""Test the calculate_weights function with no variance."""
G, _ = load_street_network()
barneydobson marked this conversation as resolved.
Show resolved Hide resolved
params = parameters.TopologyDerivation()
for weight in params.weights:
for ix, (u,v,data) in enumerate(G.edges(data=True)):
data[weight] = 1.5

G = gu.calculate_weights(G, params)
for u, v, data in G.edges(data=True):
assert 'weight' in data.keys()
assert math.isfinite(data['weight'])

def test_identify_outlets_no_river():
"""Test the identify_outlets in the no river case."""
G, _ = load_street_network()
Expand Down