Skip to content

Commit

Permalink
Merge pull request #208 from everettsp/dev
Browse files Browse the repository at this point in the history
Model summary property and RPT warning function (#154)
  • Loading branch information
aerispaha authored Nov 22, 2023
2 parents 86eaadd + 9f7e424 commit 0c52df7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions swmmio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def __init__(self, in_file_path, crs=None, include_rpt=True):
self._links_df = None
self._subcatchments_df = None
self._network = None
self._summary = None

def rpt_is_valid(self, verbose=False):
"""
Expand Down Expand Up @@ -171,6 +172,26 @@ def rpt_is_valid(self, verbose=False):
return False
else:
return True

def rpt_warnings(self, verbose=False):
"""
Return warning messages from the rpt file
"""
# first, make sure the rpt is valid
if self.rpt_is_valid(verbose=verbose):
# check if the rpt has WARNINGS output from SWMM
warnings = list()
with open(self.rpt.path) as f:
for line in f:
spl = line.split()
if len(spl) > 0 and spl[0] == 'WARNING':
warnings.append(line[:-1])
elif '****************' in line:
break
else:
warnings = 'RPT file is not valid'
return warnings


def conduits(self):
"""
Expand Down Expand Up @@ -446,6 +467,12 @@ def export_to_shapefile(self, shpdir, prj=None):
nodes_path = os.path.join(shpdir, self.inp.name + '_nodes.shp')
spatial.write_shapefile(nodes, nodes_path, geomtype='point', prj=prj)

@property
def summary(self):
if self._summary is None:
model_summary = functions.summarize_model(self)
self._summary = model_summary
return self._summary

class SWMMIOFile(object):
defaultSection = "Link Flow Summary"
Expand Down
22 changes: 22 additions & 0 deletions swmmio/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,25 @@ def find_network_trace(model, start_node, end_node,
raise error.NoTraceFound

return path_selection

def summarize_model(model):
model_summary = dict()

# numbers of elements
model_summary['num_subcatchments'] = len(model.inp.subcatchments)
model_summary['num_conduits'] = len(model.inp.conduits)
model_summary['num_junctions'] = len(model.inp.junctions)
model_summary['num_outfalls'] = len(model.inp.outfalls)
model_summary['num_raingages'] = len(model.inp.raingages)

# calculated values - only calculate if elements exist
if len(model.inp.subcatchments) != 0:
model_summary['catchment_area'] = model.inp.subcatchments.Area.sum()
model_summary['mean_subcatchment_slope'] = ((model.inp.subcatchments.Area / model.inp.subcatchments.Area.sum()) * model.inp.subcatchments.PercSlope).sum()

if len(model.inp.conduits) != 0:
model_summary['total_conduit_length'] = model.inp.conduits.Length.sum()

if len(model.nodes.dataframe) != 0:
model_summary['invert_range'] = model.nodes().InvertElev.max() - model.nodes().InvertElev.min()
return model_summary

0 comments on commit 0c52df7

Please sign in to comment.