Skip to content

Commit

Permalink
pre-commit reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
liuly12 committed Jul 26, 2024
1 parent e96ee1c commit 7a8d2fc
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 87 deletions.
85 changes: 53 additions & 32 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,62 +663,83 @@ def test_decay_queue(self):
def test_overrides(self):
# node - no need to test
# tank
tank = Tank(capacity=10, area=8, datum = 4)
tank.apply_overrides({'capacity': 3,
'area': 2,
'datum': 3.5})
tank = Tank(capacity=10, area=8, datum=4)
tank.apply_overrides({"capacity": 3, "area": 2, "datum": 3.5})
self.assertEqual(tank.capacity, 3)
self.assertEqual(tank.area, 2)
self.assertEqual(tank.datum, 3.5)
self.assertEqual(tank.get_excess()['volume'], 3)
self.assertEqual(tank.get_excess()["volume"], 3)
# residence tank
tank = ResidenceTank(capacity=10, area=8, datum = 4, residence_time = 8)
tank.apply_overrides({'capacity': 3,
'area': 2,
'datum': 3.5,
'residence_time': 6})
tank = ResidenceTank(capacity=10, area=8, datum=4, residence_time=8)
tank.apply_overrides(
{"capacity": 3, "area": 2, "datum": 3.5, "residence_time": 6}
)
self.assertEqual(tank.capacity, 3)
self.assertEqual(tank.area, 2)
self.assertEqual(tank.datum, 3.5)
self.assertEqual(tank.residence_time, 6)
# decay tank
tank = DecayTank(capacity=10, area=8, datum = 4, decays = {'nitrate' : {'constant' : 0.001, 'exponent' : 1.005}})
tank.apply_overrides({'capacity': 3,
'area': 2,
'datum': 3.5,
'decays': {'phosphate' : {'constant' : 1.001, 'exponent' : 10.005}}
})
tank = DecayTank(
capacity=10,
area=8,
datum=4,
decays={"nitrate": {"constant": 0.001, "exponent": 1.005}},
)
tank.apply_overrides(
{
"capacity": 3,
"area": 2,
"datum": 3.5,
"decays": {"phosphate": {"constant": 1.001, "exponent": 10.005}},
}
)
self.assertEqual(tank.capacity, 3)
self.assertEqual(tank.area, 2)
self.assertEqual(tank.datum, 3.5)
self.assertDictEqual(tank.decays, {'nitrate' : {'constant' : 0.001, 'exponent' : 1.005},
'phosphate' : {'constant' : 1.001, 'exponent' : 10.005}
})
self.assertDictEqual(
tank.decays,
{
"nitrate": {"constant": 0.001, "exponent": 1.005},
"phosphate": {"constant": 1.001, "exponent": 10.005},
},
)
# queue tank
tank = QueueTank(capacity=10, area=8, datum = 4, number_of_timesteps = 8)
tank.apply_overrides({'capacity': 3,
'area': 2,
'datum': 3.5,
'number_of_timesteps': 6})
tank = QueueTank(capacity=10, area=8, datum=4, number_of_timesteps=8)
tank.apply_overrides(
{"capacity": 3, "area": 2, "datum": 3.5, "number_of_timesteps": 6}
)
self.assertEqual(tank.capacity, 3)
self.assertEqual(tank.area, 2)
self.assertEqual(tank.datum, 3.5)
self.assertEqual(tank.number_of_timesteps, 6)
self.assertEqual(tank.internal_arc.number_of_timesteps, 6)
# decay queue tank
tank = DecayQueueTank(capacity=10, area=8, datum = 4, number_of_timesteps = 8, decays = {'phosphate' : {'constant' : 0.001, 'exponent' : 1.005}})
tank.apply_overrides({'capacity': 3,
'area': 2,
'datum': 3.5,
'number_of_timesteps': 6,
'decays': {'phosphate' : {'constant' : 1.001, 'exponent' : 10.005}}
})
tank = DecayQueueTank(
capacity=10,
area=8,
datum=4,
number_of_timesteps=8,
decays={"phosphate": {"constant": 0.001, "exponent": 1.005}},
)
tank.apply_overrides(
{
"capacity": 3,
"area": 2,
"datum": 3.5,
"number_of_timesteps": 6,
"decays": {"phosphate": {"constant": 1.001, "exponent": 10.005}},
}
)
self.assertEqual(tank.capacity, 3)
self.assertEqual(tank.area, 2)
self.assertEqual(tank.datum, 3.5)
self.assertEqual(tank.number_of_timesteps, 6)
self.assertEqual(tank.internal_arc.number_of_timesteps, 6)
self.assertDictEqual(tank.internal_arc.decays, {'phosphate' : {'constant' : 1.001, 'exponent' : 10.005}})
self.assertDictEqual(
tank.internal_arc.decays,
{"phosphate": {"constant": 1.001, "exponent": 10.005}},
)


if __name__ == "__main__":
unittest.main()
20 changes: 11 additions & 9 deletions tests/test_sewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,24 @@ def test_make_discharge(self):

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}
})
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
})
self.assertEqual(sewer.pipe_timearea, {0: 0.5, 1: 0.5})


if __name__ == "__main__":
unittest.main()
54 changes: 26 additions & 28 deletions wsimod/nodes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,25 +793,22 @@ def __init__(self, capacity=0, area=1, datum=10, initial_storage=0):
else:
self.storage = self.empty_vqip()
self.storage_ = self.empty_vqip() # Lagged storage for mass balance

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the tank.
Enables a user to override any of the following parameters:
Enables a user to override any of the following parameters:
area, capacity, datum.
Args:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
self.capacity = overrides.pop("capacity",
self.capacity)
self.area = overrides.pop("area",
self.area)
self.datum = overrides.pop("datum",
self.datum)
self.capacity = overrides.pop("capacity", self.capacity)
self.area = overrides.pop("area", self.area)
self.datum = overrides.pop("datum", self.datum)
if len(overrides) > 0:
print(f"No override behaviour defined for: {overrides.keys()}")

def ds(self):
"""Should be called by parent object to get change in storage.
Expand Down Expand Up @@ -1119,15 +1116,14 @@ def __init__(self, residence_time=2, **kwargs):

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the residencetank.
Enables a user to override any of the following parameters:
Enables a user to override any of the following parameters:
residence_time.
Args:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
self.residence_time = overrides.pop("residence_time",
self.residence_time)
self.residence_time = overrides.pop("residence_time", self.residence_time)
super().apply_overrides(overrides)

def pull_outflow(self):
Expand Down Expand Up @@ -1175,10 +1171,10 @@ def __init__(self, decays={}, parent=None, **kwargs):

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the decaytank.
Enables a user to override any of the following parameters:
Enables a user to override any of the following parameters:
decays.
Args:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
Expand Down Expand Up @@ -1235,15 +1231,16 @@ def __init__(self, number_of_timesteps=0, **kwargs):

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the queuetank.
Enables a user to override any of the following parameters:
Enables a user to override any of the following parameters:
number_of_timesteps.
Args:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
self.number_of_timesteps = overrides.pop("number_of_timesteps",
self.number_of_timesteps)
self.number_of_timesteps = overrides.pop(
"number_of_timesteps", self.number_of_timesteps
)
self.internal_arc.number_of_timesteps = self.number_of_timesteps
super().apply_overrides(overrides)

Expand Down Expand Up @@ -1417,15 +1414,16 @@ def __init__(self, decays={}, parent=None, number_of_timesteps=1, **kwargs):

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the decayqueuetank.
Enables a user to override any of the following parameters:
Enables a user to override any of the following parameters:
number_of_timesteps, decays.
Args:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
self.number_of_timesteps = overrides.pop("number_of_timesteps",
self.number_of_timesteps)
self.number_of_timesteps = overrides.pop(
"number_of_timesteps", self.number_of_timesteps
)
self.internal_arc.number_of_timesteps = self.number_of_timesteps
self.internal_arc.decays.update(overrides.pop("decays", {}))
super().apply_overrides(overrides)
Expand Down
36 changes: 18 additions & 18 deletions wsimod/nodes/sewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
@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, QueueTank
from typing import Any, Dict


class Sewer(Node):
""""""
Expand Down Expand Up @@ -114,31 +116,29 @@ def __init__(

def apply_overrides(self, overrides: Dict[str, Any] = {}):
"""Apply overrides to the sewer.
Enables a user to override any of the following parameters:
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.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()])

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)
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):
Expand Down

0 comments on commit 7a8d2fc

Please sign in to comment.