aequilibrae.transit#
- class aequilibrae.transit.Transit(project)[source]#
- build_pt_preload(start: int, end: int, inclusion_cond: str = 'start') DataFrame[source]#
Builds a preload vector for the transit network over the specified time period
- Arguments:
start (
int): The start of the period for which to check pt schedules (seconds from midnight)end (
int): The end of the period for which to check pt schedules, (seconds from midnight)inclusion_cond (
str): Specifies condition with which to include/exclude pt trips from the preload.- Returns:
preloads (
pd.DataFrame): A DataFrame of preload from transit vehicles that can be directly used in an assignment
>>> project = create_example(project_path, "coquimbo") >>> project.network.build_graphs() >>> start = int(6.5 * 60 * 60) # 6:30 am >>> end = int(8.5 * 60 * 60) # 8:30 am >>> transit = Transit(project) >>> preload = transit.build_pt_preload(start, end) >>> project.close()
- create_graph(**kwargs) TransitGraphBuilder[source]#
Create a transit graph from an existing GTFS import.
All arguments are forwarded to ‘TransitGraphBuilder’.
A ‘period_id’ may be specified to select a time period. By default, a whole day is used. See ‘project.network.Periods’ for more details.
- load(period_ids: List[int] = None)[source]#
Load the previously saved transit graphs from the ‘public_transport.sqlite’ database. Loading may be filtered by ‘period_id’.
- Arguments:
period_ids (
int): List of periods of to load. Defaults to all available graph configurations.
- new_gtfs_builder(agency, file_path, day='', description='') GTFSRouteSystemBuilder[source]#
Returns a
GTFSRouteSystemBuilderobject 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’)- Returns:
gtfs_feed (
StaticGTFS): A GTFS feed that can be added to this network
- remove_graphs(period_ids: List[int], unload: bool = False)[source]#
Remove the previously saved transit graphs from the ‘public_transport.sqlite’ database. Removing may be filtered by ‘period_id’.
- Arguments:
period_ids (
int): List of periods of to save. unload (bool): Also unload the graph.
- save_graphs(period_ids: List[int] = None, force: bool = False)[source]#
Save the previously build transit graphs to the ‘public_transport.sqlite’ database. Saving may be filtered by ‘period_id’.
- Arguments:
- period_ids (
int): List of periods of to save. Defaults to ‘project.network.periods.default_period.period_id’.
force (
bool): Remove the existing graphs before saving the ‘period_ids’ graphs. Default ‘False’.- period_ids (
- 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]}#
- default_pces = {'other': 2.0, 0: 5.0, 1: 5.0, 11: 3.0, 3: 4.0, 5: 4.0}#
- graphs: Dict[str, TransitGraph] = {}#
- pt_con: Connection#
- transit = <aequilibrae.utils.python_signal.PythonSignal object>#
- class aequilibrae.transit.TransitGraphBuilder(project, period_id: int = 1, time_margin: int = 0, projected_crs: str = 'EPSG:3857', num_threads: int = -1, seed: int = None, geometry_noise: bool = None, noise_coef: float = None, 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]#
Graph builder for the transit assignment Spiess & Florian algorithm.
- Arguments:
public_transport_conn (
sqlite3.Connection): Connection to thepublic_transport.sqlitedatabase.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 to0.projected_crs (
str): Projected CRS of the network, intended for more accurate distance calculations. Defaults toEPSG:3857, Spherical Mercator.num_threads (
int): Number of threads to be used where possible. Defaults to-1(using all available threads).seed (
int): Deprecated. No longer in use.geometry_noise (
bool): Deprecated. No longer in use.noise_coef (
float): Deprecated. No longer in use.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-1for unlimited.
- classmethod from_db(project, 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:
project (
Project): AequilbraE project to use.period_id (
int): Period ID to use.
- static remove_config(conn: Connection, period_id: int)[source]#
Remove a transit graph configuration from the project database specified by it’s period_id.
- Arguments:
conn (
sqlite3.Connection): Connection to theproject.sqlitedatabase.period_id (
int): period_id key for the transit_graph_configs table.
- static remove_edges(pt_conn: Connection, period_id: int)[source]#
Remove a transit graph’s edges from the public transport database specified by it’s period_id.
- Arguments:
pt_conn (
sqlite3.Connection): Connection to thepublic_transport.sqlitedatabase.period_id (
int): period_id to remove.
- static remove_vertices(pt_conn: Connection, period_id: int)[source]#
Remove a transit graph’s vertices from the public transport database specified by it’s period_id.
- Arguments:
pt_conn (
sqlite3.Connection): Connection to thepublic_transport.sqlitedatabase.period_id (
int):period_idto remove.
- add_zones(zones, from_crs: str = 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 inself.projected_crs. If provided, the geometry will be projected toself.projected_crs. Defaults toNone.
- 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 correspondingnode_id’s.
- create_additional_db_fields(conn: Connection = None)[source]#
Create the additional required entries in the tables.
- Arguments:
pt_conn (
sqlite.Connection): Optional PT connection to use
- 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.
- create_od_node_mapping()[source]#
Build a dataframe mapping the centroid node ids with to transport assignment zone ids.
- save(robust=True, pt_conn: Connection = None, project_conn: Connection = None)[source]#
Save the current graph to the public transport database.
- Arguments:
robust (
bool): Deprecated. No longer in use.pt_conn (
sqlite.Connection): Optional PT connection to useproject_conn (
sqlite.Connection): Optional project connection to use
- save_edges(recreate_line_geometry=False, conn: Connection = None)[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.pt_conn (
sqlite.Connection): Optional PT connection to use
- save_vertices(robust=None, conn: Connection = None)[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=Trueto move the nodes slightly.- Arguments:
robust (
bool): Deprecated. No longer in use.pt_conn (
sqlite.Connection): Optional PT connection to use
- to_transit_graph() TransitGraph[source]#
Create an AequilibraE
TransitGraphobject from an SF graph builder.
- property config#
Modules
Create the graph used by public transport assignment algorithms. |