Skip to content

Commit

Permalink
Merge branch 'main' into experimenter_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
barneydobson committed May 28, 2024
2 parents 0170d46 + ecb9fdf commit b4954ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 12 additions & 4 deletions swmmanywhere/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ def download_river(bbox: tuple[float, float, float, float]) -> nx.MultiDiGraph:
``truncate_by_edge set`` to True.
"""
west, south, east, north = bbox
graph = ox.graph_from_bbox(
bbox = (north, south, east, west),
truncate_by_edge=True,
custom_filter='["waterway"]')
try:
graph = ox.graph_from_bbox(
bbox = (north, south, east, west),
truncate_by_edge=True,
custom_filter='["waterway"]',
retain_all=True)
except ValueError as e:
if str(e) == "Found no graph nodes within the requested polygon":
logger.warning('No water network found within the bounding box.')
return nx.MultiDiGraph()
else:
raise # Re-raise the exception

return cast("nx.MultiDiGraph", graph)

Expand Down
12 changes: 11 additions & 1 deletion tests/test_prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,22 @@ def test_river_downloader():
bbox = (0.0402, 51.55759, 0.09825591114207548, 51.6205)

mock_graph = nx.MultiDiGraph()
mock_graph.add_node(1)
# Mock ox.graph_from_bbox
with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph):
with mock.patch.object(ox,
'graph_from_bbox',
return_value=mock_graph) as mock_from_bbox:
# Call download_street
G = downloaders.download_river(bbox)
assert G == mock_graph

mock_from_bbox.side_effect = ValueError(
"Found no graph nodes within the requested polygon"
)
G = downloaders.download_river(bbox)
assert G.size() == 0


def test_elevation_downloader():
"""Check elevation downloads, writes, contains data, and a known elevation."""
# Please do not reuse api_key
Expand Down

0 comments on commit b4954ea

Please sign in to comment.