Developer reference

This is the complete developer reference for the GrowBikeNet package. If you are looking for an introduction to GrowBikeNet, read the Getting started guide.

growbikenet.growbikenet

growbikenet.growbikenet.growbikenet(city_query, ranking='betweenness_centrality', seed_point_type='auto', seed_point_grid_spacing='auto', seed_point_linking='auto', existing_network_spacing=None, export_data=True, city_id=None, export_plots=False, allow_edge_overlaps=False, import_files={}, seed_point_tags=None)[source]

Creates a list of urban street network edges ordered by a ranking method.

The edges form a subnetwork of a city’s street network, interpreted as a growing bicycle network following [1]. By default, growth is from scratch, but the existing bicycle network can also be used as a starting point[Raf425b00f903-2]_. The original paper [1] uses minimum weight triangulation, but Delaunay triangulation is implemented much faster and in practice gives identical results. Triangulation and metrics (betweenness, closeness) are calculated for the unrouted, abstract network for which egde lengths are taken from the routed network.

Parameters:
city_querystr

Search string for the city that the analysis should be performed on. This is the query used to fetch the data from nominatim. Overruled for data fetching if city_boundary or street_network is set.

rankingstr, default ‘betweenness_centrality’

Method used to rank edges. Must be ‘betweenness_centrality’ (default), ‘closeness_centrality’, or ‘random’.

seed_point_typestr (‘auto’ | ‘grid_square’ | ‘grid_triangle’ | ‘rail’ | ‘school’ | ‘park’ | ‘file’ | ‘tags’), default ‘auto’

If set to ‘auto’, selects ‘grid_square’ or ‘grid_triangle’ automatically depending on the street network’s orientation entropy, see [3]. If set to ‘grid_square’, creates a square grid. If set to ‘grid_triangle’, creates a triangle grid. In this case, seed_point_linking must not be set to ‘quadrangulate’. If set to ‘rail’, uses railway stations and halts. If set to ‘school’, uses kindergartens, schools, colleges, and universities. If set to ‘park’, uses parks, gardens, nature reserves, and public bathing places. If set to ‘file’, imports seed_point. If set to ‘tags’, uses geocodable seed_point_tags, see [4].

seed_point_grid_spacing‘auto’ | int, default ‘auto’

If seed_point_type is set to ‘grid_square’ or ‘grid_triangle’, this is the spacing between seed points, in meters. Auto-value for seed_point_type ‘grid_square’ with seed_point_linking ‘triangulate_delaunay’: 1707 Auto-value for seed_point_type ‘grid_square’ with seed_point_linking ‘quadrangulate’: 1000 Auto-value for seed_point_type ‘grid_triangle’: 1154 Auto-value otherwise: 1707 These values ensure that any point in the city is always within 500m of the network (under perfect conditions). For case 1707, see [1].

seed_point_linkingstr (‘auto’ | ‘triangulate_delaunay’ | ‘quadrangulate’), default ‘auto’

The algorithm for linking up the seed points into an unrouted, abstract network. If set to ‘auto’, selects ‘triangulate_delaunay’ or ‘quadrangulate’ automatically depending on the street network’s orientation entropy, see [3]. If set to ‘triangulate_delaunay’, uses Delaunay triangulation. If set to ‘quadrangulate’, uses quadrangulation, which only works for seed_point_type ‘grid_square’ and existing_network_spacing None. Useful for grid-like street networks like Manhattan or Barcelona.

existing_network_spacingNone | ‘auto’ | int, default None

Spacing between seed points, in meters, only on the existing bicycle network. If not set to a positive integer, the existing network is ignored. existing_network_spacing is recommended to be smaller than seed_point_grid_spacing, ideally around 50%, to ensure that the existing bicycle network is built first. Option ‘auto’ sets existing_network_spacing to 50% of the seed_point_grid_spacing.

export_databool, default True

If set to True, data is saved to a file. The filename is [slug]-[ranking]-[seed_point_type].[settings.export_file_format], where slug is a string id made out of city_query.

city_idstr | None, default None

If set, the slugified city_id is used as the filename of the data export. For example, a city_id “Athens” will turn to “athens” in filenames. If set to None, the slugified city_query is used as the filename of the data export. It is useful to set a city_id for cities where the city_query is not the city name, for example to set for a city_query “Municipality of Athens” the city_id to “Athens”.

export_plotsbool, default False

If set to True, plots are saved to files, overwriting existing ones.

allow_edge_overlapsbool, default False

If set to False, removes edge overlaps in consecutive growth stages and deletes growth stages that do not add anything new.

import_files: dict, default {}
The following key:value entries can be set:
“city_boundary”str | None, default None

If not set to None, the study area is selected from the (Multi)Polygon provided in the city_boundary shape or gpkg file, ideally in unprojected latitude-longitude degrees (EPSG:4326), but EPSG:3857 also works. For example, “./tests/test_data/copenhagen_city_boundary.shp”.

“street_network”str | None, default None

If not set to None, the street network is loaded from this file. Must be a gpkg file in unprojected crs EPSG:4326 with layers nodes and edges, with the structure that an undirected osmnx street network g has after saved via ox.io.save_graph_geopackage(). For example: >>> g = ox.graph_from_place(“Barcelona”, network_type=’drive’) >>> g = nx.MultiGraph(ox.convert.to_digraph(g)) >>> ox.io.save_graph_geopackage(g, “Barcelona_streets.gpkg”).

“bike_network”str | None, default None

If not set to None, the existing bike network is loaded from this file. Must be a gpkg file in unprojected crs EPSG:4326 with layers nodes and edges, with the structure that an undirected osmnx bike network has after saved via ox.io.save_graph_geopackage().

“seed_points”str | None, default None

If not set to None, the seed points is loaded from this file. Must be a gpkg file in unprojected crs EPSG:4326 containing only point objects. For example, “./tests/test_data/oelde_seed_points.shp”. seed_point_type must be set to ‘file’.

“point_data”str | None, default None

If not set to None, an additional data set of points will be loaded from this file, representing point events like crashes or citizen feedback to improve bike infrastructure. Must be a gpkg file in unprojected crs EPSG:4326 containing only point objects, optionally with an int “num” column that encodes the number of point events. To be used in future versions of growbikenet.

“trip_data”str | None, default None

If not set to None, an additional data set of trips will be loaded from this file, representing trip events for prioritizing bike infrastructure growth. Must be a csv file in unprojected crs EPSG:4326 containing the following fields: o_lat, o_lon, d_lat, d_lon. Optionally there can be an int “num” field that encodes the number of trips between each origin and destination. To be used in future versions of growbikenet.

seed_point_tagsNone | dict[str, bool | str | list[str]], default None

If not None, must be a geocodable seed_point_tags, see [4], and seed_point_type must be set to ‘tags’. For example, seed_point_tags={“railway”: [“station”, “halt”]} retrieves exactly the same as seed_point_type=’rail’.

Returns:
edges_rankedgeopandas.geodataframe.GeoDataFrame

ordered geodataframe of all edges in street network

References

[1] (1,2,3)
  1. Szell, S. Mimar, T. Perlman, G. Ghoshal, R. Sinatra, “Growing urban bicycle networks”, Scientific Reports 12, 6765 (2022)

[2]
  1. Folco, L. Gauvin, M. Tizzoni, M. Szell, “Data-driven micromobility network planning for demand and safety”, Environment and planning B: Urban analytics and city science 50(8), 2087-2102 (2023)

[3] (1,2)
  1. Boeing, “Urban spatial order: Street network orientation, configuration, and entropy”, Applied Network Science 4, 67 (2019)

Examples

Minimum working example: Grow a bicycle network from scratch in Lyon.

>>> edges_ranked = gbn.growbikenet("Lyon")

Grow a bicycle network from scratch in Copenhagen, providing a study area polygon to include also Frederiksberg and Amager.

>>> edges_ranked = gbn.growbikenet("Copenhagen", import_files={'city_boundary':"./tests/test_data/copenhagen_city_boundary.shp"}) 

Expand the existing bicycle network of Lyon, connecting all educational institutions.

>>> edges_ranked = gbn.growbikenet("Lyon", seed_point_type='school', existing_network_spacing='auto') 

Grow a bicycle network in Oelde from scratch, working offline by importing the street network and custom seed points from file.

>>> edges_ranked = gbn.growbikenet("Oelde", seed_point_type='file', import_files={'street_network':"./tests/test_data/oelde_street_network.gpkg", 'seed_points':"./tests/test_data/oelde_seed_points.gpkg"})

growbikenet.constants

Global constants for growbikenet that can be tweaked during development, but should not be changed later by the user. Especially technical or internal constants start with an underscore.

PBI_CUSTOM_FILTERlist[str]

Custom filter for protected bicycle infrastructure (pbi)

_PRESET_TAGSdict

Pre-defined tags to select tags as seed points

_PHI_LIMITSlist[float]

Two orientation order limits between street networks with: 1) negligible grid elements, 2) some grid elements, 3) grid. We aimed to use the tercile limits from the paper [3]_ (Fig 2), but the values here are lower for unknown reasons, also with the unweighted version. Also, it was aimed to have Barcelona in the grid category. For these reasons, the limits were lowered.

EXISTING_NETWORK_MINIMUM_COMPONENT_LENGTHint

Minimum length a bike network component needs to have for seed points to snap, in meters

_SEED_POINT_SNAP_DISTANCE_FACTORfloat

Factor to multiply seed_point_grid_spacing with, to determine auto value of seed_point_snap_distance

_EXISTING_NETWORK_SPACING_FACTORfloat

Factor to multiply seed_point_grid_spacing with, to determine auto value of existing_network_spacing

GRID_SPACING_TRIANGULATEint

Grid spacing in meters for grid triangulation that ensures that any point in the city is always within buffer distance b=500m of the network (if seed points snap perfectly).

GRID_SPACING_QUADRANGULATEint

Grid spacing in meters for quadrangulation that ensures that any point in the city is always within buffer distance b=500m of the network (if seed points snap perfectly).

GRID_SPACING_TRIANGLEint

Grid spacing in meters for triangle grid that ensures that any point in the city is always within buffer distance b=500m of the network (if seed points snap perfectly).

_BUFFER_SEED_POINTS_EXNW_FACTORfloat

Factor to multiply existing_network_spacing with, to determine which previously determined seed points (grid or rail) to drop that are too close to the extra existing network points

_BEARING_BINSint

Number of bins to determine bearing. e.g. 72 will create 5 degrees bins

growbikenet.functions

Utility functions for growbikenet.

growbikenet.functions._count_and_merge(n, bearings)[source]

Double, then merge bins to avoid edge effects

Make twice as many bins as desired, then merge them in pairs. Prevents bin-edge effects around common values like 0° and 90°. Adapted from: https://github.com/gboeing/osmnx-examples/blob/v0.11/notebooks/17-street-network-orientations.ipynb

Parameters:
n: int

Number of bins

bearings: pandas.Series

Series of bearings

Returns:
bearings_merged: numpy.ndarray, dtype=int

The frequencies of the new merged bearings

growbikenet.functions._create_delaunay_edges(nodes_gdf)[source]

Create df with edges that are part of Delaunay triangulation

Note that the original paper [1] uses minimum weight triangulation, but Delaunay triangulation is much faster due to the Delaunay scipy function and gives in most cases identical results. Triangulation and metrics (betweenness, closeness) are calculated for the abstract network for which egde lengths are taken from the routed network.

Parameters:
nodes_gdf: geopandas.geodataframe.GeoDataFrame

seed points with osmid and corresponding point geometry

Returns:
dfpandas.DataFrame

DataFrame with Edge pairs and singled out source and target nodes

References

[1]
  1. Szell, S. Mimar, T. Perlman, G. Ghoshal, R. Sinatra, “Growing urban bicycle networks”, Scientific Reports 12, 6765 (2022)

growbikenet.functions._get_correct_edgetuples(edge_gdf, nodelist)[source]

Map a node list (from nx.shortest_paths) to the correct set of edge tuples that can be used for indexing the edge geodataframe

Parameters:
edge_gdf: geopandas.geodataframe.GeoDataFrame

The street network, in a projected coordinate reference system

nodelist: list

A list of nodes that make up source and targets of edges

Returns:
edgelist_final: list

List of edge tuples that can be used for indexing the edge geodataframe

growbikenet.functions._get_existing_network_seed_points(nodes_exnw, existing_network_spacing)[source]

Get seed points on an existing bicycle network

Start with the first (arbitrary) node from nodes_exnw. Then, for each node: Delete all other nodes closer than existing_network_spacing, proceed with the closest of the remaining nodes. Finish once all nodes are found or deleted.

Parameters:
nodes_exnw: geopandas.geodataframe.GeoDataFrame

Nodes of the existing bicycle network, in a projected coordinate reference system.

existing_network_spacing: int

Distance between seed points, in meters.

Returns
——-
seed_points_exnw: geopandas.geodataframe.GeoDataFrame

Seed points, already part of the network, in the same projected coordinate reference system as edges

growbikenet.functions._get_grid_seed_points(edges, seed_point_spacing, principal_bearing, seed_point_type='grid_square')[source]

Get grid seed points for street network, rotated by principal bearing

Adapted from: https://github.com/gboeing/osmnx-examples/blob/v0.11/notebooks/17-street-network-orientations.ipynb

Parameters:
edges: geopandas.geodataframe.GeoDataFrame

The street network, in a projected coordinate reference system

seed_point_spacing: int

Distance between seed points, in meters

principal_bearing: float

Principal bearing (most common bearing of streets)

seed_point_type: str (‘grid_square’ | ‘grid_triangle’)
Returns:
seed_points: geopandas.geodataframe.GeoDataFrame

Seed points, rotated by principal bearing, to be snapped to the street network, in the same projected coordinate reference system as edges

seed_network: networkx graph

If seed_point_type is ‘grid_square’, quadrangulated network of the seed_points, where node ids are the seed_points. If seed_point_type is ‘grid_triangle’, empty network because the seed points will be triangulated.

growbikenet.functions._get_tags_seed_points(city_query, tags, city_boundary_geometry=None)[source]

Get tags seed points for a city

Parameters:
city_querystr

Name of the city that the analysis should be performed on. This is the query string used to fetch the data from nominatim. Overruled (for data fetching) if city_boundary_geometry is set.

tagsNone | dict[str, bool | str | list[str]], default None

Geocodable tags, see [3]. For example, tags={“railway”: [“station”, “halt”]} will retrieve exactly the same as seed_point_type=’rail’.

city_boundary_geometry(shapely Polygon | shapely MultiPolygon | None), default None

If not set to None, the study area will be selected from this geometry.

Returns:
seed_points: geopandas.geodataframe.GeoDataFrame

Seed points, rotated by principal bearing, to be snapped to the street network, in the same projected coordinate reference system as edges

References

growbikenet.functions._prepare_seed_points(seed_points)[source]

Project and prepare seed points for further use

Parameters:
seed_points: geopandas.geodataframe.GeoDataFrame

Unprojected seed points

Returns:
seed_points: geopandas.geodataframe.GeoDataFrame

Projected and prepared seed points.

growbikenet.functions._rank_df(df, method)[source]

Rank dataframe by specified method

Parameters:
df: pandas.DataFrame

Dataframe with source and target information for each edge, as well as edge attributes as columns

method: str

Method used to rank edges. Must be ‘betweenness_centrality’ (default), ‘closeness_centrality’, or ‘random’.

growbikenet.functions._remove_edge_overlaps(edges_in)[source]

In the grown network, remove edge overlaps stepwise

Parameters:
edges_in: geopandas.geodataframe.GeoDataFrame

The grown bike network, in a projected coordinate reference system

Returns:
edges_out: geopandas.geodataframe.GeoDataFrame

The grown bike network without edge overlaps, in a projected coordinate reference system

growbikenet.functions._resolve_auto_parameters(seed_point_type, seed_point_grid_spacing, seed_point_linking, existing_network_spacing, phi, import_files)[source]

Resolve auto parameters and parameter inconsistencies

Parameters:
seed_point_* and existing_network_spacing and import_files from growbikenet.growbikenet()
Additionally:
phifloat

Weighted orientation order

Returns:
seed_point_* and existing_network_spacing from growbikenet.growbikenet()
growbikenet.functions._reverse_bearing(x)[source]

Reverse bearing

Adapted from: https://github.com/gboeing/osmnx-examples/blob/v0.11/notebooks/17-street-network-orientations.ipynb

Parameters:
x: float

The bearing to reverse

Returns:
x_rev: float

The reversed bearing

growbikenet.functions._update_seed_points_with_existing_bike_network(seed_points_snapped, nodes_exnw, existing_network_spacing)[source]

Update seed points with existing bike network

Updates given snapped seed points by incorporating seed points from an existing bike network.

Parameters:
seed_points_snappedgeopandas.geodataframe.GeoDataFrame

Snapped seed points on the street network, constructed with seed_point_grid_spacing

nodes_exnwgeopandas.geodataframe.GeoDataFrame

Nodes of the existing bike network, after shortest components below constants.EXISTING_NETWORK_MINIMUM_COMPONENT_LENGTH have been filtered out

existing_network_spacingint

Positive integer denoting spacing between seed points, in meters, only on the existing bicycle network.

Returns:
seed_points_snappedgeopandas.geodataframe.GeoDataFrame

Snapped seed points incorporating both street grid and existing bike network

growbikenet.functions._validate_parameters(city_query, ranking, seed_point_type, seed_point_grid_spacing, seed_point_linking, existing_network_spacing, export_data, city_id, export_plots, allow_edge_overlaps, import_files, seed_point_tags)[source]

Check if user parameter input is valid. If not, raise an exception or warning

Parameters:
Same as growbikenet.growbikenet()
Additionally:
constants._PRESET_TAGSdict

Dictionary of preset seed point tags.

Returns:
True
growbikenet.functions._validate_settings()[source]

Check if user settings input is valid. If not, raise an exception or warning

Parameters:
See settings
Returns:
True
growbikenet.functions.add_path_to_df(df, edges, g_undir)[source]

Map each unrouted edge to a merged geometry of corresponding osmnx edges (routed on g_undir)

Parameters:
df: pandas.DataFrame

Dataframe with information about edges

edges: geopandas.geodataframe.GeoDataFrame

The street network, in a projected coordinate reference system

g_undir: networkx.graph undirected

graph to use for routing

Returns:
df: pandas.DataFrame

Dataframe with added path nodes and path edges

growbikenet.functions.add_point_data_to_net(points, edges, crs_projected, matching_distance=500)[source]

Match point data to network edges

Parameters:
pointsgeopandas.geodataframe.GeoDataFrame

A gdf of unprojected point geometries, optional having a column “num” containing an integer. This could be (number of) point events like crashes or citizen feedback to improve bike infrastructure. If “num” column is not provided, assumes 1 per point.

edgesgeopandas.geodataframe.GeoDataFrame

A gdf of projected spatial network edges. This is the routed network of seed points.

matching_distanceint

Matching distance in meters

crs_projectedstr

Coordinate reference system that is used to project osm data.

Returns:
edges_with_datageopandas.geodataframe.GeoDataFrame

The same spatial network edges, but with a new int column “num_points” populated with the summed up “num” values of all points, matched to the closest links if within matching_distance.

growbikenet.functions.add_trip_data_to_net(trips, A, crs_projected, matching_distance=500)[source]

Match trip data to network edges

First, match origin and destination points given in trips to the nodes. Only consider trips where both origins and nodes are matched within matching_distance. Then, for each trip, find the shortest path over the edges from matched origin node to matched destination node, and add 1 (or optionally “num” if column provided in trips) to the affected edges.

Parameters:
tripspandas DataFrame

A df of unprojected origin-destination coordinates (columns: o_lat, o_lon, d_lat, d_lon), with each row encoding a trip. Optional with a column “num” containing an integer. This could be (number of) trip events. If “num” column is not provided, assumes 1 per trip.

A: networkx.graph

Graph created from triangulation edge list

crs_projectedstr

Coordinate reference system that is used to project spatial data.

matching_distanceint

Matching distance in meters

Returns:
graph_with_datanetworkx.graph

The same graph created from triagulation edges list, but with a new edge attribute “num_trips” populated with the summed up “num” values of all trips where both origins and destinations could be matched to the closest network nodes within matching_distance.

growbikenet.functions.create_gdf_with_geoms(df, edges)[source]

Merge path geometries and create geodataframe

Parameters:
df: pandas.DataFrame

Dataframe with path nodes and path edges

edges: geopandas.GeoDataFrame

The street network, in a projected coordinate reference system

Returns:
gdf: geopandas.GeoDataFrame

projected GeoDataFrame with path nodes and path edges and merged geometries

growbikenet.functions.df_from_graph(A, method)[source]

Create a dataframe from an input graph

Parameters:
A: networkx.graph

Graph created from triangulation edge list

method: str

Method used to rank edges. Must be ‘betweenness_centrality’ (default), ‘closeness_centrality’, or ‘random’.

Returns:
df: pandas.DataFrame

Dataframe with source and target information for each edge, as well as edge attributes as columns

growbikenet.functions.download_network(city_query, network_type='drive', custom_filter=None, retain_all=True, city_boundary_geometry=None)[source]

Download and prepare a street network from OSM via OSMnx

Downloads a network with a given network_type and custom_filter using ox.graph_from_place. Then, stores the undirected OSM data in gdfs and projects using settings.crs_projected.

Parameters:
city_querystr

Name of the city that the analysis should be performed on. Overruled (for data fetching) if city_boundary or street_network is set.

network_type{‘all’, ‘all_public’, ‘bike’, ‘drive’, ‘drive_service’, ‘walk’}

What type of street network to retrieve if custom_filter is None.

custom_filter(str | list[str] | None)

A custom ways filter to be used instead of the network_type presets

retain_allbool, default True

If True, return the entire graph even if it is not connected, useful for disconnected bicycle networks. If False, retain only the largest weakly connected component, useful for road networks.

city_boundary_geometry(shapely Polygon | shapely MultiPolygon | None), default None

If not set to None, the study area will be selected from this geometry.

Returns:
nodesgeopandas.geodataframe.GeoDataFrame

Extracted OSM nodes, projected

edgesgeopandas.geodataframe.GeoDataFrame

Extracted OSM edges, projected

g_undirnetworkx.classes.multigraph.MultiGraph

Extracted networkX graph, undirected

growbikenet.functions.filter_network_by_component_length(g_undir)[source]

Filter a network to remove too short components

The application is that g_undir is all the components of the existing bicycle network, but we do not snap seed points to components shorter than constants.EXISTING_NETWORK_MINIMUM_COMPONENT_LENGTH. So we create a new set of nodes where the nodes from the too small components are removed.

Parameters:
g_undirnetworkx.classes.multigraph.MultiGraph

Street network networkX graph, undirected

Returns:
nodes_filteredgeopandas.geodataframe.GeoDataFrame

Filtered OSM nodes of the street network, projected

edges_filteredgeopandas.geodataframe.GeoDataFrame

Filtered OSM edges of the street network, projected

g_undir_filterednetworkx.classes.multigraph.MultiGraph

Filtered street networkX graph, undirected

growbikenet.functions.filter_points_distant_from_osm_nodes(points_snapped, snap_distance='auto')[source]

Remove points that are further than the snap distance away from an actual osm node

Parameters:
points_snappedgeopandas.geodataframe.GeoDataFrame

Points with additional information about geometries of osm nodes that seed nodes were snapped to.

snap_distanceint

Maximum distance between raw seed points and osm nodes for snapping, in meters.

Returns:
points_snapped_filteredgeopandas.geodataframe.GeoDataFrame

points within snap distance away from an actual osm node; only columns are osmid and the associated osm geometry

growbikenet.functions.get_principal_bearing(G)[source]

Determine the most common (principal) bearing, for the best grid orientation

Adapted from: https://github.com/gboeing/osmnx-examples/blob/v0.11/notebooks/17-street-network-orientations.ipynb The bearing is determined from edges weighted by length.

Parameters:
Gnetworkx MultiGraph (undirected)

The graph from which to determine the principal bearing. Its coordinate reference system must be geographical, not projected.

Returns:
principal_bearing: float

The principal bearing, precise to 5 degrees.

growbikenet.functions.import_network(street_network, import_path='./')[source]

Import and project a street network from gpkg file

For all edges between a pair of nodes u and v there must be one edge with key 0.

Parameters:
street_networkstr

The street network will be loaded from this file. Must be a gpkg file in unprojected crs EPSG:4326 with layers nodes and edges, with the structure that a osmnx street network g has after saving its undirected version via ox.io.save_graph_geopackage(). For example: >>> g = ox.graph_from_place(“Barcelona”, network_type=’drive’) >>> g = nx.MultiGraph(ox.convert.to_digraph(g)) >>> ox.io.save_graph_geopackage(g, “Barcelona_streets.gpkg”)

import_pathstr, default settings.import_path

Path to import files.

Returns:
nodesgeopandas.geodataframe.GeoDataFrame

Extracted OSM nodes, projected

edgesgeopandas.geodataframe.GeoDataFrame

Extracted OSM edges, projected

g_undirnetworkx.classes.multigraph.MultiGraph

Extracted networkX graph, undirected

city_boundary_gdfgeopandas.geodataframe.GeoDataFrame

Convex hull of the street network

growbikenet.functions.node_to_edge_attributes(values_nodes, edges)[source]

Map node to edge attributes.

Creates edge attributes by taking the average values of adjacent node attributes.

Parameters:
values_nodesdict

Keys: node ids, Values: Node attributes (for example a scalar)

edgesnetworkx.classes.reportviews.EdgeView

A view of edge attributes of a networkx graph. Could also be a list of tuples of node ids.

Returns:
values_edges: dict

Keys: tuples of node ids, Values: Edge attributes

growbikenet.functions.nx_to_nodes_edges(G)[source]

Get nodes and projected edges from networkX graph

Parameters:
Gnetworkx.classes.multigraph.MultiGraph

networkX graph, undirected

Returns:
nodesgeopandas.geodataframe.GeoDataFrame

Extracted OSM nodes, projected, osmid is index

edgesgeopandas.geodataframe.GeoDataFrame

Extracted OSM edges, projected

growbikenet.functions.orientation_order(g_undir)[source]

Calculate a graph’s weighted orientation order phi, see [1]

Whether phi is weighted or unweighted does not matter much, but for the purpose of growing bike networks, weighted seems more appropriate. Note that the values here are lower than in the paper [1] for unknown reasons, also with the unweighted version.

Parameters:
g_undirnetworkx.classes.multigraph.MultiGraph

networkX street network, undirected, weighted with “length”

Returns:
phifloat

Weighted orientation order

References

[1] (1,2)
  1. Boeing, “Urban spatial order: Street network orientation, configuration, and entropy”, Applied Network Science 4, 67 (2019)

growbikenet.functions.prepare_nodes_edges(nodes, edges, crs_projected='3857')[source]

Project and prepare nodes and edges for further use

For all edges between a pair of nodes u and v there must be one edge with key 0.

Parameters:
nodesgeopandas.geodataframe.GeoDataFrame

OSM nodes, unprojected

edgesgeopandas.geodataframe.GeoDataFrame

OSM edges, unprojected

crs_projectedstr

EPSG code of the coordinate reference system that is used to project osm data.

Returns:
nodesgeopandas.geodataframe.GeoDataFrame

OSM nodes, projected, osmid is index

edgesgeopandas.geodataframe.GeoDataFrame

OSM edges, projected

growbikenet.functions.slugify(s)[source]

Slugify a string

Source: https://github.com/Chalarangelo/30-seconds-of-code/blob/master/content/snippets/python/s/slugify.md

Parameters:
sstr

String to slufigy

Returns:
sstr

Slugified string

growbikenet.functions.snap_points_to_osm_nodes(points, nodes)[source]

Snap points to osm nodes

Parameters:
points: geopandas.geodataframe.GeoDataFrame

Points that were created within city area, to be snapped to actual osm nodes

nodes: geopandas.geodataframe.GeoDataFrame

Actual osm nodes, downloaded from osmnx

Returns:
points_snapped: geopandas.geodataframe.GeoDataFrame

Points with additional information about geometries of osm nodes that nodes were snapped to

growbikenet.functions.update_with_existing_bike_network(city_query, g_undir, import_files, city_boundary_geometry=None)[source]

Update street network with existing bike network

Downloads a network of protected bike infrastructure from OSM (retaining all connected components) or imports it from a local file and merges it to a given street network graph g_undir.

Parameters:
city_querystr

Name of the city that the analysis should be performed on. Overruled (for data fetching) if city_boundary_geometry is set.

g_undirnetworkx.classes.multigraph.MultiGraph

Street network networkX graph, undirected

import_filesdict

Dictionary containing the key “bike_network” and value None or a string with the path of a bicycle network to import. Must be a gpkg file in unprojected crs EPSG:4326 with layers nodes and edges, with the structure that an undirected osmnx bike network has after saved via ox.io.save_graph_geopackage().

city_boundary_geometry(shapely Polygon | shapely MultiPolygon | None), default None

If not set to None, the study area will be selected from this geometry.

Returns:
nodesgeopandas.geodataframe.GeoDataFrame

Updated OSM nodes of the street network, projected

edgesgeopandas.geodataframe.GeoDataFrame

Updated OSM edges of the street network, projected

g_undirnetworkx.classes.multigraph.MultiGraph

Updated street networkX graph, undirected

nodes_exnwgeopandas.geodataframe.GeoDataFrame

OSM nodes of the corresponding bike network, projected

edges_exnwgeopandas.geodataframe.GeoDataFrame

OSM edges of the corresponding bike network, projected

growbikenet.settings

Global settings for growbikenet that can be configured by the user.

export_pathdict(str | Path)

Paths to results, plots, and video folders to save data, plots, and videos.

import_pathstr | Path

Path to import files (as defined in growbikenet’s import_files parameter).

crs_projectedstr, default ‘3857’

EPSG code of the coordinate reference system that is used to project osm data. Default is ‘3857’ (WGS 84 / Pseudo-Mercator). If this web mercator projection is not needed, then for Europe ‘3035’ (LAEA) and globally ‘54035’ (Equal Earth) or ‘54030’ (Robinson) is better.

export_file_formatstr (‘geojson’ | ‘gpkg’), default ‘gpkg’

File format for the data export, relevant if export_data set to True. If exporting as geojson, generates extra files for seed points and city boundary. If exporting as gkpg, these are added all in one file as extra layers.

seed_point_snap_distance‘auto’ | int, default ‘auto’

Maximum distance between raw seed points and osm nodes for snapping, in meters. Auto-value is ceil(seed_point_grid_spacing*constants._SEED_POINT_SNAP_DISTANCE_FACTOR). If integer, must be positive.

random_seedint

Random number generator seed for reproducibility

vizdict

Dictionary of visualization settings

growbikenet.visualization

Visualization functions for growbikenet.

growbikenet.visualization.create_plots(edges_ranked, seed_points_snapped, ranking, with_existing_bike_network)[source]

Plot frames of a growing bicycle network

Results are png files saved into settings.export_path[‘plots’].

Parameters:
edges_rankedgeopandas.geodataframe.GeoDataFrame

Ordered geodataframe of all edges in street network, representing a growing bicycle network

seed_points_snappedgeopandas.geodataframe.GeoDataFrame

Set of seed points snapped to the street network, representing the growing bicycle network nodes

rankingstr

Method used to rank edges.

with_existing_bike_networkbool

Boolean deciding whether the plot is with or without existing bike network.

Returns:
figslist

List of figure handles