From c6b340917a636492464de47d57a03dc9f06566a3 Mon Sep 17 00:00:00 2001 From: luitjan Date: Fri, 31 May 2024 12:20:43 +0200 Subject: [PATCH 1/3] now validating screen top > screen bottom --- imod/mf6/wel.py | 10 +++++++++- imod/tests/test_mf6/test_mf6_wel.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/imod/mf6/wel.py b/imod/mf6/wel.py index 080046c99..45d1939c9 100644 --- a/imod/mf6/wel.py +++ b/imod/mf6/wel.py @@ -1,5 +1,6 @@ from __future__ import annotations +from collections import defaultdict import warnings from typing import Any, Optional, Tuple, Union @@ -12,6 +13,7 @@ import imod from imod.logging import init_log_decorator +from imod.logging.logging_decorators import standard_log_decorator from imod.mf6.boundary_condition import ( BoundaryCondition, DisStructuredBoundaryCondition, @@ -26,6 +28,7 @@ from imod.prepare import assign_wells from imod.prepare.layer import create_layered_top from imod.schemata import ( + AllValueSchema, AnyNoDataSchema, DTypeSchema, EmptyIndexesSchema, @@ -177,7 +180,7 @@ def y(self) -> npt.NDArray[np.float64]: } _write_schemata = { "screen_top": [AnyNoDataSchema(), EmptyIndexesSchema()], - "screen_bottom": [AnyNoDataSchema(), EmptyIndexesSchema()], + "screen_bottom": [AnyNoDataSchema(), EmptyIndexesSchema(), AllValueSchema("<", "screen_top")], "y": [AnyNoDataSchema(), EmptyIndexesSchema()], "x": [AnyNoDataSchema(), EmptyIndexesSchema()], "rate": [AnyNoDataSchema(), EmptyIndexesSchema()], @@ -362,6 +365,11 @@ def __create_wells_df(self) -> pd.DataFrame: ) return wells_df + + @standard_log_decorator() + def _validate(self, schemata: dict, **kwargs) -> dict[str, list[ValidationError]]: + kwargs["screen_top"] = self.dataset["screen_top"] + return Package._validate(self, schemata, **kwargs) def __create_assigned_wells( self, diff --git a/imod/tests/test_mf6/test_mf6_wel.py b/imod/tests/test_mf6/test_mf6_wel.py index e91714826..c7e1f51c7 100644 --- a/imod/tests/test_mf6/test_mf6_wel.py +++ b/imod/tests/test_mf6/test_mf6_wel.py @@ -67,6 +67,24 @@ def test_to_mf6_pkg__validate(well_high_lvl_test_data_stationary): errors = wel._validate(wel._write_schemata) assert len(errors) == 1 +def test_to_mf6_pkg__validate_filter_top(well_high_lvl_test_data_stationary): + + # Arrange + x, y, screen_top, screen_bottom, rate_wel, concentration =well_high_lvl_test_data_stationary + screen_top = [-2., 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] + screen_bottom = [ 0., -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0] + well_test_data = ( x, y, screen_top, screen_bottom, rate_wel, concentration) + + wel = imod.mf6.Well(*well_test_data) + + # Act + kwargs = { "screen_top" : wel.dataset["screen_top"]} + errors = wel._validate(wel._write_schemata, **kwargs) + + # Assert + assert len(errors) == 1 + assert str(errors["screen_bottom"][0]) == 'not all values comply with criterion: < screen_top' + def test_to_mf6_pkg__high_lvl_multilevel(basic_dis, well_high_lvl_test_data_stationary): """ From 97343fd0fc30de179c227ed2b94201218f2f6951 Mon Sep 17 00:00:00 2001 From: luitjan Date: Fri, 31 May 2024 12:21:06 +0200 Subject: [PATCH 2/3] formatting --- imod/mf6/wel.py | 11 +++++++---- imod/tests/test_mf6/test_mf6_wel.py | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/imod/mf6/wel.py b/imod/mf6/wel.py index 45d1939c9..e10ec3b4b 100644 --- a/imod/mf6/wel.py +++ b/imod/mf6/wel.py @@ -1,6 +1,5 @@ from __future__ import annotations -from collections import defaultdict import warnings from typing import Any, Optional, Tuple, Union @@ -180,7 +179,11 @@ def y(self) -> npt.NDArray[np.float64]: } _write_schemata = { "screen_top": [AnyNoDataSchema(), EmptyIndexesSchema()], - "screen_bottom": [AnyNoDataSchema(), EmptyIndexesSchema(), AllValueSchema("<", "screen_top")], + "screen_bottom": [ + AnyNoDataSchema(), + EmptyIndexesSchema(), + AllValueSchema("<", "screen_top"), + ], "y": [AnyNoDataSchema(), EmptyIndexesSchema()], "x": [AnyNoDataSchema(), EmptyIndexesSchema()], "rate": [AnyNoDataSchema(), EmptyIndexesSchema()], @@ -365,11 +368,11 @@ def __create_wells_df(self) -> pd.DataFrame: ) return wells_df - + @standard_log_decorator() def _validate(self, schemata: dict, **kwargs) -> dict[str, list[ValidationError]]: kwargs["screen_top"] = self.dataset["screen_top"] - return Package._validate(self, schemata, **kwargs) + return Package._validate(self, schemata, **kwargs) def __create_assigned_wells( self, diff --git a/imod/tests/test_mf6/test_mf6_wel.py b/imod/tests/test_mf6/test_mf6_wel.py index c7e1f51c7..c95d5b7e0 100644 --- a/imod/tests/test_mf6/test_mf6_wel.py +++ b/imod/tests/test_mf6/test_mf6_wel.py @@ -67,23 +67,28 @@ def test_to_mf6_pkg__validate(well_high_lvl_test_data_stationary): errors = wel._validate(wel._write_schemata) assert len(errors) == 1 -def test_to_mf6_pkg__validate_filter_top(well_high_lvl_test_data_stationary): +def test_to_mf6_pkg__validate_filter_top(well_high_lvl_test_data_stationary): # Arrange - x, y, screen_top, screen_bottom, rate_wel, concentration =well_high_lvl_test_data_stationary - screen_top = [-2., 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] - screen_bottom = [ 0., -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0] - well_test_data = ( x, y, screen_top, screen_bottom, rate_wel, concentration) + x, y, screen_top, screen_bottom, rate_wel, concentration = ( + well_high_lvl_test_data_stationary + ) + screen_top = [-2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] + screen_bottom = [0.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0] + well_test_data = (x, y, screen_top, screen_bottom, rate_wel, concentration) wel = imod.mf6.Well(*well_test_data) # Act - kwargs = { "screen_top" : wel.dataset["screen_top"]} + kwargs = {"screen_top": wel.dataset["screen_top"]} errors = wel._validate(wel._write_schemata, **kwargs) # Assert assert len(errors) == 1 - assert str(errors["screen_bottom"][0]) == 'not all values comply with criterion: < screen_top' + assert ( + str(errors["screen_bottom"][0]) + == "not all values comply with criterion: < screen_top" + ) def test_to_mf6_pkg__high_lvl_multilevel(basic_dis, well_high_lvl_test_data_stationary): From 06352a53c6decb5317eea612735e8e1b9e712e81 Mon Sep 17 00:00:00 2001 From: luitjan Date: Fri, 7 Jun 2024 11:11:37 +0200 Subject: [PATCH 3/3] updated changelog --- docs/api/changelog.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/api/changelog.rst b/docs/api/changelog.rst index 597bed3aa..64da9b116 100644 --- a/docs/api/changelog.rst +++ b/docs/api/changelog.rst @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file. The format is based on `Keep a Changelog`_, and this project adheres to `Semantic Versioning`_. + +[Unreleased- feature branch] +---------------------------- + +Changed +~~~~~~~ +- :class:`imod.mf6.Well` now also validates that well filter top is above well filter bottom + [Unreleased] ------------