Skip to content

Commit

Permalink
Adapt codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Feb 26, 2024
1 parent 491911b commit 7818fd1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
78 changes: 39 additions & 39 deletions python/ribasim/ribasim/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -49,60 +49,75 @@ 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)
control_state: Series[str] = pa.Field(nullable=True)


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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -155,52 +170,37 @@ 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)
control_state: Series[str] = pa.Field(nullable=True)


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)
8 changes: 6 additions & 2 deletions utils/templates/model.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit 7818fd1

Please sign in to comment.