Skip to content

Commit

Permalink
Also allow Missing in basin.static (#1079)
Browse files Browse the repository at this point in the history
Missing is currently only allowed in the basin.time, thanks to
#1028.

This makes it consistent and allows it for basin.static as well (which
is currently the reason a bunch of imod_coupler tests are failing).

---------

Co-authored-by: Martijn Visser <[email protected]>
  • Loading branch information
Huite and visr authored Feb 5, 2024
1 parent 999527b commit 1694f7f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 31 deletions.
10 changes: 5 additions & 5 deletions core/src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ end

@version BasinStaticV1 begin
node_id::Int
drainage::Float64
potential_evaporation::Float64
infiltration::Float64
precipitation::Float64
urban_runoff::Float64
drainage::Union{Missing, Float64}
potential_evaporation::Union{Missing, Float64}
infiltration::Union{Missing, Float64}
precipitation::Union{Missing, Float64}
urban_runoff::Union{Missing, Float64}
end

@version BasinTimeV1 begin
Expand Down
5 changes: 5 additions & 0 deletions core/test/run_models_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ end
@test ispath(toml_path)
model = Ribasim.run(toml_path)
@test model isa Ribasim.Model
@test model.integrator.u.storage [1000]
@test model.integrator.p.basin.precipitation == [0.0]
@test model.integrator.p.basin.potential_evaporation == [0.0]
@test model.integrator.p.basin.drainage == [0.0]
@test model.integrator.p.basin.infiltration == [0.0]
@test successful_retcode(model)
end

Expand Down
62 changes: 46 additions & 16 deletions docs/schema/BasinStatic.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,59 @@
"type": "integer"
},
"drainage": {
"format": "double",
"type": "number"
"format": "default",
"anyOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"potential_evaporation": {
"format": "double",
"type": "number"
"format": "default",
"anyOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"infiltration": {
"format": "double",
"type": "number"
"format": "default",
"anyOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"precipitation": {
"format": "double",
"type": "number"
"format": "default",
"anyOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"urban_runoff": {
"format": "double",
"type": "number"
"format": "default",
"anyOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"remarks": {
"description": "a hack for pandera",
Expand All @@ -37,11 +72,6 @@
}
},
"required": [
"node_id",
"drainage",
"potential_evaporation",
"infiltration",
"precipitation",
"urban_runoff"
"node_id"
]
}
10 changes: 5 additions & 5 deletions python/ribasim/ribasim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class BasinState(BaseModel):

class BasinStatic(BaseModel):
node_id: int
drainage: float
potential_evaporation: float
infiltration: float
precipitation: float
urban_runoff: float
drainage: float | None = None
potential_evaporation: float | None = None
infiltration: float | None = None
precipitation: float | None = None
urban_runoff: float | None = None
remarks: str = Field("", description="a hack for pandera")


Expand Down
10 changes: 5 additions & 5 deletions python/ribasim_testmodels/ribasim_testmodels/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def bucket_model() -> ribasim.Model:
static = pd.DataFrame(
data={
"node_id": [1],
"drainage": [0.0],
"potential_evaporation": [0.0],
"infiltration": [0.0],
"precipitation": [0.0],
"urban_runoff": [0.0],
"drainage": [np.nan],
"potential_evaporation": [np.nan],
"infiltration": [np.nan],
"precipitation": [np.nan],
"urban_runoff": [np.nan],
}
)
basin = ribasim.Basin(profile=profile, static=static, state=state)
Expand Down

0 comments on commit 1694f7f

Please sign in to comment.