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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading