Skip to content

Commit

Permalink
Label edges, not entire network
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-fred committed Feb 8, 2024
1 parent 7f9e503 commit 7f697e5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/open_gira/direct_damages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
from typing import Union

import geopandas as gpd
import pandas as pd
import snkit

Expand Down Expand Up @@ -271,26 +272,26 @@ def road_rehab_cost(row: pd.Series, rehab_costs: pd.DataFrame) -> float:
)


def annotate_rehab_cost(network: snkit.network.Network, network_type: str, rehab_cost: pd.DataFrame) -> snkit.network.Network:
def annotate_rehab_cost(edges: gpd.GeoDataFrame, network_type: str, rehab_cost: pd.DataFrame) -> gpd.GeoDataFrame:
"""
Label a network with rehabilitation costs to be used in subsequent direct
Label edges with rehabilitation costs to be used in subsequent direct
damage cost estimate.
Args:
network: Network with edges to label.
edges: Edges to label.
network_type: Category string, currently either road or rail.
rehab_cost: Table containing rehabilitation cost data per km. See lookup
functions for more requirements.
Returns:
Network labelled with rehabilitation cost data.
Edges labelled with rehabilitation cost data.
"""

if network_type == "road":
network.edges[fields.REHAB_COST] = network.edges.apply(road_rehab_cost, axis=1, args=(rehab_cost,)) * network.edges.lanes
edges[fields.REHAB_COST] = edges.apply(road_rehab_cost, axis=1, args=(rehab_cost,)) * edges.lanes
elif network_type == "rail":
network.edges[fields.REHAB_COST] = network.edges.apply(rail_rehab_cost, axis=1, args=(rehab_cost,))
edges[fields.REHAB_COST] = edges.apply(rail_rehab_cost, axis=1, args=(rehab_cost,))
else:
raise ValueError(f"No lookup function available for {network_type=}")

return network
return edges

0 comments on commit 7f697e5

Please sign in to comment.