swmmio Core Objects¶
-
class
swmmio.core.
Model
(in_file_path, crs=None, include_rpt=True)[source]¶ Bases:
object
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
-
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
-
property
links
¶ 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
>>> from swmmio.examples import philly >>> philly.links.dataframe
-
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
-
property
subcatchments
¶ collect all useful and available data related subcatchments and organize in one dataframe.
-
to_crs
(*args, **kwargs)[source]¶ Convert coordinate reference system of the model coordinates
- Parameters
target_crs – coordinate reference system to reproject
- Returns
True
>>> import swmmio >>> m = swmmio.Model(MODEL_FULL_FEATURES_XY, crs="EPSG:2272") >>> m.to_crs("EPSG:4326") # convert to WGS84 web mercator >>> m.inp.coordinates X Y Name J3 -74.866424 42.365958 1 -74.870614 42.368292 2 -74.867615 42.367916 3 -74.869387 42.368527 4 -74.869024 42.368089 5 -74.868888 42.367709 J2 -74.868458 42.366748 J4 -74.864787 42.365966 J1 -74.868861 42.366968 >>> m.inp.vertices X Y Name C1:C2 -74.868703 42.366833 C2.1 -74.868034 42.366271 C2.1 -74.867305 42.365974
-
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.
-
-
class
swmmio.core.
inp
(file_path)[source]¶ Bases:
swmmio.core.SWMMIOFile
-
property
conduits
¶ Get/set conduits section of the INP file.
- Returns
Conduits section of the INP file
- Return type
pandas.DataFrame
Examples:
>>> import swmmio >>> from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH >>> model = swmmio.Model(MODEL_FULL_FEATURES__NET_PATH) >>> model.inp.conduits[['InletNode', 'OutletNode', 'Length', 'ManningN']] InletNode OutletNode Length ManningN Name C1:C2 J1 J2 244.63 0.01 C2.1 J2 J3 666.00 0.01 1 1 4 400.00 0.01 2 4 5 400.00 0.01 3 5 J1 400.00 0.01 4 3 4 400.00 0.01 5 2 5 400.00 0.01
-
property
coordinates
¶ Get/set coordinates section of model :return: dataframe of model coordinates
-
property
curves
¶ get/set curves section of model :return: multi-index dataframe of model curves
-
property
files
¶ Get/set files section of the INP file.
- Returns
files section of the INP file
- Return type
pandas.DataFrame
Examples:
-
property
headers
¶ Return all headers and associated column names found in the INP file.
-
property
infiltration
¶ Get/set infiltration section of the INP file.
>>> import swmmio >>> from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH >>> m = swmmio.Model(MODEL_FULL_FEATURES__NET_PATH) >>> m.inp.infiltration MaxRate MinRate Decay DryTime MaxInfil Subcatchment S1 3.0 0.5 4 7 0 S2 3.0 0.5 4 7 0 S3 3.0 0.5 4 7 0 S4 3.0 0.5 4 7 0
-
property
inflows
¶ Get/set inflows section of model
- Returns
dataframe of nodes with inflows
>>> from swmmio.examples import jersey >>> jersey.inp.inflows[['Constituent', 'Mfactor', 'Baseline']] Constituent Mfactor Baseline Node J3 Flow 1.0 1 J2 FLOW 1.0 1 J1 FLOW 1.0 1
-
property
junctions
¶ Get/set junctions section of the INP file.
- Returns
junctions section of the INP file
- Return type
pandas.DataFrame
Examples:
>>> import swmmio >>> from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH >>> model = swmmio.Model(MODEL_FULL_FEATURES__NET_PATH) >>> model.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
-
property
options
¶ Get/set options section of the INP file.
- Returns
options section of the INP file
- Return type
pandas.DataFrame
>>> import swmmio >>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY >>> model = swmmio.Model(MODEL_FULL_FEATURES_XY) >>> model.inp.options.loc['INFILTRATION'] Value HORTON Name: INFILTRATION, dtype: object >>> model.inp.headers['[INFILTRATION]'] ['Subcatchment', 'MaxRate', 'MinRate', 'Decay', 'DryTime', 'MaxInfil'] >>> model.inp.options.loc['INFILTRATION', 'Value'] = 'GREEN_AMPT' >>> model.inp.headers['[INFILTRATION]'] ['Subcatchment', 'Suction', 'HydCon', 'IMDmax']
-
property
orifices
¶ Get/set orifices section of the INP file.
-
property
outfalls
¶ Get/set outfalls section of the INP file.
- Returns
outfalls section of the INP file
- Return type
pandas.DataFrame
Examples:
>>> import swmmio >>> from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH >>> model = swmmio.Model(MODEL_FULL_FEATURES__NET_PATH) >>> model.inp.outfalls InvertElev OutfallType StageOrTimeseries TideGate Name J4 0 FREE NO NaN
-
property
polygons
¶ get/set polygons section of model :return: dataframe of model coordinates
-
property
pumps
¶ Get/set pumps section of the INP file.
-
save
(target_path=None)[source]¶ Save the inp file to disk. File will be overwritten unless a target_path is provided
- Parameters
target_path – optional path to new inp file
- Returns
None
>>> from swmmio.examples import philly >>> philly.inp.save('copy-of-philly.inp')
-
property
storage
¶ Get/set storage section of the INP file.
- Returns
storage section of the INP file
- Return type
pandas.DataFrame
Examples:
-
property
subareas
¶ Get/set subareas section of the INP file.
-
property
subcatchments
¶ Get/set subcatchments section of the INP file.
- Returns
subcatchments section of the INP file
- Return type
pandas.DataFrame
Examples:
-
property
timeseries
¶ get/set timeseries section of model :return: multi-index dataframe of model curves
-
property
vertices
¶ get/set vertices section of model :return: dataframe of model coordinates
-
property
weirs
¶ Get/set weirs section of the INP file.
-
property
xsections
¶ Get/set pumps section of the INP file.
-
property
-
class
swmmio.core.
rpt
(filePath)[source]¶ Bases:
swmmio.core.SWMMIOFile
An accessible SWMM .rpt object
>>> from swmmio.tests.data import RPT_FULL_FEATURES >>> report = rpt(RPT_FULL_FEATURES) >>> report.link_flow_summary >>> from swmmio.examples import spruce >>> spruce.rpt.link_results
-
property
cross_section_summary
¶ Return values for the Cross Section Summary description
-
property
headers
¶ Return all section headers and associated column names found in the RPT file.
-
property
link_flow_summary
¶ Return values for the Link Flow Summary description
-
property
link_results
¶ Return values for the Link Results description
-
property
link_summary
¶ Return values for the Link Summary description
-
property
node_depth_summary
¶ Return values for the Node Depth Summary description
-
property
node_flooding_summary
¶ Return values for the Node Flooding Summary description
-
property
node_inflow_summary
¶ Return values for the Node Inflow Summary description
-
property
node_results
¶ Return values for the Node Results description
-
property
node_summary
¶ Return values for the Node Summary description
-
property
node_surcharge_summary
¶ Return values for the Node Surcharge Summary description
-
property
storage_volume_summary
¶ Return values for the Storage Volume Summary description
-
property
subcatchment_results
¶ Return values for the Subcatchment Results description
-
property
subcatchment_runoff_summary
¶ Return values for the Subcatchment Runoff Summary description
-
property
subcatchment_summary
¶ Return values for the Subcatchment Summary description
-
property