Reference

Python wrapper for R5.

class r5py.BreakdownStat

Statistical functions to apply to detailed routing results summary.

BreakdownStat.MEAN, BreakdownStat.MINIMUM

class r5py.LegMode

Transport modes (a superset of r5py.StreetMode).

LegMode.WALK, LegMode.BICYCLE, LegMode.CAR, LegMode.BICYCLE_RENT, LegMode.CAR_PARK

class r5py.RegionalTask(transport_network, origin, destinations, departure=datetime.datetime(2022, 9, 9, 6, 46, 59, 206226), departure_time_window=datetime.timedelta(seconds=3600), percentiles=[50], transport_modes=[<TransitMode.TRANSIT: <java object 'com.conveyal.r5.api.util.TransitModes'>>], access_modes=[<LegMode.WALK: <java object 'com.conveyal.r5.api.util.LegMode'>>], 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: 1 hour

  • 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.TransitMode | r5py.LegMode]) – The mode of transport to use for routing. Default: [r5py.TransitMode.TRANSIT] (all public transport)

  • access_modes (list[r5py.LegMode]) – Mode of transport to public transport stops. Default: [r5py.LegMode.WALK]

  • egress_modes (list[r5py.LegMode]) – 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.LegMode).

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).

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.LegMode).

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.TransitMode | r5py.LegMode])

class r5py.TransitMode

Public transport modes.

LegMode.AIR, LegMode.TRAM, LegMode.SUBWAY, LegMode.RAIL, LegMode.BUS, LegMode.FERRY, LegMode.CABLE_CAR, LegMode.GONDOLA, LegMode.FUNICULAR, LegMode.TRANSIT

LegMode.TRANSIT is a shorthand of all of the others combined.

class r5py.TransportNetwork(osm_pbf, gtfs=[], build_config={})

Load a transport network.

Parameters
  • osm_pbf (str) – file path of an OpenStreetMap extract in PBF format

  • gtfs (list[str]) – paths to public transport schedule information in GTFS format

  • build_json (dict) – options accepted by TNBuilderConfig (including SpeedConfig)

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.

property street_layer

Expose the TransportNetwork’s streetLayer to Python.

property timezone

Determine the timezone of the GTFS data.

class r5py.TravelTimeMatrixComputer(transport_network, origins, destinations=None, breakdown=False, breakdown_stat=<BreakdownStat.MEAN: <java object 'com.conveyal.r5.analyst.cluster.PathResult.Stat'>>, **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

  • breakdown (bool) – Return a more detailed breakdown of the routing results. Default: False

  • breakdown_stat (r5py.BreakdownStat) – Summarise the values of the detailed breakdown using this statistical function. Default: r5py.BreakdownStat.MEAN

  • **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, breakdown

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. If breakdown=True: in addition to the columns above routes, board_stops, alight_stops, ride_times, access_time, egress_time, transfer_time, wait_times, total_time, n_iterations.

Return type

pandas.DataFrame