aequilibrae.project#
- class aequilibrae.project.About(project)[source]#
Provides an interface for querying and editing the about table of an AequilibraE project
>>> project = create_example(project_path) # Adding a new field and saving it >>> project.about.add_info_field('my_super_relevant_field') >>> project.about.my_super_relevant_field = 'super relevant information' >>> project.about.write_back() # changing the value for an existing value/field >>> project.about.scenario_name = 'Just a better scenario name' >>> project.about.write_back() >>> project.close()
- add_info_field(info_field: str) None[source]#
Adds new information field to the model
- Arguments:
info_field (
str): Name of the desired information field to be added. Has to be a valid Python VARIABLE name (i.e. letter as first character, no spaces and no special characters)
>>> project = create_example(project_path) >>> project.about.add_info_field('a_cool_field') >>> project.about.a_cool_field = 'super relevant information' >>> project.about.write_back() >>> project.close()
- class aequilibrae.project.FieldEditor(project, table_name: str)[source]#
Allows user to edit the project data tables
The field editor is used for two different purposes:
Managing data tables (adding and removing fields)
Editing the tables’ metadata (description of each field)
This is a general class used to manage all project’s data tables accessible to the user and but it should be accessed directly from within the module corresponding to the data table one wants to edit. Example:
>>> project = create_example(project_path) # To edit the fields of the link_types table >>> lt_fields = project.network.link_types.fields # To edit the fields of the modes table >>> m_fields = project.network.modes.fields >>> project.close()
Field descriptions are kept in the table attributes_documentation
- add(field_name: str, description: str, data_type='NUMERIC') None[source]#
Adds new field to the data table
- Arguments:
field_name (
str): Field to be added to the table. Must be a valid SQLite field namedescription (
str): Description of the field to be inserted in the metadatadata_type (
str, Optional): Valid SQLite Data type. Default: “NUMERIC”
- class aequilibrae.project.Log(project_base_path: Path)[source]#
API entry point to the log file contents
>>> project = Project() >>> project.new(project_path) >>> log = project.log() # We get all entries for the log file >>> entries = log.contents() # Or clear everything (NO UN-DOs) >>> log.clear() >>> project.close()
- class aequilibrae.project.Matrices(project)[source]#
Gateway into the matrices available/recorded in the model
- check_exists(name: str) bool[source]#
Checks whether a matrix with a given name exists
- Returns:
exists (
bool): Does the matrix exist?
- delete_record(matrix_name: str) None[source]#
Deletes a Matrix Record from the model and attempts to remove from disk
- get_matrix(matrix_name: str) AequilibraeMatrix[source]#
Returns an AequilibraE matrix available in the project
Raises an error if matrix does not exist
- Arguments:
matrix_name (
str): Name of the matrix to be loaded- Returns:
matrix (
AequilibraeMatrix): Matrix object
- get_record(matrix_name: str) MatrixRecord[source]#
Returns a model Matrix Record for manipulation in memory
- list() DataFrame[source]#
List of all matrices available
- Returns:
df (
pd.DataFrame): Pandas DataFrame listing all matrices available in the model
- new_record(name: str, file_name: str, matrix=None) MatrixRecord[source]#
Creates a new record for a matrix in disk, but does not save it
If the matrix file is not already on disk, it will fail
- Arguments:
name (
str): Name of the matrixfile_name (
str): Name of the file on disk- Returns:
matrix_record (
MatrixRecord): A matrix record that can be manipulated in memory before saving
- class aequilibrae.project.Network(project)[source]#
Network class. Member of an AequilibraE Project
- build_graphs(fields: list = None, modes: list = None, limit_to_area: Polygon = None) None[source]#
Builds graphs for all modes currently available in the model
When called, it overwrites all graphs previously created and stored in the networks’ dictionary of graphs
- Arguments:
fields (
list, Optional): When working with very large graphs with large number of fields in the database, it may be useful to specify which fields to usemodes (
list, Optional): When working with very large graphs with large number of fields in the database, it may be useful to generate only those we needlimit_to_area (
Polygon, Optional): When working with a very large model area, you may want to filter your database to a small area for your computation, which you can do by providing a polygon. The search is limited to a spatial index search, so it is very fast but NOT PRECISE.
To use the ‘fields’ parameter, a minimalistic option is the following
>>> project = create_example(project_path) >>> fields = ['distance'] >>> project.network.build_graphs(fields, modes = ['c', 'w']) >>> project.close()
- convex_hull() Polygon[source]#
Queries the model for the convex hull of the entire network
- Returns:
model coverage (
Polygon): Shapely (Multi)polygon of the model network.
- count_centroids() int[source]#
Returns the number of centroids in the model
- Returns:
int: Number of centroids
- create_from_gmns(link_file_path: str, node_file_path: str, use_group_path: str = None, geometry_path: str = None, srid: int = 4326) None[source]#
Creates AequilibraE model from links and nodes in GMNS format.
- Arguments:
link_file_path (
str): Path to a links csv file in GMNS formatnode_file_path (
str): Path to a nodes csv file in GMNS formatuse_group_path (
str, Optional): Path to a csv table containing groupings of uses. This helps AequilibraE know when a GMNS use is actually a group of other GMNS usesgeometry_path (
str, Optional): Path to a csv file containing geometry information for a line object, if not specified in the link tablesrid (
int, Optional): Spatial Reference ID in which the GMNS geometries were created
- create_from_osm(model_area: Polygon | None = None, place_name: str | None = None, modes=('car', 'transit', 'bicycle', 'walk'), clean=True) None[source]#
Downloads the network from OpenStreetMap (OSM)
- Arguments:
area (
Polygon, Optional): Polygon for which the network will be downloaded. If not provided, a place name would be requiredplace_name (
str, Optional): If not downloading with East-West-North-South boundingbox, this is requiredmodes (
tuple, Optional): List of all modes to be downloaded. Defaults to the modes in the parameter fileclean (
bool, Optional): Keeps only the links that intersects the model area polygon. Defaults toTrue. Does not apply to networks downloaded with a place name
>>> project = Project() >>> project.new(project_path) # Now we can import the network for any place we want >>> project.network.create_from_osm(place_name="my_beautiful_hometown") >>> project.close()
- export_to_gmns(path: str)[source]#
Exports AequilibraE network to csv files in GMNS format.
- Arguments:
path (
str): Output folder path.
- extent()[source]#
Queries the extent of the network included in the model
- Returns:
model extent (
Polygon): Shapely polygon with the bounding box of the model network.
- list_modes()[source]#
Returns a list of all the modes in this model
- Returns:
list: List of all modes
- set_time_field(time_field: str) None[source]#
Set the time field for all graphs built in the model
- Arguments:
time_field (
str): Network field with travel time information
- skimmable_fields()[source]#
Returns a list of all fields that can be skimmed
- Returns:
list: List of all fields that can be skimmed
- protected_fields = ['ogc_fid', 'geometry']#
- req_link_flds = ['link_id', 'a_node', 'b_node', 'direction', 'distance', 'modes', 'link_type']#
- req_node_flds = ['node_id', 'is_centroid']#
- signal = <aequilibrae.utils.python_signal.PythonSignal object>#
- class aequilibrae.project.NetworkSimplifier(project=None)[source]#
- collapse_links_into_nodes(links: List[int])[source]#
Collapses links into nodes, adjusting the network in the neighborhood.
- Arguments:
links (
List[int]): List containing link IDs to be collapsed.
- rebuild_network()[source]#
Rebuilds the network elements that would have to be rebuilt after massive network simplification
- simplify(graph: Graph, max_speed_ratio: float = 1.1)[source]#
Simplifies the network by merging links that are shorter than a given threshold
- Arguments:
graph (
Graph): AequilibraE graphmax_speed_ratio (
float, Optional): Maximum ratio between the fastest and slowest speed for a link to be considered for simplification.
- signal = <aequilibrae.utils.python_signal.PythonSignal object>#
- class aequilibrae.project.Period(dataset, project)[source]#
A Period object represents a single record in the periods table
>>> project = create_example(project_path, "coquimbo") >>> all_periods = project.network.periods # We can just get one link in specific >>> period1 = all_periods.get(1) # We can find out which fields exist for the period >>> which_fields_do_we_have = period1.data_fields() >>> project.close()
- data_fields() list[source]#
Lists all data fields for the period, as available in the database
- Returns:
data fields (
list): list of all fields available for editing
- class aequilibrae.project.Periods(net)[source]#
Access to the API resources to manipulate the periods table in the network
>>> project = create_example(project_path, "coquimbo") >>> all_periods = project.network.periods # We can just get one link in specific >>> period = all_periods.get(1) # We can save changes for all periods we have edited so far >>> all_periods.save() >>> project.close()
- extent()[source]#
Queries the extent of the layer included in the model
- Returns:
model extent (
Polygon): Shapely polygon with the bounding box of the layer.
- get(period_id: int) Period[source]#
Get a period from the network by its period_id
It raises an error if period_id does not exist
- Arguments:
period_id (
int): Id of a period to retrieve- Returns:
period (
Period): Period object for requested period_id
- new_period(period_id: int, start: int, end: int, description: str = None) Period[source]#
Creates a new period with a given ID
- Arguments:
period_id (
int): Id of the centroid to be createdstart (
int): Start time of the period to be createdend (
int): End time of the period to be createddescription (
str): Optional human readable description of the time period e.g. ‘1pm - 5pm’
- refresh_fields() None[source]#
After adding a field one needs to refresh all the fields recognized by the software
- property data: DataFrame#
Returns all periods data as a Pandas DataFrame
- Returns:
table (
DataFrame): Pandas DataFrame with all the periods
- property fields: FieldEditor#
Returns a FieldEditor class instance to edit the zones table fields and their metadata
- sql = ''#
Query sql for retrieving periods
- class aequilibrae.project.Project[source]#
AequilibraE project class
Create Project#>>> new_project = Project() >>> new_project.new(project_path) # Safely closes the project >>> new_project.close()
Open Project#>>> existing_project = Project() >>> existing_project.open(project_path) >>> existing_project.close()
- check_file_indices() None[source]#
Makes results_database.sqlite and the matrices folder compatible with project database
- clone_scenario(scenario_name: str, description: str = '')[source]#
Clones the active scenario.
- Arguments:
scenario_name (
str): scenario namedescription (
str): useful scenario description
- create_empty_scenario(scenario_name: str, description: str = '')[source]#
Creates an empty scenario, without any links, nodes, and zones.
- Arguments:
scenario_name (
str): scenario namedescription (
str): useful scenario description
- list_scenarios()[source]#
Lists the existing scenarios.
- Returns:
scenarios (
pd.DataFrame): Pandas DataFrame with existing scenarios
- new(project_path: str) None[source]#
Creates a new project
- Arguments:
project_path (
str): Full path to the project data folder. If folder exists, it will fail
- open(project_path: str) None[source]#
Loads project from disk
- Arguments:
project_path (
str): Full path to the project data folder. If the project inside does not exist, it will fail.
- upgrade(ignore_project: bool = False, ignore_transit: bool = False, ignore_results: bool = False)[source]#
Find and apply all applicable migrations.
All database upgrades are applied within a single transaction.
Optionally ignore specific databases. This is useful when a database is known to be incompatible with some migrations but you’d still like to upgrade the others. Take care when ignoring a database. For a particular version of aequilibrae, it is assumed that all migrations have been applied successfully or the project was created with the latest schema, skipping/ignoring migrations will likely lead to issues/broken assumptions.
If skipping a specific migration is required, use the
aequilibrae.project.tools.MigrationManagerobject directly. Consult it’s documentation page for details. Take care when skipping migrations.- Arguments:
- ignore_project (
bool, optional): Ignore the project database. No direct migrations will be applied. Defaults to False.
- ignore_transit (
bool, optional): Ignore the transit database. No direct migrations will be applied. Defaults to False.
- ignore_results (
bool, optional): Ignore the results database. No direct migrations will be applied. Defaults to False.
- ignore_project (
- use_scenario(scenario_name: str)[source]#
Switch the active scenario.
- Arguments:
scenario_name (
str): name of the scenario to be activated
- property db_connection#
- property db_connection_spatial#
- property logger: Logger#
- property parameters: dict#
- property path_to_file#
- property project_base_path#
- property project_parameters: Parameters#
- property results_connection#
- property run#
Load and return the AequilibraE run module with the default arguments from
parameters.ymlpartially applied.Refer to
run/__init__.pyfile within the project folder for documentation.
- property transit_connection#
- property zoning#
- class aequilibrae.project.Scenario(name: str, base_path: Path, path_to_file: Path)[source]#
Represents a modelling scenario within an AequilibraE project.
Each scenario operates independently with its own database and file structure while sharing the overall project configuration.
Scenarios are typically managed through the Project class rather than instantiated directly by users.
The root scenario is special-cased and represents the original project configuration. All other scenarios are stored in subdirectories and reference their own database files.
- base_path: Path#
- logger: Logger#
- name: str#
- path_to_file: Path#
- class aequilibrae.project.Zone(dataset: dict, zoning)[source]#
Single zone object that can be queried and manipulated in memory
- add_centroid(point: Point, robust=True) None[source]#
Adds a centroid to the network file
- Arguments:
point (
Point): Shapely Point corresponding to the desired centroid position. If None, uses the geometric center of the zonerobust (
Bool, Optional): Moves the centroid location around to avoid node conflict. Defaults toTrue.
- connect_mode(mode_id: str, link_types='', connectors=1, conn: Connection | None = None, limit_to_zone=True) None[source]#
Adds centroid connectors for the desired mode to the network file
Centroid connectors are created by connecting the zone centroid to one or more nodes selected from all those that satisfy the mode and link_types criteria and are inside the zone.
The selection of the nodes that will be connected is done simply by searching for the node closest to the zone centroid, or the N closest nodes to the centroid.
If fewer candidates than required connectors are found, all candidates are connected.
- Arguments:
mode_id (
str): Mode ID we are trying to connectlink_types (
str, Optional): String with all the link type IDs that can be considered. eg: yCdR. Defaults to ALL link typesconnectors (
int, Optional): Number of connectors to add. Defaults to 1conn (
sqlite3.Connection, Optional): Connection to the database.limit_to_zone (
bool): Limits the search for nodes inside the zone. Defaults toTrue.
- class aequilibrae.project.Zoning(network)[source]#
Access to the API resources to manipulate the ‘zones’ table in the project
>>> project = create_example(project_path) >>> zoning = project.zoning >>> zone_downtown = zoning.get(1) >>> zone_downtown.population = 637 >>> zone_downtown.employment = 10039 >>> zone_downtown.save() # We can also add one more field to the table >>> fields = zoning.fields >>> fields.add('parking_spots', 'Total licensed parking spots', 'INTEGER') >>> project.close()
- add_centroids(robust=True)[source]#
Adds automatic centroids to the network file. It adds centroids to all zones that do not have one Centroid is added to the geographic centroid of the zone.
- Arguments:
robust (
bool, Optional): Moves the centroid location around to avoid node conflict. Defaults toTrue.
- all_zones() dict[source]#
Returns a dictionary with all Zone objects available in the model, using
zone_idas key
- connect_mode(mode_id: str, link_types='', connectors=1, limit_to_zone=True, bulk: bool = False)[source]#
Adds centroid connectors for the desired mode to the network file
Centroid connectors are created by connecting each zone centroid to one or more nodes selected from all those that satisfy the mode and link_types criteria and are inside the zone.
The selection of the nodes that will be connected is done simply by searching for the node closest to each zone centroid, or the N closest nodes to the centroid.
If fewer candidates than required connectors are found, all candidates are connected.
CENTROIDS THAT ARE CURRENTLY CONNECTED ARE SKIPPED ALTOGETHER
- Arguments:
mode_id (
str): Mode ID we are trying to connect- link_types (
str, Optional): String with all the link type IDs that can be considered. eg: yCdR. Defaults to ALL link types
connectors (
int, Optional): Number of connectors to add. Defaults to 1limit_to_zone (
bool): Limits the search for nodes inside the zone. Defaults toTrue.- bulk (
bool, Optional): Whether to use the bulk connector method or not. This is method is considerably faster for connecting a large amount of centroids but has a high runtime overhead.
- link_types (
- coverage() Polygon[source]#
Returns a single polygon for the entire zoning coverage
- Returns:
model coverage (
Polygon): Shapely (Multi)polygon of the zoning system.
- create_zoning_layer()[source]#
Creates the ‘zones’ table for project files that did not previously contain it
- extent() Polygon#
Queries the extent of the layer included in the model
- Returns:
model extent (
Polygon): Shapely polygon with the bounding box of the layer.
- get_closest_zone(geometry: Point | LineString | MultiLineString) int[source]#
Returns the zone in which the given geometry is located.
If the geometry is not fully enclosed by any zone, the zone closest to the geometry is returned
- Arguments:
geometry (
PointorLineString): A Shapely geometry object- Returns:
zone_id (
int): ID of the zone applicable to the point provided
- new(zone_id: int) Zone[source]#
Creates a new zone
- Returns:
zone (
Zone): A new zone object populated only withzone_id(but not saved in the model yet)
- property data: GeoDataFrame#
Returns all zones data as a Pandas DataFrame
- Returns:
table (
GeoDataFrame): GeoPandas GeoDataFrame with all the nodes
- property fields: FieldEditor#
Returns a FieldEditor class instance to edit the zones table fields and their metadata
Modules