aequilibrae.transit package#
Subpackages#
- aequilibrae.transit.functions package
- aequilibrae.transit.gtfs_writer package
- Submodules
- aequilibrae.transit.gtfs_writer.agency_writer module
- aequilibrae.transit.gtfs_writer.fare_writer module
- aequilibrae.transit.gtfs_writer.routes_writer module
- aequilibrae.transit.gtfs_writer.shape_writer module
- aequilibrae.transit.gtfs_writer.stop_times_writer module
- aequilibrae.transit.gtfs_writer.stops_writer module
- aequilibrae.transit.gtfs_writer.trips_writer module
- Module contents
- aequilibrae.transit.route_system_reader package
- Submodules
- aequilibrae.transit.route_system_reader.agency_reader module
- aequilibrae.transit.route_system_reader.pattern_reader module
- aequilibrae.transit.route_system_reader.routes_reader module
- aequilibrae.transit.route_system_reader.stop_reader module
- aequilibrae.transit.route_system_reader.stop_times_reader module
- aequilibrae.transit.route_system_reader.trips_reader module
- Module contents
- aequilibrae.transit.transit_elements package
- Submodules
- aequilibrae.transit.transit_elements.agency module
- aequilibrae.transit.transit_elements.basic_element module
- aequilibrae.transit.transit_elements.fare module
- aequilibrae.transit.transit_elements.fare_rule module
- aequilibrae.transit.transit_elements.link module
- aequilibrae.transit.transit_elements.mode_correspondence module
- aequilibrae.transit.transit_elements.pattern module
- aequilibrae.transit.transit_elements.route module
- aequilibrae.transit.transit_elements.service module
- aequilibrae.transit.transit_elements.stop module
- aequilibrae.transit.transit_elements.trip module
- Module contents
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] = {}#
- links: Dict[int, int] = {}#
- transit_links: Dict[int, int] = {1: 20000156}#
aequilibrae.transit.date_tools module#
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’)
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],…}”
- capacities (
- 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]
orTuple[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
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
aequilibrae.transit.parse_csv module#
aequilibrae.transit.route_system module#
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_graph(**kwargs) TransitGraphBuilder [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 thepublic_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 thestart
andend
times bytime_margin
([start
,end
] becomes [start
-time_margin
,end
+time_margin
]), in order to include more trips when computing mean values. Defaults to0
.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 forself.rng
. Defaults to124
.geometry_noise (
bool
): Whether to use noise in geometry creation, in order to avoid colocated nodes. Defaults toTrue
.noise_coef (
float
): Scaling factor of the noise. Defaults to1.0e-5
.with_inner_stop_transfers (
bool
): Whether to create transfer edges within parent stations. Defaults toFalse
.with_outer_stop_transfers (
bool
): Whether to create transfer edges between parent stations. Defaults toFalse
.with_walking_edges (
bool
): Whether to create walking edges between distinct stops of each station. Defaults toTrue
.distance_upper_bound (
float
): Upper bound on connector distance. Defaults tonp.inf
.blocking_centroid_flows (
bool
): Whether to block flow through centroids. Defaults toTrue
.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 includezone_id
andgeometry
.from_crs (
str
): The CRS of thegeometry
column ofzones
. If not provided it’s assumed that the geometry is already inself.projected_crs
. If provided, the geometry will be projected toself.projected_crs
. Defaults toNone
.
- create_od_node_mapping()[source]#
Build a dataframe mapping the centroid node ids with to transport assignment zone ids.
- 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 withinproject.network.graphs
.
- 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 toTrue
.
- 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 toFalse
.
- 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 toFalse
.
- 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 thepublic_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#