Transport registry¶
Transport registries define public-transport mode parameters used to estimate edge travel time.
To use different speeds for an OSM route service, give its specification a <mode>:<service> key. DEFAULT_REGISTRY_W_TRAIN includes train:high_speed, which applies to train relations tagged service=high_speed. Select train when building the graph. Other train services fall back to the base train specification, which also supplies the boarding wait for every train route. Use list_types() to see all keys, list_modes() to see the selectable modes, and add(), update() or remove() to customize variants.
# To install IduEdu in a clean environment:
# !pip install IduEdu
OSM_ID = 1114252
from iduedu import DEFAULT_REGISTRY, DEFAULT_REGISTRY_W_TRAIN
print(DEFAULT_REGISTRY.list_types())
print(DEFAULT_REGISTRY_W_TRAIN.list_types())
['bus', 'trolleybus', 'tram', 'subway', 'monorail', 'taxi']
['bus', 'trolleybus', 'tram', 'subway', 'monorail', 'taxi', 'train', 'train:high_speed']
Inspect a transport specification¶
Each TransportSpec stores the speed, acceleration, braking, dwell and waiting-time parameters of a mode or service variant.
bus = DEFAULT_REGISTRY.get("bus")
print(bus)
print("Travel time for 800 m:", round(bus.travel_time_min(800), 2), "min")
TransportSpec(name='bus', vmax_tech_kmh=90, accel_dist_m=25.9, brake_dist_m=24.1, base_speed_kmh=29.5, avg_wait_time_min=12.24, dwell_min=0.387, long_speed_kmh=None, speed_half_length_m=None)
Travel time for 800 m: 2.12 min
Free speed growing with segment length¶
Tram and train also set long_speed_kmh and speed_half_length_m: their free speed grows with the distance between stops, from base_speed_kmh towards long_speed_kmh, and is halfway there at speed_half_length_m. Long stretches between stops run on tracks built for speed, which one free speed cannot express. Bus, trolleybus and subway keep one free speed for every segment.
tram = DEFAULT_REGISTRY.get("tram")
print(f"base {tram.base_speed_kmh} km/h -> long {tram.long_speed_kmh} km/h, halfway at {tram.speed_half_length_m} m")
for length in (300, 800, 2000, 5000):
print(
f"{length:>5} m: free speed {tram.free_speed_kmh(length):5.1f} km/h, "
f"travel time {tram.travel_time_min(length):5.2f} min"
)
base 11.5 km/h -> long 74.1 km/h, halfway at 3506.0 m
300 m: free speed 16.4 km/h, travel time 1.46 min
800 m: free speed 23.1 km/h, travel time 2.33 min
2000 m: free speed 34.2 km/h, travel time 3.68 min
5000 m: free speed 48.3 km/h, travel time 6.34 min
Create a custom registry¶
Use a custom registry when you need project-specific speed assumptions or additional transport modes.
from iduedu import TransportRegistry, TransportSpec
registry = TransportRegistry()
registry.add(
TransportSpec(
name="bus",
vmax_tech_kmh=80,
accel_dist_m=220,
brake_dist_m=160,
base_speed_kmh=34.0,
)
)
registry.add(
TransportSpec(
name="tram",
vmax_tech_kmh=70,
accel_dist_m=180,
brake_dist_m=140,
base_speed_kmh=40.0,
)
)
registry.list_types()
['bus', 'tram']
Update, ensure, and remove specs¶
Names are normalized internally. ensure creates a missing mode from defaults when needed.
registry.update("bus", base_speed_kmh=32.0)
registry.update("bus", long_speed_kmh=40.0, speed_half_length_m=5000.0) # faster on long stretches
registry.ensure("ferry")
registry.remove("ferry")
registry.get("bus")
TransportSpec(name='bus', vmax_tech_kmh=80, accel_dist_m=220, brake_dist_m=160, base_speed_kmh=32.0, avg_wait_time_min=1.0, dwell_min=0.0, long_speed_kmh=40.0, speed_half_length_m=5000.0)
Use a registry in graph construction¶
Pass the registry to public-transport builders through transport_registry.
from iduedu import get_public_transport_graph
G_pt_custom = get_public_transport_graph(
osm_id=OSM_ID,
transport_types=["bus", "tram"],
transport_registry=registry,
clip_by_territory=True,
)
G_pt_custom
UrbanGraph(nodes=935, edges=2056, is_multigraph=True, is_directed=True, edge_direction_column='oneway', crs='EPSG:32636', type='public_transport')