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

Fix geometry and indexing of new/modified roadway nodes/links #310

Merged
merged 32 commits into from
Mar 9, 2023

Conversation

e-lo
Copy link
Collaborator

@e-lo e-lo commented Mar 1, 2023

This PR contains major refactoring of several key pieces of RoadwayNetwork to be more efficient, resilient and understandable.

Improves:

  • Efficiency in apply managed lane, add/delete and modify property changes
  • Decomposes many monolithic functions and files (still many more to address)
  • Adds num_managed_lane_links() method to easily test for managed lanes ([Refactor] Separate out and be more rigorous about checking for managed lane network presence #294)
  • DRY principles
  • Efficiency in tests: uses small network when able to, uses fixtures for network so only need to read in once ([FEATURE] Use network fixture for testing #300)
  • Comprehensiveness in tests: actual assert statements, more tests
  • Organization of tests: into smaller files so that can easily run them and understand what each does
  • Organization of model-network functions into separate file as a model for decomposing some of roadway network which is...massive
  • added documentation at function level
  • formatting

Fixes:

...still a lot to do and that this PR doesn't fix.

e-lo added 21 commits April 25, 2022 09:40
- make easier to find various tests, utils and roadway network
- troubleshooting test_model_roadway.py
Fixed:
- indexing when created new links and nodes
- merge that was creating excess records b/c it should have been an inner join

Also:
- added missing node from small ex network
- made tests quicker by using small example network instead of large network
- edited tests to be flexible to network tested
- Made networks and directories test fixtures for simplicity
Because we are using separate files, don't need marks.
As separate from unique_model_link_identifiers so that we can use identifiers such as osm_link_id which may not be unique because of link splitting, but are sufficient for things like specifying links for project cards.
Fixed:
- Querying if "set" or "existing" or "change" is a key, not if the value of it produces a True b/c a value of 0 is a valid "set"...but produces a False.

Also:
- Updated roadway change tests to actually test if change is accurate.
- To better manage and run them, tests for different apply methods are separated in different files
- managed lane tests now have explicit assert statements testing actual truthiness
Also:
- convenience method added to RoadwayNetwork to count number of managed lane links
- Added RoadwayNetwork class variables for properties to coerce
- Added class function to do coercion and call it at read-in and write out

Also:
- fixed bug in how test was looping
various minor bug fixes
- currently failing but not fixing as part of this PR
Includes:
- added validation of new links and nodes
- better handling of unique IDs
- better structure for geometry creation/updating
Also:
- corrected occurrences of in/outboundReferenceId --> in/outboundReferenceId*s*
- Added a simple roadway addition test
- fixed testing data to comply with roadway network requirements
- added step to make sure new nodes had correct geometry
- refactored how to delete nodes and links to be more efficient rather than searching through whole network for each selection
- refactored how to search for shapes that should be deleted when links are
- added better testing to make sure it was 'safe' to delete nodes

Also:
- black
@e-lo e-lo added bug Something isn't working enhancement New feature or request labels Mar 1, 2023
@e-lo e-lo added this to the v1.0 milestone Mar 1, 2023
@e-lo e-lo requested review from lmz, DavidOry and i-am-sijia March 1, 2023 17:01
@e-lo e-lo self-assigned this Mar 1, 2023
@e-lo e-lo changed the base branch from master to develop March 1, 2023 17:07
@e-lo e-lo marked this pull request as draft March 1, 2023 17:07
@e-lo e-lo marked this pull request as ready for review March 1, 2023 23:49
@e-lo
Copy link
Collaborator Author

e-lo commented Mar 1, 2023

@lmz @DavidOry @i-am-sijia - This is passing the roadway tests on my machine. Def not perfect but better and more resilient.

@i-am-sijia
Copy link
Member

tests\test_utils.py fails at test_point_from_xy():

image

After I change the output_crs to 4269, it passes. I think this is related to Issue #302

Copy link
Member

@i-am-sijia i-am-sijia left a comment

Choose a reason for hiding this comment

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

  • ran all tests locally, proposed changes necessary for tests to pass
  • the returns in transitnetwork.py seem inconsistent, after introducing net which is a deepcopy of self
  • the roadwaynetwork.py has tons of changes, which I have not yet detailly reviewed, but the tests all passed.
  • the SCRATCH_DIR in "test_transit.py" and "test_scenario.py" does not exist by default. It will be created after test_io.py is run which calls the pytest fixture. We need to be careful about the test dependencies when migrating to GitHub Actions.

network_wrangler/transitnetwork.py Show resolved Hide resolved
return updated_network
q = net.feed.frequencies.trip_id.isin(freq["trip_id"])

net.loc[q, properties["property"]] = build_value
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
net.loc[q, properties["property"]] = build_value
net.feed.frequencies.loc[q, properties["property"]] = build_value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch!

SHAPES = os.path.join(EX_DIR, "shape.geojson")


def read_ex_net(benchmark):
Copy link
Member

Choose a reason for hiding this comment

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

Where is fixture benchmark defined?

Copy link
Collaborator Author

@e-lo e-lo Mar 8, 2023

Choose a reason for hiding this comment

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

Benchmark is a keyword for pytest benchmark for timing the tests.

net = copy.deepcopy(small_net)
net.links_df["my_ad_hoc_field"] = 22.5

print("Network with field...\n ", net.links_df["my_ad_hoc_field"][0:5])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print("Network with field...\n ", net.links_df["my_ad_hoc_field"][0:5])
print("Network with field...\n ", net.links_df["my_ad_hoc_field"].iloc[0:5])

network_wrangler/utils/__init__.py Outdated Show resolved Hide resolved
"""
net = copy.deepcopy(self)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a deepcopy here? The same function in roadwaynetwork.py does not deepcopy.

network_wrangler/transitnetwork.py Show resolved Hide resolved
net.feed.shapes = shapes
net.feed.stops = stops
net.feed.stop_times = stop_times
return net
Copy link
Member

Choose a reason for hiding this comment

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

The indentation of this return seems off, should we move it outside of the if?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch

@@ -15,7 +15,7 @@
"roadway": "residential",
"length": 80.935,
"maxspeed": "",
"name": "Arkwright Street,North Rivoli Street",
"name": "Arkwright Street",
Copy link
Member

Choose a reason for hiding this comment

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

Why shorten the name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to differentiate from the larger network when I'm reading errors (this net is really not "real")

@e-lo e-lo requested a review from i-am-sijia March 8, 2023 18:01
e-lo added 2 commits March 8, 2023 15:34
- did slightly different than suggestion so that would work if index value changed
- minor bug fixes
@e-lo
Copy link
Collaborator Author

e-lo commented Mar 8, 2023

@i-am-sijia I think this is ready for you to re-review

Copy link
Member

@i-am-sijia i-am-sijia left a comment

Choose a reason for hiding this comment

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

Just one small issue. Otherwise looks good.

network_wrangler/transitnetwork.py Show resolved Hide resolved
@e-lo e-lo requested a review from i-am-sijia March 9, 2023 17:46
@e-lo
Copy link
Collaborator Author

e-lo commented Mar 9, 2023

📓 that most of the transit tests aren't passing yet and will be worked on in a separate PR

@i-am-sijia
Copy link
Member

@e-lo I added a lot of transit related codes to MTC's network wrangler: https://github.com/BayAreaMetro/network_wrangler/tree/generic_agency/network_wrangler, so that it can actually apply real transit project cards. it might be useful to include those in the transit related PR.

@e-lo e-lo merged commit 5d87f2f into develop Mar 9, 2023
@e-lo e-lo deleted the add-update-node-geometry branch March 9, 2023 23:40
@e-lo
Copy link
Collaborator Author

e-lo commented Mar 10, 2023

@i-am-sijia I created an issue where you can add more detail if you think it would be useful: #319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
2 participants