From edeccdb21f0b196f3eec75502145b9ce12df4dd3 Mon Sep 17 00:00:00 2001 From: Dobson Date: Wed, 11 Dec 2024 15:31:00 +0000 Subject: [PATCH 1/5] add and fix test --- tests/test_land.py | 91 ++++++++++++++++++++++++++++++++++++++++++++ wsimod/nodes/land.py | 3 ++ 2 files changed, 94 insertions(+) diff --git a/tests/test_land.py b/tests/test_land.py index 89e69340..0430cb3d 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1423,6 +1423,97 @@ def test_nutrientpool_overrides(self): ) self.assertEqual(growingsurface.nutrient_pool.fraction_dry_n_to_fast, 0.71) + """Test surface parameter override.""" + + +def test_apply_surface_overrides(tmp_path): + """Test surface overrides are applied in model load.""" + import yaml + from wsimod.orchestration.model import Model + + config = { + "arcs": { + "arc1": { + "name": "arc1", + "in_port": "land1", + "out_port": "river1", + "type_": "Arc", + "capacity": 10, + "preference": 1, + }, + }, + "nodes": { + "land1": { + "name": "land1", + "type_": "Land", + "percolation_residence_time": 0.1, + "surfaces": { + "Woodland": { + "area": 100, + "datum": 10, + "type_": "GrowingSurface", + "ET_depletion_factor": 0.75, + "surface": "Woodland", + }, + "Grass": { + "area": 200, + "datum": 20, + "type_": "GrowingSurface", + "ET_depletion_factor": 0.75, + "surface": "Grass", + }, + }, + }, + "river1": { + "name": "river1", + "type_": "River", + }, + }, + "overrides": { + "arcs": { + "arc1": { + "name": "arc1", + "type_": "Arc", + "capacity": 20, + } + }, + "nodes": { + "land1": { + "surfaces": { + "Woodland": { + "surface": "Woodland", + "type_": "GrowingSurface", + "area": 1000, + } + }, + "percolation_residence_time": 1, + "name": "land1", + "type_": "Land", + } + }, + }, + } + + # Create the config file + with (tmp_path / "config.yml").open("w") as f: + yaml.dump(config, f) + + # Load in the model + model = Model() + model.load(tmp_path) + + # Perform the test + assert hasattr(model.nodes["land1"], "surfaces") + assert hasattr(model.nodes["land1"].get_surface("Woodland"), "surface") + assert hasattr(model.nodes["land1"].get_surface("Grass"), "surface") + assert model.arcs["arc1"].capacity == 20 + assert model.arcs["arc1"].preference == 1 + assert model.nodes["land1"].percolation_residence_time == 1 + assert model.nodes["land1"].get_surface("Woodland").datum == 10 + assert model.nodes["land1"].get_surface("Grass").area == 200 + assert model.nodes["land1"].get_surface("Grass").datum == 20 + assert model.nodes["land1"].get_surface("Woodland").area == 1000 + if __name__ == "__main__": unittest.main() diff --git a/wsimod/nodes/land.py b/wsimod/nodes/land.py index 2c8e004e..0409ffa3 100644 --- a/wsimod/nodes/land.py +++ b/wsimod/nodes/land.py @@ -185,6 +185,9 @@ def apply_overrides(self, overrides=Dict[str, Any]): self.percolation.residence_time = self.percolation_residence_time super().apply_overrides(overrides) + for surface, override in overrides.get("surfaces", {}).items(): + self.get_surface(surface).apply_overrides(override) + def apply_irrigation(self): """Iterate over any irrigation functions (needs further testing.. From 08473760c4869f65e186bd9925c080539bb6ff29 Mon Sep 17 00:00:00 2001 From: Dobson Date: Wed, 11 Dec 2024 16:45:35 +0000 Subject: [PATCH 2/5] add growing specific param --- tests/test_land.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_land.py b/tests/test_land.py index 0430cb3d..c5698d02 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1484,6 +1484,7 @@ def test_apply_surface_overrides(tmp_path): "surface": "Woodland", "type_": "GrowingSurface", "area": 1000, + "rooting_depth": 0.1, } }, "percolation_residence_time": 1, @@ -1513,6 +1514,7 @@ def test_apply_surface_overrides(tmp_path): assert model.nodes["land1"].get_surface("Grass").area == 200 assert model.nodes["land1"].get_surface("Grass").datum == 20 assert model.nodes["land1"].get_surface("Woodland").area == 1000 + assert model.nodes["land1"].get_surface("Woodland").rooting_depth == 0.1 if __name__ == "__main__": From 3fdd33d596c213b3b1759f40c52cdc8c799ceb7e Mon Sep 17 00:00:00 2001 From: barneydobson Date: Thu, 12 Dec 2024 09:22:06 +0000 Subject: [PATCH 3/5] Update tests/test_land.py Co-authored-by: Robin Maes-Prior <87651497+RobinMaesPrior@users.noreply.github.com> --- tests/test_land.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_land.py b/tests/test_land.py index c5698d02..66a9a488 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1484,7 +1484,7 @@ def test_apply_surface_overrides(tmp_path): "surface": "Woodland", "type_": "GrowingSurface", "area": 1000, - "rooting_depth": 0.1, + "ET_depletion_factor": 0.8 } }, "percolation_residence_time": 1, From a87eeb107fde64d18677c40c01c8d101f418a637 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Thu, 12 Dec 2024 09:22:12 +0000 Subject: [PATCH 4/5] Update tests/test_land.py Co-authored-by: Robin Maes-Prior <87651497+RobinMaesPrior@users.noreply.github.com> --- tests/test_land.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_land.py b/tests/test_land.py index 66a9a488..6b820e29 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1514,7 +1514,7 @@ def test_apply_surface_overrides(tmp_path): assert model.nodes["land1"].get_surface("Grass").area == 200 assert model.nodes["land1"].get_surface("Grass").datum == 20 assert model.nodes["land1"].get_surface("Woodland").area == 1000 - assert model.nodes["land1"].get_surface("Woodland").rooting_depth == 0.1 + assert model.nodes["land1"].get_surface("Woodland").ET_depletion_factor == 0.8 if __name__ == "__main__": From 5651d26b0dcf10d469a400f448960ccff1037a09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:26:57 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_land.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_land.py b/tests/test_land.py index 6b820e29..7925def3 100644 --- a/tests/test_land.py +++ b/tests/test_land.py @@ -1484,7 +1484,7 @@ def test_apply_surface_overrides(tmp_path): "surface": "Woodland", "type_": "GrowingSurface", "area": 1000, - "ET_depletion_factor": 0.8 + "ET_depletion_factor": 0.8, } }, "percolation_residence_time": 1,