-
Notifications
You must be signed in to change notification settings - Fork 2
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
Apply overrides in Storage and its superclasses #81
Changes from 7 commits
b6b164d
426ea31
d6fa53a
eb05cd9
c0a1921
df1e3ec
1540c7f
b9e7ec0
07e196b
f5eaf1c
8cd6b4e
da7c538
0a63072
8ede84a
bf716c4
d59a6e6
9be6ab8
ce74892
ca7668f
bdd0b1b
a5335da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
from wsimod.core import constants | ||
from wsimod.nodes.nodes import DecayQueueTank, DecayTank, Node, QueueTank, Tank | ||
|
||
from typing import Any, Dict | ||
|
||
class Storage(Node): | ||
"""""" | ||
|
@@ -72,6 +72,29 @@ def __init__( | |
# Mass balance | ||
self.mass_balance_ds.append(lambda: self.tank.ds()) | ||
|
||
def apply_overrides(self, overrides = Dict[str, Any]): | ||
"""Override parameters. | ||
|
||
Enables a user to override any of the following parameters: | ||
capacity, area, datum, decays. | ||
|
||
Args: | ||
overrides (Dict[str, Any]): Dict describing which parameters should | ||
be overridden (keys) and new values (values). Defaults to {}. | ||
""" | ||
# not using pop as these items need to stay in the overrides to be fed into the tank overrides | ||
if 'capacity' in overrides.keys(): | ||
self.capacity = overrides['capacity'] | ||
if 'area' in overrides.keys(): | ||
self.area = overrides['area'] | ||
if 'datum' in overrides.keys(): | ||
self.datum = overrides['datum'] | ||
if 'decays' in overrides.keys(): | ||
self.decays.update(overrides['decays']) | ||
# apply tank overrides | ||
self.tank.apply_overrides(overrides) | ||
super().apply_overrides(overrides) | ||
|
||
def push_set_storage(self, vqip): | ||
"""A node wrapper for the tank push_storage. | ||
|
||
|
@@ -171,6 +194,24 @@ def __init__( | |
self.data_input_dict = data_input_dict | ||
super().__init__(**kwargs) | ||
|
||
def apply_overrides(self, overrides = Dict[str, Any]): | ||
"""Override parameters. | ||
|
||
Enables a user to override any of the following parameters: | ||
residence_time, infiltration_threshold, infiltration_pct. | ||
|
||
Args: | ||
overrides (Dict[str, Any]): Dict describing which parameters should | ||
be overridden (keys) and new values (values). Defaults to {}. | ||
""" | ||
self.residence_time = overrides.pop("residence_time", | ||
self.residence_time) | ||
self.infiltration_threshold = overrides.pop("infiltration_threshold", | ||
self.infiltration_threshold) | ||
self.infiltration_pct = overrides.pop("infiltration_pct", | ||
self.infiltration_pct) | ||
super().apply_overrides(overrides) | ||
|
||
def distribute(self): | ||
"""Calculate outflow with residence time and send to Nodes or Rivers.""" | ||
avail = self.tank.get_avail()["volume"] / self.residence_time | ||
|
@@ -266,6 +307,20 @@ def __init__(self, timearea={0: 1}, data_input_dict={}, **kwargs): | |
initial_storage=self.initial_storage, | ||
) | ||
|
||
def apply_overrides(self, overrides = Dict[str, Any]): | ||
"""Override parameters. | ||
|
||
Enables a user to override any of the following parameters: | ||
timearea. | ||
|
||
Args: | ||
overrides (Dict[str, Any]): Dict describing which parameters should | ||
be overridden (keys) and new values (values). Defaults to {}. | ||
""" | ||
self.timearea = overrides.pop("timearea", | ||
self.timearea) | ||
super().apply_overrides(overrides) | ||
|
||
def push_set_timearea(self, vqip): | ||
"""Push setting that enables timearea behaviour, (see __init__ for | ||
description).Used to receive flow that is assumed to occur widely across some | ||
|
@@ -394,7 +449,6 @@ class River(Storage): | |
# TODO non-day timestep | ||
def __init__( | ||
self, | ||
depth=2, | ||
length=200, | ||
width=20, | ||
velocity=0.2 * constants.M_S_TO_M_DT, | ||
|
@@ -449,7 +503,6 @@ def __init__( | |
_Units_: m3/day | ||
""" | ||
# Set parameters | ||
self.depth = depth # [m] | ||
self.length = length # [m] | ||
self.width = width # [m] | ||
self.velocity = velocity # [m/dt] | ||
|
@@ -490,16 +543,6 @@ def __init__( | |
) | ||
self.muptNpar = 0.001 # [kg/m2/day] nitrogen macrophyte uptake rate | ||
self.muptPpar = 0.0001 # 0.01, # [kg/m2/day] phosphorus macrophyte uptake rate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see that these aren't used - but I guess they were used in CatchWat? Are we likely to need them again? If so, maybe just copy this excerpt into #2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably not as they are for the solids and we haven't decided which sedimentation-resuspension model we are going to integrate ... plus these parameters are not performing very well in previous case studies |
||
self.qbank_365_days = [1e6, 1e6] # [m3/day] store outflow in the previous year | ||
self.qbank = ( | ||
1e6 # [m3/day] bankfull flow = second largest outflow in the previous year | ||
) | ||
self.qbankcorrpar = 0.001 # [-] correction coefficient for qbank flow | ||
self.sedexppar = 1 # [-] | ||
self.EPC0 = 0.05 * constants.MG_L_TO_KG_M3 # [mg/l] | ||
self.kd_s = 0 * constants.MG_L_TO_KG_M3 # 6 * 1e-6, # [kg/m3] | ||
self.kadsdes_s = 2 # 0.9, # [-] | ||
self.Dsed = 0.2 # [m] | ||
|
||
self.max_temp_lag = 20 | ||
self.lagged_temperatures = [] | ||
|
@@ -550,7 +593,62 @@ def __init__( | |
# self.v_change_vqip(vqip_, min(vqip_['volume'], | ||
# self.get_dt_excess()['volume'])) _ = self.tank.push_storage(vqip_, force=True) | ||
# return self.extract_vqip(vqip, vqip_) | ||
|
||
|
||
def apply_overrides(self, overrides = Dict[str, Any]): | ||
"""Override parameters. | ||
|
||
Enables a user to override any of the following parameters: | ||
timearea. | ||
|
||
Args: | ||
overrides (Dict[str, Any]): Dict describing which parameters should | ||
be overridden (keys) and new values (values). Defaults to {}. | ||
""" | ||
self.length = overrides.pop("length", | ||
self.length) | ||
self.width = overrides.pop("width", | ||
self.width) | ||
self.velocity = overrides.pop("velocity", | ||
self.velocity) | ||
self.damp = overrides.pop("damp", | ||
self.damp) | ||
self.mrf = overrides.pop("mrf", | ||
self.mrf) | ||
self.uptake_PNratio = overrides.pop("uptake_PNratio", | ||
self.uptake_PNratio) | ||
self.bulk_density = overrides.pop("bulk_density", | ||
self.bulk_density) | ||
self.denpar_w = overrides.pop("denpar_w", | ||
self.denpar_w) | ||
self.T_wdays = overrides.pop("T_wdays", | ||
self.T_wdays) | ||
self.halfsatINwater = overrides.pop("halfsatINwater", | ||
self.halfsatINwater) | ||
self.hsatTP = overrides.pop("hsatTP", | ||
self.hsatTP) | ||
self.limpppar = overrides.pop("limpppar", | ||
self.limpppar) | ||
self.prodNpar = overrides.pop("prodNpar", | ||
self.prodNpar) | ||
self.prodPpar = overrides.pop("prodPpar", | ||
self.prodPpar) | ||
self.muptNpar = overrides.pop("muptNpar", | ||
self.muptNpar) | ||
self.muptPpar = overrides.pop("muptPpar", | ||
self.muptPpar) | ||
self.max_temp_lag = overrides.pop("max_temp_lag", | ||
self.max_temp_lag) | ||
self.max_phosphorus_lag = overrides.pop("max_phosphorus_lag", | ||
self.max_phosphorus_lag) | ||
liuly12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if 'area' in overrides.keys(): | ||
print('ERROR: specifying area is depreciated in overrides for river, please specify length and width instead') | ||
overrides['area'] = self.length * self.width | ||
if 'capacity' in overrides.keys(): | ||
print('ERROR: specifying capacity is depreciated in overrides for river, it is always set as unbounded capacity') | ||
overrides['capacity'] = constants.UNBOUNDED_CAPACITY | ||
super().apply_overrides(overrides) | ||
|
||
def pull_check_river(self, vqip=None): | ||
"""Check amount of water that can be pulled from river tank and upstream. | ||
|
||
|
@@ -936,6 +1034,20 @@ def __init__(self, environmental_flow=0, **kwargs): | |
|
||
self.__class__.__name__ = "Reservoir" | ||
|
||
def apply_overrides(self, overrides = Dict[str, Any]): | ||
"""Override parameters. | ||
|
||
Enables a user to override any of the following parameters: | ||
environmental_flow. | ||
|
||
Args: | ||
overrides (Dict[str, Any]): Dict describing which parameters should | ||
be overridden (keys) and new values (values). Defaults to {}. | ||
""" | ||
self.environmental_flow = overrides.pop("environmental_flow", | ||
self.environmental_flow) | ||
super().apply_overrides(overrides) | ||
|
||
def push_set_river_reservoir(self, vqip): | ||
"""Receive water. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's a great idea to remove arguments. As there will be many
config
files that specifydepth
forRiver
nodes, and these will crash. Instead I would suggest to allowdepth
as an argument and have something like the following:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added - see commit 07e196b