Skip to content

Commit

Permalink
Add ability to input single demand from giw/dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Angus committed Sep 26, 2024
1 parent eeb16c3 commit 6f13005
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion wntr/network/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def to_dict(self):
d['node_type'] = self.node_type
for k in dir(self):
if not k.startswith('_') and \
k not in ['demand', 'base_demand', 'head', 'leak_area', 'leak_demand',
k not in ['demand', 'head', 'leak_area', 'leak_demand',
'leak_discharge_coeff', 'leak_status', 'level', 'pressure', 'quality', 'vol_curve', 'head_timeseries']:
try:
val = getattr(self, k)
Expand Down
31 changes: 30 additions & 1 deletion wntr/network/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class Junction(Node):
_base_attributes = ["name",
"elevation",
"coordinates"]
_optional_attributes = ["emitter_coefficient",
_optional_attributes = ["base_demand",
"demand_pattern",
"demand_category",
"emitter_coefficient",
"initial_quality",
"minimum_pressure",
"required_pressure",
Expand Down Expand Up @@ -216,6 +219,32 @@ def base_demand(self):
def base_demand(self, value):
raise RuntimeWarning('The base_demand property is read-only. Please modify using demand_timeseries_list[0].base_value.')

@property
def demand_pattern(self):
"""Get the pattern_name of the first demand in the demand_timeseries_list.
This is a read-only property.
"""
if len(self.demand_timeseries_list) > 0:
return self.demand_timeseries_list[0].pattern_name
return 0.0
@demand_pattern.setter
def demand_pattern(self, value):
raise RuntimeWarning('The demand_pattern property is read-only. Please modify using demand_timeseries_list[0].pattern_name')

@property
def demand_category(self):
"""Get the category of the first demand in the demand_timeseries_list.
This is a read-only property.
"""
if len(self.demand_timeseries_list) > 0:
return self.demand_timeseries_list[0].category
return 0.0
@demand_category.setter
def demand_category(self, value):
raise RuntimeWarning('The demand_category property is read-only. Please modify using demand_timeseries_list[0].category.')

def add_leak(self, wn, area, discharge_coeff=0.75, start_time=None, end_time=None):
"""
Add a leak control to the water network model
Expand Down
10 changes: 5 additions & 5 deletions wntr/network/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ def from_dict(d: dict, append=None):
if dl is not None and len(dl) > 0:
base_demand = dl[0].setdefault("base_val", 0.0)
pattern_name = dl[0].setdefault("pattern_name")
category = dl[0].setdefault("category")
demand_category = dl[0].setdefault("category")
else:
base_demand = 0.0
pattern_name = None
category = None
base_demand = node.setdefault('base_demand',0.0)
pattern_name = node.setdefault('pattern_name')
demand_category = node.setdefault('demand_category')
wn.add_junction(
name=name,
base_demand=base_demand,
demand_pattern=pattern_name,
elevation=node.setdefault("elevation"),
coordinates=node.setdefault("coordinates", list()),
demand_category=category,
demand_category=demand_category,
)
j = wn.get_node(name)
j.emitter_coefficient = node.setdefault("emitter_coefficient")
Expand Down

0 comments on commit 6f13005

Please sign in to comment.