aequilibrae.project.network package#

Subpackages#

Submodules#

aequilibrae.project.network.connector_creation module#

aequilibrae.project.network.connector_creation.connector_creation(geo, zone_id: int, srid: int, mode_id: str, network, link_types='', connectors=1, conn_: Connection | None = None)[source]#

aequilibrae.project.network.gmns_builder module#

class aequilibrae.project.network.gmns_builder.GMNSBuilder(net, link_path: str, node_path: str, uses_path: str | None = None, geom_path: str | None = None, srid: int = 4326)[source]#

Bases: WorkerThread

doWork()[source]#
maybe_transform_srid(srid)[source]#
get_aeq_direction()[source]#
get_ab_lists(direction)[source]#
save_types_to_aeq()[source]#
save_modes_to_aeq()[source]#
correct_geometries()[source]#
save_to_database(links_fields, nodes_fields)[source]#

aequilibrae.project.network.gmns_exporter module#

class aequilibrae.project.network.gmns_exporter.GMNSExporter(net, path)[source]#

Bases: WorkerThread

doWork()[source]#
update_direction_field()[source]#
update_field_names()[source]#

Updates field names according to equivalency between AequilibraE and GMNS fields.

reorder_fields()[source]#
update_modes_fields()[source]#

Updates AequilibraE modes table so it can be exported as a GMNS use_definition table.

aequilibrae.project.network.haversine module#

aequilibrae.project.network.haversine.haversine(lon1, lat1, lon2, lat2)[source]#

Calculate the great circle distance between two points on the earth (specified in decimal degrees)

aequilibrae.project.network.mode module#

class aequilibrae.project.network.mode.Mode(mode_id: str, project)[source]#

Bases: object

A mode object represents a single record in the modes table

save()[source]#

aequilibrae.project.network.modes module#

class aequilibrae.project.network.modes.Modes(net)[source]#

Bases: object

Access to the API resources to manipulate the modes table in the network

>>> from aequilibrae import Project

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

>>> modes = p.network.modes

# We can get a dictionary of all modes in the model
>>> all_modes = modes.all_modes()

# And do a bulk change and save it
>>> for mode_id, mode_obj in all_modes.items():
...     mode_obj.beta = 1
...     mode_obj.save()

# or just get one mode in specific
>>> car_mode = modes.get('c')

# or just get this same mode by name
>>> car_mode = modes.get_by_name('car')

# We can change the description of the mode
>>> car_mode.description = 'personal autos only'

# Let's say we are using alpha to store the PCE for a future year with much smaller cars
>>> car_mode.alpha = 0.95

# To save this mode we can simply
>>> car_mode.save()

# We can also create a completely new mode and add to the model
>>> new_mode = modes.new('k')
>>> new_mode.mode_name = 'flying_car'  # Only ASCII letters and *_* allowed # other fields are not mandatory

# We then explicitly add it to the network
>>> modes.add(new_mode)

# we can even keep editing and save it directly once we have added it to the project
>>> new_mode.description = 'this is my new description'
>>> new_mode.save()
add(mode: Mode) None[source]#

We add a mode to the project

delete(mode_id: str) None[source]#

Removes the mode with mode_id from the project

property fields: FieldEditor#

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

get(mode_id: str) Mode[source]#

Get a mode from the network by its mode_id

get_by_name(mode: str) Mode[source]#

Get a mode from the network by its mode_name

all_modes() dict[source]#

Returns a dictionary with all mode objects available in the model. mode_id as key

new(mode_id: str) Mode[source]#

Returns a new mode with mode_id that can be added to the model later

aequilibrae.project.network.network module#

class aequilibrae.project.network.network.Network(project)[source]#

Bases: WorkerThread

Network class. Member of an AequilibraE Project

netsignal#
req_node_flds = ['node_id', 'is_centroid']#
protected_fields = ['ogc_fid', 'geometry']#
graphs: Dict[Graph]#
skimmable_fields()[source]#

Returns a list of all fields that can be skimmed

Returns:

list: List of all fields that can be skimmed

list_modes()[source]#

Returns a list of all the modes in this model

Returns:

list: List of all modes

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 Open-Street Maps

Arguments:

area (Polygon, Optional): Polygon for which the network will be downloaded. If not provided, a place name would be required

place_name (str, Optional): If not downloading with East-West-North-South boundingbox, this is required

modes (tuple, Optional): List of all modes to be downloaded. Defaults to the modes in the parameter file

clean (bool, Optional): Keeps only the links that intersects the model area polygon. Defaults to True. Does not apply to networks downloaded with a place name

>>> from aequilibrae import Project

>>> p = Project()
>>> p.new("/tmp/new_project")

# We now choose a different overpass endpoint (say a deployment in your local network)
>>> par = Parameters()
>>> par.parameters['osm']['overpass_endpoint'] = "http://192.168.1.234:5678/api"

# Because we have our own server, we can set a bigger area for download (in M2)
>>> par.parameters['osm']['max_query_area_size'] = 10000000000

# And have no pause between successive queries
>>> par.parameters['osm']['sleeptime'] = 0

# Save the parameters to disk
>>> par.write_back()

# Now we can import the network for any place we want
# p.network.create_from_osm(place_name="my_beautiful_hometown")

>>> p.close()
create_from_gmns(link_file_path: str, node_file_path: str, use_group_path: str | None = None, geometry_path: str | None = 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 format

node_file_path (str): Path to a nodes csv file in GMNS format

use_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 uses

geometry_path (str, Optional): Path to a csv file containing geometry information for a line object, if not specified in the link table

srid (int, Optional): Spatial Reference ID in which the GMNS geometries were created

export_to_gmns(path: str)[source]#

Exports AequilibraE network to csv files in GMNS format.

Arguments:

path (str): Output folder path.

signal_handler(val)[source]#
build_graphs(fields: list | None = None, modes: list | None = 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 use

modes (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 need

To use the fields parameter, a minimalistic option is the following

>>> from aequilibrae import Project

>>> p = Project.from_path("/tmp/test_project")
>>> fields = ['distance']
>>> p.network.build_graphs(fields, modes = ['c', 'w'])
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

Returns the number of links in the model

Returns:

int: Number of links

count_centroids() int[source]#

Returns the number of centroids in the model

Returns:

int: Number of centroids

count_nodes() int[source]#

Returns the number of nodes in the model

Returns:

int: Number of nodes

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.

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.

aequilibrae.project.network.node module#

class aequilibrae.project.network.node.Node(dataset, project)[source]#

Bases: SafeClass

A Node object represents a single record in the nodes table

>>> from aequilibrae import Project
>>> from shapely.geometry import Point

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

>>> all_nodes = proj.network.nodes

# We can just get one link in specific
>>> node1 = all_nodes.get(7)

# We can find out which fields exist for the links
>>> which_fields_do_we_have = node1.data_fields()

# It success if the node_id already does not exist
>>> node1.renumber(998877)

>>> node1.geometry = Point(1,2)

# We can just save the node
>>> node1.save()
save()[source]#

Saves node to database

data_fields() list[source]#

lists all data fields for the node, as available in the database

Returns:

data fields (list): list of all fields available for editing

renumber(new_id: int)[source]#

Renumbers the node in the network

Logs a warning if another node already exists with this node_id

Arguments:

new_id (int): New node_id

connect_mode(area: Polygon, mode_id: str, link_types='', connectors=1, conn: Connection | 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 provided area.

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 provided area, is it progressively expanded until at least one candidate is found.

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

Arguments:

area (Polygon): Initial area where AequilibraE will look for nodes to connect

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

aequilibrae.project.network.nodes module#

class aequilibrae.project.network.nodes.Nodes(net)[source]#

Bases: BasicTable

Access to the API resources to manipulate the links table in the network

>>> from aequilibrae import Project

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

>>> all_nodes = proj.network.nodes

# We can just get one link in specific
>>> node = all_nodes.get(21)

# We can save changes for all nodes we have edited so far
>>> all_nodes.save()
sql = ''#

Query sql for retrieving nodes

get(node_id: int) Node[source]#

Get a node from the network by its node_id

It raises an error if node_id does not exist

Arguments:

node_id (int): Id of a node to retrieve

Returns:

node (Node): Node object for requested node_id

refresh_fields() None[source]#

After adding a field one needs to refresh all the fields recognized by the software

refresh()[source]#

Refreshes all the nodes in memory

new_centroid(node_id: int) Node[source]#

Creates a new centroid with a given ID

Arguments:

node_id (int): Id of the centroid to be created

save()[source]#
property data: DataFrame#

Returns all nodes data as a Pandas DataFrame

Returns:

table (DataFrame): Pandas DataFrame with all the nodes, complete with Geometry

property lonlat: DataFrame#

Returns all nodes lon/lat coords as a Pandas DataFrame

Returns:

table (DataFrame): Pandas DataFrame with all the nodes, with geometry as lon/lat

aequilibrae.project.network.period module#

class aequilibrae.project.network.period.Period(dataset, project)[source]#

Bases: SafeClass

A Period object represents a single record in the periods table

>>> from aequilibrae import Project

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

>>> all_periods = proj.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()

# It succeeds if the period_id already does not exist
>>> period1.renumber(998877)

# We can just save the period
>>> period1.save()
save()[source]#

Saves period to database

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

renumber(new_id: int)[source]#

Renumbers the period in the network

Logs a warning if another period already exists with this period_id

Arguments:

new_id (int): New period_id

aequilibrae.project.network.periods module#

class aequilibrae.project.network.periods.Periods(net)[source]#

Bases: BasicTable

Access to the API resources to manipulate the links table in the network

>>> from aequilibrae import Project

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

>>> all_periods = proj.network.periods

# We can just get one link in specific
>>> period = all_periods.get(21)

# We can save changes for all periods we have edited so far
>>> all_periods.save()
sql = ''#

Query sql for retrieving periods

extent()[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)

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

refresh_fields() None[source]#

After adding a field one needs to refresh all the fields recognized by the software

refresh()[source]#

Refreshes all the periods in memory

new_period(period_id: int, start: int, end: int, description: str | None = None) Period[source]#

Creates a new period with a given ID

Arguments:

period_id (int): Id of the centroid to be created start (int): Start time of the period to be created end (int): End time of the period to be created description (str): Optional human readable description of the time period e.g. ‘1pm - 5pm’

save()[source]#
property data: DataFrame#

Returns all periods data as a Pandas DataFrame

Returns:

table (DataFrame): Pandas DataFrame with all the periods

property default_period: Period#

aequilibrae.project.network.safe_class module#

class aequilibrae.project.network.safe_class.SafeClass(data_set: dict, project)[source]#

Bases: object

connect_db()[source]#

Module contents#