Reference#

Python wrapper for the R5 routing analysis engine.

class r5py.DetailedItinerariesComputer(transport_network, origins=None, destinations=None, snap_to_network=False, force_all_to_all=False, **kwargs)#

Compute travel times between many origins and destinations.

Parameters
  • transport_network (r5py.TransportNetwork | tuple(str, list(str), dict)) – The transport network to route on. This can either be a readily initialised r5py.TransportNetwork or a tuple of the parameters passed to TransportNetwork.__init__(): the path to an OpenStreetMap extract in PBF format, a list of zero of more paths to GTFS transport schedule files, and a dict with build_config options.

  • origins (geopandas.GeoDataFrame) – Places to find a route _from_ Has to have a point geometry, and at least an id column

  • destinations (geopandas.GeoDataFrame (optional)) – Places to find a route _to_ Has to have a point geometry, and at least an id column If omitted, use same data set as for origins

  • snap_to_network (bool or int, default False) – Should origin an destination points be snapped to the street network before routing? If True, the default search radius (defined in com.conveyal.r5.streets.StreetLayer.LINK_RADIUS_METERS) is used, if int, use snap_to_network meters as the search radius.

  • force_all_to_all (bool, default False) – If origins and destinations have the same length, by default, DetailedItinerariesComputer finds routes between pairs of origins and destinations, i.e., it routes from origin #1 to destination #1, origin #2 to destination #2, … . Set all_to_all=True to route from each origin to all destinations (this is the default, if origins and destinations have different lengths, or if destinations is omitted)

  • **kwargs (mixed) – Any arguments than can be passed to r5py.RegionalTask: departure, departure_time_window, percentiles, transport_modes, access_modes, egress_modes, max_time, max_time_walking, max_time_cycling, max_time_driving, speed_cycling, speed_walking, max_public_transport_rides, max_bicycle_traffic_stress Not that not all arguments might make sense in this context, and the underlying R5 engine might ignore some of them.

compute_travel_details()#

Compute travel times from all origins to all destinations.

Returns

The resulting detailed routes. For each origin/destination pair, multiple route alternatives (‘options’) might be reported that each consist of one or more segments. Each segment represents one row. The data frame comprises of the following columns: from_id, to_id, option (int), segment (int), transport_mode (r5py.TransportMode), departure_time (datetime.datetime), distance (float, metres), travel_time (datetime.timedelta), wait_time (datetime.timedelta), route (str, public transport route number or name), geometry (shapely.LineString) TODO: Add description of output data frame columns and format

Return type

geopandas.GeoDataFrame

class r5py.RegionalTask(transport_network, origin=None, destinations=None, departure=datetime.datetime(2023, 10, 25, 13, 40, 49, 725729), departure_time_window=datetime.timedelta(seconds=600), percentiles=[50], transport_modes=[<TransportMode.TRANSIT: 'TRANSIT'>], access_modes=[<TransportMode.WALK: 'WALK'>], egress_modes=None, max_time=datetime.timedelta(seconds=7200), max_time_walking=datetime.timedelta(seconds=7200), max_time_cycling=datetime.timedelta(seconds=7200), max_time_driving=datetime.timedelta(seconds=7200), speed_walking=3.6, speed_cycling=12.0, max_public_transport_rides=8, max_bicycle_traffic_stress=3, breakdown=False)#

Create a RegionalTask, a computing request for R5.

A RegionalTask wraps a com.conveyal.r5.analyst.cluster.RegionalTask, which is used to specify the details of a requested computation. RegionalTasks underlie virtually all major computations carried out, such as, e.g., TravelTimeMatrixComputer or AccessibilityEstimator.

In r5py, there is usually no need to explicitely create a RegionalTask. Rather, the constructors to the computation classes (TravelTimeMatrixComputer, AccessibilityEstimator, …) accept the arguments, and pass them through to an internally handled RegionalTask.

Parameters
  • transport_network (r5py.TransportNetwork) – The street + public transport network to route on

  • origin (shapely.geometry.Point) – Point to route from

  • destinations (geopandas.GeoDataFrame) – Points to route to, has to have at least an id column and a geometry

  • departure (datetime.datetime) – Find public transport connections leaving every minute within departure_time_window after departure. Default: current date and time

  • departure_time_window (datetime.timedelta) – (see departure) Default: 10 minutes

  • percentiles (list[int]) – Return the travel time for these percentiles of all computed trips, by travel time. By default, return the median travel time. Default: [50]

  • transport_modes (list[r5py.TransportMode] or list[str]) – The mode of transport to use for routing. Can be a r5py mode enumerable, or a string representation (e.g. “TRANSIT”) Default: [r5py.TransportMode.TRANSIT] (all public transport)

  • access_modes (list[r5py.TransportMode] or list[str]) – Mode of transport to public transport stops. Can be a r5py mode object, or a string representation (e.g. “WALK”) Default: [r5py.TransportMode.WALK]

  • egress_modes (list[r5py.TransportMode]) – Mode of transport from public transport stops. Default: access_modes

  • max_time (datetime.timedelta) – Maximum trip duration. Default: 2 hours

  • max_time_walking (datetime.timedelta) – Maximum time spent walking, potentially including access and egress Default: max_time

  • max_time_cycling (datetime.timedelta) – Maximum time spent cycling, potentially including access and egress Default: max_time

  • max_time_driving (datetime.timedelta) – Maximum time spent driving Default: max_time

  • speed_walking (float) – Mean walking speed for routing, km/h. Default: 3.6 km/h

  • speed_cycling (float) – Mean cycling speed for routing, km/h. Default: 12.0 km/h

  • max_public_transport_rides (int) – Use at most max_public_transport_rides consecutive public transport connections. Default: 8

  • max_bicycle_traffic_stress (int) – Maximum stress level for cyclist routing, ranges from 1-4 see https://docs.conveyal.com/learn-more/traffic-stress Default: 3

  • breakdown (bool) – Compute a more detailed breakdown of the routes. Default: False

property access_modes#

Route with these modes of transport to reach public transport (r5py.TransportMode).

property breakdown#

Compute a more detailed breakdown of the routes.

property departure#

Find public transport connections leaving within departure_time_window after departure (datetime.datetime).

property departure_time_window#

Find public transport connections leaving within departure_time_window after departure (datetime.timedelta).

Note: The value of departure_time_window should be set with some caution. Specifically, setting values near or below the typical headways in the studied transit network may lead to routing problems. See this GitHub discussion for details.

property destinations#

Points to route to.

A geopandas.GeoDataFrame with a point geometry, and at least an id column (which R5 mangles to str).

property egress_modes#

Route with these modes of transport to reach the destination from public transport (r5py.TransportMode).

property max_bicycle_traffic_stress#

Find routes with this maximum stress level for cyclists.

Int, in the range 1-4, see https://docs.conveyal.com/learn-more/traffic-stress

property max_public_transport_rides#

Include at most this many consecutive public transport rides (int).

property max_time#

Restrict trip duration (datetime.timedelta).

property max_time_cycling#

Restrict routes to at most this duration of cycling (datetime.timedelta).

Depending on the transport modes specified, this includes times on the main leg of the trip, as well as during access and egress.

property max_time_driving#

Restrict routes to at most this duration of driving (datetime.timedelta).

property max_time_walking#

Restrict routes to at most this duration of walking (datetime.timedelta).

Depending on the transport modes specified, this includes times on the main leg of the trip, as well as during access and egress.

property origin#

Set the origin for the routing operation (shapely.geometry.Point).

property percentiles#

Return the travel time for these percentiles of all computed trips, by travel time.

By default, return the median travel time. (collections.abc.Sequence[int])

property scenario#

Expose the RegionalTask’s Scenario to Python.

property speed_cycling#

Use this speed for routing for cyclists (km/h, float).

property speed_walking#

Use this speed for routing pedestrian movement (km/h, float).

property transport_modes#

Get/set the transport modes used to route the main leg of trips.

(list[r5py.TransportMode])

class r5py.TransportMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Transport modes.

TransportMode.AIR, TransportMode.TRAM, TransportMode.SUBWAY, TransportMode.RAIL, TransportMode.BUS, TransportMode.FERRY, TransportMode.CABLE_CAR, TransportMode.GONDOLA, TransportMode.FUNICULAR, TransportMode.TRANSIT (translate into R5’s TransitMode)

TransportMode.WALK, TransportMode.BICYCLE, TransportMode.CAR (translate into R5’s StreetMode or LegMode)

TransportMode.BICYCLE_RENT, TransportMode.CAR_PARK (translate into R5’s LegMode)

property is_leg_mode#

Can this TransportMode function as a LegMode?

property is_street_mode#

Can this TransportMode function as a StreetMode?

property is_transit_mode#

Can this TransportMode function as a TransitMode?

class r5py.TransportNetwork(osm_pbf, gtfs=[])#

Load a transport network.

Parameters
classmethod from_directory(path)#

Find input data in path, load an r5py.TransportNetwork.

This mimicks r5r’s behaviour to accept a directory path as the only input to setup_r5().

If more than one OpenStreetMap extract (.osm.pbf) is found in path, the (alphabetically) first one is used. In case no OpenStreetMap extract is found, a FileNotFound exception is raised. Any and all GTFS data files are used.

Parameters

path (str) – directory path in which to search for GTFS and .osm.pbf files

Returns

A fully initialised r5py.TransportNetwork

Return type

TransportNetwork

property linkage_cache#

Expose the TransportNetwork’s linkageCache to Python.

snap_to_network(points, radius=1600.0, street_mode=TransportMode.WALK)#

Snap points to valid locations on the network.

Parameters
  • points (geopandas.GeoSeries) – point geometries that will be snapped to the network

  • radius (float) – Search radius around each point

  • street_mode (travel mode that the snapped-to street should allow) –

Returns

point geometries that have been snapped to the network, using the same index and order as the input points

Return type

geopandas.GeoSeries

property street_layer#

Expose the TransportNetwork’s streetLayer to Python.

property timezone#

Determine the timezone of the GTFS data.

property transit_layer#

Expose the TransportNetwork’s transitLayer to Python.

class r5py.TravelTimeMatrixComputer(transport_network, origins=None, destinations=None, snap_to_network=False, **kwargs)#

Compute travel times between many origins and destinations.

Parameters
  • transport_network (r5py.TransportNetwork | tuple(str, list(str), dict)) – The transport network to route on. This can either be a readily initialised r5py.TransportNetwork or a tuple of the parameters passed to TransportNetwork.__init__(): the path to an OpenStreetMap extract in PBF format, a list of zero of more paths to GTFS transport schedule files, and a dict with build_config options.

  • origins (geopandas.GeoDataFrame) – Places to find a route _from_ Has to have a point geometry, and at least an id column

  • destinations (geopandas.GeoDataFrame (optional)) – Places to find a route _to_ Has to have a point geometry, and at least an id column If omitted, use same data set as for origins

  • snap_to_network (bool or int, default False) – Should origin an destination points be snapped to the street network before routing? If True, the default search radius (defined in com.conveyal.r5.streets.StreetLayer.LINK_RADIUS_METERS) is used, if int, use snap_to_network meters as the search radius.

  • **kwargs (mixed) – Any arguments than can be passed to r5py.RegionalTask: departure, departure_time_window, percentiles, transport_modes, access_modes, egress_modes, max_time, max_time_walking, max_time_cycling, max_time_driving, speed_cycling, speed_walking, max_public_transport_rides, max_bicycle_traffic_stress

compute_travel_times()#

Compute travel times from all origins to all destinations.

Returns

A data frame containing the columns from_id, to_id, and travel_time, where travel_time is the median calculated travel time between from_id and to_id or numpy.nan if no connection with the given parameters was found. If non-default percentiles were requested: one or more columns travel_time_p{:02d} representing the particular percentile of travel time.

Return type

pandas.DataFrame