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

dedicated minimal tests -- nodes.remove_false_nodes() #59

Merged
merged 7 commits into from
Oct 24, 2024

Conversation

jGaboardi
Copy link
Collaborator

@jGaboardi jGaboardi commented Oct 23, 2024

@jGaboardi jGaboardi self-assigned this Oct 23, 2024
@jGaboardi jGaboardi mentioned this pull request Oct 23, 2024
5 tasks
@jGaboardi jGaboardi requested a review from martinfleis October 23, 2024 02:33
Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.3%. Comparing base (35bd6a0) to head (b9653b5).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main     #59     +/-   ##
=======================================
+ Coverage   98.1%   98.3%   +0.2%     
=======================================
  Files          6       6             
  Lines        894     894             
=======================================
+ Hits         877     879      +2     
+ Misses        17      15      -2     
Files with missing lines Coverage Δ
sgeop/nodes.py 98.8% <100.0%> (+1.2%) ⬆️

... and 1 file with indirect coverage changes

Copy link
Contributor

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

We should probably also copy all the tests from momepy here.

@jGaboardi
Copy link
Collaborator Author

We should probably also copy all the tests from momepy here.

We are not expecting the same results here, though right? Just trying the first little block locally and it fails.

        false_network = geopandas.read_file(momepy.datasets.get_path("tests"), layer="network")
        false_network["vals"] = range(len(false_network))
        fixed = sgeop.nodes.remove_false_nodes(false_network)
>       assert len(fixed) == 56
E       assert 61 == 56
E        +  where 61 = len(                                                geometry  vals\n61.0   LINESTRING (-727482.257 -1052966.07, -727485.5...     0\n62.0   LINESTRING (-727210.943 -1053072.14, -727212.8...     1\n63.0   LINESTRING (-727210.943 -1053072.14, -727206.5...     2\n64.0   LINESTRING (-727141.085 -1053103.182, -727129....     3\n65.0   LINESTRING (-727136.904 -1053091.833, -727117....     4\n...                                                  ...   ...\n117.0  LINESTRING (-727412.897 -1052948.823, -727407....    56\n118.0  LINESTRING (-727248.835 -1052881.77, -727254.5...    57\n119.0  LINESTRING (-727289.896 -1052909.828, -727281....    58\n120.0  LINESTRING (-727227.04 -1052735.582, -727226.1...    59\n121.0  LINESTRING (-727238.493 -1052817.281, -727253....    60\n\n[61 rows x 2 columns])

sgeop/tests/test_nodes.py:399: AssertionError

@martinfleis
Copy link
Contributor

Not entirely sure on those test data to be fair. The one in sgeop does contain some fixes but it may be worth verifying the differences.

@jGaboardi
Copy link
Collaborator Author

Not entirely sure on those test data to be fair. The one in sgeop does contain some fixes but it may be worth verifying the differences.

OK after the PR on the momepy side is settled I will back in this.

@jGaboardi
Copy link
Collaborator Author

jGaboardi commented Oct 23, 2024

This seems to specifically be happening in the sgeop implementation when passing in a GeoSeries -- passing in a GeoDataFrame succeeds.

Wrong, I was using momepy.remove_false_nodes() instead of sgeop.remove_false_nodes(). This is still very much unsolved from both frames and series.

@jGaboardi
Copy link
Collaborator Author

Key piece in momepy.remove_false_nodes() that is not in sgeop.remove_false_nodes():

# explode to avoid MultiLineStrings
 # reset index due to the bug in GeoPandas explode
 df = gdf.reset_index(drop=True).explode(ignore_index=True)

@jGaboardi
Copy link
Collaborator Author

When adding the line above into sgeop.remove_false_nodes() all chunks here pass (when some index tinkering) except for the coordinate ordering chunk:

# check loop order
expected = np.array(
    [
        [-727238.49292668, -1052817.28071986],
        [-727253.1752498, -1052827.47329062],
        [-727223.93217677, -1052829.47624082],
        [-727238.49292668, -1052817.28071986],
    ]
)
np.testing.assert_almost_equal(
    np.array(fixed.loc[53].geometry.coords), expected
)

This appears to be due to the indices of the resultant edges not lining up, and the index location produced from the sgeop implementation is now 55. Can confirm testing suite passes locally with this adjustment.

@jGaboardi jGaboardi requested a review from martinfleis October 23, 2024 23:10
sgeop/nodes.py Outdated Show resolved Hide resolved
Co-authored-by: Martin Fleischmann <[email protected]>
@jGaboardi jGaboardi requested a review from martinfleis October 24, 2024 12:41
@martinfleis
Copy link
Contributor

Let's also add notes on 3D geometry being downcast, potentially. And about MultiLineStrings being exploded.

@jGaboardi jGaboardi merged commit 25181a3 into main Oct 24, 2024
10 checks passed
@jGaboardi jGaboardi deleted the GH20_nodes_tests_remove_false_nodes branch October 24, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rough edge in sgeop.nodes.remove_false_nodes when multilinestrings passed
2 participants