Skip to content

Commit

Permalink
Merge pull request #392 from nens/eli-laterals-and-boundary-conditions
Browse files Browse the repository at this point in the history
upgrade laterals and boundary conditions
  • Loading branch information
elisalle authored Sep 9, 2024
2 parents c821d5e + 6911059 commit 6395c90
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changelog of threedi-modelchecker
2.10.4 (unreleased)
-------------------

- Nothing changed yet.
- Adapt modelchecker to work with schema upgrades for boundary conditions and laterals (0.225)


2.10.3 (2024-09-05)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"Click",
"GeoAlchemy2>=0.9,!=0.11.*",
"SQLAlchemy>=1.4",
"threedi-schema==0.224.*"
"threedi-schema==0.225.*"
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion threedi_modelchecker/checks/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_invalid(self, session):

def description(self):
return (
"The timesteps for the first v2_1d_boundary_conditions.timeseries did not match the timesteps for the first v2_2d_boundary_conditions.timeseries. "
"The timesteps for the first boundary_condition_1d.timeseries did not match the timesteps for the first boundary_condition_2d.timeseries. "
+ "All boundary conditions must have the same timesteps in their timeseries."
)

Expand Down
52 changes: 45 additions & 7 deletions threedi_modelchecker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,39 +483,52 @@ def is_none_or_empty(col):
== models.Pumpstation.connection_node_end_id
),
),
message="v2_1d_boundary_conditions cannot be connected to a pumpstation",
message="boundary_condition_1d cannot be connected to a pumpstation",
),
# 1d boundary conditions should be connected to exactly 1 object
BoundaryCondition1DObjectNumberCheck(error_code=72),
QueryCheck(
error_code=73,
column=models.BoundaryConditions2D.boundary_type,
column=models.BoundaryConditions2D.type,
filters=~CONDITIONS["has_groundwater_flow"].exists(),
invalid=Query(models.BoundaryConditions2D).filter(
models.BoundaryConditions2D.boundary_type.in_(
models.BoundaryConditions2D.type.in_(
[
constants.BoundaryType.GROUNDWATERLEVEL,
constants.BoundaryType.GROUNDWATERDISCHARGE,
]
)
),
message=(
"v2_2d_boundary_conditions cannot have a groundwater type when there "
"boundary_condition_2d cannot have a groundwater type when there "
"is no groundwater hydraulic conductivity"
),
),
QueryCheck(
error_code=74,
column=models.BoundaryCondition1D.boundary_type,
column=models.BoundaryCondition1D.type,
invalid=Query(models.BoundaryCondition1D).filter(
models.BoundaryCondition1D.boundary_type.in_(
models.BoundaryCondition1D.type.in_(
[
constants.BoundaryType.GROUNDWATERLEVEL,
constants.BoundaryType.GROUNDWATERDISCHARGE,
]
)
),
message=("v2_1d_boundary_conditions cannot have a groundwater type"),
message=("boundary_condition_1d cannot have a groundwater type"),
),
QueryCheck(
error_code=75,
column=models.BoundaryCondition1D.connection_node_id,
invalid=Query(models.BoundaryCondition1D)
.outerjoin(
models.ConnectionNode,
models.BoundaryCondition1D.connection_node_id == models.ConnectionNode.id,
)
.filter(models.ConnectionNode.id == None),
message=(
"boundary_condition_1d.connection_node_id must point to an existing connection_node.id"
),
),
]

Expand Down Expand Up @@ -2648,6 +2661,23 @@ def is_none_or_empty(col):
NotNullCheck(error_code=1230 + i, column=col) for i, col in enumerate(not_null_cols)
]

# 124x laterals
CHECKS += [
QueryCheck(
error_code=1240,
column=models.Lateral1d.connection_node_id,
invalid=Query(models.Lateral1d)
.outerjoin(
models.ConnectionNode,
models.Lateral1d.connection_node_id == models.ConnectionNode.id,
)
.filter(models.ConnectionNode.id == None),
message=(
"lateral_1d.connection_node_id must point to an existing connection_node.id"
),
),
]


## 018x cross section parameters (continues 008x)
vegetation_parameter_columns = [
Expand Down Expand Up @@ -3028,9 +3058,13 @@ def is_none_or_empty(col):
models.Surface,
models.SurfaceMap,
models.SurfaceParameter,
models.Lateral2D,
models.Lateral1d,
models.DryWeatherFlow,
models.DryWeatherFlowMap,
models.DryWeatherFlowDistribution,
models.BoundaryConditions2D,
models.BoundaryCondition1D,
models.ControlMemory,
models.ControlTable,
models.ControlMeasureLocation,
Expand All @@ -3051,9 +3085,13 @@ def is_none_or_empty(col):
models.Surface,
models.SurfaceMap,
models.SurfaceParameter,
models.Lateral2D,
models.Lateral1d,
models.DryWeatherFlow,
models.DryWeatherFlowMap,
models.DryWeatherFlowDistribution,
models.BoundaryConditions2D,
models.BoundaryCondition1D,
models.ControlMemory,
models.ControlTable,
models.ControlMeasureLocation,
Expand Down
13 changes: 8 additions & 5 deletions threedi_modelchecker/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ class Meta:
model = models.BoundaryConditions2D
sqlalchemy_session = None

boundary_type = constants.BoundaryType.WATERLEVEL.value
type = constants.BoundaryType.WATERLEVEL.value
timeseries = "0,-0.5"
display_name = Faker("name")
geom = "SRID=4326;LINESTRING(4.885534714757985 52.38513158257129,4.88552805617346 52.38573773758626)"


class BoundaryConditions1DFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.BoundaryCondition1D
sqlalchemy_session = None

boundary_type = constants.BoundaryType.WATERLEVEL
type = constants.BoundaryType.WATERLEVEL
timeseries = "0,-0.5"
connection_node = factory.SubFactory(ConnectionNodeFactory)
connection_node_id = 1
geom = "SRID=4326;POINT(-71.064544 42.28787)"


class PumpstationFactory(factory.alchemy.SQLAlchemyModelFactory):
Expand Down Expand Up @@ -175,7 +177,8 @@ class Meta:
sqlalchemy_session = None

timeseries = "0,-0.1"
connection_node = factory.SubFactory(ConnectionNodeFactory)
connection_node_id = 1
geom = "SRID=4326;POINT(-71.064544 42.28787)"


class Lateral2DFactory(factory.alchemy.SQLAlchemyModelFactory):
Expand All @@ -184,7 +187,7 @@ class Meta:
sqlalchemy_session = None

timeseries = "0,-0.2"
the_geom = "SRID=4326;POINT(-71.064544 42.28787)"
geom = "SRID=4326;POINT(-71.064544 42.28787)"
type = constants.Later2dType.SURFACE


Expand Down
6 changes: 3 additions & 3 deletions threedi_modelchecker/tests/test_checks_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_geometry_type_check(session):
def test_enum_check(session):
factories.BoundaryConditions2DFactory()

enum_check = EnumCheck(models.BoundaryConditions2D.boundary_type)
enum_check = EnumCheck(models.BoundaryConditions2D.type)
invalid_rows = enum_check.get_invalid(session)
assert len(invalid_rows) == 0

Expand All @@ -355,9 +355,9 @@ def test_enum_check_with_null_values(session):

def test_enum_check_with_invalid_value(session):
factories.BoundaryConditions2DFactory()
faulty_boundary = factories.BoundaryConditions2DFactory(boundary_type=-1)
faulty_boundary = factories.BoundaryConditions2DFactory(type=-1)

enum_check = EnumCheck(models.BoundaryConditions2D.boundary_type)
enum_check = EnumCheck(models.BoundaryConditions2D.type)
invalid_rows = enum_check.get_invalid(session)
assert len(invalid_rows) == 1
assert invalid_rows[0].id == faulty_boundary.id
Expand Down
2 changes: 1 addition & 1 deletion threedi_modelchecker/tests/test_checks_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_gen_enum_checks():
enum_checks = generate_enum_checks(models.BoundaryConditions2D.__table__)

assert len(enum_checks) == 1
assert enum_checks[0].column == models.BoundaryConditions2D.boundary_type
assert enum_checks[0].column == models.BoundaryConditions2D.type


def test_gen_enum_checks_varcharenum():
Expand Down
6 changes: 2 additions & 4 deletions threedi_modelchecker/tests/test_checks_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,8 @@ def test_beta_values(session, value, expected_result):
constants.BoundaryType.GROUNDWATERLEVEL,
constants.BoundaryType.GROUNDWATERDISCHARGE,
]
factories.BoundaryConditions1DFactory(boundary_type=value)
check = BetaValuesCheck(
column=models.BoundaryCondition1D.boundary_type, values=beta_values
)
factories.BoundaryConditions1DFactory(type=value)
check = BetaValuesCheck(column=models.BoundaryCondition1D.type, values=beta_values)
invalid = check.get_invalid(session)
assert len(invalid) == expected_result

Expand Down

0 comments on commit 6395c90

Please sign in to comment.