ra2ce.analysis.losses package#

Subpackages#

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/>.

class AnalysisLossesProtocol(*args, **kwargs)[source]#

Bases: AnalysisProtocol

analysis: AnalysisSectionLosses#
graph_file: Optional[GraphFile]#
graph_file_hazard: Optional[GraphFile]#
hazard_names: HazardNames#
input_path: Path#
output_path: Path#
static_path: Path#

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:

AnalysisResultWrapper

Returns:

AnalysisResultWrapper: The result of the analysis.

graph_file_hazard: GraphFile#
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 = ';'#

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:

AnalysisResultWrapper

Returns:

AnalysisResultWrapper: The result of the analysis.

file_id: str#
graph_file_hazard: GraphFile#
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:

AnalysisResultWrapper

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)

graph_file: GraphFile#
hazard_names: HazardNames#
input_path: Path#
Return type:

DataFrame

Parameters:
  • road_network (GeoDataFrame)

  • od_table (GeoDataFrame)

  • equity (DataFrame)

optimal_route_origin_destination(graph, analysis)[source]#
Return type:

GeoDataFrame

Parameters:
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)

load_destinations()[source]#
Return type:

GeoDataFrame

load_origins()[source]#
Return type:

GeoDataFrame

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]

update_destinations(destinations, destination_name, nr_per_route, col_name)[source]#
Return type:

GeoDataFrame

Parameters:
  • destinations (GeoDataFrame)

  • destination_name (str)

  • nr_per_route (float)

  • col_name (str)

update_origins(origins, other, col_name)[source]#
Return type:

GeoDataFrame

Parameters:
  • origins (GeoDataFrame)

  • other (list)

  • col_name (str)

Module contents#