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

Wdod #201

Merged
merged 9 commits into from
Dec 12, 2024
Merged

Wdod #201

Show file tree
Hide file tree
Changes from 6 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
13 changes: 7 additions & 6 deletions notebooks/drents_overijsselse_delta/01_fix_model_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,16 @@
"remove_basin_area",
"split_basin",
"merge_basins",
"add_basin",
"update_node",
"add_basin_area",
"add_basin",
"update_basin_area",
"redirect_edge",
"reverse_edge",
"deactivate_node",
"move_node",
"remove_node",
"connect_basins",
]

actions = [i for i in actions if i in gpd.list_layers(model_edits_path).name.to_list()]
Expand All @@ -364,16 +365,16 @@
kwargs = {k: v for k, v in row._asdict().items() if k in keywords}
method(**kwargs)

# remove unassigned basin area
model.fix_unassigned_basin_area()
model.remove_unassigned_basin_area()

# %% Reset static tables

# Reset static tables
model = reset_static_tables(model)

# %% write model
model.use_validation = True
model.write(ribasim_toml)

model.invalid_topology_at_node().to_file(ribasim_toml.with_name("invalid_topology_at_connector_nodes.gpkg"))

model.report_basin_area()
model.report_internal_basins()
# %%
10 changes: 5 additions & 5 deletions src/ribasim_nl/ribasim_nl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,17 +784,17 @@ def merge_basins(
if node_id in self.basin.area.df.node_id.to_numpy():
poly = self.basin.area.df.set_index("node_id").at[node_id, "geometry"]

if isinstance(poly, Polygon):
poly = MultiPolygon([poly])

# if to_node_id has area we union both areas
if to_node_id in self.basin.area.df.node_id.to_numpy():
if len(self.basin.area.df.loc[self.basin.area.df.node_id == to_node_id]) == 1:
poly = poly.union(self.basin.area.df.set_index("node_id").at[to_node_id, "geometry"])
if isinstance(poly, Polygon):
poly = MultiPolygon([poly])

self.basin.area.df.loc[self.basin.area.df.node_id == to_node_id, ["geometry"]] = poly

# else we add a record to basin
else:
if isinstance(poly, Polygon):
poly = MultiPolygon([poly])
self.basin.area.df.loc[self.basin.area.df.index.max() + 1] = {
"node_id": to_node_id,
"geometry": poly,
Expand Down
Loading