Usage | 2. Network growth

This notebook explains how GrowBikeNet orders the edges and why this is important.

Parameters covered: ordering

We start every Usage notebook with the standard way of importing GrowBikeNet:

import growbikenet as gbn

Ordering of edges

GrowBikeNet not only creates a potential bicycle network, but also an ordering of the edges. The ordering is important, as it provides an ordering, informing a city which edges to implement first to arrive at a functional network early. The ordering metric is controlled by the parameter ordering which is by default set to 'betweenness'. Other options are 'closeness' and 'random'.

Here we work with Paris, France. We are going to generate all different orderings (saved in the dictionary edges_ordered_all) and visualize them interactively in the end.

edges_ordered_all = {}

Betweenness centrality

Betweenness centrality is a network centrality measure approximating flow. By ordering edges like this, the first built edge is the one with highest expected flow of cyclists. As was shown in the research on which GrowBikeNet is based, this is a much better ordering than random, and in most cases also better than ordering by closeness centrality.

edges_ordered = gbn.growbikenet("Paris",
    ordering="betweenness",)
edges_ordered_all["betweenness"] = edges_ordered

The content of the output edges_ordered shows several columns:

edges_ordered.head()
betweenness geometry source target ordering length length_cumulative
0 0.116956 LINESTRING (2.38274 48.85333, 2.38253 48.85368... 25255896 24972212 0 1574 1574
1 0.108434 LINESTRING (2.35176 48.84957, 2.35187 48.84956... 25255896 260015405 1 1639 3213
2 0.106083 LINESTRING (2.34687 48.89478, 2.34695 48.89469... 94164238 94173781 2 1819 5032
3 0.089921 LINESTRING (2.34145 48.88399, 2.34147 48.88395... 25254925 24972212 3 1474 6507
4 0.088745 LINESTRING (2.35614 48.85936, 2.35623 48.85934... 25034466 26401904 4 1520 8027

They are:

  • betweenness: The metric to order edges by.

  • geometry: The geometries of the edges connecting source and target seed points, in the coordinate references system (crs) given by the setting settings.crs_result. These geometries are typically a mix between linestrings and multilinestrings.

  • source, target: The OSM IDs of source and target seed points. These are nodes that can be looked up on OSM, for example for OSM ID 298719867: https://www.openstreetmap.org/node/298719867

  • ordering: The ordering of the edges by betweenness centrality. These are increasing integers, but not necessarily consecutive, due to potentially empty pieces in-between that are removed due to edge overlaps, see end of this notebook.

  • length: Length of the current edge, rounded to whole meters.

  • length_cumulative: Cumulative length of current and all previous edges, rounded to whole meters.

Closeness centrality

Ranking by closeness centrality means growing from the center.

edges_ordered = gbn.growbikenet("Paris",
    ordering="closeness",)
edges_ordered_all["closeness"] = edges_ordered

Random

GrowBikeNet can also showcase suboptimal random growth.

edges_ordered = gbn.growbikenet("Paris",
    ordering="random",)
edges_ordered_all["random"] = edges_ordered

Visualization

Below the three different growths are visualized together interactively. Use the slider and buttons to see the different growth patterns:

Note

This interactive widget does not work in the online docs, but it works when you run the notebook yourself.

Hide code cell source

import ipywidgets as widgets
import matplotlib.pyplot as plt

step = widgets.IntSlider(
    value=4, min=0, max=max(edges_ordered["ordering"]), step=1, description="Growth step:", layout=widgets.Layout(width='500px')
)
ordering = widgets.ToggleButtons(
    options=['betweenness', 'closeness', 'random'],
    description='Ranking:',
)
def update_map(step=step, ordering=ordering):
    fig, ax = plt.subplots(figsize=(8, 6))
    edges_ordered_all[ordering][edges_ordered_all[ordering]["ordering"] <= step].plot(
        linewidth=3,
        color="#096a51",
        ax=ax,
    )
    ax.set_title(f"Paris bike net growth, growth step {step}", fontsize=12)
    ax.set_ylim(edges_ordered.total_bounds[1], edges_ordered.total_bounds[3])
    ax.set_xlim(edges_ordered.total_bounds[0], edges_ordered.total_bounds[2])
    plt.axis('off')
    plt.show()

widgets.interactive(update_map, step=step, ordering=ordering)