Skip to content

Commit

Permalink
add notations to function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
YueeeeeLi committed Oct 17, 2024
1 parent cf64149 commit 24f5503
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/nird/road.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Road Network Flow Model - Functions
"""

from typing import Union, Tuple, List, Dict
from typing import Tuple, List, Dict
from collections import defaultdict

import numpy as np
Expand Down Expand Up @@ -54,9 +54,9 @@ def select_partial_roads(
selected_links = pd.concat(selected_links, ignore_index=True)
selected_links = gpd.GeoDataFrame(selected_links, geometry="geometry")

selected_links["e_id"] = selected_links.id
selected_links["from_id"] = selected_links.start_node
selected_links["to_id"] = selected_links.end_node
selected_links["e_id"] = selected_links["id"]
selected_links["from_id"] = selected_links["start_node"]
selected_links["to_id"] = selected_links["end_node"]

# road nodes selection
sel_node_idx = list(
Expand All @@ -65,9 +65,9 @@ def select_partial_roads(

selected_nodes = road_nodes[road_nodes.id.isin(sel_node_idx)]
selected_nodes.reset_index(drop=True, inplace=True)
selected_nodes["nd_id"] = selected_nodes.id
selected_nodes["lat"] = selected_nodes.geometry.y
selected_nodes["lon"] = selected_nodes.geometry.x
selected_nodes["nd_id"] = selected_nodes["id"]
selected_nodes["lat"] = selected_nodes["geometry"].y
selected_nodes["lon"] = selected_nodes["geometry"].x

return selected_links, selected_nodes

Expand Down Expand Up @@ -279,7 +279,7 @@ def edge_initial_speed_func(
urban_flow_speed_dict: Dict[str, float],
min_flow_speed_dict: Dict[str, float], # add a minimum speed cap
max_flow_speed_dict: Dict[str, float] = None,
) -> Union[pd.DataFrame, Dict[str, float]]:
) -> Tuple[pd.DataFrame, Dict[str, float]]:
"""Calculate the initial vehicle speed for network edges.
Parameters
Expand Down Expand Up @@ -459,7 +459,14 @@ def speed_flow_func(
def create_igraph_network(
road_links: gpd.GeoDataFrame,
road_nodes: gpd.GeoDataFrame,
) -> Tuple[igraph.Graph, Dict[str, float], Dict[str, float], Dict[str, float]]:
) -> Tuple[
igraph.Graph,
Dict[str, float],
Dict[str, float],
Dict[str, float],
Dict[str, float],
pd.DataFrame,
]:
"""Create an undirected igraph network.
Parameters
Expand Down Expand Up @@ -775,7 +782,7 @@ def compute_edge_costs(
return (od_voc, od_vot, od_toll)


def clip_to_zero(arr: np.ndarray) -> np.ndarray:
def clip_to_zero(arr: np.NDArray) -> np.NDArray:
"""Convert values less than one to zero"""
return np.where(arr >= 0.5, arr, 0)

Expand Down Expand Up @@ -832,11 +839,8 @@ def network_flow_model(
min_speed_cap: Dict[str, float],
urban_speed_cap: Dict[str, float],
od_node_2021: pd.DataFrame,
max_flow_speed_dict: Dict[str, float] = None,
) -> Tuple[
pd.DataFrame,
pd.DataFrame,
]:
max_flow_speed_dict=None,
) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[Tuple[str, str], float]]:
"""Model the passenger flows on the road network.
Parameters
Expand Down

0 comments on commit 24f5503

Please sign in to comment.