From 7818fd194724bd6ab106c4642f5811a09c2e921d Mon Sep 17 00:00:00 2001 From: Hofer-Julian Date: Mon, 26 Feb 2024 11:11:32 +0100 Subject: [PATCH] Adapt codegen --- python/ribasim/ribasim/schemas.py | 78 +++++++++++++++---------------- utils/templates/model.py.jinja | 8 +++- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/python/ribasim/ribasim/schemas.py b/python/ribasim/ribasim/schemas.py index 6785bb3c7..69f455a89 100644 --- a/python/ribasim/ribasim/schemas.py +++ b/python/ribasim/ribasim/schemas.py @@ -32,7 +32,7 @@ class BasinStaticSchema(_BaseSchema): class BasinSubgridSchema(_BaseSchema): - subgrid_id: Series[int] = pa.Field(nullable=False) + subgrid_id: Series[int] = pa.Field(nullable=False, default=0) node_id: Series[int] = pa.Field(nullable=False, default=0) basin_level: Series[float] = pa.Field(nullable=False) subgrid_level: Series[float] = pa.Field(nullable=False) @@ -49,52 +49,67 @@ class BasinTimeSchema(_BaseSchema): class DiscreteControlConditionSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) listen_feature_type: Series[str] = pa.Field(nullable=True) - listen_feature_id: Series[int] = pa.Field(nullable=False) + listen_feature_id: Series[int] = pa.Field(nullable=False, default=0) variable: Series[str] = pa.Field(nullable=False) greater_than: Series[float] = pa.Field(nullable=False) look_ahead: Series[float] = pa.Field(nullable=True) class DiscreteControlLogicSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) truth_state: Series[str] = pa.Field(nullable=False) control_state: Series[str] = pa.Field(nullable=False) class FlowBoundaryStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) flow_rate: Series[float] = pa.Field(nullable=False) class FlowBoundaryTimeSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) time: Series[Timestamp] = pa.Field(nullable=False) flow_rate: Series[float] = pa.Field(nullable=False) class FractionalFlowStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) fraction: Series[float] = pa.Field(nullable=False) control_state: Series[str] = pa.Field(nullable=True) class LevelBoundaryStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) level: Series[float] = pa.Field(nullable=False) class LevelBoundaryTimeSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) time: Series[Timestamp] = pa.Field(nullable=False) level: Series[float] = pa.Field(nullable=False) +class LevelDemandStaticSchema(_BaseSchema): + node_id: Series[int] = pa.Field(nullable=False, default=0) + min_level: Series[float] = pa.Field(nullable=False) + max_level: Series[float] = pa.Field(nullable=False) + priority: Series[int] = pa.Field(nullable=False, default=0) + + +class LevelDemandTimeSchema(_BaseSchema): + node_id: Series[int] = pa.Field(nullable=False, default=0) + time: Series[Timestamp] = pa.Field(nullable=False) + min_level: Series[float] = pa.Field(nullable=False) + max_level: Series[float] = pa.Field(nullable=False) + priority: Series[int] = pa.Field(nullable=False, default=0) + + class LinearResistanceStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) resistance: Series[float] = pa.Field(nullable=False) max_flow_rate: Series[float] = pa.Field(nullable=True) @@ -102,7 +117,7 @@ class LinearResistanceStaticSchema(_BaseSchema): class ManningResistanceStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) length: Series[float] = pa.Field(nullable=False) manning_n: Series[float] = pa.Field(nullable=False) @@ -112,7 +127,7 @@ class ManningResistanceStaticSchema(_BaseSchema): class OutletStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) flow_rate: Series[float] = pa.Field(nullable=False) min_flow_rate: Series[float] = pa.Field(nullable=True) @@ -122,10 +137,10 @@ class OutletStaticSchema(_BaseSchema): class PidControlStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) listen_node_type: Series[str] = pa.Field(nullable=True) - listen_node_id: Series[int] = pa.Field(nullable=False) + listen_node_id: Series[int] = pa.Field(nullable=False, default=0) target: Series[float] = pa.Field(nullable=False) proportional: Series[float] = pa.Field(nullable=False) integral: Series[float] = pa.Field(nullable=False) @@ -134,9 +149,9 @@ class PidControlStaticSchema(_BaseSchema): class PidControlTimeSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) listen_node_type: Series[str] = pa.Field(nullable=True) - listen_node_id: Series[int] = pa.Field(nullable=False) + listen_node_id: Series[int] = pa.Field(nullable=False, default=0) time: Series[Timestamp] = pa.Field(nullable=False) target: Series[float] = pa.Field(nullable=False) proportional: Series[float] = pa.Field(nullable=False) @@ -146,7 +161,7 @@ class PidControlTimeSchema(_BaseSchema): class PumpStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) flow_rate: Series[float] = pa.Field(nullable=False) min_flow_rate: Series[float] = pa.Field(nullable=True) @@ -155,7 +170,7 @@ class PumpStaticSchema(_BaseSchema): class TabulatedRatingCurveStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) level: Series[float] = pa.Field(nullable=False) flow_rate: Series[float] = pa.Field(nullable=False) @@ -163,44 +178,29 @@ class TabulatedRatingCurveStaticSchema(_BaseSchema): class TabulatedRatingCurveTimeSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) time: Series[Timestamp] = pa.Field(nullable=False) level: Series[float] = pa.Field(nullable=False) flow_rate: Series[float] = pa.Field(nullable=False) -class LevelDemandStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) - min_level: Series[float] = pa.Field(nullable=False) - max_level: Series[float] = pa.Field(nullable=False) - priority: Series[int] = pa.Field(nullable=False) - - -class LevelDemandTimeSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) - time: Series[Timestamp] = pa.Field(nullable=False) - min_level: Series[float] = pa.Field(nullable=False) - max_level: Series[float] = pa.Field(nullable=False) - priority: Series[int] = pa.Field(nullable=False) - - class TerminalStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) class UserDemandStaticSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) active: Series[pa.BOOL] = pa.Field(nullable=True) demand: Series[float] = pa.Field(nullable=False) return_factor: Series[float] = pa.Field(nullable=False) min_level: Series[float] = pa.Field(nullable=False) - priority: Series[int] = pa.Field(nullable=False) + priority: Series[int] = pa.Field(nullable=False, default=0) class UserDemandTimeSchema(_BaseSchema): - node_id: Series[int] = pa.Field(nullable=False) + node_id: Series[int] = pa.Field(nullable=False, default=0) time: Series[Timestamp] = pa.Field(nullable=False) demand: Series[float] = pa.Field(nullable=False) return_factor: Series[float] = pa.Field(nullable=False) min_level: Series[float] = pa.Field(nullable=False) - priority: Series[int] = pa.Field(nullable=False) + priority: Series[int] = pa.Field(nullable=False, default=0) diff --git a/utils/templates/model.py.jinja b/utils/templates/model.py.jinja index ae1620365..fbb6aa074 100644 --- a/utils/templates/model.py.jinja +++ b/utils/templates/model.py.jinja @@ -11,7 +11,11 @@ class _BaseSchema(pa.DataFrameModel): {% for m in models %} class {{m[:name]}}Schema(_BaseSchema): -{% for f in m[:fields] %} + {% for f in m[:fields] %} + {% if (f[2] == "Series[int]") %} + {{ f[1] }}: {{ f[2] }} = pa.Field(nullable={{ f[3] }}, default=0) + {% else %} {{ f[1] }}: {{ f[2] }} = pa.Field(nullable={{ f[3] }}) -{% end %} + {% end %} + {% end %} {% end %}