diff --git a/docs/_quarto.yml b/docs/_quarto.yml index 574163100..db06752ef 100644 --- a/docs/_quarto.yml +++ b/docs/_quarto.yml @@ -91,8 +91,3 @@ quartodoc: - Terminal - DiscreteControl - PidControl - - title: Utility functions - desc: Collection of utility functions. - contents: - - utils.geometry_from_connectivity - - utils.connectivity_from_geometry diff --git a/docs/gen_schema.jl b/docs/gen_schema.jl index 7cde8ffa5..1f7ccf15c 100644 --- a/docs/gen_schema.jl +++ b/docs/gen_schema.jl @@ -67,7 +67,7 @@ function gen_root_schema(TT::Vector, prefix = prefix, name = "root") "type" => "object", ) for T in TT - tname = strip_prefix(T) + tname = lowercase(strip_prefix(T)) schema["properties"][tname] = OrderedDict("\$ref" => "$tname.schema.json") end open(normpath(@__DIR__, "schema", "$(name).schema.json"), "w") do io diff --git a/docs/python/examples.ipynb b/docs/python/examples.ipynb index faf812591..49130ac37 100644 --- a/docs/python/examples.ipynb +++ b/docs/python/examples.ipynb @@ -361,7 +361,7 @@ "to_id = np.array(\n", " [2, 3, 4, 5, 8, 6, 7, 9, 9, 10, 12, 3, 13, 14, 6, 1, 17], dtype=np.int64\n", ")\n", - "lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id)\n", + "lines = node.geometry_from_connectivity(from_id, to_id)\n", "edge = ribasim.Edge(\n", " df=gpd.GeoDataFrame(\n", " data={\n", @@ -705,7 +705,7 @@ "\n", "edge_type = 6 * [\"flow\"] + 2 * [\"control\"]\n", "\n", - "lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id)\n", + "lines = node.geometry_from_connectivity(from_id, to_id)\n", "edge = ribasim.Edge(\n", " df=gpd.GeoDataFrame(\n", " data={\"from_node_id\": from_id, \"to_node_id\": to_id, \"edge_type\": edge_type},\n", @@ -1132,7 +1132,7 @@ "from_id = np.array([1, 2, 3, 4, 6, 5, 7], dtype=np.int64)\n", "to_id = np.array([2, 3, 4, 6, 2, 3, 6], dtype=np.int64)\n", "\n", - "lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id)\n", + "lines = node.geometry_from_connectivity(from_id, to_id)\n", "edge = ribasim.Edge(\n", " df=gpd.GeoDataFrame(\n", " data={\n", diff --git a/docs/schema/root.schema.json b/docs/schema/root.schema.json index ad7a55499..751f152f0 100644 --- a/docs/schema/root.schema.json +++ b/docs/schema/root.schema.json @@ -1,77 +1,77 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { - "BasinProfile": { - "$ref": "BasinProfile.schema.json" + "basinprofile": { + "$ref": "basinprofile.schema.json" }, - "BasinState": { - "$ref": "BasinState.schema.json" + "basinstate": { + "$ref": "basinstate.schema.json" }, - "BasinStatic": { - "$ref": "BasinStatic.schema.json" + "basinstatic": { + "$ref": "basinstatic.schema.json" }, - "BasinTime": { - "$ref": "BasinTime.schema.json" + "basintime": { + "$ref": "basintime.schema.json" }, - "DiscreteControlCondition": { - "$ref": "DiscreteControlCondition.schema.json" + "discretecontrolcondition": { + "$ref": "discretecontrolcondition.schema.json" }, - "DiscreteControlLogic": { - "$ref": "DiscreteControlLogic.schema.json" + "discretecontrollogic": { + "$ref": "discretecontrollogic.schema.json" }, - "Edge": { - "$ref": "Edge.schema.json" + "edge": { + "$ref": "edge.schema.json" }, - "FlowBoundaryStatic": { - "$ref": "FlowBoundaryStatic.schema.json" + "flowboundarystatic": { + "$ref": "flowboundarystatic.schema.json" }, - "FlowBoundaryTime": { - "$ref": "FlowBoundaryTime.schema.json" + "flowboundarytime": { + "$ref": "flowboundarytime.schema.json" }, - "FractionalFlowStatic": { - "$ref": "FractionalFlowStatic.schema.json" + "fractionalflowstatic": { + "$ref": "fractionalflowstatic.schema.json" }, - "LevelBoundaryStatic": { - "$ref": "LevelBoundaryStatic.schema.json" + "levelboundarystatic": { + "$ref": "levelboundarystatic.schema.json" }, - "LevelBoundaryTime": { - "$ref": "LevelBoundaryTime.schema.json" + "levelboundarytime": { + "$ref": "levelboundarytime.schema.json" }, - "LinearResistanceStatic": { - "$ref": "LinearResistanceStatic.schema.json" + "linearresistancestatic": { + "$ref": "linearresistancestatic.schema.json" }, - "ManningResistanceStatic": { - "$ref": "ManningResistanceStatic.schema.json" + "manningresistancestatic": { + "$ref": "manningresistancestatic.schema.json" }, - "Node": { - "$ref": "Node.schema.json" + "node": { + "$ref": "node.schema.json" }, - "OutletStatic": { - "$ref": "OutletStatic.schema.json" + "outletstatic": { + "$ref": "outletstatic.schema.json" }, - "PidControlStatic": { - "$ref": "PidControlStatic.schema.json" + "pidcontrolstatic": { + "$ref": "pidcontrolstatic.schema.json" }, - "PidControlTime": { - "$ref": "PidControlTime.schema.json" + "pidcontroltime": { + "$ref": "pidcontroltime.schema.json" }, - "PumpStatic": { - "$ref": "PumpStatic.schema.json" + "pumpstatic": { + "$ref": "pumpstatic.schema.json" }, - "TabulatedRatingCurveStatic": { - "$ref": "TabulatedRatingCurveStatic.schema.json" + "tabulatedratingcurvestatic": { + "$ref": "tabulatedratingcurvestatic.schema.json" }, - "TabulatedRatingCurveTime": { - "$ref": "TabulatedRatingCurveTime.schema.json" + "tabulatedratingcurvetime": { + "$ref": "tabulatedratingcurvetime.schema.json" }, - "TerminalStatic": { - "$ref": "TerminalStatic.schema.json" + "terminalstatic": { + "$ref": "terminalstatic.schema.json" }, - "UserStatic": { - "$ref": "UserStatic.schema.json" + "userstatic": { + "$ref": "userstatic.schema.json" }, - "UserTime": { - "$ref": "UserTime.schema.json" + "usertime": { + "$ref": "usertime.schema.json" } }, "$id": "https://deltares.github.io/Ribasim/schema/root.schema.json", diff --git a/pixi.toml b/pixi.toml index cf694701b..9bb58c2e5 100644 --- a/pixi.toml +++ b/pixi.toml @@ -77,7 +77,7 @@ tests = { depends_on = ["lint", "test-ribasim-python", "test-ribasim-core"] } generate-schema = { cmd = "julia --project=docs docs/gen_schema.jl", depends_on = [ "instantiate-julia", ] } -generate-python = "datamodel-codegen --use-union-operator --use-title-as-name --use-double-quotes --disable-timestamp --use-default --strict-nullable --input-file-type=jsonschema --input docs/schema/root.schema.json --output python/ribasim/ribasim/models.py" +generate-python = "datamodel-codegen --output-model-type pydantic_v2.BaseModel --base-class ribasim.input_base.BaseModel --use-union-operator --use-title-as-name --use-double-quotes --disable-timestamp --use-default --strict-nullable --input-file-type=jsonschema --input docs/schema/root.schema.json --output python/ribasim/ribasim/models.py" codegen = { depends_on = ["generate-schema", "generate-python", "lint"] } # Publish build-ribasim-python-wheel = { cmd = "rm --recursive --force dist && python -m build && twine check dist/*", cwd = "python/ribasim" } diff --git a/python/ribasim/ribasim/geometry/node.py b/python/ribasim/ribasim/geometry/node.py index 052966f12..a4f9f552e 100644 --- a/python/ribasim/ribasim/geometry/node.py +++ b/python/ribasim/ribasim/geometry/node.py @@ -1,9 +1,12 @@ +from collections.abc import Sequence from typing import Any import matplotlib.pyplot as plt import numpy as np import pandas as pd import pandera as pa +import shapely +from numpy.typing import NDArray from pandera.typing import Series from pandera.typing.geopandas import GeoSeries @@ -56,6 +59,77 @@ def node_ids_and_types(*nodes): return node_id, node_type + def geometry_from_connectivity( + self, from_id: Sequence[int], to_id: Sequence[int] + ) -> NDArray[Any]: + """ + Create edge shapely geometries from connectivities. + + Parameters + ---------- + node : Ribasim.Node + from_id : Sequence[int] + First node of every edge. + to_id : Sequence[int] + Second node of every edge. + + Returns + ------- + edge_geometry : np.ndarray + Array of shapely LineStrings. + """ + geometry = self.df["geometry"] + from_points = shapely.get_coordinates(geometry.loc[from_id]) + to_points = shapely.get_coordinates(geometry.loc[to_id]) + n = len(from_points) + vertices = np.empty((n * 2, 2), dtype=from_points.dtype) + vertices[0::2, :] = from_points + vertices[1::2, :] = to_points + indices = np.repeat(np.arange(n), 2) + return shapely.linestrings(coords=vertices, indices=indices) + + def connectivity_from_geometry( + self, lines: NDArray[Any] + ) -> tuple[NDArray[Any], NDArray[Any]]: + """ + Derive from_node_id and to_node_id for every edge in lines. LineStrings + may be used to connect multiple nodes in a sequence, but every linestring + vertex must also a node. + + Parameters + ---------- + node : Node + lines : np.ndarray + Array of shapely linestrings. + + Returns + ------- + from_node_id : np.ndarray of int + to_node_id : np.ndarray of int + """ + node_index = self.df.index + node_xy = shapely.get_coordinates(self.df.geometry.values) + edge_xy = shapely.get_coordinates(lines) + + xy = np.vstack([node_xy, edge_xy]) + _, inverse = np.unique(xy, return_inverse=True, axis=0) + _, index, inverse = np.unique( + xy, return_index=True, return_inverse=True, axis=0 + ) + uniques_index = index[inverse] + + node_node_id, edge_node_id = np.split(uniques_index, [len(node_xy)]) + if not np.isin(edge_node_id, node_node_id).all(): + raise ValueError( + "Edge lines contain coordinates that are not in the node layer. " + "Please ensure all edges are snapped to nodes exactly." + ) + + edge_node_id = edge_node_id.reshape((-1, 2)) + from_id = node_index[edge_node_id[:, 0]].to_numpy() + to_id = node_index[edge_node_id[:, 1]].to_numpy() + return from_id, to_id + def plot(self, ax=None, zorder=None) -> Any: """ Plot the nodes. Each node type is given a separate marker. diff --git a/python/ribasim/ribasim/input_base.py b/python/ribasim/ribasim/input_base.py index ddb80a5e5..c7346ad7c 100644 --- a/python/ribasim/ribasim/input_base.py +++ b/python/ribasim/ribasim/input_base.py @@ -20,11 +20,13 @@ ConfigDict, DirectoryPath, Field, + field_validator, model_serializer, model_validator, ) from ribasim.types import FilePath +from ribasim.utils import prefix_column __all__ = ("TableModel",) @@ -146,6 +148,16 @@ def _load(cls, filepath: Path | None) -> dict[str, Any]: class TableModel(FileModel, Generic[TableT]): df: DataFrame[TableT] | None = Field(default=None, exclude=True, repr=False) + @field_validator("df") + @classmethod + def prefix_extra_columns(cls, v: DataFrame[TableT]): + """Prefix extra columns with meta_.""" + if isinstance(v, pd.DataFrame): + v.rename( + lambda x: prefix_column(x, cls.columns()), axis="columns", inplace=True + ) + return v + @model_serializer def set_model(self) -> Path | None: return self.filepath @@ -256,14 +268,24 @@ def tableschema(cls) -> TableT: T: TableT = fieldtype.__args__[0] return T - def record(self): + @classmethod + def record(cls) -> type[PydanticBaseModel] | None: """Retrieve Pydantic Record used in Pandera Schema.""" - T = self.tableschema() - return T.Config.dtype.type + T = cls.tableschema() + if hasattr(T.Config, "dtype"): + # We always set a PydanticBaseModel dtype (see schemas.py) + return T.Config.dtype.type # type: ignore + else: + return None - def columns(self): + @classmethod + def columns(cls) -> list[str]: """Retrieve column names.""" - return list(self.record().model_fields.keys()) + T = cls.record() + if T is not None: + return list(T.model_fields.keys()) + else: + return [] class SpatialTableModel(TableModel[TableT], Generic[TableT]): diff --git a/python/ribasim/ribasim/models.py b/python/ribasim/ribasim/models.py index be7474a56..1d82a6fa8 100644 --- a/python/ribasim/ribasim/models.py +++ b/python/ribasim/ribasim/models.py @@ -5,7 +5,9 @@ from datetime import datetime -from pydantic import BaseModel, Field +from pydantic import Field + +from ribasim.input_base import BaseModel class BasinProfile(BaseModel): @@ -218,27 +220,27 @@ class UserTime(BaseModel): class Root(BaseModel): - BasinProfile: BasinProfile | None - BasinState: BasinState | None - BasinStatic: BasinStatic | None - BasinTime: BasinTime | None - DiscreteControlCondition: DiscreteControlCondition | None - DiscreteControlLogic: DiscreteControlLogic | None - Edge: Edge | None - FlowBoundaryStatic: FlowBoundaryStatic | None - FlowBoundaryTime: FlowBoundaryTime | None - FractionalFlowStatic: FractionalFlowStatic | None - LevelBoundaryStatic: LevelBoundaryStatic | None - LevelBoundaryTime: LevelBoundaryTime | None - LinearResistanceStatic: LinearResistanceStatic | None - ManningResistanceStatic: ManningResistanceStatic | None - Node: Node | None - OutletStatic: OutletStatic | None - PidControlStatic: PidControlStatic | None - PidControlTime: PidControlTime | None - PumpStatic: PumpStatic | None - TabulatedRatingCurveStatic: TabulatedRatingCurveStatic | None - TabulatedRatingCurveTime: TabulatedRatingCurveTime | None - TerminalStatic: TerminalStatic | None - UserStatic: UserStatic | None - UserTime: UserTime | None + basinprofile: BasinProfile | None = None + basinstate: BasinState | None = None + basinstatic: BasinStatic | None = None + basintime: BasinTime | None = None + discretecontrolcondition: DiscreteControlCondition | None = None + discretecontrollogic: DiscreteControlLogic | None = None + edge: Edge | None = None + flowboundarystatic: FlowBoundaryStatic | None = None + flowboundarytime: FlowBoundaryTime | None = None + fractionalflowstatic: FractionalFlowStatic | None = None + levelboundarystatic: LevelBoundaryStatic | None = None + levelboundarytime: LevelBoundaryTime | None = None + linearresistancestatic: LinearResistanceStatic | None = None + manningresistancestatic: ManningResistanceStatic | None = None + node: Node | None = None + outletstatic: OutletStatic | None = None + pidcontrolstatic: PidControlStatic | None = None + pidcontroltime: PidControlTime | None = None + pumpstatic: PumpStatic | None = None + tabulatedratingcurvestatic: TabulatedRatingCurveStatic | None = None + tabulatedratingcurvetime: TabulatedRatingCurveTime | None = None + terminalstatic: TerminalStatic | None = None + userstatic: UserStatic | None = None + usertime: UserTime | None = None diff --git a/python/ribasim/ribasim/utils.py b/python/ribasim/ribasim/utils.py index 0028d8b29..4ab4b946a 100644 --- a/python/ribasim/ribasim/utils.py +++ b/python/ribasim/ribasim/utils.py @@ -1,79 +1,14 @@ from collections.abc import Sequence -from typing import Any -import numpy as np -import shapely -from numpy.typing import NDArray -from ribasim.geometry.node import Node - - -def geometry_from_connectivity( - node: Node, from_id: Sequence[int], to_id: Sequence[int] -) -> NDArray[Any]: - """ - Create edge shapely geometries from connectivities. - - Parameters - ---------- - node : Ribasim.Node - from_id : Sequence[int] - First node of every edge. - to_id : Sequence[int] - Second node of every edge. - - Returns - ------- - edge_geometry : np.ndarray - Array of shapely LineStrings. - """ - geometry = node.df["geometry"] - from_points = shapely.get_coordinates(geometry.loc[from_id]) - to_points = shapely.get_coordinates(geometry.loc[to_id]) - n = len(from_points) - vertices = np.empty((n * 2, 2), dtype=from_points.dtype) - vertices[0::2, :] = from_points - vertices[1::2, :] = to_points - indices = np.repeat(np.arange(n), 2) - return shapely.linestrings(coords=vertices, indices=indices) - - -def connectivity_from_geometry( - node: Node, lines: NDArray[Any] -) -> tuple[NDArray[Any], NDArray[Any]]: - """ - Derive from_node_id and to_node_id for every edge in lines. LineStrings - may be used to connect multiple nodes in a sequence, but every linestring - vertex must also a node. - - Parameters - ---------- - node : Node - lines : np.ndarray - Array of shapely linestrings. - - Returns - ------- - from_node_id : np.ndarray of int - to_node_id : np.ndarray of int - """ - node_index = node.df.index - node_xy = shapely.get_coordinates(node.df.geometry.values) - edge_xy = shapely.get_coordinates(lines) - - xy = np.vstack([node_xy, edge_xy]) - _, inverse = np.unique(xy, return_inverse=True, axis=0) - _, index, inverse = np.unique(xy, return_index=True, return_inverse=True, axis=0) - uniques_index = index[inverse] - - node_node_id, edge_node_id = np.split(uniques_index, [len(node_xy)]) - if not np.isin(edge_node_id, node_node_id).all(): - raise ValueError( - "Edge lines contain coordinates that are not in the node layer. " - "Please ensure all edges are snapped to nodes exactly." - ) - - edge_node_id = edge_node_id.reshape((-1, 2)) - from_id = node_index[edge_node_id[:, 0]].to_numpy() - to_id = node_index[edge_node_id[:, 1]].to_numpy() - return from_id, to_id +def prefix_column( + column: str, record_columns: Sequence[str], prefix: str = "meta_" +) -> str: + """Prefix column name with `prefix` if not in record_columns.""" + if ( + len(record_columns) > 0 + and column not in record_columns + and not column.startswith(prefix) + ): + column = f"{prefix}{column}" + return column diff --git a/python/ribasim/tests/test_io.py b/python/ribasim/tests/test_io.py index a9b9a760a..e06972e12 100644 --- a/python/ribasim/tests/test_io.py +++ b/python/ribasim/tests/test_io.py @@ -66,3 +66,13 @@ def test_repr(): pump_1 = Pump(static=static_data) assert repr(pump_1) == "Pump(static=TableModel[PumpStaticSchema]())" + + +def test_extra_columns(): + static_data = pd.DataFrame( + data={"node_id": [1, 2, 3], "flow_rate": [1.0, -1.0, 0.0], "id": [-1, -2, -3]} + ) + + pump_1 = Pump(static=static_data) + + assert "meta_id" in pump_1.static.df.columns diff --git a/python/ribasim/tests/test_utils.py b/python/ribasim/tests/test_utils.py index 6ff4c74ac..8d2e427b4 100644 --- a/python/ribasim/tests/test_utils.py +++ b/python/ribasim/tests/test_utils.py @@ -26,11 +26,17 @@ def test_utils(): from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) assert lines[0].equals(LineString([xy[from_id[0] - 1], xy[to_id[0] - 1]])) assert lines[1].equals(LineString([xy[from_id[1] - 1], xy[to_id[1] - 1]])) - from_id_, to_id_ = utils.connectivity_from_geometry(node, lines) + from_id_, to_id_ = node.connectivity_from_geometry(lines) assert_array_equal(from_id, from_id_) assert_array_equal(to_id, to_id_) + + +def test_prefix_column(): + assert utils.prefix_column("a", ["b"]) == "meta_a" + assert utils.prefix_column("meta_a", ["b"]) == "meta_a" + assert utils.prefix_column("a", ["a"]) == "a" diff --git a/python/ribasim_testmodels/ribasim_testmodels/allocation.py b/python/ribasim_testmodels/ribasim_testmodels/allocation.py index e860d6fd0..f84d60441 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/allocation.py +++ b/python/ribasim_testmodels/ribasim_testmodels/allocation.py @@ -33,7 +33,7 @@ def user_model(): # Setup the edges: from_id = np.array([1, 1, 2, 3], dtype=np.int64) to_id = np.array([2, 3, 4, 4], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -178,7 +178,7 @@ def subnetwork_model(): to_id = np.array([2, 3, 4, 10, 5, 6, 7, 8, 11, 12, 13, 9, 2, 6, 8], dtype=np.int64) allocation_network_id = len(from_id) * [None] allocation_network_id[0] = 1 - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -421,7 +421,7 @@ def looped_subnetwork_model(): ], dtype=np.int64, ) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -567,7 +567,7 @@ def minimal_subnetwork_model(): ) allocation_network_id = len(from_id) * [None] allocation_network_id[0] = 1 - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/backwater.py b/python/ribasim_testmodels/ribasim_testmodels/backwater.py index 4fa5d8a82..e9adc4f07 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/backwater.py +++ b/python/ribasim_testmodels/ribasim_testmodels/backwater.py @@ -29,7 +29,7 @@ def backwater_model(): ids = np.arange(1, x.size + 1, dtype=np.int64) from_id = ids[:-1] to_id = ids[1:] - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/basic.py b/python/ribasim_testmodels/ribasim_testmodels/basic.py index dd49ba779..eceea3ce1 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/basic.py +++ b/python/ribasim_testmodels/ribasim_testmodels/basic.py @@ -173,7 +173,7 @@ def basic_model() -> ribasim.Model: to_id = np.array( [2, 3, 4, 5, 8, 6, 7, 9, 9, 10, 12, 3, 13, 14, 6, 1, 17], dtype=np.int64 ) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -353,7 +353,7 @@ def tabulated_rating_curve_model() -> ribasim.Model: # Setup the edges: from_id = np.array([1, 1, 2, 3], dtype=np.int64) to_id = np.array([2, 3, 4, 4], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -406,7 +406,7 @@ def outlet_model(): # Setup the edges: from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/bucket.py b/python/ribasim_testmodels/ribasim_testmodels/bucket.py index 301cfcb36..3d284ff9b 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/bucket.py +++ b/python/ribasim_testmodels/ribasim_testmodels/bucket.py @@ -28,7 +28,7 @@ def bucket_model() -> ribasim.Model: # Setup the dummy edges: from_id = np.array([], dtype=np.int64) to_id = np.array([], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/discrete_control.py b/python/ribasim_testmodels/ribasim_testmodels/discrete_control.py index 7eaf62751..211a4d931 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/discrete_control.py +++ b/python/ribasim_testmodels/ribasim_testmodels/discrete_control.py @@ -49,7 +49,7 @@ def pump_discrete_control_model() -> ribasim.Model: edge_type = 4 * ["flow"] + 2 * ["control"] - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={"from_node_id": from_id, "to_node_id": to_id, "edge_type": edge_type}, @@ -184,7 +184,7 @@ def flow_condition_model(): # Setup the edges: from_id = np.array([1, 2, 3, 5], dtype=np.int64) to_id = np.array([2, 3, 4, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -325,7 +325,7 @@ def level_boundary_condition_model(): # Setup the edges: from_id = np.array([1, 2, 3, 4, 6], dtype=np.int64) to_id = np.array([2, 3, 4, 5, 4], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -473,7 +473,7 @@ def tabulated_rating_curve_control_model() -> ribasim.Model: # Setup the edges: from_id = np.array([1, 2, 4], dtype=np.int64) to_id = np.array([2, 3, 2], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -607,7 +607,7 @@ def level_setpoint_with_minmax_model(): # Setup the edges: from_id = np.array([1, 3, 4, 2, 1, 5, 7, 7], dtype=np.int64) to_id = np.array([3, 4, 2, 1, 5, 6, 2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/dutch_waterways.py b/python/ribasim_testmodels/ribasim_testmodels/dutch_waterways.py index d32badd25..e82e358f1 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/dutch_waterways.py +++ b/python/ribasim_testmodels/ribasim_testmodels/dutch_waterways.py @@ -311,7 +311,7 @@ def dutch_waterways_model(): "", # 17 -> 9 ] - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/equations.py b/python/ribasim_testmodels/ribasim_testmodels/equations.py index b1ffc3248..bbb678f11 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/equations.py +++ b/python/ribasim_testmodels/ribasim_testmodels/equations.py @@ -32,7 +32,7 @@ def linear_resistance_model(): # Setup the edges: from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -128,7 +128,7 @@ def rating_curve_model(): # Setup the edges: from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -237,7 +237,7 @@ def manning_resistance_model(): # Setup the edges: from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -343,7 +343,7 @@ def misc_nodes_model(): # Setup the edges: from_id = np.array([1, 2, 3, 4, 1, 6], dtype=np.int64) to_id = np.array([2, 3, 4, 5, 6, 7], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -475,7 +475,7 @@ def pid_control_equation_model(): # Setup the edges: from_id = np.array([1, 2, 4], dtype=np.int64) to_id = np.array([2, 3, 2], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/invalid.py b/python/ribasim_testmodels/ribasim_testmodels/invalid.py index 4b5949824..9158afb22 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/invalid.py +++ b/python/ribasim_testmodels/ribasim_testmodels/invalid.py @@ -28,7 +28,7 @@ def invalid_qh_model(): # Setup the edges: from_id = np.array([], dtype=np.int64) to_id = np.array([], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -136,7 +136,7 @@ def invalid_fractional_flow_model(): # Invalid: Node #7 combines fractional flow outneighbors with other outneigbor types. from_id = np.array([1, 7, 7, 3, 7, 4], dtype=np.int64) to_id = np.array([7, 2, 3, 5, 4, 6], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -227,7 +227,7 @@ def invalid_discrete_control_model(): # Setup the edges: from_id = np.array([1, 2, 4, 5], dtype=np.int64) to_id = np.array([2, 3, 3, 2], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -355,7 +355,7 @@ def invalid_edge_types_model(): # Setup the edges: from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/pid_control.py b/python/ribasim_testmodels/ribasim_testmodels/pid_control.py index 2cc2175a1..865067e42 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/pid_control.py +++ b/python/ribasim_testmodels/ribasim_testmodels/pid_control.py @@ -45,7 +45,7 @@ def pid_control_model(): from_id = np.array([1, 2, 3, 4, 6, 5, 7], dtype=np.int64) to_id = np.array([2, 3, 4, 6, 2, 3, 6], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ @@ -198,7 +198,7 @@ def discrete_control_of_pid_control_model(): from_id = np.array([1, 2, 3, 4, 6, 7], dtype=np.int64) to_id = np.array([2, 3, 4, 5, 2, 6], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/time.py b/python/ribasim_testmodels/ribasim_testmodels/time.py index 005861441..bb34dfea7 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/time.py +++ b/python/ribasim_testmodels/ribasim_testmodels/time.py @@ -33,7 +33,7 @@ def flow_boundary_time_model(): # Setup the edges: from_id = np.array([1, 3], dtype=np.int64) to_id = np.array([2, 2], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={ diff --git a/python/ribasim_testmodels/ribasim_testmodels/trivial.py b/python/ribasim_testmodels/ribasim_testmodels/trivial.py index 904a22075..9524aa219 100644 --- a/python/ribasim_testmodels/ribasim_testmodels/trivial.py +++ b/python/ribasim_testmodels/ribasim_testmodels/trivial.py @@ -34,7 +34,7 @@ def trivial_model() -> ribasim.Model: # Setup the edges: from_id = np.array([1, 2], dtype=np.int64) to_id = np.array([2, 3], dtype=np.int64) - lines = ribasim.utils.geometry_from_connectivity(node, from_id, to_id) + lines = node.geometry_from_connectivity(from_id, to_id) edge = ribasim.Edge( df=gpd.GeoDataFrame( data={