Build a case from OpenStreetMap and GTFS#

This guide builds a complete multimodal case for a city from open data, and runs it:

  • the street network from an OpenStreetMap extract;

  • public transport from a GTFS feed;

  • parkings from the same extract;

  • a morning’s trips from an origin–destination matrix.

The example is Delft, in the Netherlands, with the files of the starter data bundle. The same steps work for any city you have an extract and a feed for. The figure shows the way the data takes: each file is read into an object, a Scenario combines them with the settings, and a run turns them into results.

The data flow: input files are read into four objects, a Scenario combines them with the settings, and a run turns them into a Run object and output files The data flow: input files are read into four objects, a Scenario combines them with the settings, and a run turns them into a Run object and output files

1. The network#

import openmobisim as ms

region = (4.315, 51.965, 4.41, 52.035)  # west, south, east, north, in degrees
network = ms.network_read_osm("network.osm.pbf", region=region)
print(network)  # Network(21663 nodes, 46951 links, with street geometry)

region cuts the study area out of a larger extract, as a box or as a polygon (a list of (longitude, latitude) points). The network you get holds:

  • the roads, with each link’s traffic parameters derived from its OpenStreetMap tags;

  • a walk layer and a bike layer over the same streets (network.layer("walk"), network.layer("bike")), with cycleways, cycle lanes and one-way streets open to bikes as the tags say.

Check the network before you run it:

report = ms.network_check(network)
report["verdict"]  # "pass", "warn" or "fail"
[c for c in report["checks"] if c["status"] != "pass"]

Each check names its layer, what it tests, its status, the value found and the rule it applies. For Delft the verdict is warn, with one finding: 2.1 % of the road links run parallel to another between the same two nodes. This is worth a look on the map, but it does not stop a run. A fail, such as a road network in several pieces that cannot reach one another, means some car trips will find no route. How the network is built, and every option that shapes it (network_options), is in Networks.

2. Public transport#

transit = ms.transit_read_gtfs("gtfs.zip", network, date="2026-10-09")
print(transit)  # Transit(2026-10-09: 869 runs, 255 stops, 24 lines)

A feed covers many days; a run uses one service day, date (without it, the feed’s busiest weekday). Given the network, the reader keeps only the stops a pedestrian can reach on its walk layer (within 300 m of its nearest node), and every run keeps its calls at them. The buses among them will ride the roads with the cars; trams, metros, trains and ferries keep to their timetable. See Transit.

3. Parkings#

parkings = ms.parking_read_osm("network.osm.pbf", region=region)
print(parkings)  # Parkings(2 car, 190 bike)

These are the car and bike parkings that park-and-ride and bike-and-ride trips can use. From OpenStreetMap, openmobisim keeps the car parks tagged or named as park-and-ride and every public bike parking. A capacity comes from the capacity tag, else from the parking’s area, else a default; parkings of one kind closer than 100 m are merged into one site. A table of your own works too, read with openmobisim.parking_read_table(). See Parking.

4. The demand#

A morning’s trips are drawn from an origin–destination matrix between zones. Each traveller is given a class, which says the modes they may use, what they own and how they weigh time and money:

zones = ms.demand_read_zones("demand/zones.csv")      # 65 zones, each a point
od = ms.demand_read_od("demand/od.csv")               # 5093 rows: origin_zone, destination_zone, trips, …
classes = ms.demand_read_classes("demand/classes.csv")

trips = ms.demand_from_od(
    od, zones,
    start_s=7.5 * 3600, end_s=8.5 * 3600, profile="am_peak",  # departures 07:30–08:30, peaked
    spread_m=500.0,             # trips start and end up to 500 m around their zone's point
    user_class="drawn",         # the class of rows that do not name one
    seed=0,
)

Some rows of Delft’s matrix name their own class and mode: through traffic entering at the edge of the study area, and goods vehicles. Draw classes only for the other trips, so those keep theirs:

drawn = ms.demand_assign_classes([t for t in trips if t[7] == "drawn"], classes, seed=0)
given = iter(drawn)
trips = [next(given) if t[7] == "drawn" else t for t in trips]

t[7] is the trip’s class. A trip is a row of (traveller_id, trip_seq, origin_lon, origin_lat, destination_lon, destination_lat, departure_time_s, user_class, weight, mode), trip_seq being the trip’s place in the traveller’s day and departure_time_s seconds after midnight; see Input files. openmobisim.demand_assign_classes() gives each traveller a class by the classes’ shares: who gets which class is random, but how many people each class gets is met to within one traveller.

For a faster run, simulate one traveller for every few people:

trips = ms.demand_sample(trips, weight=4, seed=0)   # 106 596 trips → 26 651, each standing for 4 people

Each kept traveller then stands for four people, and travels as a group of four on the real network. Totals in the results stay those of the whole demand. See Running faster.

5. The scenario and the run#

scenario = ms.Scenario.from_parts(
    network, trips,
    classes=classes, transit=transit, parkings=parkings,
    window=("07:30", "09:30"),   # the simulation window
    link_bin_s=900,              # per-link results in 15-minute bins
)
run = scenario.run("delft", output_dir="runs/delft")

Because the classes say which modes their travellers may use, every trip without a stated mode chooses its mode among walking, cycling, driving, transit, park-and-ride and bike-and-ride, as its class allows. The run iterates towards an equilibrium (msa) and stops when it has converged:

run.fingerprint          # '1108c37f732cbe5d': what was run, see Reproducibility
run.converged            # True
run.convergence_gap      # 0.034
run.completion           # trips completed, unfinished at the window's end, without a route, …

The run writes its files into runs/delft:

  • kpis.parquet and link_bins.parquet;

  • link_bins_bike.parquet and link_bins_walk.parquet, for the cycling and walking layers;

  • transit_calls.parquet and parking_bins.parquet;

  • events.parquet and diagnostics.parquet;

  • manifest.json and timings.csv.

Each file is described in Output files, and the figures in Results and figures.

What to watch#

  • Trips outside the window are left out, with a warning. A trip departing before the window’s start or after its end is not simulated. Each run warns how many trips and people that is and what to change; see The simulation window.

  • Trips with no alternative are reported. The warning says how many, and between which places most of them are. See When something goes wrong.

For bikes#

The bike layer comes with the network: cycleways, cycle lanes and contraflow cycling are read from the tags, and each bike link carries its facility (separated, lane or mixed), which the choice model can weigh. network_check reports the bike layer’s length and its share of separated cycleways and cycle lanes. A class that may cycle needs bike among its modes (and owns a bike); bike-and-ride needs bike parkings near stops, which parking_read_osm reads.