Skip to content

Commit d0f7dd9

Browse files
authored
Merge pull request #15 from michaeltryby/dev
Ongoing development work
2 parents c46242a + df57649 commit d0f7dd9

File tree

13 files changed

+713
-90
lines changed

13 files changed

+713
-90
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# .gitignore for swmm-python repo
3+
#
4+
5+
.*
6+
!.gitignore
7+
8+
*.py[ocd]
9+
10+
*.dll
11+
*.lib
12+
*.exp
13+
*.so
14+
*.h
15+
16+
build/
17+
dist/
18+
.pytest_cache/
19+
*.egg-info/
20+
21+
output.py
22+
output_wrap.c
23+
24+
toolkit.py
25+
toolkit_wrap.c

output/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
-e ./

output/swmm/output/__init__.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@
44

55
# Units of Measurement
66
#
7-
# Parameter Long Name US Customary SI Metric
8-
# AREA_SUBCATCH Subcatchment Area acres ac hectares ha
9-
# AREA_STOR Storage Unit Area square feet sq ft square meters sq m
10-
# AREA_POND Ponding Area square feet sq ft square meters sq m
11-
# CAP_SUC Capillary Suction inches in millimeters mm
12-
# CONC Concentration milligrams/liter mg/L milligrams/liter mg/L
13-
# micrograms/liter ug/L micrograms/liter ug/L
14-
# counts/liter Count/L counts/liter Count/L
15-
# INFIL_DECAY Infiltration Decay Constant 1/hours 1/hrs 1/hours 1/hrs
16-
# POLLUT_DECAY Pollutant Decay Constant 1/days 1/days 1/days 1/days
17-
# DEPRES_STOR Depression Storage inches in millimeters mm
18-
# DEPTH Depth feet ft meters m
19-
# DIAM Diameter feet ft meters m
20-
# DISC_COEFF_ORIF Orifice Discharge Coefficient dimensionless dimless dimensionless dimless
21-
# DISC_COEFF_WEIR Weir Discharge Coefficient CFS/foot^n CFS/ft^n CMS/meter^n CMS/m^n
22-
# ELEV Elevation feet ft meters m
23-
# EVAP_RATE Evaporation inches/day in/day millimeters/day mm/day
24-
# FLOW_RATE Flow cubic feet/sec CFS cubic meter/sec CMS
25-
# gallons/minute GPM liter/sec LPS
26-
# million gallons/day MGD million liter/day MLD
27-
# HEAD Head feet ft meters m
28-
# HYD_CONDUCT Hydraulic Conductivity inches/hour in/hr millimeters/hour mm/hr
29-
# INFIL_RATE Infiltration Rate inches/hour in/hr millimeters/hour mm/hr
30-
# LEN Length feet ft meters m
31-
# MANN_N Manning's n seconds/meter^1/3 sec/m^1/3 seconds/meter^1/3 sec/m^1/3
32-
# POLLUT_BUILDUP Pollutant Buildup mass/length mass/len mass/length mass/len
33-
# mass/acre mass/ac mass/hectare mass/ha
34-
# RAIN_INTENSITY Rainfall Intensity inches/hour in/hr millimeters/hour mm/hr
35-
# RAIN_VOLUME Rainfall Volume inches in millimeters mm
36-
# SLOPE_SUBCATCH Subcatchment Slope percent percent percent percent
37-
# SLOPE_XSEC Cross Section Slope rise/run rise/run rise/run rise/run
38-
# STREET_CLEAN_INT Street Cleaning Interval days days days days
39-
# VOLUME Volume cubic feet cu ft cubic meters cu m
40-
# WIDTH Width feet ft meters m
7+
# Units US Customary SI Metric
8+
# AREA_SUBCATCH acres ac hectares ha
9+
# AREA_STOR square feet sq ft square meters sq m
10+
# AREA_POND square feet sq ft square meters sq m
11+
# CAP_SUC inches in millimeters mm
12+
# CONC milligrams/liter mg/L milligrams/liter mg/L
13+
# micrograms/liter ug/L micrograms/liter ug/L
14+
# counts/liter Count/L counts/liter Count/L
15+
# INFIL_DECAY 1/hours 1/hrs 1/hours 1/hrs
16+
# POLLUT_DECAY 1/days 1/days 1/days 1/days
17+
# DEPRES_STOR inches in millimeters mm
18+
# DEPTH feet ft meters m
19+
# DIAM feet ft meters m
20+
# DISC_COEFF_ORIF dimensionless dimless dimensionless dimless
21+
# DISC_COEFF_WEIR CFS/foot^n CFS/ft^n CMS/meter^n CMS/m^n
22+
# ELEV feet ft meters m
23+
# EVAP_RATE inches/day in/day millimeters/day mm/day
24+
# FLOW_RATE cubic feet/sec CFS cubic meter/sec CMS
25+
# gallons/minute GPM liter/sec LPS
26+
# million gallons/day MGD million liter/day MLD
27+
# HEAD feet ft meters m
28+
# HYD_CONDUCT inches/hour in/hr millimeters/hour mm/hr
29+
# INFIL_RATE inches/hour in/hr millimeters/hour mm/hr
30+
# LEN feet ft meters m
31+
# MANN_N seconds/meter^1/3 sec/m^1/3 seconds/meter^1/3 sec/m^1/3
32+
# POLLUT_BUILDUP mass/length mass/len mass/length mass/len
33+
# mass/acre mass/ac mass/hectare mass/ha
34+
# RAIN_INTENSITY inches/hour in/hr millimeters/hour mm/hr
35+
# RAIN_VOLUME inches in millimeters mm
36+
# SLOPE_SUBCATCH percent percent percent percent
37+
# SLOPE_XSEC rise/run rise/run rise/run rise/run
38+
# STREET_CLEAN_INT days days days days
39+
# VOLUME cubic feet cu ft cubic meters cu m
40+
# WIDTH feet ft meters m
4141

4242

4343
# Output Metadata
4444
#
45-
# Subcatch Attributes Long Name Parameter Name
45+
# Subcatch Attributes Long Name Units
4646
# RAINFALL Rainfall RAIN_INTENSITY
4747
# SNOW_DEPTH Snow Depth DEPTH
4848
# EVAP_LOSS Evaporation Loss LOSS_RATE

output/swmm/output/output.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ typedef enum {
6868
} SMO_linkAttribute;
6969

7070
typedef enum {
71-
SMO_air_temp, // (deg. F or deg. C),
71+
SMO_air_temp, // (deg. F or deg. C),
7272
SMO_rainfall_system, // (in/hr or mm/hr),
7373
SMO_snow_depth_system, // (in or mm),
7474
SMO_evap_infil_loss, // (in/hr or mm/hr),
@@ -208,7 +208,7 @@ SMO_nodeAttribute, SMO_linkAttribute, SMO_systemAttribute};
208208

209209

210210
/* RENAME FUNCTIONS PYTHON STYLE */
211-
%rename("%(undercase)s") "";
211+
%rename("%(regex:/^\w+_([a-zA-Z]+)/\L\\1/)s") "";
212212

213213
/* GENERATES DOCUMENTATION */
214214
%feature("autodoc", "2");

output/tests/data/Example1.out

43 KB
Binary file not shown.

output/tests/data/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# __init__.py
4+
#
5+
# Created: 8/7/2018
6+
# Author: Michael E. Tryby
7+
# US EPA - ORD/NRMRL
8+
#
9+
10+
import os
11+
12+
DATA_PATH = os.path.abspath(os.path.dirname(__file__))
13+
14+
OUTPUT_FILE_EXAMPLE1 = os.path.join(DATA_PATH, 'Example1.out')

output/tests/test_output.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#
2+
# test_output.py
3+
#
4+
# Created: 8/7/2018
5+
# Author: Michael E. Tryby
6+
# US EPA - ORD/NRMRL
7+
#
8+
# Unit testing for SWMM Output API using pytest.
9+
#
10+
11+
import pytest
12+
import numpy as np
13+
14+
from swmm.output import output as smo
15+
16+
from data import OUTPUT_FILE_EXAMPLE1
17+
18+
19+
def test_openclose():
20+
_handle = smo.init()
21+
smo.open(_handle, OUTPUT_FILE_EXAMPLE1)
22+
smo.close()
23+
24+
25+
@pytest.fixture()
26+
def handle(request):
27+
_handle = smo.init()
28+
smo.open(_handle, OUTPUT_FILE_EXAMPLE1)
29+
30+
def close():
31+
smo.close()
32+
33+
request.addfinalizer(close)
34+
return _handle
35+
36+
37+
def test_getversion(handle):
38+
39+
assert smo.getversion(handle) == 51000
40+
41+
42+
def test_getprojectsize(handle):
43+
44+
assert smo.getprojectsize(handle) == [8, 14, 13, 2]
45+
46+
47+
def test_getpollutantunits(handle):
48+
49+
assert smo.getpollutantunits(handle) == [0, 1]
50+
51+
52+
def test_getstartdate(handle):
53+
54+
assert smo.getstartdate(handle) == 35796
55+
56+
57+
def test_gettimes(handle):
58+
59+
assert smo.gettimes(handle, smo.Time.NUM_PERIODS) == 36
60+
61+
62+
def test_getelementname(handle):
63+
64+
assert smo.getelementname(handle, smo.ElementType.NODE, 1) == "10"
65+
66+
67+
def test_getsubcatchseries(handle):
68+
69+
ref_array = np.array([0.0,
70+
1.2438242,
71+
2.5639679,
72+
4.524055,
73+
2.5115132,
74+
0.69808137,
75+
0.040894926,
76+
0.011605669,
77+
0.00509294,
78+
0.0027438672])
79+
80+
test_array = smo.getsubcatchseries(handle, 1, smo.SubcatchAttribute.RUNOFF_RATE, 0, 10)
81+
82+
assert len(test_array) == 10
83+
assert np.allclose(test_array, ref_array)
84+
85+
86+
def test_getsubcatchresult(handle):
87+
88+
ref_array = np.array([0.5,
89+
0.0,
90+
0.0,
91+
0.125,
92+
1.2438242,
93+
0.0,
94+
0.0,
95+
0.0,
96+
33.481991,
97+
6.6963983])
98+
99+
test_array = smo.getsubcatchresult(handle, 1, 1)
100+
101+
assert len(test_array) == 10
102+
assert np.allclose(test_array, ref_array)
103+
104+
105+
def test_getnoderesult(handle):
106+
107+
ref_array = np.array([0.296234,
108+
995.296204,
109+
0.0,
110+
1.302650,
111+
1.302650,
112+
0.0,
113+
15.361463,
114+
3.072293])
115+
116+
test_array = smo.getnoderesult(handle, 2, 2)
117+
118+
assert len(test_array) == 8
119+
assert np.allclose(test_array, ref_array)
120+
121+
122+
def test_getlinkresult(handle):
123+
124+
ref_array = np.array([4.631762,
125+
1.0,
126+
5.8973422,
127+
314.15927,
128+
1.0,
129+
19.070757,
130+
3.8141515])
131+
132+
test_array = smo.getlinkresult(handle, 3, 3)
133+
134+
assert len(test_array) == 7
135+
assert np.allclose(test_array, ref_array)
136+
137+
138+
def test_getsystemresult(handle):
139+
140+
ref_array = np.array([70.0,
141+
0.1,
142+
0.0,
143+
0.19042271,
144+
14.172027,
145+
0.0,
146+
0.0,
147+
0.0,
148+
0.0,
149+
14.172027,
150+
0.55517411,
151+
13.622702,
152+
2913.0793,
153+
0.0])
154+
155+
test_array = smo.getsystemresult(handle, 4, 4)
156+
157+
assert len(test_array) == 14
158+
assert np.allclose(test_array, ref_array)
159+

toolkit/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
-e ./

toolkit/swmm/toolkit/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11

2-
from swmm.toolkit import toolkit

0 commit comments

Comments
 (0)