diff --git a/core/src/graph.jl b/core/src/graph.jl index 666591e8e..e2a3273e0 100644 --- a/core/src/graph.jl +++ b/core/src/graph.jl @@ -19,8 +19,7 @@ function create_graph(db::DB, config::Config)::MetaGraph FromNode.node_type AS from_node_type, ToNode.node_id AS to_node_id, ToNode.node_type AS to_node_type, - Edge.edge_type, - Edge.subnetwork_id + Edge.edge_type FROM Edge LEFT JOIN Node AS FromNode ON FromNode.node_id = Edge.from_node_id LEFT JOIN Node AS ToNode ON ToNode.node_id = Edge.to_node_id diff --git a/core/src/model.jl b/core/src/model.jl index e0047ca0d..2197d72b7 100644 --- a/core/src/model.jl +++ b/core/src/model.jl @@ -47,6 +47,7 @@ function Model(config::Config)::Model # so we can directly close it again. db = SQLite.DB(db_path) + database_warning(db) if !valid_nodes(db) error("Invalid nodes found.") end diff --git a/core/src/validation.jl b/core/src/validation.jl index 3eba4339a..81a372421 100644 --- a/core/src/validation.jl +++ b/core/src/validation.jl @@ -182,6 +182,14 @@ function valid_nodes(db::DB)::Bool return !errors end +function database_warning(db::DB)::Nothing + cols = SQLite.columns(db, "Edge") + if "subnetwork_id" in cols.name + @warn "The 'subnetwork_id' column in the 'Edge' table is deprecated since ribasim v2024.12." + end + return nothing +end + """ Test for each node given its node type whether the nodes that # are downstream ('down-edge') of this node are of an allowed type diff --git a/docs/changelog.qmd b/docs/changelog.qmd index d9c04350e..373ab6cc8 100644 --- a/docs/changelog.qmd +++ b/docs/changelog.qmd @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### Changed +- The Edge table no longer supports `subnetwork_id`; this is automatically inferred. [#1956](https://github.com/Deltares/Ribasim/pull/1956) + ## [v2024.11.0] - 2024-10-08 This major new release contains many improvements. diff --git a/python/ribasim/ribasim/geometry/edge.py b/python/ribasim/ribasim/geometry/edge.py index 62a73cb28..faa2e92fa 100644 --- a/python/ribasim/ribasim/geometry/edge.py +++ b/python/ribasim/ribasim/geometry/edge.py @@ -47,7 +47,6 @@ class EdgeSchema(_GeoBaseSchema): from_node_id: Series[Int32] = pa.Field(default=0) to_node_id: Series[Int32] = pa.Field(default=0) edge_type: Series[str] = pa.Field(default="flow") - subnetwork_id: Series[pd.Int32Dtype] = pa.Field(default=pd.NA, nullable=True) geometry: GeoSeries[LineString] = pa.Field(default=None, nullable=True) @classmethod @@ -73,7 +72,6 @@ def add( to_node: NodeData, geometry: LineString | MultiLineString | None = None, name: str = "", - subnetwork_id: int | None = None, edge_id: Optional[NonNegativeInt] = None, **kwargs, ): @@ -90,6 +88,8 @@ def add( The geometry of a line. If not supplied, it creates a straight line between the nodes. name : str An optional name for the edge. + id : int + An optional non-negative edge ID. If not supplied, it will be automatically generated. **kwargs : Dict """ if not can_connect(from_node.node_type, to_node.node_type): @@ -120,7 +120,6 @@ def add( "to_node_id": [to_node.node_id], "edge_type": [edge_type], "name": [name], - "subnetwork_id": [subnetwork_id], **kwargs, }, geometry=geometry_to_append, diff --git a/python/ribasim/ribasim/migrations.py b/python/ribasim/ribasim/migrations.py index 5f3e09d3c..31a326e83 100644 --- a/python/ribasim/ribasim/migrations.py +++ b/python/ribasim/ribasim/migrations.py @@ -27,7 +27,7 @@ def edgeschema_migration(gdf: GeoDataFrame, schema_version: int) -> GeoDataFrame warnings.warn("Migrating outdated Edge table.", UserWarning) assert gdf["edge_id"].is_unique, "Edge IDs have to be unique." gdf.set_index("edge_id", inplace=True) - if "subnetwork_id" in gdf.columns and schema_version == 0: + if "subnetwork_id" in gdf.columns: warnings.warn("Migrating outdated Edge table.", UserWarning) gdf.drop(columns="subnetwork_id", inplace=True, errors="ignore") diff --git a/python/ribasim/tests/test_model.py b/python/ribasim/tests/test_model.py index ba703d5fa..f5e341561 100644 --- a/python/ribasim/tests/test_model.py +++ b/python/ribasim/tests/test_model.py @@ -145,7 +145,6 @@ def test_edge_table(basic): df = model.edge.df assert df.geometry.is_unique assert df.from_node_id.dtype == np.int32 - assert df.subnetwork_id.dtype == pd.Int32Dtype() assert df.crs == CRS.from_epsg(28992) diff --git a/ribasim_qgis/core/nodes.py b/ribasim_qgis/core/nodes.py index 9a1859c77..c638a58e0 100644 --- a/ribasim_qgis/core/nodes.py +++ b/ribasim_qgis/core/nodes.py @@ -253,7 +253,6 @@ def attributes(cls) -> list[QgsField]: QgsField("from_node_id", QVariant.Int), QgsField("to_node_id", QVariant.Int), QgsField("edge_type", QVariant.String), - QgsField("subnetwork_id", QVariant.Int), ] @classmethod