Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add and fix test #137

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/test_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 3 additions & 0 deletions wsimod/nodes/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..

Expand Down
Loading