Skip to content

Commit

Permalink
Update managed lane network
Browse files Browse the repository at this point in the history
- output links, nodes, shapes for managed lane network
- externalize `has_managed_lanes()`
  • Loading branch information
e-lo committed Feb 24, 2021
1 parent 1ab57b0 commit 37cd673
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions network_wrangler/roadwaynetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,18 @@ def _get_connector_references(ref_1: list, ref_2: list, type: str):

return (access_df, egress_df)

@staticmethod
def has_managed_lanes(links_df: GeoDataFrame) -> bool:
ml_lanes_attributes = [i for i in self.links_df.columns.values.tolist() if i.lower().startswith("ml_lanes")]

if not ml_lanes_attributes:
WranglerLogger.info("No managed lanes attributes found when calculating managed lane network. Returning original network.")
return False
if not self.links_df[ml_lanes_attributes].max()>0:
WranglerLogger.info("Max number of managed lanes is not greater than zero ({}). Returning original network.".format(self.links_df[ml_lanes_attributes].max()))
return False
return True

def create_managed_lane_network(
self,
keep_same_attributes_ml_and_gp: list = None,
Expand All @@ -2201,7 +2213,7 @@ def create_managed_lane_network(
managed_lanes_node_id_scalar: int = None,
managed_lanes_link_id_scalar: int = None,
in_place: bool = False,
) -> RoadwayNetwork:
) -> Union[None,Collection[GeoDataFrame]:
"""
Create a roadway network with managed lanes links separated out.
Add new parallel managed lane links, access/egress links,
Expand All @@ -2222,22 +2234,23 @@ def create_managed_lane_network(
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
in_place: If True, will update self.links_model_df, self.shapes_df, and self.nodes_model_df.
Otherwise, will return a tuple with self.links_model_df, self.shapes_df, and self.nodes_model_df.
returns: A RoadwayNetwork instance
returns:
None if `in_place' True.
A Tuple of self.model_links_df, self.shapes_df, and self.model_nodes_df if `in_place` is False.
.. todo:: make this a more rigorous test
"""

WranglerLogger.info("Creating network with duplicated managed lanes")

if "ml_access" in self.links_df["roadway"].tolist():
msg = "managed lane access links already exist in network; shouldn't be running create managed lane network. Returning network as-is."
WranglerLogger.error(msg)
# assess first if you need to run the rest of this by identifying if any managed lane attributes exist
if not RoadwayNetwork.has_managed_lanes(self.links_df):
if in_place:
return
return
else:
return copy.deepcopy(self)
return self

WranglerLogger.info("Creating network with duplicated managed lanes")

# identify parameters to use
if not keep_same_attributes_ml_and_gp:
Expand Down Expand Up @@ -2404,15 +2417,11 @@ def create_managed_lane_network(
out_shapes_df = out_shapes_df.reset_index()

if in_place:
self.links_df = out_links_df
self.nodes_df = out_nodes_df
self.model_links_df = out_links_df
self.nodes_df = out_nodes_df
self.shapes_df = out_shapes_df
else:
out_network = copy.deepcopy(self)
out_network.links_df = out_links_df
out_network.nodes_df = out_nodes_df
out_network.shapes_df = out_shapes_df
return out_network
return out_links_df, out_nodes_df, out_shapes_df

@staticmethod
def get_modal_links_nodes(
Expand Down

0 comments on commit 37cd673

Please sign in to comment.