Skip to content

Commit

Permalink
Merge pull request #170 from aerispaha/feat/57
Browse files Browse the repository at this point in the history
Add INP sections to model.inp properties
  • Loading branch information
aerispaha authored Dec 29, 2022
2 parents e7c8441 + 683a6c6 commit 07df723
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 2 deletions.
270 changes: 270 additions & 0 deletions swmmio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,17 @@ class inp(SWMMIOFile):
def __init__(self, file_path):
self._options_df = None
self._files_df = None
self._raingages_df = None
self._evaporation_df = None
self._report_df = None
self._conduits_df = None
self._xsections_df = None
self._pollutants_df = None
self._landuses_df = None
self._buildup_df = None
self._washoff_df = None
self._coverages_df = None
self._loadings_df = None
self._pumps_df = None
self._orifices_df = None
self._weirs_df = None
Expand All @@ -515,6 +523,8 @@ def __init__(self, file_path):
self._storage_df = None
self._coordinates_df = None
self._dwf_df = None
self._rdii_df = None
self._hydrographs_df = None
self._vertices_df = None
self._polygons_df = None
self._subcatchments_df = None
Expand All @@ -530,9 +540,17 @@ def __init__(self, file_path):
self._sections = [
'[OPTIONS]',
'[FILES]',
'[RAINGAGES]',
'[EVAPORATION]',
'[REPORT]',
'[CONDUITS]',
'[XSECTIONS]',
'[POLLUTANTS]',
'[LANDUSES]',
'[BUILDUP]',
'[WASHOFF]',
'[COVERAGES]',
'[LOADINGS]',
'[PUMPS]',
'[ORIFICES]',
'[WEIRS]',
Expand All @@ -546,6 +564,8 @@ def __init__(self, file_path):
'[CURVES]',
'[COORDINATES]',
'[DWF]',
'[RDII]',
'[HYDROGRAPHS]',
'[INFLOWS]',
'[Polygons]',
'[TIMESERIES]'
Expand Down Expand Up @@ -667,6 +687,57 @@ def files(self, df):
first_col = df.columns[0]
self._files_df = df.set_index(first_col)

@property
def raingages(self):
"""
get/set raingages section of model
:return: dataframe of raingages in the model
Examples:
>>> from swmmio.examples import philly
>>> philly.inp.raingages #doctest: +NORMALIZE_WHITESPACE
RainType TimeIntrvl SnowCatch DataSource DataSourceName
Name
RG1 INTENSITY 1:00 1.0 TIMESERIES design-storm
"""
if self._raingages_df is not None:
return self._raingages_df
self._raingages_df = dataframe_from_inp(self.path, 'raingages')
return self._raingages_df

@raingages.setter
def raingages(self, df):
"""Set inp.raingages DataFrame."""
self._raingages_df = df

@property
def evaporation(self):
"""
get/set evaporation section of model
:return: dataframe of evaporation section in inp file
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.evaporation #doctest: +NORMALIZE_WHITESPACE
Value
Key
CONSTANT 0.0
DRY_ONLY NO
"""
if self._evaporation_df is not None:
return self._evaporation_df
self._evaporation_df = dataframe_from_inp(self.path, 'evaporation')
return self._evaporation_df

@evaporation.setter
def evaporation(self, df):
"""Set inp.evaporation DataFrame."""
self._evaporation_df = df

@property
def report(self):
"""
Expand Down Expand Up @@ -741,6 +812,159 @@ def xsections(self, df):
"""Set inp.xsections DataFrame."""
self._xsections_df = df

@property
def pollutants(self):
"""
get/set pollutants section of model
:return: dataframe of pollutants section in inp file
Examples:
The `walnut` example model contains two entries in the POLLUTANTS section, one
of which is TSS. Below we show how to retrieve this information, by accessing the
`TSS` index of the pollutants dataframe:
>>> from swmmio.examples import walnut
>>> walnut.inp.pollutants.loc['TSS'] #doctest: +NORMALIZE_WHITESPACE
MassUnits MG/L
RainConcen 0.0
GWConcen 0.0
I&IConcen 0
DecayCoeff 0.0
SnowOnly NO
CoPollutName *
CoPollutFraction 0.0
DWFConcen 0
InitConcen 0
Name: TSS, dtype: object
"""
if self._pollutants_df is not None:
return self._pollutants_df
self._pollutants_df = dataframe_from_inp(self.path, 'pollutants')
return self._pollutants_df

@pollutants.setter
def pollutants(self, df):
"""Set inp.pollutants DataFrame."""
self._pollutants_df = df

@property
def landuses(self):
"""
Get/set landuses section of the INP file.
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.landuses #doctest: +NORMALIZE_WHITESPACE
CleaningInterval FractionAvailable LastCleaned
Name
Residential 0 0 0
Undeveloped 0 0 0
"""
if self._landuses_df is None:
self._landuses_df = dataframe_from_inp(self.path, "LANDUSES")
return self._landuses_df

@landuses.setter
def landuses(self, df):
"""Set inp.landuses DataFrame."""
self._landuses_df = df

@property
def buildup(self):
"""
Get/set buildup section of the INP file.
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.buildup[['Pollutant', 'Function', 'Normalizer']] #doctest: +NORMALIZE_WHITESPACE
Pollutant Function Normalizer
LandUse
Residential Lead NONE AREA
Residential TSS SAT AREA
Undeveloped Lead NONE AREA
Undeveloped TSS SAT AREA
"""
if self._buildup_df is None:
self._buildup_df = dataframe_from_inp(self.path, "BUILDUP")
return self._buildup_df

@buildup.setter
def buildup(self, df):
"""Set inp.buildup DataFrame."""
self._buildup_df = df

@property
def washoff(self):
"""
Get/set washoff section of the INP file.
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.washoff[['Pollutant', 'Function']] #doctest: +NORMALIZE_WHITESPACE
Pollutant Function
LandUse
Residential Lead EMC
Residential TSS EXP
Undeveloped Lead EMC
Undeveloped TSS EXP
"""
if self._washoff_df is None:
self._washoff_df = dataframe_from_inp(self.path, "WASHOFF")
return self._washoff_df

@washoff.setter
def washoff(self, df):
"""Set inp.washoff DataFrame."""
self._washoff_df = df

@property
def coverages(self):
"""
Get/set coverages section of the INP file.
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.coverages #doctest: +NORMALIZE_WHITESPACE
LandUse Percent
Subcatchment
1 Residential 100.0
2 Residential 50.0
2 Undeveloped 50.0
3 Residential 100.0
4 Residential 50.0
4 Undeveloped 50.0
5 Residential 100.0
6 Undeveloped 100.0
7 Undeveloped 100.0
8 Undeveloped 100.0
"""
if self._coverages_df is None:
self._coverages_df = dataframe_from_inp(self.path, "coverages")
return self._coverages_df

@coverages.setter
def coverages(self, df):
"""Set inp.coverages DataFrame."""
self._coverages_df = df

@property
def loadings(self):
"""
Get/set loadings section of the INP file.
"""
if self._loadings_df is None:
self._loadings_df = dataframe_from_inp(self.path, "loadings")
return self._loadings_df

@loadings.setter
def loadings(self, df):
"""Set inp.loadings DataFrame."""
self._loadings_df = df

@property
def pumps(self):
"""
Expand Down Expand Up @@ -952,6 +1176,52 @@ def dwf(self, df):
"""Set inp.dwf DataFrame."""
self._dwf_df = df

@property
def rdii(self):
"""
Get/set RDII section of the INP file.
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.rdii #doctest: +NORMALIZE_WHITESPACE
UnitHydrograph SewerArea
Node
13 Hydrograph1 58.944186
14 Hydrograph1 58.944186
"""
if self._rdii_df is None:
self._rdii_df = dataframe_from_inp(self.path, "[RDII]")
return self._rdii_df

@rdii.setter
def rdii(self, df):
"""Set inp.rdii DataFrame."""
self._rdii_df = df

@property
def hydrographs(self):
"""
Get/set hydrographs section of the INP file.
Examples:
>>> from swmmio.examples import walnut
>>> walnut.inp.hydrographs #doctest: +NORMALIZE_WHITESPACE
RainGage/Month
Hydrograph
Hydrograph1 TS1
"""
if self._hydrographs_df is None:
self._hydrographs_df = dataframe_from_inp(self.path, "hydrographs")
return self._hydrographs_df

@hydrographs.setter
def hydrographs(self, df):
"""Set inp.hydrographs DataFrame."""
self._hydrographs_df = df


@property
def vertices(self):
"""
Expand Down
11 changes: 11 additions & 0 deletions swmmio/defs/inp_sections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ inp_file_objects:
columns: [Action, FileType, FileName]
RAINGAGES:
columns: [Name, RainType, TimeIntrvl, SnowCatch, DataSource, DataSourceName]
EVAPORATION:
keys: [Type, Parameters]
LOSSES:
# SeepageRage is new?
columns:
Expand All @@ -36,6 +38,13 @@ inp_file_objects:
JUNCTIONS: [Name, InvertElev, MaxDepth, InitDepth, SurchargeDepth, PondedArea]
DWF:
columns: [Node, Parameter, AverageValue, TimePatterns]
RDII: [Node, UnitHydrograph, SewerArea]
HYDROGRAPHS: [Hydrograph, RainGage/Month, Response, R, T, K, Dmax, Drecov, Dinit]
LANDUSES: [Name, CleaningInterval, FractionAvailable, LastCleaned]
BUILDUP: [LandUse, Pollutant, Function, Coeff1, Coeff2, Coeff3, Normalizer]
WASHOFF: [LandUse, Pollutant, Function, Coeff1, Coeff2, CleaningEffic, BMPEffic]
COVERAGES: [Subcatchment, LandUse, Percent]
LOADINGS: [Subcatchment, Pollutant, Loading]
ORIFICES:
columns: [Name, InletNode, OutletNode, OrificeType, CrestHeight, DischCoeff, FlapGate, OpenCloseTime]
OUTFALLS: [Name, InvertElev, OutfallType, StageOrTimeseries, TideGate, RouteTo]
Expand All @@ -49,6 +58,8 @@ inp_file_objects:
WEIRS: [Name, InletNode, OutletNode, WeirType, CrestHeight, DischCoeff, FlapGate, EndCon, EndCoeff,
Surcharge, RoadWidth, RoadSurf]
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]

TIMESERIES: [Name, Date, Time, Value]
Expand Down
5 changes: 3 additions & 2 deletions swmmio/examples.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from swmmio import Model
from swmmio.tests.data import MODEL_A_PATH
from swmmio.tests.data import MODEL_FULL_FEATURES_XY, MODEL_FULL_FEATURES__NET_PATH, MODEL_FULL_FEATURES_XY_B
from swmmio.tests.data import (MODEL_A_PATH, MODEL_EX_1, MODEL_FULL_FEATURES_XY,
MODEL_FULL_FEATURES__NET_PATH, MODEL_FULL_FEATURES_XY_B)

# example models
philly = Model(MODEL_A_PATH, crs="+init=EPSG:2817")
jersey = Model(MODEL_FULL_FEATURES_XY)
jerzey = Model(MODEL_FULL_FEATURES_XY_B)
spruce = Model(MODEL_FULL_FEATURES__NET_PATH)
walnut = Model(MODEL_EX_1)
12 changes: 12 additions & 0 deletions swmmio/tests/data/Example1.inp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ Residential TSS EXP 0.1 1 0 0
Undeveloped Lead EMC 0 0 0 0
Undeveloped TSS EXP 0.1 0.7 0 0

[HYDROGRAPHS]
;;Hydrograph Rain Gage/Month Response R T K Dmax Drecov Dinit
;;-------------- ---------------- -------- -------- -------- -------- -------- -------- --------
Hydrograph1 TS1


[RDII]
;;Node Unit Hydrograph Sewer Area
;;-------------- ---------------- ----------
13 Hydrograph1 58.944186
14 Hydrograph1 58.944186

[TIMESERIES]
;;Name Date Time Value
;;-------------- ---------- ---------- ----------
Expand Down

0 comments on commit 07df723

Please sign in to comment.