Developer reference

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

fixbikenet.fixbikenet

fixbikenet.fixbikenet.fixbikenet(city_query, radius=2500, mingap=20, maxgap=800, numgaps=50, export_data=True, city_id=None, export_plot=False, import_files={})[source]

Finds gaps in bicycle networks and returns the numgaps that are the most important to fill.

Parameters:
city_querystr

name of the city that the analysis should be performed on

radiusint, default 2500

cut-off length for computation of local betweenness centrality, in meters

mingapint, default 20

minimum distance between node pairs to be considered as a potential gap, in meters

maxgapint, default 800

maximum distance between node pairs to be considered as a potential gap, in meters

numgapsint, default 50

Number of gaps to find.

export_databool, optional, default True

If set to True, data will be saved to a file. The filename is [slug].gpkg, where slug is a string id made out of city_name

city_idstr | None, default None

If set, the slugified city_id is used in the filename of the data export. For example, a city_id “Athens” will slugify into “athens” in filenames. If set to None, the slugified city_query is used in 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_plotbool, optional, default False

If set to True, plot will be saved to a file

import_files: dict, default {}

The following key:value entries can be set:

  • ‘city_boundary’None or str, 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.

  • ‘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: >>> ox.settings.useful_tags_way = [“highway”, “cycleway”, “cycleway:right”, “cycleway:left”, “cycleway:both”, “cyclestreet”] >>> g = ox.graph_from_place(“Barcelona”, network_type=’all’, simplify=False) >>> g = nx.MultiGraph(ox.convert.to_digraph(g)) >>> ox.io.save_graph_geopackage(g, “Barcelona_streets.gpkg”).

Returns:
gaps_orderedgeopandas.geodataframe.GeoDataFrame

ordered geodataframe with the numgaps most important gaps to fill

References

[1] Vybornova, A., Cunha, T., Gühnemann, A. and Szell, M. (2023), Automated Detection of Missing Links in Bicycle Networks. Geogr Anal, 55: 239-267. https://doi.org/10.1111/gean.12324

fixbikenet.functions

Utility functions for fixbikenet.

Print footer.

fixbikenet.functions._print_header(city_query)[source]

Print header.

fixbikenet.functions._reset_auto_settings(setting_was_auto)[source]

Reset settings and constants to auto.

fixbikenet.functions._resolve_crs_calculations(gdf)[source]

Resolve constants._CRS_CALCULATIONS = ‘auto’

Parameters:
gdfgeopandas.geodataframe.GeoDataFrame

A geodataframe from which to estimate the UTM CRS

fixbikenet.functions._validate_parameters(city_query, radius, mingap, maxgap, export_data, import_files)[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:
import_filesdefaultdict

Defaultdict of file names to import.

fixbikenet.functions._validate_settings()[source]

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

Returns:
setting_was_autodict

Dictionary remembering which setting or constant was set to auto, so it can be reset to auto in the end.

fixbikenet.functions.bike_infra_mapping_gdf(g, edges_gdf)[source]

add binary edge attribute pbi to edges_gdf

Parameters:
gnetworkx.MultiDiGraph

simplified graph representing the street network, with added binary edge attribute “pbi”

edges_gdf: geopandas.GeoDataFrame

edges representing the street network

Returns:
edges_gdf: geopandas.GeoDataFrame

edges representing the street network with added binary attribute “pbi”

fixbikenet.functions.compute_benefit_metric(comp, node_path, ebc)[source]

computes Benefit metric B for edge in connected component of edges.

Parameters:
compnetworkx.Graph

connected component of edges

node_pathlist

list of nodes on path

ebc: dict

local betweenness centrality values for all edges in network

Returns:
B: float

Benefit metric B for edge

fixbikenet.functions.compute_local_betweenness_centrality(G, nodes_gdf, radius)[source]

computes weighted betweenness centrality for paths within radius

Parameters:
G: networkx.Graph

undirected simple graph representing the street network with weighted edges

nodes_gdf: geopandas.GeoDataFrame

all nodes in street network

radius: int

maximum length of path for betweennessn centrality calculation, set by user

Returns:
ebc: dict

local betweenness centrality values for all edges in network

fixbikenet.functions.create_gdf_with_geoms(df, edges)[source]
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

fixbikenet.functions.find_actual_gaps(G, potential_gaps, mingap)[source]

determines which potential gaps are actual gaps by finding paths between all contact nodes and only keeping the gaps that have no protected bike infrastructure

Parameters:
G: networkx.Graph

undirected simple graph representing the street network with weighted edges

potential_gaps: list

all unique potential gaps in protected bicycle network

Returns:
found_gaps: list

list of all gaps in protected bicycle network

found_gaps_nsp: list

list of paths in network for all gaps in protected bicycle network

fixbikenet.functions.find_contact_nodes(G)[source]

find nodes that have both edges with protected and without protected bike infrastructure incident on them

Parameters:
G:networkx.Graph

undirected simple graph representing the street network with weighted edges

fixbikenet.functions.find_edges_to_drop(g)[source]

find parallel edges that have different pbi values, list the ones with pbi=0

Parameters:
gnetworkx.MultiDiGraph

simplified graph representing the street network, with added binary edge attribute “pbi”

Returns:
edges_to_drop: list

unique list of edges to drop-> edges where pbi values differ and pbi value=0 gets dropped

fixbikenet.functions.find_potential_gaps(contact_nodes, nodes_gdf, maxgap)[source]

finds potential gaps in protected bicycle network, corresponding to two contact nodes that are within maxgap euclidean distance of each other

Parameters:
contact_nodeslist

list of all nodes that fulfill criteria to be a contact node

nodes_gdfgeopandas.GeoDataFrame

all nodes in street network

maxgapint

user defined maximal euclidean distance between two contact nodes

Returns:
potential_gapslist

all unique potential gaps in protected bicycle network

fixbikenet.functions.gap_declustering(gaps_df, G, ebc, contact_nodes)[source]
Parameters:
gaps_dfpd.DataFrame

Dataframe containing gaps in protected bicycle network

Gnetworkx.Graph

undirected simple graph representing the street network with weighted edges

ebc: dict

local betweenness centrality values for all edges in network

contact_nodeslist
Returns:
result: pd.DataFrame

Dataframe with node path for gaps and the newly calculated benefit metric

fixbikenet.functions.get_correct_edgetuples(edge_gdf, nodelist)[source]

helper function that maps a node list (output of nx.shortest_paths) to the correct set of edge tuples that can be used for INDEXING THE EDGE GDF

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 GDF

fixbikenet.functions.graph_edges_to_gdf(G)[source]
Parameters:
G: networkx.Graph

undirected simple graph representing the street network with weighted edges

Returns:
edges_gdf: geopandas.GeoDataFrame

geodataframe with edges from G, including edge attributes

fixbikenet.functions.graph_nodes_to_gdf(G)[source]
Parameters:
G: networkx.Graph

undirected simple graph representing the street network with weighted edges

Returns:
nodes_gdf: geopandas.GeoDataFrame

geodataframe with nodes from G

fixbikenet.functions.import_network(street_network)[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=’all’) >>> 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

fixbikenet.functions.initialize_progress_bar(desc_string, total=1, unit='step')[source]

Initialize tqdm progress bar.

fixbikenet.functions.map_edges_to_bike_infrastructure(g)[source]

map if edges in graph have bike infrastructure as specified in config.py

Parameters:
g :networkx.MultiDiGraph

simplified graph representing the street network

Returns:
gnetworkx.MultiDiGraph

simplified graph representing the street network, with added binary edge attribute “pbi”

fixbikenet.functions.rank_gaps_by_b(found_gaps_nsp, G, ebc)[source]

calculates b for all gaps

Parameters:
found_gaps_nsp: list

list of paths in network for all gaps in protected bicycle network

G: networkx.Graph

undirected simple graph representing the street network with weighted edges

ebc: dict

local betweenness centrality values for all edges in network

Returns:
Bs: list

list of values of b for all gaps in protected bicycle network

fixbikenet.functions.slugify(s)[source]

Slugify a string

Source: https://github.com/Chalarangelo/30-seconds-of-code/blob/master/content/snippets/python/s/slugify.md Note: A clean global solution would be using unidecode, but we do not want extra dependencies for this. We assume European city names in latin alphabet, some special letters like Hungarian long ö already mapped.

Parameters:
sstr

String to slufigy

Returns:
sstr

Slugified string

fixbikenet.functions.weigh_edges(G)[source]

adds weight parameter to all edges in G, which is calculated by multiplying the length of the edge with the corresponding penalty value

Parameters:
G: networkx.Graph

undirected simple graph representing the street network

Returns:
G: networkx.Graph

undirected simple graph representing the street network with weighted edges