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

River bug #177

Merged
merged 3 commits into from
May 28, 2024
Merged

River bug #177

merged 3 commits into from
May 28, 2024

Conversation

barneydobson
Copy link
Collaborator

Description

Crashes when no rivers inside the bbox. Though this is fine now that we have option to use lowest elevation point.

Now fixed and tested

@barneydobson barneydobson requested review from dalonsoa and cheginit May 23, 2024 15:02
graph = ox.graph_from_bbox(
bbox = (north, south, east, west),
truncate_by_edge=True,
custom_filter='["waterway"]')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adding retain_all=True for getting rivers, since by default it will only keep the largest connected network, which is fine for streets but not necessarily for other network types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, didn't realise that - thanks!

# Mock ox.graph_from_bbox
with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using pytest, exceptions can be checked like so:

def test_no_river():
    bbox = (0.0402, 51.55759, 0.09825591114207548, 51.6205)
    with pytest.raises(ValueError, match="Found no graph nodes"):
        _ = ox.graph_from_bbox(bbox)
    G = downloaders.download_river(bbox)
    assert G.size() == 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - though that will actually run the download which the testing module aims to avoid - I will add this test with @pytest.mark.downloads - these are separate tests to test the actual downloads.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure I fully understand actually - this test isn't checking an exception. The graph_from_bbox will raise an exception inside download_river, causing it to return an empty graph - which is what the test is checking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the test was that you want to first check if the ox.graph_from_bbox indeed raises ValueError and then run the same with downloaders.download_river and check if it handles the exception correctly and returns an empty graph.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding getting data with osmnx, I recommend enabling its caching. You can set it with osmnx.settings.use_cache = True

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now in issue #183

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just agreed with @cheginit comment on using pytest features to test exceptions.

@barneydobson barneydobson merged commit ecb9fdf into main May 28, 2024
8 checks passed
@barneydobson barneydobson deleted the no_rivers_in_bbox branch May 28, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants