ra2ce.network.network_simplification package#

Submodules#

ra2ce.network.network_simplification.network_graph_simplificator 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 NetworkGraphSimplificator(*, graph_complex, attributes_to_exclude, new_id='rfid')[source]#

Bases: object

Factory dataclass to simplify the containing graph.

Parameters:
  • graph_complex (Graph | MultiGraph | MultiDiGraph)

  • attributes_to_exclude (list[str])

  • new_id (str)

attributes_to_exclude: list[str]#
graph_complex: Graph | MultiGraph | MultiDiGraph#
new_id: str = 'rfid'#
simplify()[source]#

Create a simplified graph with unique ids from a complex graph

Return type:

tuple[Graph, Graph, tuple[dict, dict]]

Returns:

tuple[nx.Graph, nx.Graph, tuple[dict, dict]]: The simple and complex graph and the “id” tables.

ra2ce.network.network_simplification.network_simplification_with_attribute_exclusion 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 NetworkSimplificationWithAttributeExclusion(*, nx_graph, attributes_to_exclude)[source]#

Bases: object

Simplifies a network by excluding a given set of attributes (columns).

Parameters:
  • nx_graph (Graph | MultiGraph | MultiDiGraph)

  • attributes_to_exclude (list[str])

attributes_to_exclude: list[str]#
nx_graph: Graph | MultiGraph | MultiDiGraph#
simplify_graph()[source]#

Simplifies the inner graph by using the snkit package.

Return type:

Graph

Returns:

nx.Graph: Resulting simplified graph.

ra2ce.network.network_simplification.network_simplification_without_attribute_exclusion 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 NetworkSimplificationWithoutAttributeExclusion(*, nx_graph)[source]#

Bases: object

Simplifies a network with the osmnx.simplification functionality.

Parameters:

nx_graph (Graph | MultiGraph | MultiDiGraph)

nx_graph: Graph | MultiGraph | MultiDiGraph#
simplify_graph()[source]#

Simplify the graph after adding missing x and y attributes to nodes

Return type:

Graph

Returns:

nx.Graph: Simplified graph

ra2ce.network.network_simplification.nx_to_snkit_network_converter 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 NxToSnkitNetworkConverter(*, networkx_graph, node_id_column_name='id', edge_from_id_column_name='from_id', edge_to_id_column_name='to_id')[source]#

Bases: object

Class responsible to convert a networkx.MultiGraph into a matching snkit.network.Network.

Parameters:
  • networkx_graph (Graph | MultiGraph | MultiDiGraph)

  • node_id_column_name (str)

  • edge_from_id_column_name (str)

  • edge_to_id_column_name (str)

convert()[source]#

Converts a regular NetworkX.graph into a snkit.network.Network object.

Return type:

Network

Returns:

SnkitNetwork: The resulting snkit.network.Network converted object.

edge_from_id_column_name: str = 'from_id'#
edge_to_id_column_name: str = 'to_id'#
networkx_graph: Graph | MultiGraph | MultiDiGraph#
node_id_column_name: str = 'id'#

ra2ce.network.network_simplification.snkit_network_merge_wrapper 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 GdfSnkitNetworkMerger(geo_dataframe, snkit_network)[source]#

Bases: object

Merger of a gpd.GeoDataFrame and a snkit.network.network. This class was created to contain the related close and try reducing the code’s complexity.

Parameters:
  • geo_dataframe (GeoDataFrame)

  • snkit_network (Network)

merge(by, aggregate_func)[source]#

Merges the inner defined gpd.GeoDataFrame and snkit.network.Network based on the given arguments (by) and aggregation function ()`aggregate_func`).

Return type:

GeoDataFrame

Parameters:
  • by (list)

  • aggregate_func (dict)

NxGraph = networkx.classes.graph.Graph | networkx.classes.multigraph.MultiGraph | networkx.classes.multidigraph.MultiDiGraph#

Disclaimer!

This file contains several complex logic introduced in feature #277. At the moment it was not possible to streamline / improve it further than its current state.

merge_edges(snkit_network, networkx_graph, aggregate_func, by, id_col)[source]#

Merges the edges of a given snkit.network.Network.

Return type:

Network

Parameters:
  • snkit_network (Network)

  • networkx_graph (Graph | MultiGraph | MultiDiGraph)

  • aggregate_func (str | dict)

  • by (str | list)

  • id_col (str)

Args:

snkit_network (SnkitNetwork): network to merge. networkx_graph (NxGraph): networkx graph to merge aggregate_func (str | dict): Aggregation function to apply. by (str | list): Arguments (column names). id_col (str, optional): Name of the column representing the ‘id’.

Returns:

SnkitNetwork: _description_

ra2ce.network.network_simplification.snkit_network_wrapper 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 SnkitNetworkWrapper(snkit_network, node_id_column_name, edge_from_id_column_name, edge_to_id_column_name)[source]#

Bases: object

Wrapper created to reduce complexity of conversion and processing of a snkit.network.Network within the rest of the code.

Parameters:
  • snkit_network (Network)

  • node_id_column_name (str)

  • edge_from_id_column_name (str)

  • edge_to_id_column_name (str)

edge_from_id_column_name: str#
edge_to_id_column_name: str#
classmethod from_networkx(networkx_graph, column_names_dict)[source]#

Generates a SnkitNetworkWrapper based on the given NxGraph.

Return type:

SnkitNetworkWrapper

Parameters:
  • networkx_graph (Graph | MultiGraph | MultiDiGraph)

  • column_names_dict (dict[str, str])

Args:

networkx_graph (NxGraph): Graph to convert. column_names_dict (dict[str, str]): Column names to use.

Returns:

SnkitNetworkWrapper: Wrapper containing the converted snkit.network.Network.

merge_edges(attributes_to_exclude)[source]#
Return type:

None

Parameters:

attributes_to_exclude (list[str])

node_id_column_name: str#
process_network()[source]#
Return type:

None

snkit_network: Network#
to_networkx()[source]#

Converts the wrapped snkit_network into a corresponding networkx.Graph.

Return type:

Graph | MultiGraph | MultiDiGraph

Returns:

NxGraph: The converted graph.

ra2ce.network.network_simplification.snkit_to_nx_network_converter 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 SnkitToNxNetworkConverter(*, snkit_network, node_id_column_name='id', edge_from_id_column_name='from_id', edge_to_id_column_name='to_id')[source]#

Bases: object

Class responsible to convert a snkit.network.Network into a matching networkx.MultiGraph.

Parameters:
  • snkit_network (Network)

  • node_id_column_name (str)

  • edge_from_id_column_name (str)

  • edge_to_id_column_name (str)

convert()[source]#

Converts the given snkit.network.Network into a matching networkx.MultiGraph.

Return type:

MultiDiGraph

Args:

snkit_network (SnkitNetwork): The snkit network to convert.

Returns:

networkx.MultiDiGraph: The converted graph.

edge_from_id_column_name: str = 'from_id'#
edge_to_id_column_name: str = 'to_id'#
node_id_column_name: str = 'id'#
snkit_network: Network#

Module contents#