Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage for the LID_USAGE section #193

Merged
merged 4 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool! It is making think, though, that we need to provide coverage for the whole Flow Routing Continuity section of the rpt file. What do you think?

If you agree, maybe we can tackle that in a separate issue.
Then we could extend that logic to provide coverage for the rest of the rpt sections that follow this structure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be handled in #194

"""
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this commented line?

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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raingages getter section is already defined above around line 731. Please remove this property.

"""
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,]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace this line with the following:

  LID_USAGE: [Subcatchment, LID_Process, Number, Area, Width, InitSat, FromImp, ToPerv, RptFile, DrainTo, FromPerv,]

This edit just removes the extra white space. Thanks!


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