Note

This page was generated from usage_02_network_growth.ipynb.

Usage | 2. Network growth

This notebook explains how growbikenet orders the edges and why this is important.
Parameters covered: ranking, allow_edge_overlaps, crs_projected

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

[1]:
import growbikenet as gbn

We are going to work with Paris. Downloading its street network for further use:

[2]:
import osmnx as ox
g = ox.graph_from_place("Paris", network_type='drive')
ox.io.save_graph_geopackage(g.to_undirected(), "Paris_streets.gpkg")

Ranking of edges

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

We are going to generate all different rankings (saved in the dictionary edges_ranked_all) and visualize them interactively in the end.

[3]:
edges_ranked_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.

[4]:
edges_ranked = gbn.growbikenet("Paris",
                               ranking="betweenness_centrality",
                               street_network_file="Paris_streets.gpkg",)
edges_ranked_all["betweenness_centrality"] = edges_ranked
==============================================
RUNNING GROWBIKENET FOR CITY: Paris
betweenness_centrality | auto | from scratch
----------------------------------------------╮
Importing network data : 100%|████████████████| 1/1 [00:01<00:00,  1.51s/network]
Creating seed points   : 100%|████████████████| 3/3 [00:00<00:00,  3.33step/s]
Triangulation          : 100%|████████████████| 1/1 [00:00<00:00, 255.42step/s]
Routing                : 100%|████████████████| 3/3 [00:01<00:00,  2.90step/s]
Computing edge metrics : 100%|████████████████| 2/2 [00:00<00:00,  9.44step/s]
Removing edge overlaps : 100%|████████████████| 539/539 [00:04<00:00, 127.21edge/s]
Exporting data         : 100%|████████████████| 1/1 [00:00<00:00, 18.99step/s]
----------------------------------------------╯
Data exported to results/
----------------------------------------------
FINISHED IN 0:00:08
==============================================

The content of the output edges_ranked shows several columns:

[5]:
edges_ranked.head()
[5]:
betweenness_centrality geometry source target rank length length_cumulative
0 0.100523 LINESTRING (259001 6248937, 259010 6248935, 25... 25256276 24972213 0 1122 1122
1 0.095915 LINESTRING (257745 6248845, 257757 6248850, 25... 94262804 25256276 1 1435 2558
2 0.093867 LINESTRING (260539 6253313, 260536 6253305, 26... 94173047 29604212 2 1340 3898
3 0.080953 LINESTRING (263178 6248542, 263175 6248545, 26... 382071 244580618 3 1616 5515
4 0.080612 LINESTRING (261150 6249413, 261160 6249410, 26... 25031218 382071 4 1155 6670

They are:

  • betweenness_centrality: The metric to rank edges by.

  • geometry: The geometries of the edges connecting source and target seed points, projected in the coordinate references system (crs) given by the parameter crs_projected, rounded to meters. The coordinates correspond to the easting and northing in the crs. 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 11037313412: https://www.openstreetmap.org/node/11037313412

  • rank: The rank which orders the edge 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.

[6]:
edges_ranked = gbn.growbikenet("Paris",
                               ranking="closeness_centrality",
                               street_network_file="Paris_streets.gpkg",)
edges_ranked_all["closeness_centrality"] = edges_ranked
==============================================
RUNNING GROWBIKENET FOR CITY: Paris
closeness_centrality | auto | from scratch
----------------------------------------------╮
Importing network data : 100%|████████████████| 1/1 [00:01<00:00,  1.29s/network]
Creating seed points   : 100%|████████████████| 3/3 [00:00<00:00,  3.30step/s]
Triangulation          : 100%|████████████████| 1/1 [00:00<00:00, 280.80step/s]
Routing                : 100%|████████████████| 3/3 [00:01<00:00,  2.87step/s]
Computing edge metrics : 100%|████████████████| 2/2 [00:00<00:00, 21.97step/s]
Removing edge overlaps : 100%|████████████████| 539/539 [00:05<00:00, 102.06edge/s]
Exporting data         : 100%|████████████████| 1/1 [00:00<00:00, 19.50step/s]
----------------------------------------------╯
Data exported to results/
----------------------------------------------
FINISHED IN 0:00:09
==============================================

Random

Growbikenet can also showcase suboptimal random growth.

[7]:
edges_ranked = gbn.growbikenet("Paris",
                               ranking="random",
                               street_network_file="Paris_streets.gpkg",)
edges_ranked_all["random"] = edges_ranked
==============================================
RUNNING GROWBIKENET FOR CITY: Paris
random | auto | from scratch
----------------------------------------------╮
Importing network data : 100%|████████████████| 1/1 [00:01<00:00,  1.32s/network]
Creating seed points   : 100%|████████████████| 3/3 [00:01<00:00,  2.75step/s]
Triangulation          : 100%|████████████████| 1/1 [00:00<00:00, 258.57step/s]
Routing                : 100%|████████████████| 3/3 [00:01<00:00,  2.87step/s]
Computing edge metrics : 100%|████████████████| 2/2 [00:00<00:00, 369.49step/s]
Removing edge overlaps : 100%|████████████████| 539/539 [00:04<00:00, 114.40edge/s]
Exporting data         : 100%|████████████████| 1/1 [00:00<00:00, 19.58step/s]
----------------------------------------------╯
Data exported to results/
----------------------------------------------
FINISHED IN 0:00:08
==============================================

Visualization

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

[8]:
import ipywidgets as widgets
import matplotlib.pyplot as plt
step = widgets.IntSlider(
    value=4, min=0, max=max(edges_ranked["rank"]), step=1, description="Growth step:", layout=widgets.Layout(width='500px')
)
ranking = widgets.ToggleButtons(
    options=['betweenness_centrality', 'closeness_centrality', 'random'],
    description='Ranking:',
)
def update_map(step=step, ranking=ranking):
    fig, ax = plt.subplots(figsize=(8, 6))
    edges_ranked_all[ranking][edges_ranked_all[ranking]["rank"] <= 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_ranked.total_bounds[1], edges_ranked.total_bounds[3])
    ax.set_xlim(edges_ranked.total_bounds[0], edges_ranked.total_bounds[2])
    plt.axis('off')
    plt.show()

widgets.interactive(update_map, step=step, ranking=ranking)
[8]:

Allowing edge overlaps

Considerable computing time is spent on “Removing edge overlaps”.

What are edge overlaps? In the abstract, unrouted network, there can be no edge overlaps in the seed network. However, when the edges are routed, there are often many such overlaps. In general, we do not want to have overlaps as they render length calculations wrong, i.e., the length and length_cumulative columns in the result:

[9]:
edges_ranked_all["betweenness_centrality"].head()
[9]:
betweenness_centrality geometry source target rank length length_cumulative
0 0.100523 LINESTRING (259001 6248937, 259010 6248935, 25... 25256276 24972213 0 1122 1122
1 0.095915 LINESTRING (257745 6248845, 257757 6248850, 25... 94262804 25256276 1 1435 2558
2 0.093867 LINESTRING (260539 6253313, 260536 6253305, 26... 94173047 29604212 2 1340 3898
3 0.080953 LINESTRING (263178 6248542, 263175 6248545, 26... 382071 244580618 3 1616 5515
4 0.080612 LINESTRING (261150 6249413, 261160 6249410, 26... 25031218 382071 4 1155 6670

Because edge overlaps are removed by default, the lengths are correct. In particular, the total length of the grown network is

[10]:
int(edges_ranked_all["betweenness_centrality"].length_cumulative.iloc[-1]/1000)
[10]:
614

kilometers.

Edge overlap removal also removes edges that would end up completely empty, which is the reason why the rank can show gaps. This can be seen by the difference of the following two numbers:

[11]:
print(len(edges_ranked_all["betweenness_centrality"]),
      max(edges_ranked_all["betweenness_centrality"]["rank"])+1)
523 538

However, if we allow edge overlaps, via allow_edge_overlaps=True, this will make the calculation faster:

[12]:
edges_ranked = gbn.growbikenet("Paris",
                               ranking="betweenness_centrality",
                               allow_edge_overlaps=True,
                               street_network_file="Paris_streets.gpkg",)
==============================================
RUNNING GROWBIKENET FOR CITY: Paris
betweenness_centrality | auto | from scratch
----------------------------------------------╮
Importing network data : 100%|████████████████| 1/1 [00:01<00:00,  1.28s/network]
Creating seed points   : 100%|████████████████| 3/3 [00:00<00:00,  3.30step/s]
Triangulation          : 100%|████████████████| 1/1 [00:00<00:00, 293.62step/s]
Routing                : 100%|████████████████| 3/3 [00:01<00:00,  2.88step/s]
Computing edge metrics : 100%|████████████████| 2/2 [00:00<00:00,  9.57step/s]
Exporting data         : 100%|████████████████| 1/1 [00:00<00:00, 14.64step/s]
----------------------------------------------╯
Data exported to results/
----------------------------------------------
FINISHED IN 0:00:04
==============================================

It also leads to no rank gaps:

[13]:
print(len(edges_ranked),
      max(edges_ranked["rank"])+1)
539 539

But it will also wrongly skew the calculated total length of the network to be much longer:

[14]:
int(edges_ranked.length_cumulative.iloc[-1]/1000)
[14]:
908