Skip to content

280 account for all bike network components to be less than existing network minimum component length - #285

Merged
mszell merged 7 commits into
mainfrom
280-account-for-all-bike_network-components-to-be-less-than-existing_network_minimum_component_length
Aug 25, 2026
Merged

280 account for all bike network components to be less than existing network minimum component length#285
mszell merged 7 commits into
mainfrom
280-account-for-all-bike_network-components-to-be-less-than-existing_network_minimum_component_length

Conversation

@marianamirandapessoa

Copy link
Copy Markdown
Member

Description

Fix update_with_existing_bike_network() to account for when all bike network components are smaller than constants.EXISTING_NETWORK_MINIMUM_COMPONENT_LENGTH.

Changes:

  1. Swap the order of filter_network_by_component_length() and nx.compose()

Even though g_undir_exnw was filtered for component length, the results of that filter never made it into g_undir


  1. Changed filter_network_by_component_length() to export the filtered version of the graph

  1. Add the existing_network_spacing parameter as an input to the function update_with_existing_bike_network().

If the graph of the exiting network after removing the small components is empty, then there is no bike network to consider, so existing_network_spacing is set to None

Related Issue

Fixes #280

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📝 Documentation update
  • 🧹 Code refactor (no functional changes)
  • ✅ Test update

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual testing

Test configuration:

  • OS:

Screenshots (if applicable)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally

Additional Notes

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
growbikenet/functions.py 50.00% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@marianamirandapessoa

Copy link
Copy Markdown
Member Author

Process of incorporating the bike network

I will list the processes and the changes I made

1. The bike network is incorporated into g_undir via the function update_with_existing_bike_network()

if existing_network_spacing is not None: # update g_undir: add the existing bike network
    nodes, edges, g_undir, nodes_exnw, edges_exnw, g_undir_exnw, nodes_exnw_filtered = update_with_existing_bike_network(city_query, g_undir, import_files=import_files, city_boundary_geometry=city_boundary_geometry)
    progress_bar.update(1)
progress_bar.close()

The function:

  • filters out the components which are smaller than constants.EXISTING_NETWORK_MINIMUM_COMPONENT_LENGTH
  • and removes the components of bike network which are disconnected from the LCC

I switched the order of the filter_network_by_component_length() and nx.compose() to ensure the small components are not considered.

And to account for an empty g_undir_filtered, I added a check in filter_network_by_component_length(), so that the outputs are empty GeoDataFrames.

The small components are still kept in the variable edges_exnw, which will latter be used to export the bike network.

2. The seed points of the bike network are added according to existing_network_spacing, via _update_seed_points_with_existing_bike_network()

if existing_network_spacing is not None:
    seed_points_snapped_filtered = _update_seed_points_with_existing_bike_network(seed_points_snapped_filtered, nodes_exnw_filtered, existing_network_spacing)
    progress_bar.update(1)
progress_bar.close()

Here I removed the existing_network_spacing from the output of the function, and its setting to None, when:

len(seed_points_exnw) == 0:

because, even though the bike network is not considered, it should still be exported for visualisation.
Setting existing_network_spacing to None, prevents the code from entering the next step 3 👇🏻

3. The bike network is added to the exported data in the first line of GeoDataFrame, as one big MultiLineString

if existing_network_spacing:
    existing_bikenet = gpd.GeoDataFrame({c: None for c in edges_ordered.columns}, index=[-1], crs=constants._CRS_CALCULATIONS)
    existing_bikenet.loc[-1, 'geometry'] = gpd.GeoSeries(edges_exnw.geometry).union_all()
    edges_ordered.loc[-1] = existing_bikenet.loc[-1]
    edges_ordered.index = edges_ordered.index+1
    edges_ordered.sort_index(inplace=True)
    edges_ordered.crs = constants._CRS_CALCULATIONS
progress_bar.update(1)
progress_bar.close()

I've made no changes here.

4. + 5. The bike network is exported.

if existing_network_spacing:
    exnw_string = "from_bikenw"
else:
    exnw_string = "from_scratch"
if existing_network_spacing:
    edges_ordered.iloc[[0]].to_file(f, driver="GPKG", layer="Existing bike network") 
    edges_ordered.iloc[1:-1].to_file(f, driver="GPKG", layer="Grown bike network")

@marianamirandapessoa marianamirandapessoa left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Delete comment that's not used anymore.

Comment thread growbikenet/functions.py Outdated
@mszell

mszell commented Aug 25, 2026

Copy link
Copy Markdown
Member

Cool, thank you!

Just to document here openly what we discussed in another channel, what led to some of the extra commits:

  • We still want to export in the end the existing bike net and all of its components, also those that are too short for seed points to snap, because it is still good to see for the visualizations etc.
  • The bike network that is being exported contains only the components that are connected to the growable network's LCC, and this is intended.
  • "Should the undirected graph that will be used for getting the phi + principal bearing + routing have these components from the bike network that are smaller than 100m?" - It doesn't matter, so whatever is easiest.

@mszell mszell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thx! I didn't think through all the potential issues, but if there are any left, they will come out anyway when we re-export the 403 cities, so let's merge this now.

@mszell
mszell merged commit 1354b2c into main Aug 25, 2026
16 of 17 checks passed
@mszell
mszell deleted the 280-account-for-all-bike_network-components-to-be-less-than-existing_network_minimum_component_length branch August 25, 2026 15:18
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.

Account for all bike_network components to be less than EXISTING_NETWORK_MINIMUM_COMPONENT_LENGTH

2 participants