Results and figures#

A run’s results come three ways: as tables in Python, as files on disk, and as figures. What each result means is in Outputs, and every column in Output files.

Where to look first. Two pages show a whole run at once, each one self-contained file to open in a browser: viz.summary(run) writes the summary page (the headline numbers, the travel statistics by mode, the convergence with its verdict, the computation time, and at the end a map per mode: car traffic, transit, cycling and walking), and viz.map_interactive(run, "map.html") the interactive map (pan and zoom, the time bins, a click on a link for its numbers, a pair’s routes). Every run ends by saying so; the figures below are the pieces, one by one.

A run at a glance#

Delft’s default scenario (the starter cases), its summary page and its interactive map as written by the two calls above; any run writes both into its output folder.

The top of Delft's summary page: seven headline numbers, the modes' table and when people left

viz.summary(run): the headline numbers, then the travel statistics by mode and by departure time; below them the roads, transit, parking, bikes and walking, the convergence, the computation time and the settings.#

The summary page's car traffic map: Delft's roads as ribbons, one per direction, coloured by delay

The summary page ends with a map per mode. Car traffic: one ribbon per direction, its width the volume, its colour the delay over free flow.#

The summary page's transit map: Delft's lines by kind, their width the passengers on board

Transit: the lines by kind, their width the passengers on board, the stops sized by boardings.#

The summary page's bike map: Delft's cycle network, the ribbons' width the cyclists

Bike traffic on the bike layer, the width the cyclists on each link.#

The summary page's walking map: Delft's footpaths, the ribbons' width the walkers

Walking on the walk layer, the width the walkers.#

The interactive map of Delft's run: the traffic ribbons, and a panel with zoom levels, layers, the time bins, route alternatives and the legend

viz.map_interactive(run, "map.html"): pan and zoom, the layers (roads, transit, parkings, cyclists, walkers), the colour by delay or volume, the time bins played through, the links with spillback, a pair’s route alternatives, and the view exported as PNG or SVG.#

The machine behind every time quoted. Each run time in this manual and in the tutorials was measured on one machine, a MacBook Pro with an Apple M2 Pro (8 performance and 4 efficiency cores), 32 GB of memory, macOS 26, with nothing else running; it is wall-clock time, and the same run takes a different time on another machine or another day (times are in no result and not in a run’s fingerprint).

The examples on this page are one run of Delft’s default scenario, a morning from 07:30, with the outputs it gives:

import openmobisim as ms
from openmobisim import viz

case = ms.examples.case("delft")
scenario = case.scenario("base")
run = scenario.run("delft-base")
Run 'delft-base': 8.4 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)

Tables#

kpis = run.kpis().to_pandas()                         # or .to_polars()
links = run.link_bins_table().to_pandas()             # road links by time bin
bikes = run.link_bins_table(layer="bike").to_pandas() # the bike layer
calls = run.transit_calls_table().to_pandas()
run.completion                                        # how the trips ended
run.trip_results()                                    # every trip and what became of it
run.trip_modes()                                      # the mode each trip took

A Table wraps a Parquet file and reads it on demand with pandas, polars or pyarrow (.to_pandas(), .to_polars(), .to_arrow()). The same files are in the run’s output_dir for R or any other tool.

The results held in memory as columns (run.trip_modes(), run.itinerary_choices(), run.transit_calls(), run.parking_bins(), run.convergence(), run.timings(), run.logsum_od(...), ms.parameters() and the others described “as columns”) are Columns: a dict from each column’s name to its values, so modes["mode"] reads one column, with .to_pandas(), .to_polars() and .to_arrow() for the whole table and .row_count for its length. In a notebook a Columns shows as a table.

modes = run.trip_modes().to_pandas()
modes.groupby("mode")["weight"].sum()  # people by mode
mode
bike            12368
bike_transit        6
car             35465
transit         16005
walk             2112
Name: weight, dtype: uint32

Every trip, and those that did not finish. run.trip_results() has one row per trip (also written as trip_results.parquet): who, from where to where, when, by which mode, its outcome, its arrival and travel time if it completed, and, for a car still on the roads when the window ended, the link it was on. Filter on outcome to find the trips that did not finish and where they were:

trips = run.trip_results().to_pandas()
print(trips["outcome"].value_counts().to_string())  # what became of the trips
unfinished = trips[trips["outcome"] == "truncated"]
links = run.network.link_ids()
at = unfinished["link_at_end"].dropna().astype(int)
at.map(lambda i: links[i]).value_counts().head(5)  # the links where most unfinished cars were
outcome
completed    65313
truncated      643
link_at_end
126563040:00005452     45
488347925:00003309     41
1094214299:00003560    40
126548650:00011984     32
126553730:00005284     25
Name: count, dtype: int64

kpis.parquet holds every metric by iteration and mode, in long form: one row per value. The relative gap after each loading shows the run settling towards its equilibrium:

kpis = run.kpis().to_pandas()
gap = kpis[(kpis["metric"] == "gap") & (kpis["mode"] == "all")]
gap[["iteration", "value"]]  # the relative gap after each loading
     iteration     value
5            0  0.082118
26           1  0.134100
48           2  0.081047
70           3  0.098288
92           4  0.065102
114          5  0.061543
136          6  0.055383

A run read back from its folder#

run = ms.Run.open("runs/delft-base")        # a finished run's output_dir
run.completion, run.mean_travel_time_s, run.convergence_verdict

Run.open reads what the files hold: the run’s identity and settings (manifest.json), the completion by mode, the mean trip, the convergence with its verdict (kpis.parquet), every trip’s result (trip_results.parquet), the timings and every table, the same as the run gave when it ended. What only the run in memory holds (the network, the route sets and choices, the itinerary choices) is refused with a message saying so: run the scenario again for those.

Labels for a study#

scenario.run(..., design_id="tracks", replication=2) writes both into every row of kpis.parquet, so the results of many runs stack into one table. They are labels: the fingerprint does not change with them.

Many runs: the minimal outputs#

A study of thousands of runs (random disruptions, a design space) needs a few numbers from each, not their link tables. outputs="minimal" writes two small text files per run, kpis.csv (the rows of kpis.parquet) and manifest.json (every setting), a few kilobytes in all; nothing else, and no page or figure:

import random
from pathlib import Path

import pandas as pd

base = ms.examples.case("delft").scenario("base")
links = base.parts["network"].link_ids()
rng = random.Random(1)
for k in range(2000):
    closed = rng.sample(links, 3)
    base.replace(
        disruptions=[{"links": closed, "capacity_factor": 0.0, "from_s": 7.5 * 3600, "to_s": 9.5 * 3600}]
    ).run(f"disruption-{k:04d}", output_dir=f"runs/disruption-{k:04d}", outputs="minimal", quiet=True,
          design_id="closed:" + ";".join(closed))

kpis = pd.concat(
    pd.read_csv(f, float_precision="round_trip") for f in sorted(Path("runs").glob("disruption-*/kpis.csv"))
)

Name the runs so their folders sort (disruption-0001, …), and put what distinguishes them in design_id: every row of kpis.csv carries it. The run’s results in memory, its fingerprint and ms.Run.open(folder) are the same as with the default outputs="all"; the files left out (events, diagnostics, the link bins, transit_calls, parking_bins, timings.csv) are refused by name if asked for.

Figures#

The figures need pip install "openmobisim[viz]":

Function

Draws

viz.map_link(run, …)

The run’s traffic on its network, one ribbon per direction, coloured by delay or volume, for a time bin or a period; layer="bike" for the bike layer

viz.map_demand(…)

The demand as origin–destination desire lines

viz.map_route(…)

The alternative routes of one origin–destination pair

viz.map_transit(run)

Transit lines by kind, their width the passengers on board

viz.map_parking(run)

Car parks and bike parkings, sized by their use

viz.chart_demand_matrix(…)

The origin–destination matrix as a heat map

viz.chart_mode_share(run)

Each mode’s share of the trips, by departure time

viz.summary(run)

One self-contained page: headline numbers, travel statistics by mode, convergence, the computation time with the networks’ sizes, and a map per mode at the end (cars, transit, bikes, walking, each when the run has its results); summary.html in the run’s folder unless a path is given; returns the path

viz.map_interactive(run)

One interactive HTML file: the traffic by time bin, the routes, transit, with exports; map.html in the run’s folder unless a path is given

from openmobisim import viz

viz.map_link(run)                                # the busiest period; bins= picks another
viz.summary(run)                                 # <run folder>/summary.html; a path= puts it elsewhere
viz.map_interactive(run)                         # <run folder>/map.html

Every figure carries the run’s fingerprint in its footer, so it can be traced to the run that made it. Sizes are in centimetres. Each takes theme="paper" (the default) or "night", a size_cm, and a path to save it to, as PNG, PDF or SVG by the extension.

The traffic#

map_link draws the busiest part of the run unless bins names a time bin, a pair of them or two clock times. On the road, the colour is the delay over free flow by default; colour="volume" or "volume_capacity" colour by the flow instead.

viz.map_link(run)
Delft's roads in the morning, each direction of a link drawn as a ribbon coloured by its delay

On the bike layer the colour is the flow, as there is no capacity to compare it with:

viz.map_link(run, layer="bike", bins=("08:00", "08:30"))
Delft's bike layer from 08:00 to 08:30, each ribbon's width the cyclists passing

Modes, transit and parkings#

viz.chart_mode_share(run)
The share of the trips each mode took, by departure time
viz.map_transit(run)
Delft's transit lines by kind, each line's width the passengers on board
viz.map_parking(run)
Delft's car parks and bike parkings, sized by their use

The demand and the routes#

map_demand and chart_demand_matrix take the trips, before or without a run; cell_m sets the size of the cells the trips are gathered into, and top how many pairs are drawn.

trips = scenario.parts["demand"]
viz.map_demand(trips, network=run.network)
The morning's trips as desire lines between 1 km cells, the busiest drawn widest
viz.chart_demand_matrix(trips)
The morning's origin-destination matrix between 1 km cells, as a heat map

map_route draws one pair’s routes from the run’s route sets, side by side where they share a street; pair is the pair’s position among the sets, or two points.

import numpy as np

routes = run.route_sets()
counts = np.diff(routes.set_offsets())  # the routes of each pair
pair = int(np.flatnonzero(counts >= 3)[0])  # the first pair with three or more
viz.map_route(routes, run.network, pair)
The alternative routes of one origin-destination pair, drawn side by side on the network

Notebook 05 · Results and figures draws each of them on a starter case.

For bikes#

viz.map_link(run, layer="bike") maps cycling flows, and link_bins_table(layer="bike") gives them as a table. Bike parkings appear in viz.map_parking, and bike shares in viz.chart_mode_share.