Skip to content
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

Model summary property and RPT warning function (#154) #208

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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