From 2ae82fb3393916a4ecedc36f736c8b3bdb81a076 Mon Sep 17 00:00:00 2001 From: Daniel Tollenaar Date: Fri, 18 Oct 2024 15:40:09 +0200 Subject: [PATCH] fix aam --- notebooks/aa_en_maas/01_fix_model_network.py | 170 +++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/notebooks/aa_en_maas/01_fix_model_network.py b/notebooks/aa_en_maas/01_fix_model_network.py index 17f2857..f5b9270 100644 --- a/notebooks/aa_en_maas/01_fix_model_network.py +++ b/notebooks/aa_en_maas/01_fix_model_network.py @@ -1,6 +1,8 @@ # %% +import geopandas as gpd import numpy as np import pandas as pd +from ribasim import Node from ribasim.nodes import basin, level_boundary, manning_resistance, outlet from ribasim_nl import CloudStorage, Model, NetworkValidator @@ -18,6 +20,12 @@ ribasim_toml = cloud.joinpath(authority, "modellen", f"{authority}_fix_model_network", f"{short_name}.toml") network_validator = NetworkValidator(model) + +hydroobject_gdf = gpd.read_file( + cloud.joinpath(authority, "verwerkt", "4_ribasim", "hydamo.gpkg"), layer="hydroobject", fid_as_index=True +) + + # %% some stuff we'll need again manning_data = manning_resistance.Static(length=[100], manning_n=[0.04], profile_width=[10], profile_slope=[1]) level_data = level_boundary.Static(level=[0]) @@ -42,9 +50,158 @@ # Verwijderen duplicate edges model.edge.df.drop_duplicates(inplace=True) +# %% https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2421959240 + +# Verwijderen edge met 0m lengte +model.remove_node(34, remove_edges=True) +model.update_node(1568, "LevelBoundary", data=[level_data], node_properties={"name": ""}) + + +# %% see: https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2421946693 +# toevoegen ontbrekende basins + +basin_edges_df = network_validator.edge_incorrect_connectivity() +basin_nodes_df = network_validator.node_invalid_connectivity() + +for row in basin_nodes_df.itertuples(): + # maak basin-node + basin_node = model.basin.add(Node(geometry=row.geometry), tables=basin_data) + + # update edge_table + model.edge.df.loc[basin_edges_df[basin_edges_df.from_node_id == row.node_id].index, ["from_node_id"]] = ( + basin_node.node_id + ) + model.edge.df.loc[basin_edges_df[basin_edges_df.to_node_id == row.node_id].index, ["to_node_id"]] = ( + basin_node.node_id + ) + +# %% see: https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2421991252 + +# Corrigeren netwerk Den Bosch + +# Binnenstad +basin_node = model.basin.add(Node(geometry=hydroobject_gdf.at[2788, "geometry"].boundary.geoms[0]), tables=basin_data) + +model.reverse_edge(edge_id=2077) +model.redirect_edge(edge_id=2077, to_node_id=basin_node.node_id) +model.redirect_edge(edge_id=2078, from_node_id=basin_node.node_id) +model.redirect_edge(edge_id=2079, from_node_id=basin_node.node_id) +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[4999, "geometry"].interpolate(0.5, normalized=True)), tables=[outlet_data] +) +model.edge.add(model.level_boundary[46], outlet_node) +model.edge.add(outlet_node, basin_node) + +# Dommel +basin_node = model.basin.add( + Node(geometry=hydroobject_gdf.at[9055, "geometry"].interpolate(0.5, normalized=True)), tables=basin_data +) +model.redirect_edge(edge_id=2082, from_node_id=basin_node.node_id) + +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[9055, "geometry"].interpolate(0.1, normalized=True)), tables=[outlet_data] +) + +model.edge.add(model.level_boundary[49], outlet_node) +model.edge.add(outlet_node, basin_node) + + +# %% see: https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2422078500 + +# Corrigeren netwerk bij sluis Empel +for node_id in [729, 730, 1990, 1962]: + model.remove_node(node_id, remove_edges=True) + + +# Omkeren edgerichting +for edge_id in [131, 398, 406, 495, 513, 515, 894]: + model.reverse_edge(edge_id=edge_id) + +# %% see: https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2422164355 + +# Corrigeren netwerk bij Spuisluis Crèvecoeur +model.remove_node(411, remove_edges=True) +model.remove_node(4, remove_edges=True) +model.redirect_edge(edge_id=2018, to_node_id=1950) + +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[4825, "geometry"].boundary.geoms[0], name="Spuisluis Crèvecoeur"), + tables=[outlet_data], +) + +model.edge.add(outlet_node, model.level_boundary[5]) +model.edge.add(model.basin[1627], outlet_node) + +# %% see: https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2422373708 + +# Corrigeren Afleidingskanaal bij Holthees + +# nabij grens +basin_node = model.basin.add(Node(geometry=hydroobject_gdf.at[8868, "geometry"].boundary.geoms[0]), tables=basin_data) +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[4680, "geometry"].interpolate(0.1, normalized=True)), tables=[outlet_data] +) + +model.redirect_edge(edge_id=2091, from_node_id=56, to_node_id=outlet_node.node_id) +model.redirect_edge(edge_id=2092, from_node_id=outlet_node.node_id, to_node_id=basin_node.node_id) +model.redirect_edge(edge_id=2093, from_node_id=653, to_node_id=basin_node.node_id) +model.redirect_edge(edge_id=2094, from_node_id=basin_node.node_id, to_node_id=82) + +# nabij afleidingskanaal +basin_node = model.basin.add(Node(geometry=hydroobject_gdf.at[7466, "geometry"].boundary.geoms[0]), tables=basin_data) +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[8456, "geometry"].interpolate(0.1, normalized=True)), tables=[outlet_data] +) +model.redirect_edge(edge_id=2089, to_node_id=outlet_node.node_id) +model.redirect_edge(edge_id=2088, from_node_id=outlet_node.node_id, to_node_id=basin_node.node_id) +model.edge.add(model.tabulated_rating_curve[82], basin_node) +model.edge.add(basin_node, model.tabulated_rating_curve[853]) + +# nabij Maas +basin_node = model.basin.add(Node(geometry=hydroobject_gdf.at[2385, "geometry"].boundary.geoms[0]), tables=basin_data) +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[2539, "geometry"].boundary.geoms[0]), tables=[outlet_data] +) + +model.redirect_edge(edge_id=2054, to_node_id=basin_node.node_id) +model.edge.add(basin_node, outlet_node) +model.edge.add(outlet_node, model.level_boundary[26]) + + +# %% see: https://github.com/Deltares/Ribasim-NL/issues/149#issuecomment-2422452167 + +# Toevoegen basin bij Oude Zuid-Willemsvaart +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[3174, "geometry"].boundary.geoms[0], name="Sluis 9"), tables=[outlet_data] +) +basin_node = model.basin.add(Node(geometry=hydroobject_gdf.at[6499, "geometry"].boundary.geoms[0]), tables=basin_data) +model.redirect_edge(edge_id=2102, to_node_id=outlet_node.node_id) +model.edge.add(outlet_node, basin_node) +model.redirect_edge(edge_id=2106, to_node_id=2026) + +outlet_node = model.outlet.add( + Node(geometry=hydroobject_gdf.at[646, "geometry"].interpolate(0.9, normalized=True)), tables=[outlet_data] +) +model.edge.add(basin_node, outlet_node) +model.edge.add(outlet_node, model.level_boundary[66]) + # EINDE ISSUES +# %% +# corrigeren knoop-topologie + +# ManningResistance bovenstrooms LevelBoundary naar Outlet +for row in network_validator.edge_incorrect_type_connectivity().itertuples(): + model.update_node(row.from_node_id, "Outlet", data=[outlet_data]) + +# Inlaten van ManningResistance naar Outlet +for row in network_validator.edge_incorrect_type_connectivity( + from_node_type="LevelBoundary", to_node_type="ManningResistance" +).itertuples(): + model.update_node(row.to_node_id, "Outlet", data=[outlet_data]) + + ## UPDATEN STATIC TABLES # %% @@ -103,6 +260,19 @@ df.index.name = "fid" model.manning_resistance.static.df = df +# %% +# flow boundaries updaten +length = len(model.flow_boundary.node.df) +df = pd.DataFrame( + { + "node_id": model.flow_boundary.node.df.index.to_list(), + "flow_rate": [0.0] * length, + } +) +df.index.name = "fid" +model.flow_boundary.static.df = df + + # %% write model model.use_validation = True model.write(ribasim_toml)