-
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
provide read/write interface to all INP sections #57
Comments
Hi, def _add_coords(self, subcatchment_id):
exist = [
(self.model.inp.polygons["X"][-1], self.model.inp.polygons["Y"][-1]),
(self.model.inp.polygons["X"][-2], self.model.inp.polygons["Y"][-2]),
(self.model.inp.polygons["X"][-3], self.model.inp.polygons["Y"][-3]),
(self.model.inp.polygons["X"][-4], self.model.inp.polygons["Y"][-4]),
]
coords = pd.DataFrame(
data={
"X": [exist[0][0], exist[1][0], exist[2][0], exist[3][0]],
"Y": [exist[0][1] - 5, exist[1][1] - 5, exist[2][1] - 5, exist[3][1] - 5],
},
index=[subcatchment_id for _ in range(4)]
)
coords.index.names = ['Name']
self.model.inp.polygons = pd.concat([self.model.inp.polygons, coords])
replace_inp_section(self.model.inp.path, "[Polygons]", self.model.inp.polygons) I see that SWMM writes literally "Polygons" in the *inp file, swmmio modifies this name by writing "POLYGONS". Here is the section I have in the file before executing the code [Polygons]
;;Subcatchment X-Coord Y-Coord
;;-------------- ------------------ ------------------
S1 777180.000 592590.000
S1 777180.000 592585.000
S1 777175.000 592585.000
S1 777175.000 592590.000 This is what the section looks like after the first execution of "replace_inp_section" [POLYGONS]
;; X Y
S1 777180.0 592590.0
S1 777180.0 592585.0
S1 777175.0 592585.0
S1 777175.0 592590.0
S2 777175.0 592585.0
S2 777175.0 592580.0
S2 777180.0 592580.0
S2 777180.0 592585.0 This is what the sections looks like after the second execution of "replace_inp_section" [POLYGONS]
;; X Y
S1 777180.0 592590.0
S1 777180.0 592585.0
S1 777175.0 592585.0
S1 777175.0 592590.0
S2 777175.0 592585.0
S2 777175.0 592580.0
S2 777180.0 592580.0
S2 777180.0 592585.0
[POLYGONS]
;; X Y
S1 777180.0 592590.0
S1 777180.0 592585.0
S1 777175.0 592585.0
S1 777175.0 592590.0
S2 777175.0 592585.0
S2 777175.0 592580.0
S2 777180.0 592580.0
S2 777180.0 592585.0
S3 777180.0 592580.0
S3 777180.0 592575.0
S3 777175.0 592575.0
S3 777175.0 592580.0 In the code I execute I always use "[Polygons]", after the second execution of "replace_inp_section" the sections are duplicated. If I should post this thread in discussions I apologize and please delete. |
@BuczynskiRafal this is very interesting - I suspect that you've uncovered a bug. That said, I think we should continue this conversation in a new issue. Do you mind creating an issue and restating what you've described above? If you've found a solution already (e.g. by changing the header to [POLYGONS]), please feel free to submit a pull request with your proposed changes. Thanks for finding and documenting this issue so clearly! |
I have created a separate issue, at my spare time I will prepare a PR in which I will propose a solution. |
One hurdle in providing coverage for the rest of the INP sections is a lack of example models that can be used for testing. Others are probably aware of this, but I recently realized we can use some of GitHub's fancier search features to find examples of SWMM model INP files with some of these less-commonly-used sections. For example, we can find some INPs that use the TREATMENT section with a search query like this: |
The NCIMM-Black-White-Box repo also seems to be an excellent resource for sample SWMM models and data files. There are also some particularly big models in there that would be nice to use for documentation and examples. For example, here is a plot of the 10070_H_Elements.inp model: m = swmmio.Model('10070_H_Elements.inp')
m.links.geodataframe.plot('Geom1', linewidth=m.links.dataframe['Geom1']*0.5, capstyle='round', figsize=(10,10)) |
Summary
All INP sections that follow the common tabular structure with unique indices as the first column can be read via the
swmmio.utils.create_dataframeINP
function. However, only a limited number of these sections have been added as properties in the higher-levelswmmio.core.inp
object.Add coverage for read/writing all INP sections from the
swmmio.core.inp
object. INP sections are defined currently as properties with setter/getters in theswmmio.core
module here. List of INP sections described here in the OWA SWMM repo.INP Sections to Cover
The text was updated successfully, but these errors were encountered: