Skip to content

Commit

Permalink
Merge branch 'main' into land-surface-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
barneydobson committed Oct 1, 2024
2 parents c850d51 + 55fba2c commit 0862658
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_sewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ def test_make_discharge(self):
d3 = {"volume": 7, "phosphate": 7 * 2 / 9, "temperature": 10}
self.assertDictAlmostEqual(d3, sewer.sewer_tank.storage, 15)

def test_sewer_overrides(self):
sewer = Sewer(name="", capacity=10, pipe_timearea={0: 0.3, 1: 0.7})
sewer.apply_overrides(
{
"capacity": 3,
"chamber_area": 2,
"chamber_floor": 3.5,
"pipe_time": 8.4,
"pipe_timearea": {0: 0.5, 1: 0.5},
}
)
self.assertEqual(sewer.capacity, 3)
self.assertEqual(sewer.sewer_tank.capacity, 3)
self.assertEqual(sewer.chamber_area, 2)
self.assertEqual(sewer.sewer_tank.area, 2)
self.assertEqual(sewer.chamber_floor, 3.5)
self.assertEqual(sewer.sewer_tank.datum, 3.5)
self.assertEqual(sewer.pipe_time, 8.4)
self.assertEqual(sewer.pipe_timearea, {0: 0.5, 1: 0.5})


if __name__ == "__main__":
unittest.main()
29 changes: 29 additions & 0 deletions wsimod/nodes/sewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@author: bdobson
Converted to totals on 2022-05-03
"""
from typing import Any, Dict

from wsimod.core import constants
from wsimod.nodes.nodes import Node
from wsimod.nodes.tanks import QueueTank
Expand Down Expand Up @@ -113,6 +115,33 @@ def __init__(
# Mass balance
self.mass_balance_ds.append(lambda: self.sewer_tank.ds())

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the sewer.
Enables a user to override any of the following parameters:
capacity, chamber_area, chamber_floor, pipe_time, pipe_timearea.
Args:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
self.capacity = overrides.pop("capacity", self.capacity)
self.chamber_area = overrides.pop("chamber_area", self.chamber_area)
self.chamber_floor = overrides.pop("chamber_floor", self.chamber_floor)
self.sewer_tank.capacity = self.capacity
self.sewer_tank.area = self.chamber_area
self.sewer_tank.datum = self.chamber_floor

self.pipe_time = overrides.pop("pipe_time", self.pipe_time)
if "pipe_timearea" in overrides.keys():
pipe_timearea_sum = sum([v for k, v in overrides["pipe_timearea"].items()])
if pipe_timearea_sum != 1:
print(
"ERROR: the sum of pipe_timearea in the overrides dict \
is not equal to 1, please check it"
)
self.pipe_timearea = overrides.pop("pipe_timearea", self.pipe_timearea)
super().apply_overrides(overrides)

def push_check_sewer(self, vqip=None):
"""Generic push check, simply looks at excess.
Expand Down

0 comments on commit 0862658

Please sign in to comment.