The Python interface#
The module openmobisim has the names on this page and no other. There is no command line, no plotting
function, no log and no progress output.
Name |
Kind |
What it does |
|---|---|---|
static method |
reads a network from an OpenStreetMap extract |
|
static method |
builds a network from a nodes table and a links table |
|
method |
gives a network back as the two tables |
|
static method |
reads the timetable of one service day from a GTFS feed |
|
static method |
builds the trips of a run from a trips table |
|
function |
runs the simulation on objects held in memory and writes its files |
|
function |
runs the settings file |
|
function |
experimental: writes a case folder from an OpenStreetMap extract |
|
class |
a finished run: the paths of its files and what was repaired |
|
method |
writes the run’s interactive map as one HTML file |
|
method |
writes the run’s summary as one HTML file |
|
static method |
opens a finished run from its folder without running it |
The objects Network, Transit and Demand are immutable. They are made by the static methods above, never by
calling the class. The whole chain, on the case dotnet of the published cases:
import openmobisim as oms
network = oms.Network.from_tables("dotnet/nodes.parquet", "dotnet/links.parquet")
transit = oms.Transit.from_gtfs("dotnet/gtfs.zip", network)
classes = ["bike_only", "car_and_bike", "car_only", "no_vehicle"]
demand = oms.Demand.from_table("dotnet/trips.parquet", classes, network, transit=transit)
result = oms.run(network, demand, transit, window=(27000, 34200), out="dotnet-objects-run")
print(result.trips)
print(result.stopped_by_rule)
print(result.repairs)
print(result.map("dotnet-map.html"))
print(result.summary("dotnet-summary.html", title="DOTNET, the morning"))
dotnet-objects-run/trips.parquet
True
{'network': {}, 'demand': {}, 'transit': {}, 'run': {}}
dotnet-map.html
dotnet-summary.html
Conventions of this page. A path is a str or an os.PathLike. A table is a table in memory or the path of a
Parquet file (Input tables and files). A second of the clock is a whole number of seconds after
midnight of the run’s day. Every keyword named “a parameter” is a row of Parameters, which gives its
unit, default and source; a parameter is accepted only by the entry point listed for it there. What each call sets
right instead of refusing, and every refusal, is listed in Repairs, warnings and refusals.
Exceptions common to every entry point.
Condition |
Exception |
|---|---|
A keyword that is not a parameter, or a parameter that another entry point reads |
|
A required argument missing ( |
|
A parameter’s value that cannot be read or is out of its range (a string for a speed, a negative speed) |
|
A boolean given for a parameter or inside one ( |
|
A file that cannot be opened, read or written, or a directory given as a file |
|
A refusal of a module of the core |
|
Network.from_osm#
Network.from_osm(path, region=None, car_roads="all", **network_parameters)
Reads one OpenStreetMap extract into a network of car links, bike links and walk links. What is read from the extract is in Input tables and files; how the network is made is in Networks.
Argument |
Type |
Meaning |
|---|---|---|
|
path |
One extract in the format |
|
|
The part of the extract to read, in WGS84 degrees. |
|
|
|
|
number, vehicles per hour per lane |
A parameter. It changes nothing in a network read from an extract, because every car link takes its road class’s capacity; it is accepted and recorded. |
|
number, km/h |
A parameter: the one speed of every bike. |
|
number, km/h |
A parameter: the one speed of every walker. |
|
|
A parameter with one value: the reader’s own table of speeds, lanes and capacities by road class. |
Returns a Network. Its attribute repairs is a dict from repair key to count, what the reader set right.
Refused |
Exception |
|---|---|
|
|
|
|
|
|
The file cannot be read |
|
The file cannot be decoded, or holds no street of any mode |
|
Network.from_tables#
Network.from_tables(nodes, links, **network_parameters)
Builds a network from a nodes table and a links table.
Argument |
Type |
Meaning |
|---|---|---|
|
table |
The nodes table. |
|
table |
The links table. |
|
number, vehicles per hour per lane |
A parameter: the capacity of a car link whose |
|
number, km/h |
A parameter. |
|
number, km/h |
A parameter. |
Returns a Network, with repairs as above. A node or link read from a table carries no traffic signal.
Refused |
Exception |
|---|---|
A column missing from a table |
|
A Parquet file with a column of a type that is not read, a column name held twice, a compression other than none or snappy, or a file that is not Parquet |
|
A Parquet file that cannot be opened or read, or a directory |
|
No node left; a build value that is not a finite number above zero |
|
Network.tables#
network.tables()
Takes no argument. Returns a tuple (nodes, links): the two tables Network.from_tables reads, each a dict
from column name to a list, in id order.
Table |
Columns, in order |
|---|---|
|
|
|
|
The car’s speed and capacity are written to nine decimals. lanes, car_speed_km_h and capacity_veh_h are None
on a link without cars; shape and road_class are None where the link has none. A bike link comes back as a bike
link.
Two things are not in the tables. The signal marks that an extract gives are stored in the network and applied
nowhere; from_tables does not read them, so the network built from the tables has another fingerprint than the one
read from the extract. The values bike_speed and walk_speed are given again to from_tables.
Transit.from_gtfs#
Transit.from_gtfs(path, network, **transit_parameters)
Reads one GTFS feed into the timetable of one service day, the busiest weekday of the feed, and derives the footpaths
between its stops on the walk links of network. What is read is in
Input tables and files; the method is in Transit.
Argument |
Type |
Meaning |
|---|---|---|
|
path |
One GTFS feed, a |
|
|
A network built from longitude and latitude. Its projection places the stops; its walk links and walk speed give the footpaths. |
|
number, m |
A parameter: the longest footpath between two stops. |
Returns a Transit. Its attribute repairs is a dict from repair key to count.
Refused |
Exception |
|---|---|
A network built in metres |
|
|
|
The file cannot be read |
|
The file is no zip; a required file or a required column is missing; no day of the feed has a trip |
|
Demand.from_table#
Demand.from_table(trips, classes, network, transit=None, **demand_parameters)
Builds the trips of a run: each end of each trip is linked to the network for each mode open to the trip, and, with a timetable, to the stops within walking reach (Demand).
Argument |
Type |
Meaning |
|---|---|---|
|
table |
The trips table. |
|
list of |
The ids of the traveller classes. A trip names one of them in |
|
|
The network the trips travel on. The trips’ positions are of its kind, degrees or metres. |
|
|
The timetable, read on the same network. |
|
number, m |
A parameter: the longest walk between a door and a stop. |
Returns a Demand, with two attributes: repairs, a dict from repair key to count, and trips_given, the
number of rows of the trips table (int).
Refused |
Exception |
|---|---|
A column missing; a Parquet file’s refusals, as for |
|
|
|
Positions of another kind than the network’s, or of both kinds |
|
run#
run(network, demand, transit=None, *, window, out, **parameters)
Runs the simulation and writes five files into out: trips.parquet, links.parquet, iterations.parquet,
routes.parquet (Output files) and run_record.toml
(The settings file and the run record). How a run proceeds is in
How a run works.
Argument |
Type |
Meaning |
|---|---|---|
|
|
The network. |
|
|
The trips, built on |
|
|
The timetable the demand was built on, or |
|
two |
|
|
path, required |
The folder the files go to, created if missing. A |
The parameters run reads, each a keyword:
Keyword |
Type |
Unit |
|---|---|---|
|
|
s |
|
|
rides |
|
|
searches per trip end |
|
|
routes per origin-destination pair |
|
|
journeys per trip |
|
|
name |
|
|
cost per minute, per transfer, per euro, per unit, per alternative |
|
number |
none |
|
number |
none |
|
|
iterations |
|
|
iterations |
|
|
s |
|
|
none |
Returns a Run.
Refused |
Exception |
|---|---|
|
|
A demand built on another network or on another transit than the ones given |
|
An empty or reversed window: |
|
|
|
|
|
With a timetable, a class whose coefficient of a transit time or of the transfers is negative or not finite |
|
An |
|
A known limit of the last check: paths are compared, not files, so an input that is a hard link of one of the five
output names in out is not recognised and would be replaced.
run_file#
run_file(folder=None, *, out)
Runs the settings file run.toml. It builds the network, the timetable (when the file has [transit]) and the
demand with the functions above, gives each the parameters its entry point reads, and runs them with run. Every key
of the file is in The settings file and the run record.
Argument |
Type |
Meaning |
|---|---|---|
|
path or |
The folder holding |
|
path, required |
The folder the run is written into, as for |
Returns a Run.
import openmobisim as oms
run = oms.run_file("dotnet", out="dotnet-run")
Refused |
Exception |
|---|---|
A path where nothing is; a folder without |
|
The path of a file of another name |
|
A folder that holds a run’s record and no |
|
A settings file that is not TOML |
|
A key or table under |
|
A parameter’s value out of range |
the exception of the entry point that reads it, raised once the inputs before that entry point are built |
Every refusal of |
as for |
Warned, with one UserWarning each, and the run goes on: a key or table outside [parameters] that a settings file
never holds (ignored, all of them named); stop_walk_max or transfer_walk_max without [transit] (ignored); a
whole record renamed run.toml (its part one alone is read); an input of such a record whose fingerprint differs
from the one recorded (both fingerprints named).
make_case#
make_case(folder, osm, population, region=None, gtfs=None, car_roads="all",
trips_per_person=0.1, seed=0)
Experimental. It writes two files into folder, a trips.parquet of trips drawn from the streets of the network
by fixed rules that are not calibrated, and a run.toml, which run_file(folder, out=...) runs. The trips are a
start for trying things, not a model of the city.
Argument |
Type |
Meaning |
|---|---|---|
|
path |
The folder to write the case into. |
|
path |
The extract, read as |
|
number |
The people of the area. |
|
as for |
The part of the extract to read. |
|
path or |
A GTFS feed, named in |
|
|
As for |
|
number |
The share of the people who travel in the hour of the draw. The number of trips is |
|
|
The seed of the draw. The same arguments give the same files. |
Returns folder, as a pathlib.Path.
Refused |
Exception |
|---|---|
No trip ( |
|
Every refusal of |
as there |
Run: the result#
A Run is what run, run_file and Run.open return. It keeps nothing of the run in memory: it holds the paths of
the run’s files, and each page is read from those files when it is written.
Attribute |
Type |
Meaning |
|---|---|---|
|
|
The path of |
|
|
The path of |
|
|
The path of |
|
|
The path of |
|
|
The path of |
|
|
|
|
|
What was set right instead of refused, key to count, under |
|
|
The five counts of the OpenStreetMap reader for the run’s network (the record); |
|
|
The fifteen counts of the GTFS reader for the run’s timetable (the record); |
Run.map#
result.map(path, title=None)
Writes the run’s interactive map: one HTML file that holds its own style, script and data, loads nothing and opens from disk in a browser. What it shows is in The pages of a run.
Argument |
Type |
Meaning |
|---|---|---|
|
path |
The file to write. A file there is replaced. |
|
|
The page’s title. |
Returns path, as given. The same run written twice under the same title gives the same bytes.
Refused |
Exception |
|---|---|
A |
|
A table of the run that is missing or cannot be opened |
|
A table with a column the page needs missing or of a type that cannot be read; a row whose own trip or link names nothing the inputs hold |
|
A |
|
What the tables hold that does not agree with the run’s inputs is set aside with a UserWarning
(Warnings of a finished run).
Run.summary#
result.summary(path, title=None)
Writes the run’s summary: one HTML page of its numbers, charts and maps, which loads nothing. Its sections are in
The pages of a run. The arguments, the value returned, the refusals and the warnings are those
of Run.map.
Run.open#
Run.open(folder, network=None, demand=None, transit=None)
Opens a finished run from its folder without running anything, and returns a Run like the one run returned. The
map and the summary of an opened run are the same bytes as those of the fresh run.
Argument |
Type |
Meaning |
|---|---|---|
|
path |
The folder of a finished run, which holds |
|
|
The network the run ran on. |
|
|
The demand the run ran on. |
|
|
The timetable the run ran on. |
What it reads from the record is listed in The settings file and the run record.
Returns a Run.
import openmobisim as oms
result = oms.Run.open("dotnet-run")
print(result.stopped_by_rule)
True
Refused |
Exception |
|---|---|
A path where nothing is; a folder without |
|
The path of a file of another name, |
|
A record that is not TOML |
|
A key under |
|
An input that was given in memory when the run was made (the record names no file for it) and is not passed |
|
|
|
A demand passed that was not built on the network and transit used |
|
A table missing or unreadable, a column the pages need missing |
|
Warned, with a UserWarning, and the run is opened: an input whose fingerprint differs from the record’s; a record
without an input’s fingerprint; a transit passed to a run that had none (set aside); a key the record never holds
(ignored); and what the tables hold that does not agree with the inputs
(Warnings of a finished run).
Threads#
The interpreter’s lock is released while a file is read, while a network, timetable or demand is built, and while a
run runs and is written. The threads are those of one global pool; the environment variable RAYON_NUM_THREADS sets
their number. The results are the same at any number of threads
(Reproducibility).