Skip to content

Commit

Permalink
reset_static_tables (#197)
Browse files Browse the repository at this point in the history
reset_static_tables naar plausibele waarden bij fix en samenvoeg scripts

---------

Co-authored-by: Martijn Visser <[email protected]>
  • Loading branch information
DanielTollenaar and visr authored Dec 9, 2024
1 parent a2fd22d commit a04b169
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 599 deletions.
74 changes: 4 additions & 70 deletions notebooks/brabantse_delta/01_fix_model_network.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# %%
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
from ribasim_nl.geometry import drop_z
from ribasim_nl.reset_static_tables import reset_static_tables

cloud = CloudStorage()

Expand Down Expand Up @@ -96,75 +95,10 @@
model.update_node(row.to_node_id, "Outlet", data=[outlet_data])


## UPDATEN STATIC TABLES
# %% Reset static tables

# %%
# basin-profielen/state 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

# %%
# 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
# Reset static tables
model = reset_static_tables(model)


# %% write model
Expand Down
73 changes: 6 additions & 67 deletions notebooks/drents_overijsselse_delta/01_fix_model_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import inspect

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
from ribasim_nl.geometry import split_basin_multi_polygon
from ribasim_nl.reset_static_tables import reset_static_tables

cloud = CloudStorage()

Expand Down Expand Up @@ -332,71 +331,6 @@
).itertuples():
model.update_node(row.to_node_id, "Outlet")


# buffer out small slivers
# model.basin.area.df.loc[:, ["geometry"]] = (
# model.basin.area.df.buffer(0.1)
# .buffer(-0.1)
# .apply(lambda x: x if x.geom_type == "MultiPolygon" else MultiPolygon([x]))
# )
# %%
# 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


# %%
model.explode_basin_area() # all multipolygons to singles

Expand Down Expand Up @@ -431,6 +365,11 @@
method(**kwargs)


# %% Reset static tables

# Reset static tables
model = reset_static_tables(model)

# %% write model
model.use_validation = True
model.write(ribasim_toml)
Expand Down
87 changes: 4 additions & 83 deletions notebooks/hunze_en_aas/01_fix_model_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
import inspect

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, tabulated_rating_curve

from ribasim_nl import CloudStorage, Model, NetworkValidator
from ribasim_nl.reset_static_tables import reset_static_tables

cloud = CloudStorage()

Expand Down Expand Up @@ -87,88 +86,10 @@
model.update_node(row.to_node_id, "Outlet", data=[outlet_data])


## UPDATEN STATIC TABLES

# %%
# basin-profielen/state 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

# %%
# 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

# %%
# outlets updaten
length = len(model.outlet.node.df)
df = pd.DataFrame(
{
"node_id": model.outlet.node.df.index.to_list(),
"flow_rate": [10.0] * length,
}
)
df.index.name = "fid"
model.outlet.static.df = df
# %% Reset static tables

# Reset static tables
model = reset_static_tables(model)

# %%
actions = [
Expand Down
74 changes: 4 additions & 70 deletions notebooks/limburg/01_fix_model_network.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# %%
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
from ribasim_nl.reset_static_tables import reset_static_tables

cloud = CloudStorage()

Expand Down Expand Up @@ -232,75 +231,10 @@
model.update_node(row.to_node_id, "Outlet", data=[outlet_data])


## UPDATEN STATIC TABLES
# %% Reset static tables

# %%
# basin-profielen/state 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

# %%
# 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
# Reset static tables
model = reset_static_tables(model)

model.fix_unassigned_basin_area()

Expand Down
Loading

0 comments on commit a04b169

Please sign in to comment.