aequilibrae.project package#

Subpackages#

Submodules#

aequilibrae.project.about module#

class aequilibrae.project.about.About(project)[source]#

Bases: object

Provides an interface for querying and editing the about table of an AequilibraE project

>>> from aequilibrae import Project

>>> project = Project.from_path("/tmp/test_project")

# 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()
create()[source]#

Creates the ‘about’ table for project files that did not previously contain it

list_fields() list[source]#

Returns a list of all characteristics the about table holds

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)

>>> from aequilibrae import Project

>>> p = Project.from_path("/tmp/test_project")
>>> p.about.add_info_field('a_cool_field')
>>> p.about.a_cool_field = 'super relevant information'
>>> p.about.write_back()
write_back()[source]#

Saves the information parameters back to the project database

>>> from aequilibrae import Project

>>> p = Project.from_path("/tmp/test_project")
>>> p.about.description = 'This is the example project. Do not use for forecast'
>>> p.about.write_back()

aequilibrae.project.basic_table module#

class aequilibrae.project.basic_table.BasicTable(project)[source]#

Bases: object

Basic resources used by all subclasses

extent() Polygon[source]#

Queries the extent of the layer included in the model

Returns:

Shapely polygon with the bounding box of the layer.

Return type:

model extent (Polygon)

property fields: FieldEditor#

Returns a FieldEditor class instance to edit the zones table fields and their metadata

aequilibrae.project.data_loader module#

class aequilibrae.project.data_loader.DataLoader(path_to_file: PathLike, table_name: str)[source]#

Bases: object

load_table() DataFrame[source]#

aequilibrae.project.database_connection module#

aequilibrae.project.database_connection.database_connection(db_type: str, project_path=None) Connection[source]#

aequilibrae.project.field_editor module#

class aequilibrae.project.field_editor.FieldEditor(project, table_name: str)[source]#

Bases: object

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:

>>> from aequilibrae import Project

>>> proj = Project.from_path("/tmp/test_project")

# To edit the fields of the link_types table
>>> lt_fields = proj.network.link_types.fields

# To edit the fields of the modes table
>>> m_fields = proj.network.modes.fields

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 name description (str): Description of the field to be inserted in the metadata data_type (str, optional): Valid SQLite Data type. Default: “NUMERIC”

remove(field_name: str) None[source]#
save() None[source]#

Saves any field descriptions which my have been changed to the database

all_fields() List[str][source]#

Returns the list of fields available in the database

aequilibrae.project.project module#

class aequilibrae.project.project.Project[source]#

Bases: object

AequilibraE project class

Create Project#
>>> newfile = Project()
>>> newfile.new('/tmp/new_project')
Open Project#
>>> from aequilibrae.project import Project

>>> existing = Project()
>>> existing.open('/tmp/test_project')

>>> #Let's check some of the project's properties
>>> existing.network.list_modes()
['M', 'T', 'b', 'c', 't', 'w']
>>> existing.network.count_links()
76
>>> existing.network.count_nodes()
24
classmethod from_path(project_folder)[source]#
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.

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

close() None[source]#

Safely closes the project

load(project_path: str) None[source]#

Loads project from disk

Deprecated since version 0.7.0: Use open() instead.

Arguments:

project_path (str): Full path to the project data folder. If the project inside does not exist, it will fail.

connect()[source]#
activate()[source]#
deactivate()[source]#
log() Log[source]#

Returns a log object

allows the user to read the log or clear it

property project_parameters: Parameters#
property parameters: dict#
check_file_indices() None[source]#

Makes results_database.sqlite and the matrices folder compatible with project database

property zoning#

aequilibrae.project.project_cleaning module#

aequilibrae.project.project_cleaning.clean(project)[source]#

aequilibrae.project.project_creation module#

aequilibrae.project.project_creation.initialize_tables(project, db_type: str) None[source]#
aequilibrae.project.project_creation.create_base_tables(conn: Connection, logger: Logger, db_type: str) None[source]#
aequilibrae.project.project_creation.add_triggers(conn: Connection, logger: Logger, db_type: str) None[source]#

Adds consistency triggers to the project

aequilibrae.project.project_creation.remove_triggers(conn: Connection, logger: Logger, db_type: str) None[source]#
aequilibrae.project.project_creation.run_queries_from_sql_file(conn: Connection, logger: Logger, qry_file: str) None[source]#

aequilibrae.project.table_loader module#

class aequilibrae.project.table_loader.TableLoader[source]#

Bases: object

load_table(conn: Connection, table_name: str) List[dict][source]#
load_structure(conn: Connection, table_name: str) None[source]#

aequilibrae.project.zone module#

class aequilibrae.project.zone.Zone(dataset: dict, zoning)[source]#

Bases: SafeClass

Single zone object that can be queried and manipulated in memory

delete()[source]#

Removes the zone from the database

save()[source]#

Saves/Updates the zone data to the database

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 zone robust (Bool, Optional): Moves the centroid location around to avoid node conflict. Defaults to True.

connect_mode(mode_id: str, link_types='', connectors=1, conn: Connection | None = None) 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 computing running the KMeans2 clustering algorithm from SciPy and selecting the nodes closest to each cluster centroid.

When there are no node candidates inside the zone, the search area is progressively expanded until at least one candidate is found.

If fewer candidates than required connectors are found, all candidates are connected.

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 1

disconnect_mode(mode_id: str) None[source]#

Removes centroid connectors for the desired mode from the network file

Arguments:

mode_id (str): Mode ID we are trying to disconnect from this zone

aequilibrae.project.zoning module#

class aequilibrae.project.zoning.Zoning(network)[source]#

Bases: BasicTable

Access to the API resources to manipulate the zones table in the project

>>> from aequilibrae import Project

>>> project = Project.from_path("/tmp/test_project")


>>> zoning = project.zoning

>>> zone_downtown = zoning.get(1)
>>> zone_downtown.population = 637
>>> zone_downtown.employment = 10039
>>> zone_downtown.save()

# changing the value for an existing value/field
>>> project.about.scenario_name = 'Just a better scenario name'
>>> project.about.write_back()

# We can also add one more field to the table
>>> fields = zoning.fields
>>> fields.add('parking_spots', 'Total licensed parking spots', 'INTEGER')
new(zone_id: int) Zone[source]#

Creates a new zone

Returns:

zone (Zone): A new zone object populated only with zone_id (but not saved in the model yet)

create_zoning_layer()[source]#

Creates the ‘zones’ table for project files that did not previously contain it

coverage() Polygon[source]#

Returns a single polygon for the entire zoning coverage

Returns:

model coverage (Polygon): Shapely (Multi)polygon of the zoning system.

get(zone_id: str) Zone[source]#

Get a zone from the model by its zone_id

all_zones() dict[source]#

Returns a dictionary with all Zone objects available in the model. zone_id as key

save()[source]#
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 (Point or LineString): A Shapely geometry object

Return:

zone_id (int): ID of the zone applicable to the point provided

refresh_geo_index()[source]#

Module contents#