Reference#

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

Compute travel times between many origins and destinations.

r5py.TravelTimeMatrix are child classes of pandas.DataFrame and support all of their methods and properties, see https://pandas.pydata.org/docs/

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

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

Compute travel times between many origins and destinations.

r5py.DetailedItineraries are child classes of geopandas.GeoDataFrame and support all of their methods and properties, see https://geopandas.org/en/stable/docs.html

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, DetailedItineraries finds routes between pairs of origins and destinations, i.e., it routes from origin #1 to destination #1, origin #2 to destination #2, … . Set force_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 Note that not all arguments might make sense in this context, and the underlying R5 engine might ignore some of them.

class r5py.Isochrones(transport_network, origins, isochrones=TimedeltaIndex(['0 days 00:00:00', '0 days 00:15:00', '0 days 00:30:00', '0 days 00:45:00', '0 days 01:00:00'], dtype='timedelta64[ns]', freq='15min'), point_grid_resolution=100, point_grid_sample_ratio=1.0, **kwargs)#

Compute polygons of equal travel time from one or more destinations.

r5py.Isochrones are child classes of geopandas.GeoDataFrame and support all of their methods and properties, see https://geopandas.org/en/stable/docs.html

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 | shapely.Point) – Place(s) to find a route _from_ Must be/have a point geometry. If multiple origin points are passed, isochrones will be computed as minimum travel time from any of them.

  • isochrones (pandas.TimedeltaIndex | collections.abc.Iterable[int]) – For which interval to compute isochrone polygons. An iterable of integers is interpreted as minutes.

  • point_grid_resolution (int) – Distance in meters between points in the regular grid of points laid over the transport network’s extent that is used to compute isochrones. Increase this value for performance, decrease it for precision.

  • point_grid_sample_ratio (float) – Share of points of the point grid that are used in computation, ranging from 0.01 to 1.0. Increase this value for performance, decrease it for precision.

  • **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 Note that not all arguments might make sense in this context, and the underlying R5 engine might ignore some of them. If percentiles are specified, the lowest one will be used for isochrone computation.

property destinations#

A regular grid of points covering the range of the chosen transport mode.

property isochrones#

Compute isochrones for these travel times.

pandas.TimedeltaIndex | collections.abc.Iterable[int] An iterable of integers is interpreted as minutes.

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

Load a transport network.

Parameters:
property extent#

The geographic area covered, as a shapely.box.

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.RegionalTask(transport_network, origin=None, destinations=None, departure=datetime.datetime(2025, 3, 12, 11, 19, 43, 269708), departure_time_window=datetime.timedelta(seconds=600), percentiles=[50], transport_modes=[TransportMode.TRANSIT], access_modes=[TransportMode.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., TravelTimeMatrix or AccessibilityEstimator.

In r5py, there is usually no need to explicitely create a RegionalTask. Rather, the constructors to the computation classes (TravelTimeMatrix, 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=<not given>, *values, 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.r5.BreakdownStat(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#

Statistical functions to apply to detailed routing results summary.

BreakdownStat.MEAN, BreakdownStat.MINIMUM

class r5py.r5.TripPlanner(transport_network, request)#

Find detailed routes between two points.

Parameters:
  • transport_network (r5py.r5.TransportNetwork) – A transport network to route on

  • request (r5py.r5.regional_task) – The parameters that should be used when finding a route

property direct_paths#

Detailed routes between two points using direct modes.

Returns:

Detailed routes that meet the requested parameters, using direct modes (walking, cycling, driving).

Return type:

list[r5py.r5.Trip]

property transit_paths#

Detailed routes between two points on public transport.

Returns:

Detailed routes that meet the requested parameters, on public transport.

Return type:

list[r5py.r5.Trip]

property trips#

Detailed routes between two points.

Returns:

Detailed routes that meet the requested parameters

Return type:

list[r5py.r5.Trip]

class r5py.r5.Trip(legs=[])#

Represent one trip, consisting of one of more r5py.r5.TripLeg.

Parameters:

legs (collections.abc.Iterable) – optional list of trip legs with which to initialise this trip

as_table()#

Return a table (list of lists) of this trip’s legs.

Returns:

listsegment, transport_mode, departure_time, distance, travel_time, wait_time, feed, agency_id, route_id, start_stop_id, end_stop_id, geometry

Return type:

detailed information about this trip and its legs (segments):

property distance#

Overall distance of this trip in metres (float).

property geometry#

Joined geometries of all legs of this trip (shapely.LineString or shapely.MultiLineString).

property route_ids#

The public transport route(s) used on this trip.

property transport_modes#

The transport mode(s) used on this trip.

property travel_time#

Overall travel_time of this trip (datetime.timedelta).

property wait_time#

Overall wait_time of this trip (datetime.timedelta).

class r5py.r5.DirectLeg(transport_mode, street_segment)#

Represent one leg of a public transport trip.

Parameters:
  • transport_mode (r5py.TransportMode) – mode of transport this trip leg was travelled

  • street_segment (com.conveyal.r5.profile.StreetSegment) – the leg’s data as output by R5’s StreetRouter

as_table_row()#

Return a table row (list) of this trip leg’s details.

Returns:

listdeparture_time, distance, travel_time, wait_time, feed, agency_id route_id, start_stop_id, end_stop_id, geometry

Return type:

detailed information about this trip leg: transport_mode,

class r5py.r5.TransitLeg(transport_mode=None, departure_time=np.datetime64('NaT'), distance=None, travel_time=datetime.timedelta(0), wait_time=datetime.timedelta(0), feed=None, agency_id=None, route_id=None, start_stop_id=None, end_stop_id=None, geometry=<LINESTRING EMPTY>)#

Represent one leg of a trip.

This is a base class, use one of the more specific classes, e.g., TransitLeg, or DirectLeg

Parameters:
  • transport_mode (r5py.TransportMode) – mode of transport this trip leg was travelled

  • departure_time (datetime.datetime) – departure time of this trip leg

  • distance (float) – distance covered by this trip leg, in metres

  • travel_time (datetime.timedelta) – time spent travelling on this trip leg

  • wait_time (datetime.timedelta) – time spent waiting for a connection on this trip leg

  • feed (str) – the GTFS feed identifier used for this trip leg

  • agency_id (str) – the GTFS id the agency used for this trip leg

  • route_id (str) – the GTFS id of the public transport route used for this trip leg

  • start_stop_id (str) – the GTFS stop_id of the boarding stop used for this trip leg

  • end_stop_id (str) – the GTFS stop_id of the aligning stop used for this trip leg

  • geometry (shapely.LineString) – spatial representation of this trip leg

as_table_row()#

Return a table row (list) of this trip leg’s details.

Returns:

listdeparture_time, distance, travel_time, wait_time, feed, agency_id route_id, start_stop_id, end_stop_id, geometry

Return type:

detailed information about this trip leg: transport_mode,

class r5py.r5.AccessLeg(transport_mode, street_segment)#

Represent one leg of a public transport trip.

Parameters:
  • transport_mode (r5py.TransportMode) – mode of transport this trip leg was travelled

  • street_segment (com.conveyal.r5.profile.StreetSegment) – the leg’s data as output by R5’s StreetRouter

as_table_row()#

Return a table row (list) of this trip leg’s details.

Returns:

listdeparture_time, distance, travel_time, wait_time, feed, agency_id route_id, start_stop_id, end_stop_id, geometry

Return type:

detailed information about this trip leg: transport_mode,

class r5py.r5.TransferLeg(transport_mode, street_segment)#

Represent one leg of a public transport trip.

Parameters:
  • transport_mode (r5py.TransportMode) – mode of transport this trip leg was travelled

  • street_segment (com.conveyal.r5.profile.StreetSegment) – the leg’s data as output by R5’s StreetRouter

as_table_row()#

Return a table row (list) of this trip leg’s details.

Returns:

listdeparture_time, distance, travel_time, wait_time, feed, agency_id route_id, start_stop_id, end_stop_id, geometry

Return type:

detailed information about this trip leg: transport_mode,

class r5py.r5.EgressLeg(transport_mode, street_segment)#

Represent one leg of a public transport trip.

Parameters:
  • transport_mode (r5py.TransportMode) – mode of transport this trip leg was travelled

  • street_segment (com.conveyal.r5.profile.StreetSegment) – the leg’s data as output by R5’s StreetRouter

as_table_row()#

Return a table row (list) of this trip leg’s details.

Returns:

listdeparture_time, distance, travel_time, wait_time, feed, agency_id route_id, start_stop_id, end_stop_id, geometry

Return type:

detailed information about this trip leg: transport_mode,

class r5py.util.Config#

Load configuration from config files or command line arguments.

property CACHE_DIR#

Save persistent cache files into this directory.

property CONFIG_FILES#

List locations of potential configuration files.

property TEMP_DIR#

Save temporary files to this directory.

read-only property, use command-line option –temporary-directory to change.

property argparser#

Return a singleton instance of a configargparse.ArgumentParser.

property arguments#

Arguments passed from command line or config file.

Ignores –help: can be used while not all modules have added arguments.

get_arguments(ignore_help_args=False)#

Parse arguments passed from command line or config file.

util.start_jvm()#

Start a Java Virtual Machine (JVM) if none is running already.

Takes into account the –max-memory and –verbose command line and configuration options.