lasso.ModelRoadwayNetwork

class lasso.ModelRoadwayNetwork(nodes, links, shapes, parameters={}, **kwargs)[source]

Bases: RoadwayNetwork

Subclass of network_wrangler class RoadwayNetwork

A representation of the physical roadway network and its properties.

__init__(nodes, links, shapes, parameters={}, **kwargs)[source]

Constructor

Parameters:
  • nodes – geodataframe of nodes

  • links – dataframe of links

  • shapes – geodataframe of shapes

  • parameters – dictionary of parameter settings (see Parameters class) or an instance of Parameters. If not specified, will use default parameters.

  • crs (int) – coordinate reference system, ESPG number

  • node_foreign_key (str) – variable linking the node table to the link table

  • link_foreign_key (list) – list of variable linking the link table to the node foreign key

  • shape_foreign_key (str) – variable linking the links table and shape table

  • unique_link_ids (list) – list of variables unique to each link

  • unique_node_ids (list) – list of variables unique to each node

  • modes_to_network_link_variables (dict) – Mapping of modes to link variables in the network

  • modes_to_network_nodes_variables (dict) – Mapping of modes to node variables in the network

  • managed_lanes_node_id_scalar (int) – Scalar values added to primary keys for nodes for corresponding managed lanes.

  • managed_lanes_link_id_scalar (int) – Scalar values added to primary keys for links for corresponding managed lanes.

  • managed_lanes_required_attributes (list) – attributes that must be specified in managed lane projects.

  • keep_same_attributes_ml_and_gp (list) – attributes to copy to managed lanes from parallel general purpose lanes.

Methods

__init__(nodes, links, shapes[, parameters])

Constructor

add_counts([network_variable, ...])

Adds count variable.

add_incident_link_data_to_nodes([links_df, ...])

Add data from links going to/from nodes to node.

add_new_roadway_feature_change(links, nodes)

add the new roadway features defined in the project card.

add_variable_using_shst_reference([...])

Join network links with source data, via SHST API node match result.

addition_map(links, nodes)

Shows which links and nodes are added to the roadway network

apply(project_card_dictionary)

Wrapper method to apply a project to a roadway network.

apply_managed_lane_feature_change(link_idx, ...)

Apply the managed lane feature changes to the roadway network

apply_python_calculation(pycode[, in_place])

Changes roadway network object by executing pycode.

apply_roadway_feature_change(link_idx, ...)

Changes the roadway attributes for the selected features based on the project card information passed

assess_connectivity([mode, ...])

Returns a network graph and list of disconnected subgraphs as described by a list of their member nodes.

build_selection_key(selection_dict)

Selections are stored by a key combining the query and the A and B ids.

calculate_area_type([area_type_shape, ...])

#MC Calculates area type variable.

calculate_centroidconnect(parameters[, ...])

Calculates centroid connector variable.

calculate_county([county_shape, ...])

#MC Calculates county variable.

calculate_distance([network_variable, ...])

calculate link distance in miles

calculate_mpo([county_network_variable, ...])

Calculates mpo variable.

calculate_use([network_variable, ...])

Calculates use variable.

convert_int([int_col_names])

Convert integer columns

create_ML_variable([network_variable, overwrite])

Created ML lanes placeholder for project to write out ML changes

create_calculated_variables()

Creates calculated roadway variables.

create_dummy_connector_links(ml_df[, ...])

create dummy connector links between the general purpose and managed lanes

create_hov_corridor_variable([...])

Created hov corridor placeholder for project to write out corridor changes

create_managed_lane_network([...])

Create a roadway network with managed lanes links separated out.

create_managed_variable([network_variable, ...])

Created placeholder for project to write out managed

dataframe_to_fixed_width(df)

Convert dataframe to fixed width format, geometry column will not be transformed.

delete_roadway_feature_change(links, nodes)

delete the roadway features defined in the project card.

deletion_map(links, nodes)

Shows which links and nodes are deleted from the roadway network

fill_na()

Fill na values from create_managed_lane_network()

from_RoadwayNetwork(roadway_network_object)

RoadwayNetwork to ModelRoadwayNetwork

get_attribute(links_df, join_key, ...)

Gets attribute from source data using SHST match result.

get_managed_lane_node_ids(nodes_list[, scalar])

Transform a list of node IDS by a scalar.

get_modal_graph(links_df, nodes_df[, mode, ...])

Determines if the network graph is "strongly" connected A graph is strongly connected if each vertex is reachable from every other vertex.

get_modal_links_nodes(links_df, nodes_df[, ...])

Returns nodes and link dataframes for specific mode.

get_property_by_time_period_and_group(prop)

Return a series for the properties with a specific group or time period.

identify_segment(O_id, D_id[, ...])

param endpoints:

list of length of two unique keys of nodes making up endpoints of segment

identify_segment_endpoints([mode, links_df, ...])

param mode:

list of modes of the network, one of drive,`transit`,

is_network_connected([mode, links_df, nodes_df])

Determines if the network graph is "strongly" connected A graph is strongly connected if each vertex is reachable from every other vertex.

load_transform_network(node_filename, ...[, ...])

Reads roadway network files from disk and transforms them into GeoDataFrames.

network_connection_plot(G, ...)

Plot a graph to check for network connection.

orig_dest_nodes_foreign_key(selection[, ...])

Returns the foreign key id (whatever is used in the u and v variables in the links file) for the AB nodes as a tuple.

ox_graph(nodes_df, links_df[, ...])

create an osmnx-flavored network graph

path_search(candidate_links_df, O_id, D_id)

param candidate_links:

selection of links geodataframe with links likely to be part of path

read(link_filename, node_filename, ...[, ...])

Reads in links and nodes network standard.

read_match_result(path)

Reads the shst geojson match returns.

rename_variables_for_dbf(input_df[, ...])

Rename attributes for DBF/SHP, make sure length within 10 chars.

roadway_net_to_gdf(roadway_net)

rtype:

GeoDataFrame

roadway_standard_to_met_council_network([...])

Rename and format roadway attributes to be consistent with what metcouncil's model is expecting.

select_roadway_features(selection[, ...])

Selects roadway features that satisfy selection criteria

selection_has_unique_link_id(selection_dict)

rtype:

bool

selection_map(selected_link_idx[, A, B, ...])

Shows which links are selected for roadway property change or parallel managed lanes category of roadway projects.

shortest_path(graph_links_df, O_id, D_id[, ...])

rtype:

tuple

split_properties_by_time_period_and_category([...])

Splits properties by time period, assuming a variable structure of

update_distance([links_df, use_shapes, ...])

Calculate link distance in specified units to network variable using either straight line distance or (if specified) shape distance if available.

validate_link_schema(link_filename[, ...])

Validate roadway network data link schema and output a boolean

validate_node_schema(node_file[, ...])

Validate roadway network data node schema and output a boolean

validate_properties(properties[, ...])

If there are change or existing commands, make sure that that property exists in the network.

validate_selection(selection[, ...])

Evaluate whetther the selection dictionary contains the minimum required values.

validate_shape_schema(shape_file[, ...])

Validate roadway network data shape schema and output a boolean

validate_uniqueness()

Confirms that the unique identifiers are met.

write([path, filename])

Writes a network in the roadway network standard

write_roadway_as_fixedwidth(output_dir[, ...])

Writes out fixed width file.

write_roadway_as_shp(output_dir[, ...])

Write out dbf/shp/gpkg for cube.

Attributes

CALCULATED_VALUES

add_counts(network_variable='AADT', mndot_count_shst_data=None, widot_count_shst_data=None, mndot_count_variable_shp=None, widot_count_variable_shp=None)[source]

Adds count variable. #MC join the network with count node data, via SHST API node match result

Parameters:
  • network_variable (str) – Name of the variable that should be written to. Default to “AADT”.

  • mndot_count_shst_data (str) – File path to MNDOT count location SHST API node match result.

  • widot_count_shst_data (str) – File path to WIDOT count location SHST API node match result.

  • mndot_count_variable_shp (str) – File path to MNDOT count location geodatabase.

  • widot_count_variable_shp (str) – File path to WIDOT count location geodatabase.

Returns:

None

Add data from links going to/from nodes to node.

Return type:

DataFrame

Parameters:
  • links_df – if specified, will assess connectivity of this links list rather than self.links_df

  • nodes_df – if specified, will assess connectivity of this nodes list rather than self.nodes_df

  • link_variables – list of columns in links dataframe to add to incident nodes

Returns:

nodes DataFrame with link data where length is N*number of links going in/out

add_new_roadway_feature_change(links, nodes)

add the new roadway features defined in the project card. new shapes are also added for the new roadway links.

Return type:

None

Parameters:
  • links – list of dictionaries

  • nodes – list of dictionaries

returns: None

add_variable_using_shst_reference(var_shst_csvdata=None, shst_csv_variable=None, network_variable=None, network_var_type=<class 'int'>, overwrite=False)[source]

Join network links with source data, via SHST API node match result.

Parameters:
  • var_shst_csvdata (str) – File path to SHST API return.

  • shst_csv_variable (str) – Variable name in the source data.

  • network_variable (str) – Name of the variable that should be written to.

  • network_var_type – Variable type in the written network.

  • overwrite (bool) – True is overwriting existing variable. Default to False.

Returns:

None

addition_map(links, nodes)

Shows which links and nodes are added to the roadway network

apply(project_card_dictionary)

Wrapper method to apply a project to a roadway network.

Parameters:

project_card_dictionary – dict a dictionary of the project card object

apply_managed_lane_feature_change(link_idx, properties, in_place=True)

Apply the managed lane feature changes to the roadway network

Parameters:
  • link_idx – list of lndices of all links to apply change to

  • properties – list of dictionarys roadway properties to change

  • in_place – boolean to indicate whether to update self or return a new roadway network object

apply_python_calculation(pycode, in_place=True)

Changes roadway network object by executing pycode.

Parameters:
  • pycode – python code which changes values in the roadway network object

  • in_place – update self or return a new roadway network object

apply_roadway_feature_change(link_idx, properties, in_place=True)

Changes the roadway attributes for the selected features based on the project card information passed

Parameters:
  • link_idx – list lndices of all links to apply change to

  • properties – list of dictionarys roadway properties to change

  • in_place – boolean update self or return a new roadway network object

assess_connectivity(mode='', ignore_end_nodes=True, links_df=None, nodes_df=None)

Returns a network graph and list of disconnected subgraphs as described by a list of their member nodes.

Parameters:
  • mode – list of modes of the network, one of drive,`transit`, walk, bike

  • ignore_end_nodes – if True, ignores stray singleton nodes

  • links_df – if specified, will assess connectivity of this links list rather than self.links_df

  • nodes_df – if specified, will assess connectivity of this nodes list rather than self.nodes_df

Returns: Tuple of

Network Graph (osmnx flavored networkX DiGraph) List of disconnected subgraphs described by the list of their

member nodes (as described by their model_node_id)

build_selection_key(selection_dict)

Selections are stored by a key combining the query and the A and B ids. This method combines the two for you based on the selection dictionary.

Return type:

tuple

Parameters:

selection_dictonary – Selection Dictionary

Returns: Tuple serving as the selection key.

calculate_area_type(area_type_shape=None, area_type_shape_variable=None, network_variable='area_type', area_type_codes_dict=None, downtown_area_type_shape=None, downtown_area_type=None, overwrite=False)[source]

#MC Calculates area type variable.

This uses the centroid of the geometry field to determine which area it should be labeled. This isn’t perfect, but it much quicker than other methods.

Parameters:
  • area_type_shape (str) – The File path to area geodatabase.

  • area_type_shape_variable (str) – The variable name of area type in area geodadabase.

  • network_variable (str) – The variable name of area type in network standard. Default to “area_type”.

  • area_type_codes_dict – The dictionary to map input area_type_shape_variable to network_variable

  • downtown_area_type_shape – The file path to the downtown area type boundary.

  • downtown_area_type (int) – Integer value of downtown area type

  • overwrite (Bool) – True if overwriting existing county variable in network. Default to False.

Returns:

None

calculate_centroidconnect(parameters, network_variable='centroidconnect', highest_taz_number=None, as_integer=True, overwrite=False)[source]

Calculates centroid connector variable.

Parameters:
  • parameters (Parameters) – A Lasso Parameters, which stores input files.

  • network_variable (str) – Variable that should be written to in the network. Default to “centroidconnect”

  • highest_taz_number (int) – the max TAZ number in the network.

  • as_integer (bool) – If True, will convert true/false to 1/0s. Default to True.

  • overwrite (Bool) – True if overwriting existing county variable in network. Default to False.

Returns:

RoadwayNetwork

calculate_county(county_shape=None, county_shape_variable=None, network_variable='county', county_codes_dict=None, overwrite=False)[source]

#MC Calculates county variable.

This uses the centroid of the geometry field to determine which county it should be labeled. This isn’t perfect, but it much quicker than other methods.

Parameters:
  • county_shape (str) – The File path to county geodatabase.

  • county_shape_variable (str) – The variable name of county in county geodadabase.

  • network_variable (str) – The variable name of county in network standard. Default to “county”.

  • overwrite (Bool) – True if overwriting existing county variable in network. Default to False.

Returns:

None

calculate_distance(network_variable='distance', centroidconnect_only=False, overwrite=False)[source]

calculate link distance in miles

Parameters:
  • centroidconnect_only (Bool) – True if calculating distance for centroidconnectors only. Default to False.

  • overwrite (Bool) – True if overwriting existing variable in network. Default to False.

Returns:

None

calculate_mpo(county_network_variable='county', network_variable='mpo', as_integer=True, mpo_counties=None, overwrite=False)[source]

Calculates mpo variable. #MC :param county_variable: Name of the variable where the county names are stored. Default to “county”. :type county_variable: str :param network_variable: Name of the variable that should be written to. Default to “mpo”. :type network_variable: str :param as_integer: If true, will convert true/false to 1/0s. :type as_integer: bool :param mpo_counties: List of county names that are within mpo region. :type mpo_counties: list :param overwrite: True if overwriting existing county variable in network. Default to False. :type overwrite: Bool

Returns:

None

calculate_use(network_variable='use', as_integer=True, overwrite=False)[source]

Calculates use variable.

Parameters:
  • network_variable (str) – Variable that should be written to in the network. Default to “use”

  • as_integer (bool) – If True, will convert true/false to 1/0s. Defauly to True.

  • overwrite (Bool) – True if overwriting existing county variable in network. Default to False.

Returns:

None

convert_int(int_col_names=[])[source]

Convert integer columns

create_ML_variable(network_variable='ML_lanes', overwrite=False)[source]

Created ML lanes placeholder for project to write out ML changes

ML lanes default to 0, ML info comes from cube LOG file and store in project cards

Parameters:

overwrite (Bool) – True if overwriting existing variable in network. Default to False.

Returns:

None

create_calculated_variables()[source]

Creates calculated roadway variables.

Parameters:

None

create dummy connector links between the general purpose and managed lanes

Parameters:
  • gp_df – GeoDataFrame dataframe of general purpose links (where managed lane also exists)

  • ml_df – GeoDataFrame dataframe of corresponding managed lane links,

  • access_lanes – int number of lanes in access dummy link

  • egress_lanes – int number of lanes in egress dummy link

  • access_roadway – str roaday type for access dummy link

  • egress_roadway – str roadway type for egress dummy link

  • access_name_prefix – str prefix for access dummy link name

  • egress_name_prefix – str prefix for egress dummy link name

create_hov_corridor_variable(network_variable='segment_id', overwrite=False)[source]

Created hov corridor placeholder for project to write out corridor changes

hov corridor id default to 0, its info comes from cube LOG file and store in project cards

Parameters:

overwrite (Bool) – True if overwriting existing variable in network. Default to False.

Returns:

None

create_managed_lane_network(keep_same_attributes_ml_and_gp=None, keep_additional_attributes_ml_and_gp=[], managed_lanes_required_attributes=[], managed_lanes_node_id_scalar=None, managed_lanes_link_id_scalar=None, in_place=False)

Create a roadway network with managed lanes links separated out. Add new parallel managed lane links, access/egress links, and add shapes corresponding to the new links

Return type:

RoadwayNetwork

Parameters:
  • keep_same_attributes_ml_and_gp – list of attributes to copy from general purpose lane to managed lane. If not specified, will look for value in the RoadwayNetwork instance. If not found there, will default to KEEP_SAME_ATTRIBUTES_ML_AND_GP.

  • keep_additional_attributes_ml_and_gp – list of additional attributes to add. This is useful if you want to leave the default attributes and then ALSO some others.

  • managed_lanes_required_attributes – list of attributes that are required to be specified in new managed lanes. If not specified, will look for value in the RoadwayNetwork instance. If not found there, will default to MANAGED_LANES_REQUIRED_ATTRIBUTES.

  • managed_lanes_node_id_scalar – integer value added to original node IDs to create managed lane unique ids. If not specified, will look for value in the RoadwayNetwork instance. If not found there, will default to MANAGED_LANES_NODE_ID_SCALAR.

  • managed_lanes_link_id_scalar – integer value added to original link IDs to create managed lane unique ids. If not specified, will look for value in the RoadwayNetwork instance. If not found there, will default to MANAGED_LANES_LINK_ID_SCALAR.

  • in_place – update self or return a new roadway network object

returns: A RoadwayNetwork instance

create_managed_variable(network_variable='managed', overwrite=False)[source]

Created placeholder for project to write out managed

managed default to 0, its info comes from cube LOG file and store in project cards

Parameters:

overwrite (Bool) – True if overwriting existing variable in network. Default to False.

Returns:

None

static dataframe_to_fixed_width(df)[source]

Convert dataframe to fixed width format, geometry column will not be transformed.

Parameters:

df (pandas DataFrame) –

Returns:

dataframe with fixed width for each column. dict: dictionary with columns names as keys, column width as values.

Return type:

pandas dataframe

delete_roadway_feature_change(links, nodes, ignore_missing=True)

delete the roadway features defined in the project card. valid links and nodes defined in the project gets deleted and shapes corresponding to the deleted links are also deleted.

Return type:

None

Parameters:
  • links – dict list of dictionaries

  • nodes – dict list of dictionaries

  • ignore_missing – bool If True, will only warn about links/nodes that are missing from network but specified to “delete” in project card If False, will fail.

deletion_map(links, nodes)

Shows which links and nodes are deleted from the roadway network

fill_na()[source]

Fill na values from create_managed_lane_network()

static from_RoadwayNetwork(roadway_network_object, parameters={})[source]

RoadwayNetwork to ModelRoadwayNetwork

Parameters:
  • roadway_network_object (RoadwayNetwork) –

  • parameters – dictionary of parameter settings (see Parameters class) or an instance of Parameters. If not specified, will use default parameters.

Returns:

ModelRoadwayNetwork

static get_attribute(links_df, join_key, source_shst_ref_df, source_gdf, field_name)[source]

Gets attribute from source data using SHST match result.

Parameters:
  • links_df (dataframe) – The network dataframe that new attribute should be written to.

  • join_key (str) – SHST ID variable name used to join source data with network dataframe.

  • source_shst_ref_df (str) – File path to source data SHST match result.

  • source_gdf (str) – File path to source data.

  • field_name (str) – Name of the attribute to get from source data.

Returns:

None

static get_managed_lane_node_ids(nodes_list, scalar=4500000)

Transform a list of node IDS by a scalar. ..todo #237 what if node ids are not a number?

Parameters:
  • nodes_list – list of integers

  • scalar – value to add to node IDs

Returns: list of integers

static get_modal_graph(links_df, nodes_df, mode=None, modes_to_network_link_variables={'bike': ['bike_access'], 'bus': ['bus_only', 'drive_access'], 'drive': ['drive_access'], 'rail': ['rail_only'], 'transit': ['bus_only', 'rail_only', 'drive_access'], 'walk': ['walk_access']})

Determines if the network graph is “strongly” connected A graph is strongly connected if each vertex is reachable from every other vertex.

Parameters:
  • links_df – DataFrame of standard network links

  • nodes_df – DataFrame of standard network nodes

  • mode – mode of the network, one of drive,`transit`, walk, bike

  • modes_to_network_link_variables – dictionary mapping the mode selections to the network variables that must bool to true to select that mode. Defaults to MODES_TO_NETWORK_LINK_VARIABLES

Returns: networkx: osmnx: DiGraph of network

Returns nodes and link dataframes for specific mode.

Parameters:
  • links_df – DataFrame of standard network links

  • nodes_df – DataFrame of standard network nodes

  • modes – list of the modes of the network to be kept, must be in drive,`transit`,`rail`,`bus`, walk, bike. For example, if bike and walk are selected, both bike and walk links will be kept.

  • modes_to_network_link_variables – dictionary mapping the mode selections to the network variables that must bool to true to select that mode. Defaults to MODES_TO_NETWORK_LINK_VARIABLES

Returns: tuple of DataFrames for links, nodes filtered by mode

links with walk access are not marked as having walk access Issue discussed in https://github.com/wsp-sag/network_wrangler/issues/145 modal_nodes_df = nodes_df[nodes_df[mode_node_variable] == 1]

get_property_by_time_period_and_group(prop, time_period=None, category=None, default_return=None)

Return a series for the properties with a specific group or time period.

Parameters:
  • prop (str) – the variable that you want from network

  • time_period (list(str)) – the time period that you are querying for i.e. [‘16:00’, ‘19:00’]

  • category (str or list(str)(Optional)) –

    the group category i.e. “sov”

    or

    list of group categories in order of search, i.e. [“hov3”,”hov2”]

  • default_return (what to return if variable or time period not found. Default is None.) –

Return type:

pandas series

identify_segment(O_id, D_id, selection_dict={}, mode=None, nodes_df=None, links_df=None)
Parameters:
  • endpoints – list of length of two unique keys of nodes making up endpoints of segment

  • selection_dict – dictionary of link variables to select candidate links from, otherwise will create a graph of ALL links which will be both a RAM hog and could result in odd shortest paths.

  • segment_variables – list of variables to keep

identify_segment_endpoints(mode='', links_df=None, nodes_df=None, min_connecting_links=10, min_distance=None, max_link_deviation=2)
Parameters:
  • mode – list of modes of the network, one of drive,`transit`, walk, bike

  • links_df – if specified, will assess connectivity of this links list rather than self.links_df

  • nodes_df – if specified, will assess connectivity of this nodes list rather than self.nodes_df

is_network_connected(mode=None, links_df=None, nodes_df=None)

Determines if the network graph is “strongly” connected A graph is strongly connected if each vertex is reachable from every other vertex.

Parameters:
  • mode – mode of the network, one of drive,`transit`, walk, bike

  • links_df – DataFrame of standard network links

  • nodes_df – DataFrame of standard network nodes

Returns: boolean

static load_transform_network(node_filename, link_filename, shape_filename, crs=4326, node_foreign_key='model_node_id', validate_schema=True, **kwargs)

Reads roadway network files from disk and transforms them into GeoDataFrames.

Return type:

tuple

Parameters:
  • node_filename – file name for nodes.

  • link_filename – file name for links.

  • shape_filename – file name for shapes.

  • crs – coordinate reference system. Defaults to value in CRS.

  • node_foreign_key – variable linking the node table to the link table. Defaults to NODE_FOREIGN_KEY.

  • validate_schema – boolean indicating if network should be validated to schema.

returns: tuple of GeodataFrames nodes_df, links_df, shapes_df

static network_connection_plot(G, disconnected_subgraph_nodes)

Plot a graph to check for network connection.

Parameters:
  • G – OSMNX flavored networkX graph.

  • disconnected_subgraph_nodes – List of disconnected subgraphs described by the list of their member nodes (as described by their model_node_id).

returns: fig, ax : tuple

orig_dest_nodes_foreign_key(selection, node_foreign_key='')

Returns the foreign key id (whatever is used in the u and v variables in the links file) for the AB nodes as a tuple.

Return type:

tuple

Parameters:
  • selection – selection dictionary with A and B keys

  • node_foreign_key – variable name for whatever is used by the u and v variable

  • specified (in the links_df file. If nothing is) –

  • whatever (assume) –

  • is (default) –

Returns: tuple of (A_id, B_id)

static ox_graph(nodes_df, links_df, node_foreign_key='model_node_id', link_foreign_key=['A', 'B'], unique_link_key='model_link_id')

create an osmnx-flavored network graph

osmnx doesn’t like values that are arrays, so remove the variables that have arrays. osmnx also requires that certain variables be filled in, so do that too.

Parameters:
  • nodes_df – GeoDataFrame of nodes

  • link_df – GeoDataFrame of links

  • node_foreign_key – field referenced in link_foreign_key

  • link_foreign_key – list of attributes that define the link start and end nodes to the node foreign key

  • unique_link_key – primary key for links

Returns: a networkx multidigraph

Parameters:
  • candidate_links – selection of links geodataframe with links likely to be part of path

  • O_id – origin node foreigh key ID

  • D_id – destination node foreigh key ID

  • weight_column – column to use for weight of shortest path. Defaults to “i” (iteration)

  • weight_factor – optional weight to multiply the weight column by when finding the shortest path

  • search_breadth

Returns

static read(link_filename, node_filename, shape_filename, fast=False, recalculate_calculated_variables=False, recalculate_distance=False, parameters={}, **kwargs)[source]

Reads in links and nodes network standard.

Parameters:
  • link_filename (str) – File path to link json.

  • node_filename (str) – File path to node geojson.

  • shape_filename (str) – File path to link true shape geojson

  • fast (bool) – boolean that will skip validation to speed up read time.

  • recalculate_calculated_variables (bool) – calculates fields from spatial joins, etc.

  • recalculate_distance (bool) – re-calculates distance.

  • parameters – dictionary of parameter settings (see Parameters class) or an instance of Parameters. If not specified, will use default parameters.

  • crs (int) – coordinate reference system, ESPG number

  • node_foreign_key (str) – variable linking the node table to the link table

  • link_foreign_key (list) – list of variable linking the link table to the node foreign key

  • shape_foreign_key (str) – variable linking the links table and shape table

  • unique_link_ids (list) – list of variables unique to each link

  • unique_node_ids (list) – list of variables unique to each node

  • modes_to_network_link_variables (dict) – Mapping of modes to link variables in the network

  • modes_to_network_nodes_variables (dict) – Mapping of modes to node variables in the network

  • managed_lanes_node_id_scalar (int) – Scalar values added to primary keys for nodes for corresponding managed lanes.

  • managed_lanes_link_id_scalar (int) – Scalar values added to primary keys for links for corresponding managed lanes.

  • managed_lanes_required_attributes (list) – attributes that must be specified in managed lane projects.

  • keep_same_attributes_ml_and_gp (list) – attributes to copy to managed lanes from parallel general purpose lanes.

Returns:

ModelRoadwayNetwork

static read_match_result(path)[source]

Reads the shst geojson match returns.

Returns shst dataframe.

Reading lots of same type of file and concatenating them into a single DataFrame.

Parameters:

path (str) – File path to SHST match results.

Returns:

geopandas geodataframe

Return type:

geodataframe

##todo not sure why we need, but should be in utilities not this class

rename_variables_for_dbf(input_df, variable_crosswalk=None, output_variables=None, convert_geometry_to_xy=False)[source]

Rename attributes for DBF/SHP, make sure length within 10 chars.

Parameters:
  • input_df (dataframe) – Network standard DataFrame.

  • variable_crosswalk (str) – File path to variable name crosswalk from network standard to DBF names.

  • output_variables (list) – List of strings for DBF variables.

  • convert_geometry_to_xy (bool) – True if converting node geometry to X/Y

Returns:

dataframe

static roadway_net_to_gdf(roadway_net)
Return type:

GeoDataFrame

Turn the roadway network into a GeoDataFrame :param roadway_net: the roadway network to export

returns: shapes dataframe

roadway_standard_to_met_council_network(output_epsg=None)[source]

Rename and format roadway attributes to be consistent with what metcouncil’s model is expecting. #MC :param output_epsg: epsg number of output network. :type output_epsg: int

Returns:

None

select_roadway_features(selection, search_mode='drive', force_search=False, sp_weight_factor=None)

Selects roadway features that satisfy selection criteria

Return type:

GeoDataFrame

Example usage:
net.select_roadway_features(
selection = [ {

# a match condition for the from node using osm, # shared streets, or model node number ‘from’: {‘osm_model_link_id’: ‘1234’}, # a match for the to-node.. ‘to’: {‘shstid’: ‘4321’}, # a regex or match for facility condition # could be # of lanes, facility type, etc. ‘facility’: {‘name’:’Main St’}, }, … ])

Parameters:
  • selection – dictionary with keys for: A - from node B - to node link - which includes at least a variable for name

  • search_mode – mode which you are searching for; defaults to “drive”

  • force_search – boolean directing method to perform search even if one with same selection dict is stored from a previous search.

  • sp_weight_factor – multiple used to discourage shortest paths which meander from original search returned from name or ref query. If not set here, will default to value of sp_weight_factor in RoadwayNetwork instance. If not set there, will defaul to SP_WEIGHT_FACTOR.

Returns: a list of link IDs in selection

Return type:

bool

Parameters:

selection_dictionary – Dictionary representation of selection of roadway features, containing a “link” key.

Returns: A boolean indicating if the selection dictionary contains

a unique identifier for links.

selection_map(selected_link_idx, A=None, B=None, candidate_link_idx=[])

Shows which links are selected for roadway property change or parallel managed lanes category of roadway projects.

Parameters:
  • selected_links_idx – list of selected link indices

  • candidate_links_idx – optional list of candidate link indices to also include in map

  • A – optional foreign key of starting node of a route selection

  • B – optional foreign key of ending node of a route selection

shortest_path(graph_links_df, O_id, D_id, nodes_df=None, weight_column='i', weight_factor=100)
Return type:

tuple

Parameters:
  • graph_links_df

  • O_id – foreign key for start node

  • D_id – foreign key for end node

  • nodes_df – optional nodes df, otherwise will use network instance

  • weight_column – column to use as a weight, defaults to “i”

  • weight_factor – any additional weighting to multiply the weight column by, defaults to SP_WEIGHT_FACTOR

Returns: tuple with length of four - Boolean if shortest path found - nx Directed graph of graph links - route of shortest path nodes as List - links in shortest path selected from links_df

split_properties_by_time_period_and_category(properties_to_split=None)[source]

Splits properties by time period, assuming a variable structure of

Parameters:

properties_to_split

dict dictionary of output variable prefix mapped to the source variable and what to stratify it by e.g. {

’lanes’ : {‘v’:’lanes’, ‘times_periods’:{“AM”: (“6:00”, “10:00”),”PM”: (“15:00”, “19:00”)}}, ‘ML_lanes’ : {‘v’:’ML_lanes’, ‘times_periods’:{“AM”: (“6:00”, “10:00”),”PM”: (“15:00”, “19:00”)}}, ‘use’ : {‘v’:’use’, ‘times_periods’:{“AM”: (“6:00”, “10:00”),”PM”: (“15:00”, “19:00”)}},

}

update_distance(links_df=None, use_shapes=False, units='miles', network_variable='distance', overwrite=True, inplace=True)

Calculate link distance in specified units to network variable using either straight line distance or (if specified) shape distance if available.

Parameters:
  • links_df – Links GeoDataFrame. Useful if want to update a portion of network links (i.e. only centroid connectors). If not provided, will use entire self.links_df.

  • use_shapes – if True, will add length information from self.shapes_df rather than crow-fly. If no corresponding shape found in self.shapes_df, will default to crow-fly.

  • units – units to use. Defaults to the standard unit of miles. Available units: “meters”, “miles”.

  • network_variable – variable to store link distance in. Defaults to “distance”.

  • overwrite – Defaults to True and will overwrite all existing calculated distances. False will only update NaNs.

  • inplace – updates self.links_df

Returns:

links_df with updated distance

Validate roadway network data link schema and output a boolean

static validate_node_schema(node_file, schema_location='roadway_network_node.json')

Validate roadway network data node schema and output a boolean

validate_properties(properties, ignore_existing=False, require_existing_for_change=False)

If there are change or existing commands, make sure that that property exists in the network.

Return type:

bool

Parameters:
  • properties – properties dictionary to be evaluated

  • ignore_existing – If True, will only warn about properties that specify an “existing” value. If False, will fail.

  • require_existing_for_change – If True, will fail if there isn’t a specified value in theproject card for existing when a change is specified.

Returns: boolean value as to whether the properties dictonary is valid.

validate_selection(selection, selection_requires=['link'])

Evaluate whetther the selection dictionary contains the minimum required values.

Return type:

bool

Parameters:

selection – selection dictionary to be evaluated

Returns: boolean value as to whether the selection dictonary is valid.

static validate_shape_schema(shape_file, schema_location='roadway_network_shape.json')

Validate roadway network data shape schema and output a boolean

validate_uniqueness()

Confirms that the unique identifiers are met.

Return type:

bool

write(path='.', filename=None)

Writes a network in the roadway network standard

Return type:

None

Parameters:
  • path – the path were the output will be saved

  • filename – the name prefix of the roadway files that will be generated

write_roadway_as_fixedwidth(output_dir, node_output_variables=None, link_output_variables=None, output_link_txt=None, output_node_txt=None, output_link_header_width_txt=None, output_node_header_width_txt=None, output_cube_network_script=None, drive_only=False)[source]

Writes out fixed width file.

This function does: 1. write out link and node fixed width data files for cube. 2. write out header and width correspondence. 3. write out cube network building script with header and width specification.

Parameters:
  • output_dir (str) – File path to where links, nodes and script will be written and run

  • node_output_variables (list) – list of node variable names.

  • link_output_variables (list) – list of link variable names.

  • output_link_txt (str) – File name of output link database (within output_dir)

  • output_node_txt (str) – File name of output node database (within output_dir)

  • output_link_header_width_txt (str) – File name of link column width records (within output_dir)

  • output_node_header_width_txt (str) – File name of node column width records (within output_dir)

  • output_cube_network_script (str) – File name of CUBE network building script (within output_dir)

  • drive_only (bool) – If True, only writes drive nodes and links

Returns:

None

write_roadway_as_shp(output_dir, node_output_variables=None, link_output_variables=None, data_to_csv=True, data_to_dbf=False, output_link_shp=None, output_node_shp=None, output_link_csv=None, output_node_csv=None, output_gpkg=None, output_link_gpkg_layer=None, output_node_gpkg_layer=None, output_gpkg_link_filter=None)[source]

Write out dbf/shp/gpkg for cube. Write out csv in addition to shp with full length variable names.

Parameters:
  • output_dir (str) – File path to directory

  • node_output_variables (list) – List of strings for node output variables.

  • link_output_variables (list) – List of strings for link output variables.

  • data_to_csv (bool) – True if write network in csv format.

  • data_to_dbf (bool) – True if write network in dbf/shp format.

  • output_link_shp (str) – File name to output link dbf/shp.

  • output_node_shp (str) – File name of output node dbf/shp.

  • output_link_csv (str) – File name to output link csv.

  • output_node_csv (str) – File name to output node csv.

  • output_gpkg (str) – File name to output GeoPackage.

  • output_link_gpkg_layer (str) – Layer name within output_gpkg to output links.

  • output_node_gpkg_layer (str) – Layer name within output_gpkg to output links.

  • output_gpkg_link_filter (str) – Optional column name to additional output link subset layers

Returns:

None

CALCULATED_VALUES = ['area_type', 'county', 'centroidconnect']