From e9486088b343129e311282721c50c2a4946f8ac4 Mon Sep 17 00:00:00 2001 From: Daniel Tollenaar Date: Thu, 7 Nov 2024 13:09:50 +0100 Subject: [PATCH] Fix nxv (#184) fixes for #155 --------- Co-authored-by: Martijn Visser --- notebooks/noorderzijlvest/00_get_verwerkt.py | 11 ++ .../noorderzijlvest/01_fix_model_network.py | 111 ++++++++++++++++++ pixi.lock | 8 +- 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 notebooks/noorderzijlvest/00_get_verwerkt.py create mode 100644 notebooks/noorderzijlvest/01_fix_model_network.py diff --git a/notebooks/noorderzijlvest/00_get_verwerkt.py b/notebooks/noorderzijlvest/00_get_verwerkt.py new file mode 100644 index 0000000..fd1b030 --- /dev/null +++ b/notebooks/noorderzijlvest/00_get_verwerkt.py @@ -0,0 +1,11 @@ +# %% +from ribasim_nl import CloudStorage + +cloud = CloudStorage() + +data_url = cloud.joinurl("Noorderzijlvest", "verwerkt") + +# %% +cloud.download_content(data_url) + +# %% diff --git a/notebooks/noorderzijlvest/01_fix_model_network.py b/notebooks/noorderzijlvest/01_fix_model_network.py new file mode 100644 index 0000000..a0a4131 --- /dev/null +++ b/notebooks/noorderzijlvest/01_fix_model_network.py @@ -0,0 +1,111 @@ +# %% +import numpy as np +import pandas as pd +from ribasim.nodes import basin, level_boundary, manning_resistance, outlet, pump + +from ribasim_nl import CloudStorage, Model, NetworkValidator + +cloud = CloudStorage() + +authority = "Noorderzijlvest" +short_name = "nzv" + +ribasim_toml = cloud.joinpath(authority, "modellen", f"{authority}_2024_6_3", f"{short_name}.toml") +database_gpkg = ribasim_toml.with_name("database.gpkg") + +# %% read model +model = Model.read(ribasim_toml) +ribasim_toml = cloud.joinpath(authority, "modellen", f"{authority}_fix_model_network", f"{short_name}.toml") +network_validator = NetworkValidator(model) + +# %% 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]) + +basin_data = [ + basin.Profile(level=[0.0, 1.0], area=[0.01, 1000.0]), + basin.Static( + drainage=[0.0], + potential_evaporation=[0.001 / 86400], + infiltration=[0.0], + precipitation=[0.005 / 86400], + ), + basin.State(level=[0]), +] +outlet_data = outlet.Static(flow_rate=[100]) +pump_data = pump.Static(flow_rate=[10]) + +# %% +# %% https://github.com/Deltares/Ribasim-NL/issues/155#issuecomment-2454955046 + +# 76 edges bij opgeheven nodes verwijderen +mask = model.edge.df.to_node_id.isin(model.node_table().df.index) & model.edge.df.from_node_id.isin( + model.node_table().df.index +) +missing_edges_df = model.edge.df[~mask] + +model.edge.df = model.edge.df[~model.edge.df.index.isin(missing_edges_df.index)] + +# %% +# basin-profielen updaten + +df = pd.DataFrame( + { + "node_id": np.repeat(model.basin.node.df.index.to_numpy(), 2), + "level": [0.0, 1.0] * len(model.basin.node.df), + "area": [0.01, 1000.0] * len(model.basin.node.df), + } +) +df.index.name = "fid" +model.basin.profile.df = df + +df = model.basin.profile.df.groupby("node_id")[["level"]].max().reset_index() +df.index.name = "fid" +model.basin.state.df = df + +# %% +# tabulated_rating_curves updaten +df = pd.DataFrame( + { + "node_id": np.repeat(model.tabulated_rating_curve.node.df.index.to_numpy(), 2), + "level": [0.0, 5] * len(model.tabulated_rating_curve.node.df), + "flow_rate": [0, 0.1] * len(model.tabulated_rating_curve.node.df), + } +) +df.index.name = "fid" +model.tabulated_rating_curve.static.df = df + + +# %% + +# level_boundaries updaten +df = pd.DataFrame( + { + "node_id": model.level_boundary.node.df.index.to_list(), + "level": [0.0] * len(model.level_boundary.node.df), + } +) +df.index.name = "fid" +model.level_boundary.static.df = df + +# %% +# manning_resistance updaten +length = len(model.manning_resistance.node.df) +df = pd.DataFrame( + { + "node_id": model.manning_resistance.node.df.index.to_list(), + "length": [100.0] * length, + "manning_n": [100.0] * length, + "profile_width": [100.0] * length, + "profile_slope": [100.0] * length, + } +) +df.index.name = "fid" +model.manning_resistance.static.df = df + + +# %% write model +model.use_validation = True +model.write(ribasim_toml) + +# %% diff --git a/pixi.lock b/pixi.lock index e8534b9..c07be47 100644 --- a/pixi.lock +++ b/pixi.lock @@ -14706,10 +14706,12 @@ packages: name: peilbeheerst-model version: 0.1.0 path: src/peilbeheerst_model - sha256: e8c270f68d683c802990a8bb905cd665fd327b33e1d17bf3e01dfe9c49ec335e + sha256: 9ec22544800123361c4449542c548c1e3739a3f8d9d5bbe2f91a8d50d304fac5 requires_dist: + - fiona - geopandas - matplotlib + - networkx - numpy - pandas - pydantic @@ -16989,7 +16991,7 @@ packages: name: ribasim version: 2024.11.0 path: ../Ribasim/python/ribasim - sha256: c48692687129085ad19256cbf54c8df9853f6259b31997cc4a282fde86072751 + sha256: ba8a6a24955e974dd0d7ae81ad59546134417f48eabce10cb280ac5f8c3290db requires_dist: - geopandas - matplotlib @@ -17008,6 +17010,7 @@ packages: - pytest-cov ; extra == 'all' - pytest-xdist ; extra == 'all' - ribasim-testmodels ; extra == 'all' + - teamcity-messages ; extra == 'all' - xugrid ; extra == 'all' - jinja2 ; extra == 'delwaq' - networkx ; extra == 'delwaq' @@ -17017,6 +17020,7 @@ packages: - pytest-cov ; extra == 'tests' - pytest-xdist ; extra == 'tests' - ribasim-testmodels ; extra == 'tests' + - teamcity-messages ; extra == 'tests' requires_python: '>=3.10' editable: true - kind: conda