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

Set the Node fid back to the node_id #1316

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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 python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Any

import geopandas as gpd
import pandas as pd
import tomli
import tomli_w
Expand Down Expand Up @@ -138,6 +139,16 @@
for sub in self._nodes():
sub._save(directory, input_dir)

# Temporarily require unique node_id for #1262
# and copy them to the fid for #1306.
df = gpd.read_file(db_path, layer="Node")
if not df["node_id"].is_unique:
raise ValueError("node_id must be unique")

Check warning on line 146 in python/ribasim/ribasim/model.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/model.py#L146

Added line #L146 was not covered by tests
df.set_index("node_id", drop=False, inplace=True)
df.sort_index(inplace=True)
df.index.name = "fid"
df.to_file(db_path, layer="Node", driver="GPKG", index=True)

def node_table(self) -> NodeTable:
"""Compute the full NodeTable from all node types."""
df_chunks = [node.node.df for node in self._nodes()]
Expand Down
Loading