Skip to content

Commit

Permalink
Merge pull request #193 from asselapathirana/LID-USAGE
Browse files Browse the repository at this point in the history
Add coverage for the LID_USAGE section
  • Loading branch information
aerispaha authored May 15, 2023
2 parents adffe65 + 1fb5553 commit 24775ef
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
44 changes: 44 additions & 0 deletions swmmio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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')))

Expand All @@ -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
Expand Down Expand Up @@ -586,6 +602,7 @@ def __init__(self, file_path):
'[INFLOWS]',
'[Polygons]',
'[TIMESERIES]',
'[LID_USAGE]',
'[TAGS]',
'[STREETS]',
'[INLETS]',
Expand All @@ -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)
Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 3 additions & 1 deletion swmmio/defs/inp_sections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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',
Expand Down
13 changes: 13 additions & 0 deletions swmmio/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24775ef

Please sign in to comment.