aequilibrae.transit package#

Subpackages#

Submodules#

aequilibrae.transit.column_order module#

aequilibrae.transit.constants module#

class aequilibrae.transit.constants.Constants[source]#

Bases: object

agencies: Dict[str, Any] = {'agencies': 2}#
srid: Dict[int, int] = {}#
routes: Dict[int, int] = {1: 10001000000, 2: 20001000000}#
trips: Dict[int, int] = {10001001000: 10001001182, 10001003000: 10001003178, 20001001000: 20001001182, 20001003000: 20001003178}#
patterns: Dict[int, int] = {}#
pattern_lookup: Dict[int, int] = {'172b08ba1404ede11f347176b0a1cf8a': 20001001000, '2cb8df61c0cb7940b29c4bc20b1297f3': 20001003000}#
stops: Dict[int, int] = {1: 10000000532, 2: 20000000532}#
fares: Dict[int, int] = {}#

aequilibrae.transit.date_tools module#

aequilibrae.transit.date_tools.to_seconds(value: str | None) int | Any[source]#
aequilibrae.transit.date_tools.to_time_string(value: int | None) str | None[source]#
aequilibrae.transit.date_tools.one_day_before(date_object)[source]#
aequilibrae.transit.date_tools.create_days_between(range_start_date, range_end_date)[source]#
aequilibrae.transit.date_tools.day_of_week(date: str)[source]#
aequilibrae.transit.date_tools.format_date(date: str) str[source]#

aequilibrae.transit.gtfs_loader module#

class aequilibrae.transit.gtfs_loader.GTFSReader[source]#

Bases: WorkerThread

Loader for GTFS data. Not meant to be used directly by the user

signal#
logger = <Logger GTFS Reader (WARNING)>#
set_feed_path(file_path)[source]#

Sets GTFS feed source to be used

Arguments:

file_path (str): Full path to the GTFS feed (e.g. ‘D:/project/my_gtfs_feed.zip’)

load_data(service_date: str)[source]#

Loads the data for a respective service date.

Arguments:

service_date (str): service date. e.g. “2020-04-01”.

finished()[source]#

finished(self) [signal]

aequilibrae.transit.lib_gtfs module#

class aequilibrae.transit.lib_gtfs.GTFSRouteSystemBuilder(network, agency_identifier, file_path, day='', description='', capacities={})[source]#

Bases: WorkerThread

Container for GTFS feeds providing data retrieval for the importer

signal#
set_capacities(capacities: dict)[source]#

Sets default capacities for modes/vehicles.

Arguments:
capacities (dict): Dictionary with GTFS types as keys, each with a list

of 3 items for values for capacities: seated and total i.e. -> “{0: [150, 300],…}”

set_maximum_speeds(max_speeds: DataFrame)[source]#

Sets the maximum speeds to be enforced at segments.

Arguments:

max_speeds (pd.DataFrame): Requires 4 fields: mode, min_distance, max_distance, speed. Modes not covered in the data will not be touched and distance brackets not covered will receive the maximum speed, with a warning

dates_available() list[source]#

Returns a list of all dates available for this feed.

Returns:

feed dates (list): list of all dates available for this feed

set_allow_map_match(allow=True)[source]#

Changes behavior for finding transit-link shapes. Defaults to True.

Arguments:

allow (bool optional): If True, allows uses map-matching in search of precise transit_link shapes. If False, sets transit_link shapes equal to straight lines between stops. In the presence of GTFS raw shapes it has no effect.

map_match(route_types=[3]) None[source]#

Performs map-matching for all routes of one or more types.

Defaults to map-matching Bus routes (type 3) only.

For a reference of route types, see https://developers.google.com/transit/gtfs/reference#routestxt

Arguments:

route_types (List[int] or Tuple[int]): Default is [3], for bus only

set_agency_identifier(agency_id: str) None[source]#

Adds agency ID to this GTFS for use on import.

Arguments:

agency_id (str): ID for the agency this feed refers to (e.g. ‘CTA’)

set_feed(feed_path: str) None[source]#

Sets GTFS feed source to be used.

Arguments:

file_path (str): Full path to the GTFS feed (e.g. ‘D:/project/my_gtfs_feed.zip’)

set_description(description: str) None[source]#

Adds description to be added to the imported layers metadata

Arguments:

description (str): Description for this feed (e.g. ‘CTA2019 fixed by John Doe after strong coffee’)

set_date(service_date: str) None[source]#

Sets the date for import without doing any of data processing, which is left for the importer

load_date(service_date: str) None[source]#

Loads the transit services available for service_date

Arguments:

service_date (str): Service data contained in this field to be imported (e.g. ‘2019-10-04’)

doWork()[source]#

Alias for execute_import

execute_import()[source]#
save_to_disk()[source]#

Saves all transit elements built in memory to disk

finished()[source]#

finished(self) [signal]

Build the graph for links for a certain mode while splitting the closest links at stops’ projection

Arguments:

mode_id (int): Mode ID for which we will build the graph for

aequilibrae.transit.map_matching_graph module#

class aequilibrae.transit.map_matching_graph.MMGraph(lib_gtfs, mtmm)[source]#

Bases: WorkerThread

Build specialized map-matching graphs. Not designed to be used by the final user

signal#
build_graph_with_broken_stops(mode_id: int, distance_to_project=200)[source]#

Build the graph for links for a certain mode while splitting the closest links at stops’ projection

Arguments:

mode_id (int): Mode ID for which we will build the graph for distance_to_project (float, Optional): Radius search for links to break at the stops. Defaults to 50m

connect_node(stop) None[source]#
finished()[source]#

finished(self) [signal]

aequilibrae.transit.parse_csv module#

aequilibrae.transit.parse_csv.parse_csv(file_name: str, column_order=[])[source]#
class aequilibrae.transit.parse_csv.empty[source]#

Bases: object

shape = [0]#

aequilibrae.transit.route_system module#

class aequilibrae.transit.route_system.RouteSystem(database_path)[source]#

Bases: object

load_route_system()[source]#
write_GTFS(path_to_folder: str)[source]#

aequilibrae.transit.transit module#

class aequilibrae.transit.transit.Transit(project)[source]#

Bases: object

default_capacities = {'other': [30, 60], 0: [150, 300], 1: [280, 560], 11: [30, 60], 12: [50, 100], 2: [700, 700], 3: [30, 60], 4: [400, 800], 5: [20, 40]}#
graphs: Dict[str, TransitGraph] = {1: <aequilibrae.transit.transit_graph_builder.TransitGraphBuilder object>}#
pt_con: Connection#
new_gtfs_builder(agency, file_path, day='', description='') GTFSRouteSystemBuilder[source]#

Returns a GTFSRouteSystemBuilder object compatible with the project

Arguments:

agency (str): Name for the agency this feed refers to (e.g. ‘CTA’)

file_path (str): Full path to the GTFS feed (e.g. ‘D:/project/my_gtfs_feed.zip’)

day (str, Optional): Service data contained in this field to be imported (e.g. ‘2019-10-04’)

description (str, Optional): Description for this feed (e.g. ‘CTA2019 fixed by John Doe’)

Return:

gtfs_feed (StaticGTFS): A GTFS feed that can be added to this network

create_transit_database()[source]#

Creates the public transport database

create_graph(**kwargs) TransitGraphBuilder[source]#
save_graphs(period_ids: List[int] | None = None)[source]#
load(period_ids: List[int] | None = None)[source]#

aequilibrae.transit.transit_graph_builder module#

Create the graph used by public transport assignment algorithms.

Naming Conventions: - a_node/b_node is head/tail vertex

TransitGraphBuilder Assumtions: - opposite directions are not supported. In the GTFS files, this corresponds to direction_id from trips.txt (indicates the direction of travel for a trip), - all times are expressed in seconds [s], all frequencies in [1/s], and - headways are uniform for trips of the same pattern.

aequilibrae.transit.transit_graph_builder.shift_duplicate_geometry(df, shift=1e-05)[source]#

Shift stacked geometry by some fraction of shift vertically.

class aequilibrae.transit.transit_graph_builder.TransitGraphBuilder(public_transport_conn, period_id: int = 1, time_margin: int = 0, projected_crs: str = 'EPSG:3857', num_threads: int = -1, seed: int = 124, geometry_noise: bool = True, noise_coef: float = 1e-05, with_inner_stop_transfers: bool = False, with_outer_stop_transfers: bool = False, with_walking_edges: bool = True, distance_upper_bound: float = inf, blocking_centroid_flows: bool = True, connector_method: str = 'nearest_neighbour', max_connectors_per_zone: int = -1)[source]#

Bases: object

Graph builder for the transit assignment Spiess & Florian algorithm.

Arguments:

public_transport_conn (sqlite3.Connection): Connection to the public_transport.sqlite database.

period_id (int): Period id for the period to be used. Preferred over start and end.

time_margin (int): Time margin, extends the start and end times by time_margin ([start, end] becomes [start - time_margin, end + time_margin]), in order to include more trips when computing mean values. Defaults to 0.

projected_crs (str): Projected CRS of the network, intended for more accurate distance calculations. Defaults to "EPSG:3857", Spherical Mercator.

num_threads (int): Number of threads to be used where possible. Defaults to -1, using all available threads.

seed (int): Seed for self.rng. Defaults to 124.

geometry_noise (bool): Whether to use noise in geometry creation, in order to avoid colocated nodes. Defaults to True.

noise_coef (float): Scaling factor of the noise. Defaults to 1.0e-5.

with_inner_stop_transfers (bool): Whether to create transfer edges within parent stations. Defaults to False.

with_outer_stop_transfers (bool): Whether to create transfer edges between parent stations. Defaults to False.

with_walking_edges (bool): Whether to create walking edges between distinct stops of each station. Defaults to True.

distance_upper_bound (float): Upper bound on connector distance. Defaults to np.inf.

blocking_centroid_flows (bool): Whether to block flow through centroids. Defaults to True.

max_connectors_per_zone (int): Maximum connectors per zone. Defaults to -1 for unlimited.

add_zones(zones, from_crs: str | None = None)[source]#

Add zones as ODs.

Arguments:

zones (pd.DataFrame): Dataframe containing the zoning information. Columns must include zone_id and geometry.

from_crs (str): The CRS of the geometry column of zones. If not provided it’s assumed that the geometry is already in self.projected_crs. If provided, the geometry will be projected to self.projected_crs. Defaults to None.

create_od_node_mapping()[source]#

Build a dataframe mapping the centroid node ids with to transport assignment zone ids.

create_graph()[source]#

Create the SF transit graph (vertices and edges).

create_line_geometry(method='direct', graph='w')[source]#

Create the LineString for each edge.

The direct method creates a straight line between all points.

The connect project match method uses the existing line geometry within the project to create more accurate line strings. It creates a line string that matches the path between the shortest path between the project nodes closest to either end of the access and egress connectors.

Project graphs must be built for the “connector project match” method.

Arguments:

method (str): Must be either “direct” or “connector project match”. If method is “direct”, graph argument is ignored. graph (str): Must be a key within project.network.graphs.

create_additional_db_fields()[source]#

Create the additional required entries in the tables.

save_vertices(robust=True)[source]#

Write the vertices DataFrame to the public transport database.

Within the database nodes may not exist at the exact same point in space, provide robust=True to move the nodes slightly.

Arguments:

robust (bool): Whether to move stack nodes slightly before saving. Defaults to True.

save_edges(recreate_line_geometry=False)[source]#

Save the contents of self.edges to the public transport database.

If no geometry for the edges is present or recreate_line_geometry is True, direct lines will be created.

Arguments:

recreate_line_geometry (bool): Whether to recreate the line strings for the edges as direct lines. Defaults to False.

save_config()[source]#
save(robust=True)[source]#

Save the current graph to the public transport database.

Arguments:

recreate_line_geometry (bool): Whether to recreate the line strings for the edges as direct lines. Defaults to False.

to_transit_graph() TransitGraph[source]#

Create an AequilibraE (TransitGraph) object from an SF graph builder.

classmethod from_db(public_transport_conn, period_id: int, **kwargs)[source]#

Create a SF graph instance from an existing database save.

Assumes the database was constructed with the provided save methods. No checks are performed to see if the provided arguments are compatible with the saved graph.

All arguments are forwarded to the constructor.

Arguments:

public_transport_conn (sqlite3.Connection): Connection to the public_transport.sqlite database.

convert_demand_matrix_from_zone_to_node_ids(demand_matrix, o_zone_col='origin_zone_id', d_zone_col='destination_zone', demand_col='demand')[source]#

Convert a sparse demand matrix from ``zone_id``s to the corresponding ``node_id``s.

property config#

Module contents#