diff --git a/swmmio/core.py b/swmmio/core.py index 23acc97..0e81f3b 100644 --- a/swmmio/core.py +++ b/swmmio/core.py @@ -19,6 +19,7 @@ from swmmio.utils.functions import trim_section_to_nodes from swmmio.utils.text import get_inp_sections_details, get_rpt_sections_details, get_rpt_metadata +import swmmio.utils.text pd.set_option('display.max_columns', 5) @@ -498,6 +499,20 @@ def headers(self): return self._rpt_section_details + @property + def external_outflow_volume(self): + """ + Return the external outflow from rpt file in mm or inches + """ + return float(swmmio.utils.text.get_rpt_value(self.path, "External Outflow")) + + @property + def flooding_loss_volume(self): + """ + Return the flooding loss from rpt file in mm or inches + """ + return float(swmmio.utils.text.get_rpt_value(self.path, "Flooding Loss")) + # setattr(rpt, 'link_flow_summary', property(get_rpt_df('Link Flow Summary'))) @@ -515,6 +530,7 @@ def __init__(self, file_path): self._report_df = None self._conduits_df = None self._xsections_df = None + self._lid_usage_df = None self._pollutants_df = None self._landuses_df = None self._buildup_df = None @@ -586,6 +602,7 @@ def __init__(self, file_path): '[INFLOWS]', '[Polygons]', '[TIMESERIES]', + '[LID_USAGE]', '[TAGS]', '[STREETS]', '[INLETS]', @@ -611,10 +628,12 @@ def save(self, target_path=None): else: target_path = self.path + for section in self._sections: # reformate the [SECTION] to section (and _section_df) sect_id = section.translate({ord(i): None for i in '[]'}).lower() sect_id_private = '_{}_df'.format(sect_id) + #print(sect_id_private) data = getattr(self, sect_id_private) if data is not None: replace_inp_section(target_path, section, data) @@ -857,6 +876,31 @@ def xsections(self, df): """Set inp.xsections DataFrame.""" self._xsections_df = df + + @property + def lid_usage(self): + """ + Get/set LID_USAGE section of the INP file. + """ + if self._lid_usage_df is None: + self._lid_usage_df = dataframe_from_inp(self.path, "[LID_USAGE]") + return self._lid_usage_df + + @property + def raingages(self): + """ + Get/set RAINGAGES section of the INP file. + """ + if self._raingages_df is None: + self._raingages_df = dataframe_from_inp(self.path, "[RAINGAGES]") + return self._raingages_df + + + @lid_usage.setter + def lid_usage(self, df): + """Set inp.lid_usage DataFrame.""" + self._lid_usage_df = df + @property def pollutants(self): """ diff --git a/swmmio/defs/inp_sections.yml b/swmmio/defs/inp_sections.yml index d719159..02f858a 100644 --- a/swmmio/defs/inp_sections.yml +++ b/swmmio/defs/inp_sections.yml @@ -63,7 +63,9 @@ inp_file_objects: XSECTIONS: [Link, Shape, Geom1, Geom2, Geom3, Geom4, Barrels, XX] POLLUTANTS: [Name, MassUnits, RainConcen, GWConcen, I&IConcen, DecayCoeff, SnowOnly, CoPollutName, CoPollutFraction, DWFConcen, InitConcen] + INFLOWS: [Node, Constituent, Time Series, Type, Mfactor, Sfactor, Baseline, Pattern] + LID_USAGE: [Subcatchment, 'LID_Process', Number, Area, Width, InitSat, FromImp, ToPerv, RptFile, DrainTo, FromPerv,] TIMESERIES: [Name, Date, Time, Value] COORDINATES: [Name, X, Y] @@ -82,7 +84,7 @@ inp_file_objects: inp_section_tags: - ['[TITLE', '[OPTION', '[FILE', '[RAINGAGE', '[TEMPERATURE', '[EVAP', + ['[TITLE', '[OPTION', '[FILE', '[RAINGAGES', '[TEMPERATURE', '[EVAP', '[SUBCATCHMENT', '[SUBAREA', '[INFIL', '[AQUIFER', '[GROUNDWATER', '[SNOWPACK', '[JUNC', '[OUTFALL', '[STORAGE', '[DIVIDER', '[CONDUIT', '[PUMP', '[ORIFICE', '[WEIR', '[OUTLET', '[XSECT', '[TRANSECT', '[LOSS', '[CONTROL', '[POLLUT', '[LANDUSE', '[BUILDUP', diff --git a/swmmio/utils/text.py b/swmmio/utils/text.py index 470441b..d64bd2d 100644 --- a/swmmio/utils/text.py +++ b/swmmio/utils/text.py @@ -137,6 +137,19 @@ def extract_section_of_file(file_path, start_strings, end_strings, comment=';', return out_string +def get_rpt_value(file_path, value_type): + """ + scan rpt file and find the line starting with value_type and return the last numeric value + + """ + + with open(file_path,"r") as fi: + for ln in fi: + if ln.strip().startswith(value_type): + #print(ln) + return ln.split()[-1] + return None + def get_rpt_metadata(file_path): """ Scan rpt file and extract meta data