Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nxv #184

Merged
merged 7 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions notebooks/noorderzijlvest/00_get_verwerkt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# %%
from ribasim_nl import CloudStorage

cloud = CloudStorage()

data_url = cloud.joinurl("Noorderzijlvest", "verwerkt")

# %%
cloud.download_content(data_url)

# %%
111 changes: 111 additions & 0 deletions notebooks/noorderzijlvest/01_fix_model_network.py
Original file line number Diff line number Diff line change
@@ -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)

# %%
8 changes: 6 additions & 2 deletions pixi.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -16989,7 +16991,7 @@ packages:
name: ribasim
version: 2024.11.0
path: ../Ribasim/python/ribasim
sha256: c48692687129085ad19256cbf54c8df9853f6259b31997cc4a282fde86072751
sha256: ba8a6a24955e974dd0d7ae81ad59546134417f48eabce10cb280ac5f8c3290db
requires_dist:
- geopandas
- matplotlib
Expand All @@ -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'
Expand All @@ -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
Expand Down
Loading