ra2ce.analysis.losses package#
Subpackages#
- ra2ce.analysis.losses.resilience_curves package
- ra2ce.analysis.losses.risk_calculation package
- Submodules
- ra2ce.analysis.losses.risk_calculation.risk_calculation_base module
- ra2ce.analysis.losses.risk_calculation.risk_calculation_cut_from_year module
- ra2ce.analysis.losses.risk_calculation.risk_calculation_default module
- ra2ce.analysis.losses.risk_calculation.risk_calculation_factory module
- ra2ce.analysis.losses.risk_calculation.risk_calculation_triangle_to_null_year module
- Module contents
- ra2ce.analysis.losses.time_values package
- ra2ce.analysis.losses.traffic_analysis package
- Submodules
- ra2ce.analysis.losses.traffic_analysis.accumulated_traffic_dataclass module
- ra2ce.analysis.losses.traffic_analysis.equity_analysis module
- ra2ce.analysis.losses.traffic_analysis.traffic_analysis module
- ra2ce.analysis.losses.traffic_analysis.traffic_analysis_base module
- ra2ce.analysis.losses.traffic_analysis.traffic_analysis_factory module
- Module contents
- ra2ce.analysis.losses.traffic_intensities package
- ra2ce.analysis.losses.weighing_analysis package
- Submodules
- ra2ce.analysis.losses.weighing_analysis.length_weighing_analysis module
- ra2ce.analysis.losses.weighing_analysis.time_weighing_analysis module
- ra2ce.analysis.losses.weighing_analysis.weighing_analysis_factory module
- ra2ce.analysis.losses.weighing_analysis.weighing_analysis_protocol module
- Module contents
Submodules#
ra2ce.analysis.losses.analysis_losses_protocol module#
- GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Risk Assessment and Adaptation for Critical Infrastructure (RA2CE). Copyright (C) 2023 Stichting Deltares
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
ra2ce.analysis.losses.losses_base module#
- GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Risk Assessment and Adaptation for Critical Infrastructure (RA2CE). Copyright (C) 2023 Stichting Deltares
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- class LossesBase(analysis_input, analysis_config)[source]#
Bases:
AnalysisLossesProtocol
,AnalysisBase
,ABC
This class is the base class for the Losses analyses, containing the common methods and attributes. Based on the analysis type a different criticality analysis is executed.
- Parameters:
analysis_input (AnalysisInputWrapper)
analysis_config (AnalysisConfigWrapper)
-
analysis:
AnalysisSectionLosses
#
- calculate_vehicle_loss_hours()[source]#
This function opens an existing table with traffic data and value of time to calculate losses based on detouring values. It also includes a traffic jam estimation.
- Return type:
GeoDataFrame
- execute()[source]#
Execute the analysis on the given graph/network with the given analysis parameters. The resulting (Geo)DataFrame of the analysis is stored in the result attribute. TODO: Make the return type a result object #318
- Return type:
- Returns:
AnalysisResultWrapper: The result of the analysis.
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
-
output_path:
Path
#
-
static_path:
Path
#
ra2ce.analysis.losses.losses_input_data_reader_base module#
- GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Risk Assessment and Adaptation for Critical Infrastructure (RA2CE). Copyright (C) 2023 Stichting Deltares This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- class LossesInputDataReaderBase(*args, **kwargs)[source]#
Bases:
ABC
,FileReaderProtocol
Base class for reading losses input data from a csv file.
-
csv_columns:
list
[str
] = []#
-
object_type:
type
[Any
]#
- read(file_path)[source]#
Reads from a given file and converts the data into Any type.
- Return type:
Any
- Parameters:
file_path (Path | None)
- Args:
file_path (Path): Path to a file containing data to be read.
- Returns:
Any: Object mapped from the data in the file.
-
separator:
str
= ';'#
-
csv_columns:
ra2ce.analysis.losses.multi_link_isolated_locations module#
- class MultiLinkIsolatedLocations(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
Execute the analysis on the given graph/network with the given analysis parameters. The resulting (Geo)DataFrame of the analysis is stored in the result attribute. TODO: Make the return type a result object #318
- Return type:
- Returns:
AnalysisResultWrapper: The result of the analysis.
- get_network_with_edge_fid(graph)[source]#
This function converts a NetworkX graph into a GeoDataFrame representing the network. It also constructs an ‘edge_fid’ column based on the ‘node_A’ and ‘node_B’ columns, following a specific convention.
- Return type:
GeoDataFrame
- Parameters:
graph (Graph)
- Args:
G (nx.Graph): The NetworkX graph to be converted.
- Returns:
gpd.GeoDataFrame: The resulting GeoDataFrame, with an added ‘edge_fid’ column.
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
- multi_link_isolated_locations(graph, analysis, crs=4326)[source]#
This function identifies locations that are flooded or isolated due to the disruption of the network caused by a hazard. It iterates over multiple hazard scenarios, modifies the graph to represent direct and indirect impacts, and then spatially joins the impacted network with the location data to find out which locations are affected.
- Return type:
tuple
[GeoDataFrame
,DataFrame
]- Parameters:
graph (Graph)
analysis (AnalysisSectionLosses)
- Args:
graph (nx.Graph): The original graph representing the network, with additional hazard information. analysis (AnalysisSectionLosses): The configuration of the analysis, which contains the threshold for considering a hazard impact significant. crs (int, optional): The coordinate reference system used for geographical data. Defaults to 4326 (WGS84).
- Returns:
- tuple (gpd.GeoDataFrame, pd.DataFrame): A tuple containing the location GeoDataFrame updated with hazard impacts,
and a DataFrame summarizing the impacts per location category.
-
output_path:
Path
#
- remove_edges_from_largest_component(disconnected_graph)[source]#
This function removes all edges from the largest connected component of a graph.
- Return type:
None
- Parameters:
disconnected_graph (Graph)
- Args:
disconnected_graph (nx.Graph): The graph from which to remove the edges.
-
static_path:
Path
#
- utm_crs(bbox)[source]#
Returns wkt string of nearest UTM projects :type bbox:
list
[float
] :param bbox: (xmin, ymin, xmax, ymax) bounding box in latlon WGS84 (EPSG:4326) coordinates :type bbox:array-like
offloats
- Return type:
CRS
- Returns:
crs (
pyproj.CRS
) – CRS of UTM projectionFROM HYDROMT (
https://github.com/Deltares/hydromt - 10.5281/zenodo.6107669
)
- Parameters:
bbox (list[float])
ra2ce.analysis.losses.multi_link_losses module#
- class MultiLinkLosses(analysis_input, analysis_config)[source]#
Bases:
LossesBase
Calculates the multi-link redundancy losses of a NetworkX graph.
The function removes all links of a variable that have a minimum value of min_threshold. For each link it calculates the alternative path, if any available. This function only removes one group at the time and saves the data from removing that group.
This class is based on the LossesBase abstract base class. Don’t override other methods than _get_criticality_analysis.
- Parameters:
analysis_input (AnalysisInputWrapper)
analysis_config (AnalysisConfigWrapper)
ra2ce.analysis.losses.multi_link_origin_closest_destination module#
- class MultiLinkOriginClosestDestination(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
Execute the analysis on the given graph/network with the given analysis parameters. The resulting (Geo)DataFrame of the analysis is stored in the result attribute. TODO: Make the return type a result object #318
- Return type:
- Returns:
AnalysisResultWrapper: The result of the analysis.
-
file_id:
str
#
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
-
origins_destinations:
OriginsDestinationsSection
#
-
output_path:
Path
#
-
static_path:
Path
#
ra2ce.analysis.losses.multi_link_origin_destination module#
- class MultiLinkOriginDestination(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
Execute the analysis on the given graph/network with the given analysis parameters. The resulting (Geo)DataFrame of the analysis is stored in the result attribute. TODO: Make the return type a result object #318
- Return type:
- Returns:
AnalysisResultWrapper: The result of the analysis.
- static extract_od_nodes_from_graph(graph)[source]#
Extracts all Origin - Destination nodes from the graph, prevents from entries with list of nodes for a node.
- Return type:
list
[tuple
[str
,str
]]- Parameters:
graph (MultiGraph)
- Args:
graph (nx.MultiGraph): Graph containing origin-destination nodes.
- Returns:
list[tuple[str, str]]]: List containing tuples of origin - destination node combinations.
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
- multi_link_origin_destination(graph, analysis)[source]#
Calculates the connectivity between origins and destinations.
- Return type:
GeoDataFrame
- Parameters:
graph (MultiGraph)
analysis (AnalysisSectionLosses)
- Args:
graph: The MultiGraph representing the network. analysis: The AnalysisSectionLosses object containing OD information.
- Returns:
GeoDataFrame: Connectivity results between origins and destinations.
- multi_link_origin_destination_impact(gdf, gdf_ori)[source]#
Calculates some default indicators that quantify the impacts of disruptions to origin-destination flows The function outputs the following file:
- gdf_ori (multi_link_origin_destination_impact.csv), containing the following information:
origin and destination node
length: initial shortest path length before disruptions
length_hazardName: shortest path length after disruption
diff_length_hazardName: increase in shortest path length after disruption (length_hazardName - length)
diff_length_hazardName_pc: same as above, but as a fraction of initial length
- diff_df (multi_link_origin_destination_impact_summary.csv), containing the following information:
hazard: hazard name
od_disconnected_abs: number of OD disconnected
od_disconnected_pc (%): percentage of OD disconnected
origin_disconnected_abs: number of origin points disconnected
origin_disconnected_pc (%): percentage of origin points disconnected
destination_disconnected_abs: number of destination points disconnected
destination_disconnected_pc (%): percentage of destination points disconnected
max_increase_abs: maximum increase in travel length across all OD pairs
mean_increase_abs: mean increase in travel length across all OD pairs
median_increase_abs: median increase in travel length across all OD pairs
max_increase_pc, mean_increase_pc, median_increase_pc (%): same as above three, but as a percentage relative to no-hazard
- Return type:
tuple
[DataFrame
,GeoDataFrame
]- Parameters:
gdf (GeoDataFrame)
gdf_ori (GeoDataFrame)
- multi_link_origin_destination_regional_impact(gdf_ori)[source]#
Aggregate the impacts of disruptions at the regional level.
Users need to specify the ‘region’ and ‘region_var’ attributes in the network.ini file. See the Pontianak case study for an example.
The function outputs two files:
multi_link_origin_destination_regional_impact.csv - Impacts of disruption aggregated for each origin node. - Retains region information (which region each origin node belongs to).
multi_link_origin_destination_regional_impact_summary.csv - Impacts of disruption aggregated for each region.
Both files contain the following information:
init_length: Initial average length to all destination nodes (for each origin node and each region).
init_destination: Initial number of destination nodes.
hazardName_pc_increase: Average increase in travel time to all destination nodes (percentage relative to initial travel time, for each origin node and each region).
hazardName_pc_disconnect: Average number of OD pairs disconnected (relative to initial number of OD pairs, for each origin node and each region).
- Args:
gdf_ori (GeoDataFrame): GeoDataFrame containing the origin nodes.
- Returns:
- tuple[GeoDataFrame, GeoDataFrame]:
First GeoDataFrame: aggregated results per origin node.
Second GeoDataFrame: aggregated results per region.
- Return type:
tuple
[GeoDataFrame
,GeoDataFrame
]- Parameters:
gdf_ori (GeoDataFrame)
-
origins_destinations:
OriginsDestinationsSection
#
-
output_path:
Path
#
-
static_path:
Path
#
ra2ce.analysis.losses.multi_link_redundancy module#
- class MultiLinkRedundancy(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
Calculates the multi-link redundancy of a NetworkX graph.
The function removes all links of a variable that have a minimum value of min_threshold. For each link it calculates the alternative path, if any available. This function only removes one group at the time and saves the data from removing that group.
- Return type:
- Returns:
AnalysisResultWrapper: The results of the analysis aggregated into a table.
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
-
output_path:
Path
#
-
static_path:
Path
#
ra2ce.analysis.losses.optimal_route_origin_closest_destination module#
- class OptimalRouteOriginClosestDestination(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
Execute the analysis on the given graph/network with the given analysis parameters. The resulting (Geo)DataFrame of the analysis is stored in the result attribute. TODO: Make the return type a result object #318
- Return type:
- Returns:
AnalysisResultWrapper: The result of the analysis.
-
file_id:
str
#
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
-
origins_destinations:
OriginsDestinationsSection
#
-
output_path:
Path
#
-
static_path:
Path
#
ra2ce.analysis.losses.optimal_route_origin_destination module#
- class OptimalRouteOriginDestination(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
Execute the analysis on the given graph/network with the given analysis parameters. The resulting (Geo)DataFrame of the analysis is stored in the result attribute. TODO: Make the return type a result object #318
- Return type:
- Returns:
AnalysisResultWrapper: The result of the analysis.
- static extract_od_nodes_from_graph(graph)[source]#
Extracts all Origin - Destination nodes from the graph, prevents from entries with list of nodes for a node.
- Return type:
list
[tuple
[str
,str
]]- Parameters:
graph (MultiGraph)
- Args:
graph (nx.MultiGraph): Graph containing origin-destination nodes.
- Returns:
list[tuple[str, str]]]: List containing tuples of origin - destination node combinations.
- static find_route_ods(graph, od_nodes, weighing)[source]#
- Return type:
GeoDataFrame
- Parameters:
graph (MultiGraph)
od_nodes (list[tuple[tuple[str, str], tuple[str, str]]])
weighing (WeighingEnum)
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
- optimal_route_od_link(road_network, od_table, equity)[source]#
- Return type:
DataFrame
- Parameters:
road_network (GeoDataFrame)
od_table (GeoDataFrame)
equity (DataFrame)
- optimal_route_origin_destination(graph, analysis)[source]#
- Return type:
GeoDataFrame
- Parameters:
graph (MultiGraph)
analysis (AnalysisSectionLosses)
-
origins_destinations:
OriginsDestinationsSection
#
-
output_path:
Path
#
-
static_path:
Path
#
ra2ce.analysis.losses.origin_closest_destination module#
- GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Risk Assessment and Adaptation for Critical Infrastructure (RA2CE). Copyright (C) 2023 Stichting Deltares
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- class OriginClosestDestination(analysis_input)[source]#
Bases:
object
The origin closest destination analyses using NetworkX graphs.
- Attributes:
file_id: The file id of the network. origins_destinations: An object with the origins and destinations. analysis: An object with the analysis details. graph_file: An object with the NetworkX graph. graph_file_hazard: An object with the NetworkX graph with hazard disruption. hazard_names: An object with the hazard names.
- Parameters:
analysis_input (AnalysisInputWrapper)
- compare_route_with_without_disruption(pref_routes, nr_per_route, alt_route, alt_dist)[source]#
- Return type:
None
- Parameters:
pref_routes (GeoDataFrame)
nr_per_route (float)
alt_route (float)
alt_dist (float)
- difference_length_with_without_hazard(with_hazard, without_hazard)[source]#
- Return type:
GeoDataFrame
- Parameters:
with_hazard (GeoDataFrame)
without_hazard (GeoDataFrame)
- find_closest_location(disrupted_graph, base_graph, origins, destinations, column_name, hazard_name=None, pref_routes=None)[source]#
Find the closest destination nodes with a certain attribute from all origin nodes for a single destination.
- Return type:
tuple
[MultiGraph
,GeoDataFrame
,GeoDataFrame
,list
,GeoDataFrame
]- Parameters:
disrupted_graph (MultiGraph)
base_graph (MultiGraph)
origins (GeoDataFrame)
destinations (GeoDataFrame)
column_name (str)
hazard_name (str)
pref_routes (GeoDataFrame)
- Args:
disrupted_graph (nx.MultiGraph): NetworkX graph with origin and destination nodes and disrupted edges removed. base_graph (nx.MultiGraph): Original NetworkX graph. origins (gpd.GeoDataFrame): GeoDataFrame containing the origins. destinations (gpd.GeoDataFrame): GeoDataFrame containing the destinations. column_name (str): Name of the column to be added to the base_graph, origins, destinations, and results_dict. hazard_name (str, optional): Name of the hazard (an attribute of the edges in disrupted_graph). Defaults to None. pref_routes (gpd.GeoDataFrame, optional): GeoDataFrame containing preferred routes without disruption. Defaults to None.
- Returns:
- tuple:
base_graph (nx.MultiGraph): The updated base graph.
origins (gpd.GeoDataFrame): Updated origins GeoDataFrame.
destinations (gpd.GeoDataFrame): Updated destinations GeoDataFrame.
list_disrupted_destinations (list): List of tuples with origin and destination node id and name for unreachable destinations.
pref_routes (gpd.GeoDataFrame): Updated preferred routes.
- find_multiple_closest_locations(disrupted_graph, base_graph, origins, destinations, column_name, hazard_name=None, pref_routes=None)[source]#
Find the closest destination nodes with a certain attribute from all origin nodes for multiple destinations.
- Return type:
tuple
[MultiGraph
,GeoDataFrame
,GeoDataFrame
,list
,GeoDataFrame
]- Parameters:
disrupted_graph (MultiGraph)
base_graph (MultiGraph)
origins (GeoDataFrame)
destinations (GeoDataFrame)
column_name (str)
hazard_name (str)
pref_routes (GeoDataFrame)
- Args:
disrupted_graph (nx.MultiGraph): NetworkX graph with origin and destination nodes and disrupted edges removed. base_graph (nx.MultiGraph): Original NetworkX graph. origins (gpd.GeoDataFrame): GeoDataFrame containing the origins. destinations (gpd.GeoDataFrame): GeoDataFrame containing the destinations. column_name (str): Name of the column to be added to base_graph, origins, destinations, and results_dict. hazard_name (str, optional): Name of the hazard. Defaults to None. pref_routes (gpd.GeoDataFrame, optional): GeoDataFrame containing the preferred routes without disruption. Defaults to None.
- Returns:
- tuple:
base_graph (nx.MultiGraph): The updated base graph.
origins (gpd.GeoDataFrame): Updated origins GeoDataFrame.
destinations (gpd.GeoDataFrame): Updated destinations GeoDataFrame.
list_disrupted_destinations (list): List of tuples with origin and destination node id and node name for unreachable destinations.
pref_routes (gpd.GeoDataFrame): Updated preferred routes.
- get_nr_people_on_route(origins, origin_node)[source]#
- Return type:
float
- Parameters:
origins (GeoDataFrame)
origin_node (str)
- get_nr_without_access(origins, origins_without_access, add_key_name=None)[source]#
- Return type:
None
- Parameters:
origins (GeoDataFrame)
origins_without_access (list)
add_key_name (str)
- get_route_length(graph, origin_node, destination_node)[source]#
- Return type:
float
- Parameters:
graph (MultiGraph)
origin_node (int)
destination_node (int)
- get_route_path(graph, base_graph, origin_node, destination_node, nr_from_origin, col_name)[source]#
- Return type:
tuple
[MultiGraph
,float
,MultiLineString
]- Parameters:
graph (MultiGraph)
base_graph (MultiGraph)
origin_node (int)
destination_node (int)
nr_from_origin (float)
col_name (str)
- multi_link_origin_closest_destination()[source]#
Calculates per origin the location of its closest destination with hazard disruption
- Return type:
tuple
[MultiGraph
,GeoDataFrame
,GeoDataFrame
,DataFrame
,GeoDataFrame
]
- optimal_route_origin_closest_destination()[source]#
Calculates per origin the location of its closest destination
- Return type:
tuple
[MultiGraph
,GeoDataFrame
,GeoDataFrame
]
ra2ce.analysis.losses.single_link_losses module#
- class SingleLinkLosses(analysis_input, analysis_config)[source]#
Bases:
LossesBase
Calculates the single-link redundancy losses of a NetworkX graph. This is the function to analyse roads with a single link disruption and an alternative route.
This class is based on the LossesBase abstract base class. Don’t override other methods than _get_criticality_analysis.
- Parameters:
analysis_input (AnalysisInputWrapper)
analysis_config (AnalysisConfigWrapper)
ra2ce.analysis.losses.single_link_redundancy module#
- class SingleLinkRedundancy(analysis_input)[source]#
Bases:
AnalysisBase
,AnalysisLossesProtocol
- Parameters:
analysis_input (AnalysisInputWrapper)
-
analysis:
AnalysisSectionLosses
#
- execute()[source]#
This is the function to analyse roads with a single link disruption and an alternative route.
- Return type:
-
hazard_names:
HazardNames
#
-
input_path:
Path
#
-
output_path:
Path
#
-
static_path:
Path
#