diff --git a/swmmio/core.py b/swmmio/core.py index 6e9081b..f0f8aa0 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,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): """ @@ -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" 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