swmmio icon indicating copy to clipboard operation
swmmio copied to clipboard

Updates to support read/write of additional INP/RPT sections

Open kaklise opened this issue 1 year ago • 1 comments

The following PR adds support for the PATTERNS and CONTROLS sections of the INP file along with minor updates to support INFLOWS, XSECTIONS, and CURVES. The Pumping Summary was also added to the list of supported RPT sections.

I included a test that create a swmmio model, reassign each inp section to force the use of "replace_inp_section", save an INP file, and then uses that file to run SWMM. I ran this with a few swmmio models, INP files that come with SWMM, and some utility models I'm working with.

Thanks again for creating this great package! I'm happy to iterate on changes.

PATTERNS In core.py, I added a patterns property and setter, this reads the PATTERN section as a dataframe (using dataframe_from_inp) and then converts it to have 1 row per entry. Columns are named Factor*. The pattern is written to an INP file as a single row per entry. I did not test this with models that have a combination of patterns types (hourly, daily, etc.). Example patterns dataframe below.

        Type  Factor1  ...  Factor23  Factor24
Name                   ...                    
DWF   HOURLY   0.0121  ...   0.02789   0.02254

CONTROLS In core.py, I added a controls property and setter, this reads the CONTROLS section as a dataframe (using dataframe_from_inp) and then converts it to have 1 row per entry. The controI is written to an INP file as multiple lines separated using keywords IF, THEN, PRIORITY, AND, OR, ELSE (in utils.py). Example controls dataframe below.

                                                                   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 

INFLOWS In core.py, I replace "_!!!!_" with “” instead of NaN to keep the placeholder in the INP file

XSECTIONS In dataframes.py, I find the max number of tokens (column names) and name extras as “col”+i. This helps read in xsections that have a mixed number of entries.

CURVES In dataframes.py, I set index to just Name instead of (Name, Type)

RPT file sections In section_headers.yml, I added "Pumping Summary" and column names In dataframe_from_rpt, I added end_string “Analysis begun on” to read the final section

kaklise avatar Apr 11 '24 00:04 kaklise

@kaklise I added you to the @pyswmm/swmmio_external team which, I believe, will grant you the ability to run the github checks without one of us approving!

bemcdonnell avatar Apr 11 '24 15:04 bemcdonnell

@kaklise thank you for these great contributions! I'm in the process of reviewing this PR and will the rest of my comments prepared asap.

First, I want to do a bit of house keeping and connect this PR to existing issues. As as I understand it so far, this PR will

  • close #217 (I will add this to your PR description to trigger GitHub automation)
  • expand our coverage of INP sections by adding patterns and controls, making progress on #57
  • Presumably, this close #188

Please let me know if there are other issues that this PR may address that I missed.

Next, I think your idea to handle the PATTERNS and CONTROLS section by reformatting them to one row per entry is very clever. I would, however, like to have these new features tested. To that end, can you please provide an example INP file with patterns and controls sections that we can use for testing? With that INP file, I suggest that we create a new example model in swmmio.examples and leverage this in doc tests, like we do here:

https://github.com/pyswmm/swmmio/blob/24673b5f83e8f9c66cce9a0221f7947a3a9c232e/swmmio/core.py#L816-L829

This will provide some basic documentation like this, in addition to testing the source code.

Thanks again for contributing - I can't wait to release these new features 😄

aerispaha avatar Apr 13 '24 14:04 aerispaha

@aerispaha I added the Pump_Control_Model.inp from SWMM to swmmio.examples. The model includes patterns and controls. I also updated the documentation to illustrate the format. Let me know if additional updates are needed!

kaklise avatar Apr 19 '24 15:04 kaklise