Skip to content

Commit

Permalink
Remove Edge.subnetwork_id from the data model
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Dec 2, 2024
1 parent 57cbe51 commit de9ec5b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions core/src/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions core/src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Check warning on line 188 in core/src/validation.jl

View check run for this annotation

Codecov / codecov/patch

core/src/validation.jl#L188

Added line #L188 was not covered by tests
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
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions python/ribasim/ribasim/geometry/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
):
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check warning on line 32 in python/ribasim/ribasim/migrations.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/migrations.py#L31-L32

Added lines #L31 - L32 were not covered by tests

Expand Down
1 change: 0 additions & 1 deletion python/ribasim/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
1 change: 0 additions & 1 deletion ribasim_qgis/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de9ec5b

Please sign in to comment.