openmobisim.examples ==================== .. py:module:: openmobisim.examples .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: openmobisim.examples.CHECK_TOLERANCE openmobisim.examples.manhattan_grid openmobisim.examples.toy_network openmobisim.examples.toy_network_parkings openmobisim.examples.toy_network_transit Classes ------- .. autoapisummary:: openmobisim.examples.Case Functions --------- .. autoapisummary:: openmobisim.examples.case openmobisim.examples.case_check openmobisim.examples.case_names openmobisim.examples.case_summary openmobisim.examples.fixed_car_trips openmobisim.examples.traveller_classes openmobisim.examples.trips_random Module Contents --------------- .. py:class:: Case(name, folder) One starter case, its files checked: see :func:`openmobisim.examples.case`. .. py:method:: classes() The traveller classes, with their shares. .. py:method:: 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. .. py:method:: 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//``): the same network, bit for bit, in a fraction of the import's time. ``OPENMOBISIM_NO_NETWORK_CACHE=1`` imports it every time. .. py:method:: 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//``): the same parkings, bit for bit, in a fraction of the time. ``OPENMOBISIM_NO_NETWORK_CACHE=1`` reads them from the extract every time. .. py:method:: path(relative) A file of the case. .. py:method:: 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). .. py:method:: transit(network = None) The timetable of the case's service day, its stops reached on ``network``'s walks. .. py:method:: zones() The demand's zones: each its point. .. py:attribute:: folder .. py:attribute:: info :type: dict[str, Any] .. py:attribute:: name .. py:function:: 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. :param name: The case. :param root: A folder holding the bundle (``//``); else the folder ``OPENMOBISIM_DATA`` names, else the cache (``~/.cache/openmobisim/bundle/``), where a case is downloaded once. :param check: 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). :rtype: The case :raises ValueError: For an unknown case, or a file that fails its check. :raises FileNotFoundError: If the case is nowhere to be found and cannot be downloaded. .. py:function:: 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). :param names: The cases (``case_names()``); ``None``: every case. :param root: Where the bundle is, as for :func:`case`. :param quiet: 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``). :rtype: One row per scenario .. py:function:: case_names() The starter cases this version of the package knows. .. py:function:: 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``). .. py:function:: 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. :param network: A grid built by ``manhattan_grid``. :param trips: ``(traveller_id, (origin_row, origin_col), (destination_row, destination_col), departure_hour, weight)`` tuples. ``weight=None`` takes the scenario's default weight. :param user_class: 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. .. py:function:: 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). .. py:function:: 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``. :param network: Any network. :param count: How many trips. :param seed: The random seed. :param spread_s: Departures fall in ``[0, spread_s)`` seconds. :param min_m: The nearest a destination may be to its origin, in metres. :param max_m: The farthest, in metres. :param user_class: The class every row is tagged with. :param mode: 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``. .. py:data:: CHECK_TOLERANCE .. py:data:: manhattan_grid .. py:data:: toy_network .. py:data:: toy_network_parkings .. py:data:: toy_network_transit