-
Notifications
You must be signed in to change notification settings - Fork 43
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
Updates to support read/write of additional INP/RPT sections #219
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4b7be75
added patterns and controls to Model.inp
kaklise 9c91e65
Replace quotes for inflows
kaklise 64207c5
Find max number of tokens, resolves issue with xsection
kaklise 0049488
changed df index for curves
kaklise 020ca06
check to make sure rule name starts with RULE
kaklise 5241555
Added Pumping Summary to rpt sections and 'Analysis begun on' to read
kaklise f1ce68a
Merge branch 'inp_sections' of https://github.com/kaklise/swmmio into…
kaklise 080a9cb
Added minimal test for INP file read/write/run
kaklise 5df37ba
changed subprocess call to run_simple
kaklise 3398eca
Added pump control model and api docs for controls and patterns
kaklise 2dfd9e4
updated inp sections test to include additional models
kaklise 26a04b6
simplified output
kaklise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,6 +600,8 @@ def __init__(self, file_path): | |
self._streets_df = None | ||
self._inlets_df = None | ||
self._inlet_usage_df = None | ||
self._patterns_df = None | ||
self._controls_df = None | ||
|
||
SWMMIOFile.__init__(self, file_path) # run the superclass init | ||
|
||
|
@@ -644,6 +646,8 @@ def __init__(self, file_path): | |
'[STREETS]', | ||
'[INLETS]', | ||
'[INLET_USAGE]', | ||
'[PATTERNS]', | ||
'[CONTROLS]', | ||
] | ||
|
||
def save(self, target_path=None): | ||
|
@@ -1452,7 +1456,7 @@ def inflows(self): | |
if self._inflows_df is not None: | ||
return self._inflows_df | ||
inf = dataframe_from_inp(self.path, 'INFLOWS', quote_replace='_!!!!_') | ||
self._inflows_df = inf.replace('_!!!!_', np.nan) | ||
self._inflows_df = inf.replace('_!!!!_', '""') # revert quote replace | ||
return self._inflows_df | ||
|
||
@inflows.setter | ||
|
@@ -1508,6 +1512,98 @@ def timeseries(self, df): | |
"""Set inp.timeseries DataFrame.""" | ||
self._timeseries_df = df | ||
|
||
@property | ||
def patterns(self): | ||
""" | ||
Get/set patterns section of the model | ||
|
||
:return: dataframe of patterns | ||
|
||
>>> from swmmio.examples import pump_control | ||
>>> # NOTE, only the first 5 columns are shown in the following example | ||
>>> pump_control.inp.patterns.iloc[:,0:5] #doctest: +NORMALIZE_WHITESPACE | ||
Type Factor1 Factor2 Factor3 Factor4 | ||
Name | ||
DWF HOURLY 0.0151 0.01373 0.01812 0.01098 | ||
""" | ||
|
||
if self._patterns_df is not None: | ||
return self._patterns_df | ||
self._patterns_df = dataframe_from_inp(self.path, '[PATTERNS]') | ||
|
||
if self._patterns_df.shape[0] > 0: | ||
# reformat, 1 row per pattern | ||
pattern_entry_list = [] | ||
for name, pattern in self._patterns_df.groupby('Name'): | ||
pattern_entry = {} | ||
pattern_entry['Name'] = name | ||
pattern_entry['Type'] = pattern['Type'].iloc[0] | ||
if pattern.shape[0] > 1: | ||
# shift pattern values to the right | ||
pattern.iloc[1::, 1::] = pattern.iloc[1::, 0:-1].values | ||
pattern['Factors'] = pattern['Factors'].astype(float) | ||
values = pattern.iloc[:, 1:].values.flatten() | ||
for i in range(len(values)): | ||
pattern_entry['Factor'+str(i+1)] = values[i] | ||
pattern_entry_list.append(pattern_entry) | ||
|
||
self._patterns_df = pd.DataFrame(pattern_entry_list) | ||
self._patterns_df.set_index('Name', inplace=True) | ||
|
||
return self._patterns_df | ||
|
||
@patterns.setter | ||
def patterns(self, df): | ||
"""Set inp.patterns DataFrame.""" | ||
self._patterns_df = df | ||
|
||
@property | ||
def controls(self): | ||
""" | ||
Get/set controls section of the model | ||
|
||
:return: dataframe of controls | ||
|
||
>>> from swmmio.examples import pump_control | ||
>>> pump_control.inp.controls #doctest: +NORMALIZE_WHITESPACE | ||
Control | ||
Name | ||
RULE PUMP1A IF NODE SU1 DEPTH >= 4 THEN PUMP PUMP1 status = ON PRIORITY 1 | ||
RULE PUMP1B IF NODE SU1 DEPTH < 1 THEN PUMP PUMP1 status = OFF PRIORITY 1 | ||
""" | ||
|
||
if self._controls_df is None: | ||
self._controls_df = dataframe_from_inp(self.path, "[CONTROLS]") | ||
|
||
if self._controls_df.shape[0] > 0: | ||
# reformat, 1 row per control | ||
control_entry_list = [] | ||
control_entry = {} | ||
controls = self._controls_df['[CONTROLS]'] | ||
# make sure the first entry starts with RULE | ||
assert controls[0][0:5] == "RULE " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would best to raise an exception here if this assertion fails. But I'm fine with capturing that in a future PR. |
||
for row in controls: | ||
if row[0:5] == 'RULE ': # new control | ||
if len(control_entry) > 0: # add control to the list | ||
control_entry_list.append(control_entry) | ||
control_entry = {} | ||
control_entry['Name'] = row.rstrip() # remove white space | ||
control_entry['Control'] = '' | ||
else: | ||
control_entry['Control'] = control_entry['Control'] + row + ' ' | ||
if len(control_entry) > 0: # add last control to the list | ||
control_entry_list.append(control_entry) | ||
|
||
self._controls_df = pd.DataFrame(control_entry_list) | ||
self._controls_df.set_index('Name', inplace=True) | ||
|
||
return self._controls_df | ||
|
||
@controls.setter | ||
def controls(self, df): | ||
"""Set inp.controls DataFrame.""" | ||
self._controls_df = df | ||
|
||
@property | ||
def tags(self): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this - thanks for following our documentation pattern.