From 97e9db269c00598956fdc54d4b8ab393b590f225 Mon Sep 17 00:00:00 2001 From: everett Date: Mon, 30 Oct 2023 14:19:21 -0700 Subject: [PATCH 1/2] Added model summary property and rpt_warnings function --- swmmio/core.py | 25 +++++++++++++++++++++++++ swmmio/utils/functions.py | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/swmmio/core.py b/swmmio/core.py index 6e9081b..e27cb62 100644 --- a/swmmio/core.py +++ b/swmmio/core.py @@ -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): """ @@ -171,6 +172,24 @@ 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 ERRORS 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 + return warnings + def conduits(self): """ @@ -446,6 +465,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" diff --git a/swmmio/utils/functions.py b/swmmio/utils/functions.py index c44fae8..f679fd8 100644 --- a/swmmio/utils/functions.py +++ b/swmmio/utils/functions.py @@ -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 \ No newline at end of file From 9f7e424a06a21562f04a81d51dca32569b368101 Mon Sep 17 00:00:00 2001 From: everett Date: Mon, 30 Oct 2023 15:03:32 -0700 Subject: [PATCH 2/2] Minor changes to rpt warnings function --- swmmio/core.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swmmio/core.py b/swmmio/core.py index e27cb62..f0f8aa0 100644 --- a/swmmio/core.py +++ b/swmmio/core.py @@ -179,7 +179,7 @@ def rpt_warnings(self, verbose=False): """ # first, make sure the rpt is valid if self.rpt_is_valid(verbose=verbose): - # check if the rpt has ERRORS output from SWMM + # check if the rpt has WARNINGS output from SWMM warnings = list() with open(self.rpt.path) as f: for line in f: @@ -188,7 +188,9 @@ def rpt_warnings(self, verbose=False): warnings.append(line[:-1]) elif '****************' in line: break - return warnings + else: + warnings = 'RPT file is not valid' + return warnings def conduits(self):