Transit, parking, park-and-ride and bike-and-ride#
This guide adds public transport and parkings to a scenario, and changes the service for a study. How journeys, parkings and the station choice work is explained in Transit, Parking and Modes.
Give the scenario a timetable and parkings#
transit = ms.transit_read_gtfs("gtfs.zip", network, date="2026-10-09")
parkings = ms.parking_read_osm("city.osm.pbf", region=region) # or ms.parking_read_table("parkings.csv")
scenario = ms.Scenario.from_parts(network, trips, classes=classes, transit=transit, parkings=parkings)
With these, a trip can:
take transit: walk to a stop, ride (with transfers) and walk on;
park and ride: drive to a car park, then continue by transit;
bike and ride: cycle to a bike parking, then continue by transit.
A trip may state one of these modes (transit, car_transit, bike_transit), or choose among them when its class
allows. For park-and-ride and bike-and-ride, the station is chosen by the choice model among candidate parkings, not
fixed in advance.
Buses ride the roads. Buses are loaded among the cars, take their delays, and their realised times replace the
schedule’s. Trams, metros, trains and ferries keep to the timetable. Results are in transit_calls.parquet and
openmobisim.Run.transit_summary.
Change the service#
openmobisim.transit_edit() makes a scenario’s timetable from the original. The original is left as it was,
and stops and lines keep their ids:
more_frequent = ms.transit_edit(transit, headway={"T1": (300, 7 * 3600, 9 * 3600)}) # every 5 min, 07:00–09:00
without = ms.transit_edit(transit, cancel=["B1"]) # line out of service
A new headway applies to each of the line’s stop patterns that runs in the window; it makes a line more or less
frequent, but adds no new route. transit.lines() lists the lines with their first and last departures.
Feeds that describe service by frequency (frequencies.txt) are read as runs at those frequencies.
Hub groups in the results#
transit_calls and parking_bins (the files and the tables) carry a hub_group: a stop’s station (GTFS
parent_station), or the stop itself; a parking takes the group of the nearest stop within hub_group_m (an
argument of Scenario.run, 150 m in a straight line), unless its table named a hub, which it keeps. A station’s
platforms, its bike racks and its car park then add up under one name:
calls = run.transit_calls().to_pandas()
racks = run.parking_bins().to_pandas()
boardings = calls.groupby("hub_group")["boardings"].sum()
parked = racks[racks.vehicle == "bike"].groupby("hub_group")["arrivals"].sum()
A label of the outputs only: the model’s own hubs (each parking with the stops its travellers reach on foot) are not changed by it, and neither is any result. In Amsterdam, 547 of the 922 parkings join a station’s group, nearly all of them bike parkings.
The options that matter most#
Option |
Default |
What it limits |
|---|---|---|
|
1800 s |
The walk to and from a stop |
|
see Parameters |
The longest journey offered |
|
300 s |
A walk between two stops to transfer |
|
300 s |
The walk from a parking to its stop |
|
see Parameters |
The shortest trip offered park-and-ride or bike-and-ride |
A trip none of whose modes reaches its destination within these limits has no alternative, and is reported (see Modes).
A worked example on Delft#
Delft’s starter case carries its timetable and parkings, and its default scenario uses them:
import openmobisim as ms
import pandas as pd
case = ms.examples.case("delft")
base = case.scenario("base") # the network, the trips, the classes, the timetable and the parkings
transit = base.parts["transit"]
print(transit)
print(base.parts["parkings"])
pd.DataFrame(transit.lines()).sort_values("runs", ascending=False).head(5)
Transit(2026-10-09: 869 runs, 255 stops, 24 lines)
Parkings(2 car, 190 bike)
route_id name kind runs first_s last_s
2 154684 1 tram 74 20190 45227
22 162522 77 bus 70 21832 44318
15 154802 455 bus 61 20700 43860
4 154701 22 bus 50 21025 46764
12 154797 30 bus 48 20940 44940
The mode each person took, in the default morning:
def shares(run):
"""The share of the people taking each mode, in percent."""
modes = run.trip_modes().to_pandas()
return (modes.groupby("mode")["weight"].sum() / modes["weight"].sum() * 100).round(2)
before = base.run("delft-base")
calls = before.transit_calls().to_pandas()
busiest = calls.groupby("line")["boardings"].sum().idxmax() # the line with the most boardings
print("busiest line:", busiest)
shares(before)
Run 'delft-base': 8.2 s, window 07:30–09:30, 65,313 of 65,956 trips completed, mean trip 23.7 min, verdict good (run.timings() has every stage)
busiest line: 1
mode
bike 18.75
bike_transit 0.01
car 53.77
transit 24.27
walk 3.20
Name: weight, dtype: float64
The busiest line every five minutes through the morning peak, the rest unchanged:
# The busiest line every 5 minutes from 07:00 to 09:00.
frequent = base.replace(transit=ms.transit_edit(transit, headway={busiest: (300, 7 * 3600, 9 * 3600)}))
after = frequent.run("delft-frequent")
pd.DataFrame({"base": shares(before), "every 5 minutes": shares(after)}).fillna(0.0)
Run 'delft-frequent': 9.0 s, window 07:30–09:30, 65,229 of 65,956 trips completed, mean trip 23.4 min, verdict good (run.timings() has every stage)
base every 5 minutes
mode
bike 18.75 18.75
bike_transit 0.01 0.01
car 53.77 53.77
transit 24.27 24.37
walk 3.20 3.11
The boardings by hub group, each named by one of its stops. The groups are the feed’s own stations: where the feed gives a station’s platforms and its bus stops different stations, they stay apart, as Delft’s railway station and the stops beside it do here.
# Boardings by hub group: a station's platforms add up under one name.
calls = after.transit_calls().to_pandas()
names = pd.DataFrame(transit.stops()).set_index("stop_id")["name"]
calls["stop"] = calls["stop_id"].map(names)
by_hub = calls.groupby("hub_group").agg(name=("stop", "first"), boardings=("boardings", "sum"))
by_hub.sort_values("boardings", ascending=False).head(5)
name boardings
hub_group
stoparea:502863 Delft, Station Delft 4071.0
stoparea:624394 Rijswijk, Verffabriek 2922.0
stoparea:624445 Delft, Delft Station 2427.0
stoparea:18316 Delft 863.0
stoparea:343749 Delft Campus 845.0
For bikes#
Bike-and-ride needs bike_transit among the class’s modes, an owned bike, and bike parkings near stops. Its
candidates are the bike parkings within the bike’s reach (parking_options["reach_bike_s"]). See
Cycling.