Convert GTFS feeds to realistic, routable NetworkX graph.
Project description
gtfs2nx
Create routable NetworkX graph with realistic transfer times from GTFS feeds. 🚌 🚆 🚡
How
- Cleaning & preprocessing
- Remove trips with unrealistic travel times and speeds
- Fix trips contradictory stop sequences and departure times
- Enable routability
- Ensure each node belongs only to single route
- Calculate average segment travel times
- Calculate average stop headway and service frequency
- Add edges for walking transfer between routes with realistic transfer time (walking time + headway / 2)
Install
pip install gtfs2nx
Usage
import gtfs2nx as gx
G = gx.transit_graph('path/to/GTFS-feed.zip')
Customize transit network:
G = gx.transit_graph(
gtfs_paths='path/to/GTFS-feed.zip',
time_window=('06:00', '08:00'),
route_types=[700], # only buses
walk_transfer_max_distance=400, # allow transfers with long walking distance
)
See the API docs for more details and the getting-started notebook for a small demo.
Exemplary NetworkX analysis
import networkx as nx
# access precomputed stop characteristics
frequency = nx.get_node_attributes(G, 'frequency')
# routing
route = nx.shortest_path(G, from_stop, to_stop, weight='weight')
# travel time to other stops
travel_times = nx.single_source_dijkstra_path_length(G, source=from_stop, weight='weight')
# centrality analysis
centrality = nx.closeness_centrality(G, distance='weight')
Further use cases
- Using graph neural networks to classify missing GTFS route types
- Validating NetworkX transit graph: Comparing routes and travel times to Google Maps
Development
Build from source using poetry:
poetry build
pip install dist/gtfs2nx-*.whl
Configure post-checkout hook for branch specific .gitignore files:
git config --local core.hooksPath .githooks/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gtfs2nx-0.2.1.tar.gz.
File metadata
- Download URL: gtfs2nx-0.2.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.4 Darwin/22.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e159fe6454170afd5474affbfde6a851f04f6cb3eb86641932dbb7820d98a058
|
|
| MD5 |
501760783d5baa453282c37a630b4f13
|
|
| BLAKE2b-256 |
9e78304810a6a68c4ef635f1dbbb108651098758e4160f97541936941701135d
|
File details
Details for the file gtfs2nx-0.2.1-py3-none-any.whl.
File metadata
- Download URL: gtfs2nx-0.2.1-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.4 Darwin/22.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fb002d7e4577ada8c66ae29c9ddfe984a9dfa6653f6320d059f5e80db8745b1
|
|
| MD5 |
0a7b48f6628126cf9b8c44408fc7d105
|
|
| BLAKE2b-256 |
746812f98d2bdf51409255705b1b4e5836c33150a9c00c26be7b5940c4f0a56b
|