openmobisim.examples#

Built-in fixtures for getting started without any input data.

toy_network is a small network whose every loading number can be checked by hand. manhattan_grid is a square grid of two-way streets, optionally signalised. fixed_car_trips is deliberately thin: “car, fixed departure time, from here to there” is not a different demand format from the general one — it is what the same trips schema already expresses when classes give its class a car and nothing else. This helper only saves writing out the ten-column table by hand; it does not introduce a second demand shape. traveller_classes is an example class table: four classes by what people own, each with the modes its vehicles allow, weighing alike. case gives a starter case: Delft, Amsterdam, Paris, Lyon, Sioux Falls or Nguyen–Dupuis, its files fetched once and checked, read in one call each.

Attributes#

Classes#

Case

One starter case, its files checked: see openmobisim.examples.case().

Functions#

case(name[, root, check])

A starter case: its files found or fetched, checked, ready to read.

case_check([names, root, quiet])

Run starter cases' default scenarios and compare them with the reference results.

case_names()

The starter cases this version of the package knows.

case_summary(run)

What a starter case's run is compared on: its fingerprint, trips, mean trip and modes.

fixed_car_trips(network, trips[, user_class])

Build a trips table for car-only demand at a fixed departure time.

traveller_classes()

Four example traveller classes by what people own, as demand_read_classes gives them.

trips_random(network, count, *[, seed, spread_s, ...])

A seeded load fixture: count trips between random places on network.

Module Contents#

class openmobisim.examples.Case(name, folder)#

One starter case, its files checked: see openmobisim.examples.case().

Parameters:
  • name (str)

  • folder (pathlib.Path)

classes()#

The traveller classes, with their shares.

Return type:

dict[str, dict]

demand(multiple=1.0, seed=0, weight=None, departures=None, one_point_per_zone=False)#

The trips: the OD matrix times multiple, each traveller given a class by share.

A row of the matrix that names its user_class (and its mode: trips from outside the study area, goods vehicles) keeps it; the others’ travellers are drawn a class by the classes’ shares. A zone with a spread_m in zones.csv spreads its trips that far (0 at a gateway, a road where the area’s edge cuts it); a case with a zone_points table draws its trip ends among each zone’s points by weight. With a weight in the case’s demand, each simulated traveller stands for that many people: the matrix is divided by it and every trip carries it, so the run’s totals are the whole demand’s and its time a sample’s (demand_sample): the fast run, a small aggregation (each traveller a platoon of that many cars, each counted at full size on the network’s real capacities), not a rescaled network. weight here overrides it: 1 is the complete run, one simulated traveller per person (the slowest).

departures: keep only the trips departing in (start, end) (clock times or seconds after midnight; start included, end not), at their own times, the rest left out; the case’s own departures (case.json) by default; "all" keeps every trip of the matrix (the bundle’s demand stays whole, the selection is made here).

one_point_per_zone: every trip end at its zone’s own point instead of the zone’s points or its spread (demand_from_od’s points_per_zone=1; a gateway is one point already), so the trips of one zone pair share their two points and their routes: the demand aggregated over space, for a gap read per zone pair and departure bin (Run.gap_pairs). The departures stay as drawn.

Parameters:
  • multiple (float)

  • seed (int)

  • weight (int | None)

  • departures (tuple[str | float, str | float] | str | None)

  • one_point_per_zone (bool)

Return type:

list[tuple]

network()#

The road network, with its bike and walk layers.

Imported from the case’s files the first time it is opened, and from then on read from a cache of the built network (~/.cache/openmobisim/networks/<case>/): the same network, bit for bit, in a fraction of the import’s time. OPENMOBISIM_NO_NETWORK_CACHE=1 imports it every time.

Return type:

openmobisim._core.Network

parkings()#

The parkings of the study area, from OpenStreetMap.

Read from the case’s extract the first time they are asked for, and from then on from a cache of the parkings read (~/.cache/openmobisim/parkings/<case>/): the same parkings, bit for bit, in a fraction of the time. OPENMOBISIM_NO_NETWORK_CACHE=1 reads them from the extract every time.

Return type:

openmobisim._core.Parkings | None

path(relative)#

A file of the case.

Parameters:

relative (str)

Return type:

pathlib.Path

scenario(scenario='base', seed=0, weight=None, departures=None, one_point_per_zone=False, **options)#

The case’s scenario scenario (its case.json), with options added.

weight: people per simulated traveller (demand’s); the case’s own by default. departures: which trips run (demand’s); the case’s own by default. one_point_per_zone: every trip end at its zone’s own point (demand’s). The case’s window (case.json) is the scenario’s unless options give one, and so are its zones (zones(), read at flow_level=1 alone).

Parameters:
  • scenario (str)

  • seed (int)

  • weight (int | None)

  • departures (tuple[str | float, str | float] | str | None)

  • one_point_per_zone (bool)

  • options (Any)

Return type:

openmobisim.scenario.Scenario

transit(network=None)#

The timetable of the case’s service day, its stops reached on network’s walks.

Parameters:

network (openmobisim._core.Network | None)

Return type:

openmobisim._core.Transit | None

zones()#

The demand’s zones: each its point.

Return type:

dict[str, tuple[float, float]]

folder#
info: dict[str, Any]#
name#
openmobisim.examples.case(name, root=None, *, check=True)#

A starter case: its files found or fetched, checked, ready to read.

The cases: delft, amsterdam, paris, lyon (OpenStreetMap clipped to the study area, the transit feed of one service day, the parkings, a synthetic morning with four example traveller classes and the trips from outside: departures 07:30–08:30 simulated to 09:30 by default), siouxfalls and nguyendupuis (the benchmarks: link tables, an OD matrix, cars). case_names() lists them.

Parameters:
  • name (str) – The case.

  • root (str | pathlib.Path | None) – A folder holding the bundle (<root>/<name>/); else the folder OPENMOBISIM_DATA names, else the cache (~/.cache/openmobisim/bundle/<version>), where a case is downloaded once.

  • check (bool) – Check every file against the checksums this package carries (a changed or broken file is refused).

Returns:

network(), transit(), parkings(), zones(), classes(), demand(), scenario(), and info (its case.json: sources, licences, how it was made).

Return type:

The case

Raises:
  • ValueError – For an unknown case, or a file that fails its check.

  • FileNotFoundError – If the case is nowhere to be found and cannot be downloaded.

openmobisim.examples.case_check(names=None, root=None, *, quiet=False)#

Run starter cases’ default scenarios and compare them with the reference results.

The acceptance test of an installation: every scenario of each case (its case.json) is run with the package’s defaults, and compared with the results this version of the package carries. Same: the same fingerprint and, on the platform that made the reference, the same results to the bit. Same numbers (another platform): the same fingerprint and, on another platform, every compared number the same to the bit. Within tolerance: the same fingerprint, and on another platform results within CHECK_TOLERANCE. Different: anything else (another fingerprint means other inputs or settings: another bundle or package version).

Parameters:
  • names (list[str] | None) – The cases (case_names()); None: every case.

  • root (str | pathlib.Path | None) – Where the bundle is, as for case().

  • quiet (bool) – If false, print the build’s git commit (and the reference’s) and a line per scenario as it finishes.

Returns:

case, scenario, status ("same", "same numbers (another platform)", "within tolerance", "different" or "no reference"), notes (what differed), run_s (wall-clock seconds, reading included) and result (case_summary).

Return type:

One row per scenario

openmobisim.examples.case_names()#

The starter cases this version of the package knows.

Return type:

list[str]

openmobisim.examples.case_summary(run)#

What a starter case’s run is compared on: its fingerprint, trips, mean trip and modes.

The mode shares are of people (traveller weights), "none" for trips with nothing to choose from; platform is the build’s target, version the package’s and git_sha the commit the build is from ("unknown" without a repository; not compared by case_check).

Parameters:

run (Any)

Return type:

dict[str, Any]

openmobisim.examples.fixed_car_trips(network, trips, user_class='commuter')#

Build a trips table for car-only demand at a fixed departure time.

A convenience over the general schema, for the common case in a demo or a test: give the mode a fixed availability (a car, via classes) and a fixed departure time, rather than letting a choice model decide. Every row gets trip_seq = 0 — this helper does not build multi-trip chains.

Parameters:
  • network (openmobisim._core.Network) – A grid built by manhattan_grid.

  • trips (list[tuple[str, tuple[int, int], tuple[int, int], float, int | None]]) – (traveller_id, (origin_row, origin_col), (destination_row, destination_col), departure_hour, weight) tuples. weight=None takes the scenario’s default weight.

  • user_class (str) – The class every row is tagged with. A class that classes (passed to Scenario.from_parts, not here) does not list owns a car; one listed without a car reports every trip in this table as no_vehicle_available.

Returns:

Rows in the schema Scenario.from_parts’ demand argument (or run_pipeline) expects — the same table a trips.parquet file would produce.

Return type:

list[tuple]

openmobisim.examples.traveller_classes()#

Four example traveller classes by what people own, as demand_read_classes gives them.

The example classes, their bike constant fitted with no prices (the defaults’):

Class

Share

Modes

car_and_bike

0.40

all six

no_vehicle

0.30

walk, transit

bike_only

0.20

walk, bike, transit, bike-and-ride

car_only

0.10

walk, car, transit, park-and-ride

Each class owns what its modes need (a car for one that may drive or park and ride, a bike for one that may cycle; transit needs no pass, and none of the four holds one, so a fare, if a study sets one, is paid by all), and the two that cycle weigh alike: a bike constant of 1.23 (every other mode’s 0), on top of the default weights, which count each kilometre of a ride in mixed traffic (-0.16) and money (-1.2 per euro), though no price is charged by default: money plays no part until a study sets prices. The constant was fitted (on the starter case’s final recipe and window, a car trip paying its access and egress) so that Amsterdam’s residents drive as often as the city’s survey says they do (23 % of their trips, with 38 % by bike); public transport’s share then follows from who owns no vehicle, and walking, mostly short trips, needs a demand that has them. The shares come from the utilities and what people own, which is what a study changes. Illustrative, not calibrated: a starting point to replace with a study’s own. demand_assign_classes(trips, traveller_classes()) draws them for a demand’s travellers; Scenario.from_parts(..., classes=traveller_classes()) runs them. They assume a timetable: no_vehicle may only walk or take transit, so in a run without one its trips beyond the walk limit have no alternative. A class’s coefficients replace the run’s (choice_options) by name, so with these classes a run-wide beta_mode_bike changes nothing for the two that cycle (the run warns).

Return type:

dict[str, dict]

openmobisim.examples.trips_random(network, count, *, seed=0, spread_s=3600, min_m=500.0, max_m=5000.0, user_class='commuter', mode=None)#

A seeded load fixture: count trips between random places on network.

Not a forecast. Origins and destinations are the start points of random links, a crow-flies distance of min_m-max_m apart, departing at uniformly random times in the first spread_s seconds. It exists to put a realistic amount of traffic on a real network, so a run and its figures can be demonstrated and its cost measured. The same seed always gives the same trips.

A class that classes does not list owns a car; one listed without a car reports every trip as no_vehicle_available.

Parameters:
  • network (openmobisim._core.Network) – Any network.

  • count (int) – How many trips.

  • seed (int) – The random seed.

  • spread_s (int) – Departures fall in [0, spread_s) seconds.

  • min_m (float) – The nearest a destination may be to its origin, in metres.

  • max_m (float) – The farthest, in metres.

  • user_class (str) – The class every row is tagged with.

  • mode (str | None) – Every trip’s mode ("car", "bike", "walk", …); None (the default) leaves it out, which is a car trip.

Returns:

Rows in the trips schema Scenario.from_parts takes.

Raises:

ValueError – If no destination can be found within min_m-max_m.

Return type:

list[tuple]

openmobisim.examples.CHECK_TOLERANCE#
openmobisim.examples.manhattan_grid#
openmobisim.examples.toy_network#
openmobisim.examples.toy_network_parkings#
openmobisim.examples.toy_network_transit#