swmmio.Model#

class swmmio.core.Model(in_file_path, crs=None, include_rpt=True)[source]#

Class representing a complete SWMM model incorporating its INP and RPT files and data

Initialize a swmmio.Model object by pointing it to a directory containing a single INP (and optionally an RPT file with matching filename) or by pointing it directly to an .inp file.

>>> # initialize a model object by passing the path to an INP file
>>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY
>>> m = Model(MODEL_FULL_FEATURES_XY)
>>> # access sections of inp via the Model.inp object
>>> m.inp.junctions 
      InvertElev  MaxDepth  InitDepth  SurchargeDepth  PondedArea
Name
J3         6.547        15          0               0           0
1         17.000         0          0               0           0
2         17.000         0          0               0           0
3         16.500         0          0               0           0
4         16.000         0          0               0           0
5         15.000         0          0               0           0
J2        13.000        15          0               0           0
>>> m.inp.coordinates 
                X            Y
Name
J3    2748073.306  1117746.087
1     2746913.127  1118559.809
2     2747728.148  1118449.164
3     2747242.131  1118656.381
4     2747345.325  1118499.807
5     2747386.555  1118362.817
J2    2747514.212  1118016.207
J4    2748515.571  1117763.466
J1    2747402.678  1118092.704

Access composite sections of the model that merge together sensible sections of the inp into one dataframe. The Model.links.dataframe section, for example, returns a dataframe containing PUMPS, CONDUITS, WEIRS, and ORIFICES joined with XSECTIONS, COORDINATES and the Link Flow Summary (if there is an rpt file found).

>>> m.links.dataframe[['InletNode', 'OutletNode', 'Length', 'Roughness', 'Geom1']] 
      InletNode OutletNode  Length  Roughness  Geom1
Name
C1:C2        J1         J2  244.63       0.01    1.0
C2.1         J2         J3  666.00       0.01    1.0
1:4           1          4  400.00       0.01    1.0
4:5           4          5  400.00       0.01    1.0
5:J1          5         J1  400.00       0.01    1.0
3:4           3          4  400.00       0.01    1.0
2:5           2          5  400.00       0.01    1.0
C3           J3         J4     NaN        NaN    5.0
C2           J2         J3     NaN        NaN    NaN
>>> # return all conduits (drop coords for clarity)
>>> from swmmio.examples import jersey
>>> jersey.nodes.dataframe[['InvertElev', 'MaxDepth', 'InitDepth', 'SurchargeDepth', 'PondedArea']] 
      InvertElev  MaxDepth  InitDepth  SurchargeDepth  PondedArea
Name
J3         6.547      15.0        0.0             0.0         0.0
1         17.000       0.0        0.0             0.0         0.0
2         17.000       0.0        0.0             0.0         0.0
3         16.500       0.0        0.0             0.0         0.0
4         16.000       0.0        0.0             0.0         0.0
5         15.000       0.0        0.0             0.0         0.0
J2        13.000      15.0        0.0             0.0         0.0
J4         0.000       NaN        NaN             NaN         NaN
J1        13.392       NaN        0.0             NaN         0.0
Attributes:
links

Create a DataFrame containing all link objects in the model including conduits, pumps, weirs, and orifices.

network

Networkx MultiDiGraph representation of the model

nodes

Collect all useful and available data related model nodes and organize in one dataframe.

orifices

collect all useful and available data related model orifices and

pumps

Collect all useful and available data related model pumps and organize in one dataframe.

subcatchments

Retrieve and organize data related to subcatchments into ModelSection object which provides pandas.DataFrame and GeoPandas.GeoDataFrame accessors.

summary

Summary statistics of the SWMM model.

weirs

collect all useful and available data related model weirs and

Methods

conduits()

collect all useful and available data related model conduits and organize in one dataframe.

export_to_shapefile(shpdir[, prj])

export the model data into a shapefile.

rpt_is_valid([verbose])

Return true if the .rpt file exists and has a revision date more recent than the .inp file.

rpt_warnings([verbose])

Return warning messages from the rpt file

to_crs(*args, **kwargs)

Convert coordinate reference system of the model coordinates

to_geojson([target_path])

Return a GeoJSON representation of the entire model :param target_path: target path of geojson (optional) :return: GeoJSON representation of model

conduits()[source]#

collect all useful and available data related model conduits and organize in one dataframe.

export_to_shapefile(shpdir, prj=None)[source]#

export the model data into a shapefile. element_type dictates which type of data will be included.

default projection is PA State Plane - untested on other cases

Create a DataFrame containing all link objects in the model including conduits, pumps, weirs, and orifices.

Returns:

dataframe containing all link objects in the model

Return type:

pd.DataFrame

Examples

>>> from swmmio.examples import philly
>>> philly.links.dataframe.loc['J1-025.1']  
InletNode                                                       J1-025
OutletNode                                                      J1-026
Length                                                      309.456216
Roughness                                                        0.014
InOffset                                                             0
OutOffset                                                          0.0
InitFlow                                                             0
MaxFlow                                                              0
Shape                                                         CIRCULAR
Geom1                                                             1.25
Geom2                                                                0
Geom3                                                                0
Geom4                                                                0
Barrels                                                              1
coords        [(2746229.223, 1118867.764), (2746461.473, 1118663.257)]
Name: J1-025.1, dtype: object
property network#

Networkx MultiDiGraph representation of the model

Returns:

Networkx MultiDiGraph representation of model

Return type:

networkx.MultiDiGraph

property nodes#

Collect all useful and available data related model nodes and organize in one dataframe.

Returns:

dataframe containing all node objects in the model

Return type:

pd.DataFrame

>>> from swmmio.examples import jersey
>>> jersey.nodes.dataframe['InvertElev']
Name
J3     6.547
1     17.000
2     17.000
3     16.500
4     16.000
5     15.000
J2    13.000
J4     0.000
J1    13.392
Name: InvertElev, dtype: float64
property orifices#

collect all useful and available data related model orifices and organize in one dataframe.

property pumps#

Collect all useful and available data related model pumps and organize in one dataframe.

Returns:

dataframe containing all pumps objects in the model

Return type:

pd.DataFrame

>>> import swmmio
>>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY
>>> model = swmmio.Model(MODEL_FULL_FEATURES_XY)
>>> pumps = model.pumps.dataframe
>>> pumps[['PumpCurve', 'InitStatus']]  
     PumpCurve InitStatus
Name
C2    P1_Curve         ON
rpt_is_valid(verbose=False)[source]#

Return true if the .rpt file exists and has a revision date more recent than the .inp file. If the inp has an modified date later than the rpt, assume that the rpt should be regenerated

rpt_warnings(verbose=False)[source]#

Return warning messages from the rpt file

property subcatchments#

Retrieve and organize data related to subcatchments into ModelSection object which provides pandas.DataFrame and GeoPandas.GeoDataFrame accessors.

Returns:
swmmio.elements.ModelSection

Examples

>>> from swmmio.examples import jersey
>>> jersey.subcatchments.dataframe 
property summary: dict#

Summary statistics of the SWMM model.

Returns:
dict
to_crs(*args, **kwargs)[source]#

Convert coordinate reference system of the model coordinates

Parameters:

target_crs – coordinate reference system to reproject

Returns:

True

Examples

>>> m = swmmio.Model(MODEL_FULL_FEATURES_XY, crs="EPSG:2272")
>>> m.to_crs("EPSG:4326") # convert to WGS84 web mercator
>>> m.inp.coordinates.round(5)  
             X         Y
Name
J3   -74.86642  42.36596
1    -74.87061  42.36829
2    -74.86762  42.36792
3    -74.86939  42.36853
4    -74.86902  42.36809
5    -74.86889  42.36771
J2   -74.86846  42.36675
J4   -74.86479  42.36597
J1   -74.86886  42.36697
>>> m.inp.vertices.round(5)  
              X         Y
Name
C1:C2 -74.86870  42.36683
C2.1  -74.86803  42.36627
C2.1  -74.86731  42.36597
to_geojson(target_path=None)[source]#

Return a GeoJSON representation of the entire model :param target_path: target path of geojson (optional) :return: GeoJSON representation of model

property weirs#

collect all useful and available data related model weirs and organize in one dataframe.