From bab5f890101efaba0c957bdbdc20c0ea5e3fcce8 Mon Sep 17 00:00:00 2001 From: Assela Pathirana Date: Wed, 6 Apr 2022 12:35:02 +0200 Subject: [PATCH 1/3] updated keywords in inp_sections.yml --- swmmio/defs/inp_sections.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/swmmio/defs/inp_sections.yml b/swmmio/defs/inp_sections.yml index f3ff63e..ea62913 100644 --- a/swmmio/defs/inp_sections.yml +++ b/swmmio/defs/inp_sections.yml @@ -1,10 +1,10 @@ infiltration_cols: - CURVE_NUMBER: [CurveNum, Conductivity (depreciated), DryTime] - GREEN_AMPT: [Subcatchment, Suction, HydCon, IMDmax] - HORTON: [Subcatchment, MaxRate, MinRate, Decay, DryTime, MaxInfil] - MODIFIED_GREEN_AMPT: [Subcatchment, Suction, Ksat, IMD] - MODIFIED_HORTON: [Subcatchment, MaxRate, MinRate, Decay, DryTime, MaxInfil] + CURVE_NUMBER: [Param1, Param2, Param3, Param4, Param5] + GREEN_AMPT: [Param1, Param2, Param3, Param4, Param5] + HORTON: [Param1, Param2, Param3, Param4, Param5] + MODIFIED_GREEN_AMPT: [Param1, Param2, Param3, Param4, Param5] + MODIFIED_HORTON: [Param1, Param2, Param3, Param4, Param5] inp_file_objects: TITLE: @@ -32,7 +32,7 @@ inp_file_objects: - Flap Gate - SeepageRate CONDUITS: [Name, InletNode, OutletNode, Length, Roughness, InOffset, OutOffset, InitFlow, MaxFlow] - INFILTRATION: [Subcatchment, Suction, HydCon, IMDmax] + INFILTRATION: [Subcatchment, Param1, Param2, Param3, Param4, Param5] JUNCTIONS: [Name, InvertElev, MaxDepth, InitDepth, SurchargeDepth, PondedArea] DWF: columns: [Node, Parameter, AverageValue, TimePatterns] @@ -48,7 +48,7 @@ inp_file_objects: SUBAREAS: [Name, N-Imperv, N-Perv, S-Imperv, S-Perv, PctZero, RouteTo, PctRouted] WEIRS: [Name, InletNode, OutletNode, WeirType, CrestHeight, DischCoeff, FlapGate, EndCon, EndCoeff, Surcharge, RoadWidth, RoadSurf] - XSECTIONS: [Link, Shape, Geom1, Geom2, Geom3, Geom4, Barrels, XX] + XSECTIONS: [Link, Shape, Geom1, Geom2, Geom3, Geom4, Barrels, Culvert] INFLOWS: [Node, Constituent, Time Series, Type, Mfactor, Sfactor, Baseline, Pattern] TIMESERIES: [Name, Date, Time, Value] From 279621f99465d1d0dc0a7ac61e3fa6f8436f42df Mon Sep 17 00:00:00 2001 From: Assela Pathirana Date: Fri, 8 Apr 2022 15:50:42 +0200 Subject: [PATCH 2/3] LID_USAGE added --- swmmio/core.py | 19 ++++++++++++++++++- swmmio/defs/inp_sections.yml | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/swmmio/core.py b/swmmio/core.py index 4f0abe9..0b4d3ae 100644 --- a/swmmio/core.py +++ b/swmmio/core.py @@ -484,6 +484,7 @@ def __init__(self, file_path): self._files_df = None self._conduits_df = None self._xsections_df = None + self._lid_usage_df = None self._pumps_df = None self._orifices_df = None self._weirs_df = None @@ -522,7 +523,8 @@ def __init__(self, file_path): '[COORDINATES]', '[INFLOWS]', '[Polygons]', - '[TIMESERIES]' + '[TIMESERIES]', + '[LID_USAGE]' ] def save(self, target_path=None): @@ -686,6 +688,21 @@ 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 + + @lid_usage.setter + def lid_usage(self, df): + """Set inp.lid_usage DataFrame.""" + self._lid_usage_df = df + @property def pumps(self): """ diff --git a/swmmio/defs/inp_sections.yml b/swmmio/defs/inp_sections.yml index ea62913..fd084dd 100644 --- a/swmmio/defs/inp_sections.yml +++ b/swmmio/defs/inp_sections.yml @@ -50,6 +50,7 @@ inp_file_objects: Surcharge, RoadWidth, RoadSurf] XSECTIONS: [Link, Shape, Geom1, Geom2, Geom3, Geom4, Barrels, Culvert] 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] From f8d836e0b87a0bea4c62cdf52220a71244626443 Mon Sep 17 00:00:00 2001 From: Assela Pathirana Date: Mon, 18 Apr 2022 20:14:03 +0200 Subject: [PATCH 3/3] some fixes --- swmmio/core.py | 34 +++++++++++++++++++++++++++++++--- swmmio/defs/inp_sections.yml | 2 +- swmmio/utils/text.py | 13 +++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/swmmio/core.py b/swmmio/core.py index 0b4d3ae..b0a9e9f 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) @@ -471,6 +472,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'))) @@ -501,6 +516,7 @@ def __init__(self, file_path): self._inflows_df = None self._curves_df = None self._timeseries_df = None + self._raingages_df = None SWMMIOFile.__init__(self, file_path) # run the superclass init @@ -524,7 +540,8 @@ def __init__(self, file_path): '[INFLOWS]', '[Polygons]', '[TIMESERIES]', - '[LID_USAGE]' + '[LID_USAGE]', + '[RAINGAGES]' ] def save(self, target_path=None): @@ -541,12 +558,13 @@ def save(self, target_path=None): from swmmio.utils.modify_model import replace_inp_section import shutil target_path = target_path if target_path is not None else self.path - - shutil.copyfile(self.path, target_path) + if not self.path==target_path: + shutil.copyfile(self.path, target_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) @@ -698,6 +716,16 @@ def lid_usage(self): 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.""" diff --git a/swmmio/defs/inp_sections.yml b/swmmio/defs/inp_sections.yml index fd084dd..9df5842 100644 --- a/swmmio/defs/inp_sections.yml +++ b/swmmio/defs/inp_sections.yml @@ -66,7 +66,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 22cd16e..a2093ff 100644 --- a/swmmio/utils/text.py +++ b/swmmio/utils/text.py @@ -122,6 +122,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