From 9942e437e867378f97ca7c120ec0a3a763fc7a7f Mon Sep 17 00:00:00 2001 From: liuly12 Date: Sat, 16 Mar 2024 19:40:53 +0000 Subject: [PATCH 1/6] Apply overrides in FWTW --- tests/test_wtw.py | 22 +++++++++++++++++++++- wsimod/nodes/wtw.py | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/test_wtw.py b/tests/test_wtw.py index 1a2061f9..56bf0638 100644 --- a/tests/test_wtw.py +++ b/tests/test_wtw.py @@ -10,7 +10,7 @@ from unittest import TestCase from wsimod.core import constants -from wsimod.nodes.wtw import WTW, WWTW +from wsimod.nodes.wtw import WTW, WWTW, FWTW class MyTestClass(TestCase): @@ -113,6 +113,26 @@ def test_wwtw_overrides(self): self.assertEqual(wwtw.process_parameters['phosphate']['constant'], 0.01) self.assertEqual(wwtw.process_parameters['volume']['constant'], vol) self.assertEqual(wwtw.stormwater_storage_capacity, 100) + + def test_fwtw_overrides(self): + fwtw = FWTW(name='') + vol = fwtw.process_parameters['volume']['constant'] + fwtw.apply_overrides({'treatment_throughput_capacity' : 20, + 'process_parameters' : {'phosphate' : + {'constant' : 0.01}}, + 'service_reservoir_storage_capacity': 100, + 'service_reservoir_storage_area': 34.7, + 'service_reservoir_storage_elevation': 68.2 + }) + self.assertEqual(fwtw.treatment_throughput_capacity, 20) + self.assertEqual(fwtw.process_parameters['phosphate']['constant'], 0.01) + self.assertEqual(fwtw.process_parameters['volume']['constant'], vol) + self.assertEqual(fwtw.service_reservoir_storage_capacity, 100) + self.assertEqual(fwtw.service_reservoir_tank.capacity, 100) + self.assertEqual(fwtw.service_reservoir_storage_area, 34.7) + self.assertEqual(fwtw.service_reservoir_tank.area, 34.7) + self.assertEqual(fwtw.service_reservoir_storage_elevation, 68.2) + self.assertEqual(fwtw.service_reservoir_tank.datum, 68.2) if __name__ == "__main__": unittest.main() diff --git a/wsimod/nodes/wtw.py b/wsimod/nodes/wtw.py index db99d56e..acf4f1a2 100644 --- a/wsimod/nodes/wtw.py +++ b/wsimod/nodes/wtw.py @@ -542,6 +542,31 @@ def __init__( self.mass_balance_ds.append(lambda: self.service_reservoir_tank.ds()) self.mass_balance_out.append(lambda: self.unpushed_sludge) + def apply_overrides(self, overrides=Dict[str, Any]): + """Apply overrides to the service reservoir tank and FWTW. + + Enables a user to override any parameter of the service reservoir tank, and + then calls any overrides in WTW. + + Args: + overrides (Dict[str, Any]): Dict describing which parameters should + be overridden (keys) and new values (values). Defaults to {}. + """ + self.service_reservoir_storage_capacity = overrides.pop( + "service_reservoir_storage_capacity", + self.service_reservoir_storage_capacity) + self.service_reservoir_storage_area = overrides.pop( + "service_reservoir_storage_area", + self.service_reservoir_storage_area) + self.service_reservoir_storage_elevation = overrides.pop( + "service_reservoir_storage_elevation", + self.service_reservoir_storage_elevation) + + self.service_reservoir_tank.capacity = self.service_reservoir_storage_capacity + self.service_reservoir_tank.area = self.service_reservoir_storage_area + self.service_reservoir_tank.datum = self.service_reservoir_storage_elevation + super().apply_overrides(overrides) + def treat_water(self): """Pulls water, aiming to fill service reservoirs, calls WTW treat_current_input, avoids deficit, sends liquor and solids to sewers.""" From e950f3d8e922f46b3c24a7d13aaf722d9023232b Mon Sep 17 00:00:00 2001 From: liuly12 <59883247+liuly12@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:15:25 +0000 Subject: [PATCH 2/6] check it doesn't delete other bits Co-authored-by: barneydobson --- tests/test_wtw.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_wtw.py b/tests/test_wtw.py index 56bf0638..09e2d7be 100644 --- a/tests/test_wtw.py +++ b/tests/test_wtw.py @@ -133,6 +133,7 @@ def test_fwtw_overrides(self): self.assertEqual(fwtw.service_reservoir_tank.area, 34.7) self.assertEqual(fwtw.service_reservoir_storage_elevation, 68.2) self.assertEqual(fwtw.service_reservoir_tank.datum, 68.2) + self.assertEqual(fwtw.process_parameters['nitrate']['constant'], 0.01) if __name__ == "__main__": unittest.main() From ef7091662a5ed19e75ae0ea41cb571308978bc1b Mon Sep 17 00:00:00 2001 From: liuly12 <59883247+liuly12@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:15:46 +0000 Subject: [PATCH 3/6] use something that itsn't the default value Co-authored-by: barneydobson --- tests/test_wtw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wtw.py b/tests/test_wtw.py index 09e2d7be..105cabae 100644 --- a/tests/test_wtw.py +++ b/tests/test_wtw.py @@ -119,7 +119,7 @@ def test_fwtw_overrides(self): vol = fwtw.process_parameters['volume']['constant'] fwtw.apply_overrides({'treatment_throughput_capacity' : 20, 'process_parameters' : {'phosphate' : - {'constant' : 0.01}}, + {'constant' : 0.02}}, 'service_reservoir_storage_capacity': 100, 'service_reservoir_storage_area': 34.7, 'service_reservoir_storage_elevation': 68.2 From f7a21d6ddbbe2251ed64225a621cc1eaddb8f7cc Mon Sep 17 00:00:00 2001 From: liuly12 <59883247+liuly12@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:15:54 +0000 Subject: [PATCH 4/6] use something that itsn't the default value Co-authored-by: barneydobson --- tests/test_wtw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wtw.py b/tests/test_wtw.py index 105cabae..7c225c25 100644 --- a/tests/test_wtw.py +++ b/tests/test_wtw.py @@ -125,7 +125,7 @@ def test_fwtw_overrides(self): 'service_reservoir_storage_elevation': 68.2 }) self.assertEqual(fwtw.treatment_throughput_capacity, 20) - self.assertEqual(fwtw.process_parameters['phosphate']['constant'], 0.01) + self.assertEqual(fwtw.process_parameters['phosphate']['constant'], 0.02) self.assertEqual(fwtw.process_parameters['volume']['constant'], vol) self.assertEqual(fwtw.service_reservoir_storage_capacity, 100) self.assertEqual(fwtw.service_reservoir_tank.capacity, 100) From 05f83c07151f490a718314ee4bcf6c0c3fa949e1 Mon Sep 17 00:00:00 2001 From: liuly12 Date: Fri, 26 Jul 2024 14:31:02 +0100 Subject: [PATCH 5/6] pre-commit reformatted --- tests/test_wtw.py | 28 +++++++++++++++------------- wsimod/nodes/wtw.py | 18 ++++++++++-------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/test_wtw.py b/tests/test_wtw.py index c4ea92c0..f1d25d81 100644 --- a/tests/test_wtw.py +++ b/tests/test_wtw.py @@ -127,27 +127,29 @@ def test_wwtw_overrides(self): self.assertEqual(wwtw.process_parameters["phosphate"]["constant"], 0.01) self.assertEqual(wwtw.process_parameters["volume"]["constant"], vol) self.assertEqual(wwtw.stormwater_storage_capacity, 100) - + def test_fwtw_overrides(self): - fwtw = FWTW(name='') - vol = fwtw.process_parameters['volume']['constant'] - fwtw.apply_overrides({'treatment_throughput_capacity' : 20, - 'process_parameters' : {'phosphate' : - {'constant' : 0.02}}, - 'service_reservoir_storage_capacity': 100, - 'service_reservoir_storage_area': 34.7, - 'service_reservoir_storage_elevation': 68.2 - }) + fwtw = FWTW(name="") + vol = fwtw.process_parameters["volume"]["constant"] + fwtw.apply_overrides( + { + "treatment_throughput_capacity": 20, + "process_parameters": {"phosphate": {"constant": 0.02}}, + "service_reservoir_storage_capacity": 100, + "service_reservoir_storage_area": 34.7, + "service_reservoir_storage_elevation": 68.2, + } + ) self.assertEqual(fwtw.treatment_throughput_capacity, 20) - self.assertEqual(fwtw.process_parameters['phosphate']['constant'], 0.02) - self.assertEqual(fwtw.process_parameters['volume']['constant'], vol) + self.assertEqual(fwtw.process_parameters["phosphate"]["constant"], 0.02) + self.assertEqual(fwtw.process_parameters["volume"]["constant"], vol) self.assertEqual(fwtw.service_reservoir_storage_capacity, 100) self.assertEqual(fwtw.service_reservoir_tank.capacity, 100) self.assertEqual(fwtw.service_reservoir_storage_area, 34.7) self.assertEqual(fwtw.service_reservoir_tank.area, 34.7) self.assertEqual(fwtw.service_reservoir_storage_elevation, 68.2) self.assertEqual(fwtw.service_reservoir_tank.datum, 68.2) - self.assertEqual(fwtw.process_parameters['nitrate']['constant'], 0.01) + self.assertEqual(fwtw.process_parameters["nitrate"]["constant"], 0.01) if __name__ == "__main__": diff --git a/wsimod/nodes/wtw.py b/wsimod/nodes/wtw.py index d593db8b..002313dc 100644 --- a/wsimod/nodes/wtw.py +++ b/wsimod/nodes/wtw.py @@ -547,26 +547,28 @@ def apply_overrides(self, overrides=Dict[str, Any]): Enables a user to override any parameter of the service reservoir tank, and then calls any overrides in WTW. - + Args: overrides (Dict[str, Any]): Dict describing which parameters should be overridden (keys) and new values (values). Defaults to {}. """ self.service_reservoir_storage_capacity = overrides.pop( - "service_reservoir_storage_capacity", - self.service_reservoir_storage_capacity) + "service_reservoir_storage_capacity", + self.service_reservoir_storage_capacity, + ) self.service_reservoir_storage_area = overrides.pop( - "service_reservoir_storage_area", - self.service_reservoir_storage_area) + "service_reservoir_storage_area", self.service_reservoir_storage_area + ) self.service_reservoir_storage_elevation = overrides.pop( - "service_reservoir_storage_elevation", - self.service_reservoir_storage_elevation) + "service_reservoir_storage_elevation", + self.service_reservoir_storage_elevation, + ) self.service_reservoir_tank.capacity = self.service_reservoir_storage_capacity self.service_reservoir_tank.area = self.service_reservoir_storage_area self.service_reservoir_tank.datum = self.service_reservoir_storage_elevation super().apply_overrides(overrides) - + def treat_water(self): """Pulls water, aiming to fill service reservoirs, calls WTW treat_current_input, avoids deficit, sends liquor and solids to sewers.""" From f637860deb3ec0bea9ce5684c45576b056609cae Mon Sep 17 00:00:00 2001 From: liuly12 Date: Fri, 26 Jul 2024 14:40:44 +0100 Subject: [PATCH 6/6] Update test_wtw.py --- tests/test_wtw.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_wtw.py b/tests/test_wtw.py index f1d25d81..44fe4869 100644 --- a/tests/test_wtw.py +++ b/tests/test_wtw.py @@ -149,7 +149,6 @@ def test_fwtw_overrides(self): self.assertEqual(fwtw.service_reservoir_tank.area, 34.7) self.assertEqual(fwtw.service_reservoir_storage_elevation, 68.2) self.assertEqual(fwtw.service_reservoir_tank.datum, 68.2) - self.assertEqual(fwtw.process_parameters["nitrate"]["constant"], 0.01) if __name__ == "__main__":