openmobisim.viz =============== .. py:module:: openmobisim.viz .. autoapi-nested-parse:: Figures for openmobisim runs, in one recognisable look. ``pip install 'openmobisim[viz]'``. Functions are named with their kind first, so related ones sort and complete together: ``map_*`` draws on a map, ``chart_*`` draws a plot with axes. * :func:`map_link` — a run's traffic on its network: one ribbon per direction of every link, width = road capacity, colour = delay over free flow. * :func:`map_demand` — demand as origin-destination desire lines. * :func:`map_route` — the alternative routes of one origin-destination pair. * :func:`map_transit` — a run's transit: lines by kind, width = passengers on board, stops as hubs. * :func:`map_parking` — a run's parkings: car parks and bike parkings, sized by capacity, coloured by how full they got. * :func:`map_hubs` — a run's shared-bike hubs at one time: discs sized by the docks' slots, coloured by how full they were, ringed where mostly empty or full. * :func:`map_interactive` — a run and its route sets as one interactive HTML file: zoom levels, time, colour, hover, and route inspection. Needs no matplotlib. * :func:`map_link_select` — the select-link analysis as one interactive HTML file: click a link to see the origin-destination pairs whose trips cross it, where they came from and went. Needs no matplotlib. * :func:`chart_demand_matrix` — the origin-destination matrix as a heat-map. * :func:`chart_service` — a docked bike service's day: bikes docked and ridden, docks without a bike, and the travellers who found a dock empty. * :func:`chart_mode_share` — the share of the trips each mode took, by departure time. * :func:`summary` — a run's summary as one self-contained HTML page: headline numbers, the flow map, modes, convergence, where the time went, settings. matplotlib is imported when a figure is drawn, not when this package is, so ``import openmobisim.viz`` works without it. A figure that ends a notebook cell shows there. In a script or an IDE's console, ``plt.show()`` shows the figures drawn after ``import matplotlib.pyplot as plt``; ``path=`` saves one to a file. Functions --------- .. autoapisummary:: openmobisim.viz.chart_demand_matrix openmobisim.viz.chart_mode_share openmobisim.viz.chart_service openmobisim.viz.map_demand openmobisim.viz.map_hubs openmobisim.viz.map_interactive openmobisim.viz.map_link openmobisim.viz.map_link_select openmobisim.viz.map_parking openmobisim.viz.map_route openmobisim.viz.map_transit openmobisim.viz.summary Package Contents ---------------- .. py:function:: chart_demand_matrix(trips, *, cell_m = 500.0, top = 30, theme = 'paper', title = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw the origin-destination matrix as a heat-map. Rows are origins and columns destinations, for the `top` cells that start or end the most trips, ordered by their total. Colour is the number of trips on the *ion* ramp. Cells stand in for zones until zones exist. :param trips: Rows in the scenario's trips schema. :param cell_m: Side of the square cells that stand in for zones, in metres. :param top: How many of the busiest cells to show. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param note: A third, italic line. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If there are no trips. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: chart_mode_share(run, *, bin_s = 900, theme = 'paper', title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw the share of the trips each mode took, by departure time. One stacked bar per departure bin: the share of the trips departing then that took each mode, walk at the bottom and the car at the top; each mode's share of the day at the right. Trips count as many times as the people their traveller stands for. A trip counts under the mode it took (``Run.trip_modes``): its stated mode, or with mode choice (``modes``) the one it chose. Bins with fewer than 1% of the busiest bin's trips are left out, and so are trips that had no mode to choose. :param run: A ``Run``. :param bin_s: The departure bins' length, in seconds. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param subtitle: A line under the title; defaults to the trips and how many chose their mode. :param note: A third, italic line. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If ``bin_s`` is not positive, or no trip had a mode. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: chart_service(run, service = 'bike_share', *, theme = 'paper', title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw a docked bike service's day, or a taxi fleet's (``service`` naming one: see below). Three panels over the run's window. **Bikes**: one stacked bar per bin, the bikes docked (the docks' time-weighted means, summed) and the bikes ridden (the fleet less those docked; bikes in an operator's van would count here, and a run has no operator yet). **Docks without a bike**: the mean number of docks empty over the bin (their seconds empty over the bin's length, summed), beside the docks: a fleet with many bikes docked can still have its busy docks empty. **Travellers who found a dock empty** (people): those who went on to another dock, and those who found no bike at any dock tried and walked to their destination. **A taxi fleet** (``service="taxi"``, its name), bin by bin of ``Run.taxi_vehicles()`` and ``Run.taxi_trips()``: **vehicles** by state (the mean over the bin: carrying a passenger, driving empty to a pickup, idle, at or driving to a charger); **travellers waiting** for a taxi (the mean over the bin, from each request until the pickup, the cancellation, or the window's end); **requests cancelled** (no taxi could pick them up within the fleet's cancel limit), by the bin they were made in. :param run: A ``Run`` of a scenario with a docked bike service or a taxi fleet. :param service: The service, by name. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param subtitle: A line under the title; defaults to the fleet, the docks and the bins. :param note: A third, italic line; defaults to the trips and how they went. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If the run had no service, or no service ``service``. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: map_demand(trips, *, network = None, cell_m = 500.0, top = 300, theme = 'paper', title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw demand as origin-destination desire lines on a map. Each line runs from an origin cell to a destination cell and bends to the **right** of its direction, so a pair and its reverse are two separate curves. Width and colour are the number of trips (traveller weights included); the largest `top` pairs are drawn. Trips that start and end in one cell are counted in the subtitle, not drawn. :param trips: Rows in the scenario's trips schema. :param network: If given, its links are drawn quietly underneath as a canvas. :param cell_m: Side of the square cells that stand in for zones, in metres. :param top: How many of the largest origin-destination pairs to draw. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param subtitle: A line under the title; defaults to the counts. :param note: A third, italic line. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If there are no trips. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: map_hubs(run, at = '08:30', *, service = None, theme = 'paper', title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw how full each hub's shared-bike docks were at one time of the day. A hub is a place where travellers change vehicle (a stop, or a dock standing alone); its docks are added up. Each hub is a disc sized by its docks' slots and coloured by the share of the slots holding a bike over the time bin that holds ``at`` (the bin's time-weighted mean, ``bikes_mean`` of ``Run.bike_share_docks()``), from empty to full. A ring marks a hub whose docks held no bike for more than half of the bin (no bike to take: in the delay spectrum's red), or had no free slot (no room to return one: in its gold). The run's network is drawn quietly underneath. :param run: A ``Run`` of a scenario with a docked bike service. :param at: The time: ``"HH:MM"`` or seconds from midnight, inside the run's window. :param service: The service to draw, by name; every service of the run by default. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param subtitle: A line under the title; defaults to the time bin and what size, colour and rings mean. :param note: A third, italic line; defaults to the bin's bikes taken and returned and the travellers who found a dock empty. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If the run had no service, has no service ``service``, or ``at`` is outside its window. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: map_interactive(run, path = None, *, routes = True, theme = 'paper', title = None, note = None, credit = None, logo = True, view = None, max_route_pairs = 2000, link_width = 1.0, link_gap = 1.0, quiet = False) Write a run and its route sets as one interactive HTML file. Open the file in any modern browser: it needs no server, no network and no library. **Zoom** with the wheel, the buttons or the five level buttons (Overview, Region, District, Street, Detail): a large network shows its major roads first and adds minor streets as you zoom in, so it stays fast and readable at every scale. **Time**: a slider over the run's time bins, all bins together, or play. **Colour** links by delay over free flow (the mean crossing time over the free-flow time, less one), volume, or volume over capacity. **Hover** a link to read it; **click** it to see how many routes and pairs use it and jump to one of them. **Pick a pair** to see its alternatives side by side, with each route's time, detour and overlap. **Layers**: besides road traffic, the run's transit lines and stops, its parkings, and the cyclists' and walkers' flows on their own networks, each with a switch and each off at first (the road traffic is the main view; transit over busy roads reads only when asked for). Only the layers the run has data for are offered. The page's whole state is in its URL after the ``#``, so a view can be shared and reproduced. The figure is drawn at the screen's own resolution: it stays sharp at any zoom. **Size.** A file holds one copy of the network's street shapes, the per-bin results and the route sets, compressed. Andorra (23 000 links) with 3 000 route pairs is a few megabytes; a whole country is tens. To keep a file small, pass ``view`` to include only a region, or lower ``max_route_pairs``. :param run: A ``Run`` from ``Scenario.run()``. Built with ``link_bin_s`` it shows traffic; without, the network and routes only. :param path: Where to write the ``.html`` file; ``map.html`` in the run's output folder by default. :param routes: ``True`` (default) to include the run's route sets, ``False`` or ``None`` for none, or a ``RouteSets`` object (from ``openmobisim.route_sets_build``) to show instead. :param theme: The starting theme, ``"paper"`` or ``"night"``; the page has a button to switch. :param title: The page title; defaults to a description of what is drawn. :param note: A third, italic line under the title. :param credit: A line of your own (a name, an institution) shown before the logo. :param logo: Show the openmobisim logo at the bottom right. :param view: ``((lon_min, lat_min), (lon_max, lat_max))``: include only the links that touch this box, and only routes that lie wholly inside it. :param max_route_pairs: At most this many origin-destination pairs are embedded, those with the most alternatives first (ties by order). :param link_width: The road ribbons' width, as a multiple of the width the page chooses from the room between the roads on screen (1, the default); below 1 thinner, for a network of few, wide roads. :param link_gap: The space between a road's two directions, as a multiple of the page's own (1, the default: a fifth of the widest ribbon, 1.5 to 6 px). :param quiet: Do not say where the file was written (by default a link to it is printed, or shown in a notebook). :returns: The path written. :raises ValueError: If `theme` is unknown, `view` is empty, `link_width` or `link_gap` is not a positive number, or the region is too large to store (over about 200 km across; pass `view`). .. py:function:: map_link(run, *, bins = None, layer = 'road', colour = None, ramp = 'spectrum', theme = 'paper', title = None, subtitle = None, note = None, view = None, size_cm = SIZE_CM, dpi = 120, scale = None, chevrons = None, min_volume = 0.0, credit = None, logo = True, path = None) Draw a run's traffic on its network: one ribbon per direction of every link. Width is the road's capacity per direction, the same for every road of one capacity (on the bike and walk layers, which have no capacity, volume); colour is the delay over free flow (each link's mean crossing time over its free-flow time, less one), or volume, see `colour`. The two directions of a two-way street are drawn side by side, each on its own driver's side, so they never overlap. Free-flowing links recede and congestion glows. :param run: A ``Run`` from ``Scenario.run()`` on a scenario built with ``link_bin_s``, at ``flow_level`` 2-4 for congestion to show. :param bins: Which time bins to show: ``None`` for the busiest part of the run (the busiest bin and the bins around it carrying at least a quarter of its traffic), ``"all"`` for every bin from the first to the last that saw traffic, a clock time for the bin it falls in (``"07:45"``), a pair of clock times for the bins that cover the span (``("07:30", "08:30")``), or bin numbers counted from midnight: an ``int`` for one bin, ``(first, stop)`` for a range (``stop`` excluded). :param layer: Which layer's traffic to draw: ``"road"`` (default: cars, on the road network), ``"bike"`` or ``"walk"`` (each on its own layer's links, ``network.layer(...)``; volume counts travellers, not PCU). :param colour: What the colour shows: ``"delay"`` (the delay over free flow, a link's mean crossing time over its free-flow time less one, in four bands, 0-15 %, 15-50 %, 50-100 % and 100 % or more, after the Highway Capacity Manual's levels of service; free flow counts a signal's mean wait, so only waiting beyond it is delay; the default on the road), ``"volume"`` (the default on the bike and walk layers, where nothing is delayed), or ``"volume_capacity"`` (volume over the link's capacity as it passes traffic — at a signal, times the green fraction — in four bands coloured as the delay's: under 0.6, 0.6-0.8, 0.8-1.0 and over capacity; the road only). :param ramp: For delay and volume over capacity, ``"spectrum"`` (default: blue-green for little, gold in the middle, deeper red for more) or ``"ember"`` (the single-hue ramp of the first version). :param theme: ``"paper"`` (print, slides) or ``"night"`` (screens, video). :param title: Figure title; defaults to a description of what is drawn. :param subtitle: A line under the title; defaults to the time window and the encodings. :param note: A third, italic line, for example to say the demand is a fixture. :param view: ``((lon_min, lat_min), (lon_max, lat_max))`` to zoom to; the whole network by default. :param size_cm: Figure size, width and height in centimetres. 40.64 x 22.86 (16:9) is a full-screen frame. The text is laid out for figures **20 cm wide or more**; narrower, the footer runs into the logo and the legends crowd (a layout for a journal column is planned). :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param scale: Ribbon width multiplier; by default it follows the view, thin for a whole region and bolder when zoomed to a town. :param chevrons: Draw a small direction triangle on each ribbon; by default only when the view is a few kilometres across. :param min_volume: Links carrying no more than this (PCU/h) are drawn only as canvas; the default 0 draws every link that saw any traffic, at least a fine line wide. :param credit: A line of your own before the logo (a name, an institution, your copyright). The logo is a signature, not a claim on your figure. :param logo: Draw the openmobisim logo at the bottom right (``False`` for none). :param path: If given, also save the figure there (PNG, SVG or PDF by extension). :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If the run has no per-link results, or `colour` is unknown. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: map_link_select(run, path = None, *, zones = None, link = None, theme = 'paper', title = None, bin_s = None, quiet = False) Write the select-link analysis of a run as one interactive HTML file. **Click a link** (a road, or a bike link with the bike layer chosen) to see the origin-destination pairs whose trips cross it, as ``Run.link_select`` counts them: each pair's trips by mode, their share of the link's users and their share of the pair's travellers. The map draws where those users came from (filled discs) and went (rings), each sized by people, and their flow on every other link, so the roads that feed the link and those it feeds read at a glance. **Departures**: all of them together (the default), or one departure bin at a time with the slider. **Hover** a row of the table to see that pair alone. The page needs no server, no network and no library. :param run: A ``Run`` from ``Scenario.run()``. The bike layer is offered when the run has per-link results (``link_bin_s``) and bikes ran. :param path: Where to write the ``.html`` file; ``link_select.html`` in the run's output folder by default. :param zones: ``{zone: (lon, lat)}``: pairs of zones (each trip end at the nearest zone point), as ``Run.link_select``'s; ``None``: pairs of road nodes. :param link: The road link shown first; the one with the most people by default. :param theme: The starting theme, ``"paper"`` or ``"night"``; the page has a button to switch. :param title: The page title. :param bin_s: The departure bins' length in seconds: the run's ``link_bin_s``, or 900. :param quiet: Do not say where the file was written. :returns: The path written. :raises ValueError: If `theme` is unknown, the run does not carry its network or keep its journeys, or the region is too large to store (over about 200 km across). .. py:function:: map_parking(run, *, theme = 'paper', title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw a run's parkings: car parks and bike parkings, sized and coloured. Car parks are squares and bike parkings circles, each kind sized by its capacity on its own scale; the colour is the most vehicles parked at once over the day as a share of the capacity, from empty to full (a parking above capacity, which soft capacity allows, is full). Parkings nobody used are small hollow marks. The run's network is drawn quietly underneath. :param run: A ``Run`` of a scenario with ``parkings``. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param subtitle: A line under the title; defaults to the counts and what size and colour mean. :param note: A third, italic line; defaults to the vehicles parked and how many found their parking full. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If the run had no parkings. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: map_route(routes, network, pair = 0, *, theme = 'paper', title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw the alternative routes of one origin-destination pair on the network. Route 1 (the cheapest) is drawn first, in blue; the others follow in the order of their cost. Each route is shifted a little to the right of the one before, so where two routes use the same street they run side by side and the overlap is visible. The legend gives each route's free-flow time, its detour over the best, and the share of it that overlaps an earlier route. :param routes: ``RouteSets``, from ``Run.route_sets()`` or ``openmobisim.route_sets_build``. :param network: The network the routes are on. :param pair: Which pair: the position among the sets' keys, or two ``(lon, lat)`` points, snapped to their nearest nodes. :param theme: ``"paper"`` or ``"night"``. :param title: Figure title. :param subtitle: A line under the title; defaults to the counts. :param note: A third, italic line. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If the pair has no set, or no route. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: map_transit(run, *, theme = 'paper', colour = 'kind', stop_labels = None, title = None, subtitle = None, note = None, size_cm = SIZE_CM, dpi = 120, credit = None, logo = True, path = None) Draw a run's transit: lines by kind, width = passengers on board, stops as hubs. Each hop of every run, from one stop to the next, is a straight ribbon coloured by its kind of service (rail, metro, tram, bus, ferry, other) and as wide as the passengers on board over the whole day, summed over the runs that make it; the two directions side by side, each on the driver's side, as on the link map; the busiest on top. Stops are drawn as hubs, sized by boardings. The run's network is drawn quietly underneath. :param run: A ``Run`` of a scenario with ``transit``. :param theme: ``"paper"`` or ``"night"``. :param colour: ``"kind"``, each kind of service in its colour, or ``"line"``, each line in its own (eight colours, repeating past eight lines); lines that share a stretch are then drawn side by side, each right of its direction of travel. :param stop_labels: Write each stop's name beside it. ``None`` (the default) names them on a network of at most 40 stops, where the names fit. :param title: Figure title. :param subtitle: A line under the title; defaults to the timetable's counts. :param note: A third, italic line; defaults to the boardings. :param size_cm: Figure size, width and height in centimetres. :param dpi: Resolution in dots per inch (25.4 mm), the image-file convention. :param credit: A line of your own before the logo (a name, an institution). :param logo: Draw the openmobisim logo at the bottom right. :param path: If given, also save the figure there. :returns: A ``matplotlib.figure.Figure``. :raises ValueError: If the run had no timetable, or `colour` is unknown. :raises ImportError: If matplotlib is not installed (``openmobisim[viz]``). .. py:function:: summary(run, path = None, *, title = None, note = None, quiet = False) Write a run's summary as one self-contained HTML page, and return its path. The headline numbers (trips, completed, mean trip, total travel time, the roads' PCU-km and mean speed, run time), the travel statistics (the modes' shares, completion and mean trips; when people left, by mode; the roads' traffic over the day, its delay by band and the busiest links; transit, parking, bikes and walking in numbers), the convergence by iteration with its verdict, the computation time in three parts (reading, running, writing; stage by stage on ``timings.html`` beside it) with each layer's size (links, nodes, length), the settings with the fingerprint, and at the end a map per mode: car traffic, transit, bike traffic and walking, each where the run has its results (per-link results need ``link_bins_s``). Light and dark follow the reader's system. Needs matplotlib for the maps. :param run: A ``Run``. :param path: Where to write it; ``summary.html`` in the run's output folder by default. :param title: The page's title; ``Run `` by default. :param note: A line under the title, for example what the scenario is; none by default. :param quiet: Do not say where the page was written (by default a link to it is printed, or shown in a notebook). :returns: The path written, a ``Path``.