Skip to content

Commit 83e14a2

Browse files
Fix for issue pyswmm#187
1 parent 30f9081 commit 83e14a2

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

swmmio/graphics/drawing.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
13
from swmmio.defs.constants import red, purple, lightblue, lightgreen, black, lightgrey, grey
24
from swmmio.defs.config import FONT_PATH
35
from swmmio.graphics.utils import circle_bbox, length_bw_coords, angle_bw_points, midpoint
@@ -49,7 +51,7 @@ def conduit_draw_size(conduit):
4951
draw_size = int(round(math.pow(stress * 10, 0.8)))
5052

5153
elif 'Geom1' in conduit:
52-
draw_size = conduit.Geom1
54+
draw_size = 0 if np.isnan(conduit.Geom1) else conduit.Geom1
5355

5456
return draw_size
5557

swmmio/tests/data/model_state_plane.inp

+19-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DRY_DAYS 0
2424
REPORT_STEP 00:05:00
2525
WET_STEP 00:05:00
2626
DRY_STEP 01:00:00
27-
ROUTING_STEP 0:00:05
27+
ROUTING_STEP 0:00:05
2828

2929
INERTIAL_DAMPING NONE
3030
NORMAL_FLOW_LIMITED BOTH
@@ -63,7 +63,7 @@ S2-028 0.01 0.1 0.05 0.05 25 OUTLET
6363
S2-092 0.01 0.1 0.05 0.05 25 OUTLET
6464

6565
[INFILTRATION]
66-
;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil
66+
;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil
6767
;;-------------- ---------- ---------- ---------- ---------- ----------
6868
S2-028 3.0 0.5 4 7 0
6969
S2-092 3.0 0.5 4 7 0
@@ -107,23 +107,24 @@ J2-369 963 3 0 0 0
107107
;;Name Elevation Type Stage Data Gated Route To
108108
;;-------------- ---------- ---------- ---------------- -------- ----------------
109109
J3-485 925.661 FREE NO
110+
J4-485 925.661 FIXED 0 NO
110111

111112
[STORAGE]
112-
;;Name Elev. MaxDepth InitDepth Shape Curve Name/Params N/A Fevap Psi Ksat IMD
113+
;;Name Elev. MaxDepth InitDepth Shape Curve Name/Params N/A Fevap Psi Ksat IMD
113114
;;-------------- -------- ---------- ----------- ---------- ---------------------------- -------- -------- -------- --------
114-
J1-035 935.442 11.3 0 FUNCTIONAL 15 0 0 0 0
115-
J1-037 935.712 13.707 0 FUNCTIONAL 13.72 0 0 0 0
116-
J1-188 965.823 10 0 FUNCTIONAL 62.68 0 0 0 0
117-
J1-192 949.631 10.5 0 FUNCTIONAL 15 0 0 0 0
118-
J1-194 947.409 10.6 0 FUNCTIONAL 15 0 0 0 0
119-
J2-023 982.636 17.006 0 FUNCTIONAL 15 0 0 0 0
120-
J2-024 987.421 10 0 FUNCTIONAL 15 0 0 0 0
121-
J2-095 1017.919 11.3 0 FUNCTIONAL 15 0 0 0 0
122-
J2-260 978.662 15.8 0 FUNCTIONAL 15 0 0 0 0
123-
J2-381 1008.579 16.5 0 FUNCTIONAL 15 0 0 0 0
124-
J2-411 995.249 9.6 0 FUNCTIONAL 6.44 0 0 0 0
125-
J2-412 1000.978 12.9 0 FUNCTIONAL 22.48 0 0 0 0
126-
J2-416 979.917 16.3 0 FUNCTIONAL 15 0 0 0 0
115+
J1-035 935.442 11.3 0 FUNCTIONAL 15 0 0 0 0
116+
J1-037 935.712 13.707 0 FUNCTIONAL 13.72 0 0 0 0
117+
J1-188 965.823 10 0 FUNCTIONAL 62.68 0 0 0 0
118+
J1-192 949.631 10.5 0 FUNCTIONAL 15 0 0 0 0
119+
J1-194 947.409 10.6 0 FUNCTIONAL 15 0 0 0 0
120+
J2-023 982.636 17.006 0 FUNCTIONAL 15 0 0 0 0
121+
J2-024 987.421 10 0 FUNCTIONAL 15 0 0 0 0
122+
J2-095 1017.919 11.3 0 FUNCTIONAL 15 0 0 0 0
123+
J2-260 978.662 15.8 0 FUNCTIONAL 15 0 0 0 0
124+
J2-381 1008.579 16.5 0 FUNCTIONAL 15 0 0 0 0
125+
J2-411 995.249 9.6 0 FUNCTIONAL 6.44 0 0 0 0
126+
J2-412 1000.978 12.9 0 FUNCTIONAL 22.48 0 0 0 0
127+
J2-416 979.917 16.3 0 FUNCTIONAL 15 0 0 0 0
127128

128129
[CONDUITS]
129130
;;Name From Node To Node Length Roughness InOffset OutOffset InitFlow MaxFlow
@@ -336,6 +337,7 @@ J2-094 2747085.761 1121265.773
336337
J2-317 2747448.509 1119684.475
337338
J2-369 2747448.112 1118966.478
338339
J3-485 2749098.306 1117287.218
340+
J4-485 2749092.269 1117557.055
339341
J1-035 2747473.260 1117462.702
340342
J1-037 2747435.935 1117127.264
341343
J1-188 2747376.384 1117730.771
@@ -366,7 +368,7 @@ S2-028 2746733.836 1119701.584
366368
S2-028 2746363.029 1120048.372
367369
S2-092 2746565.169 1120521.021
368370
S2-092 2746996.417 1120396.623
369-
S2-092 2746902.427 1120692.415
371+
S2-092 2746902.427 1120692.415
370372

371373
[SYMBOLS]
372374
;;Gage X-Coord Y-Coord

swmmio/tests/test_dataframes.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
BUILD_INSTR_01, MODEL_XSECTION_ALT_01, df_test_coordinates_csv,
66
MODEL_FULL_FEATURES_XY, DATA_PATH, MODEL_XSECTION_ALT_03,
77
MODEL_CURVE_NUMBER, MODEL_MOD_HORTON, MODEL_GREEN_AMPT, MODEL_MOD_GREEN_AMPT,
8-
MODEL_INFILTRAION_PARSE_FAILURE, OWA_RPT_EXAMPLE)
8+
MODEL_INFILTRAION_PARSE_FAILURE, OWA_RPT_EXAMPLE, MODEL_A_PATH)
99
from swmmio.utils.dataframes import (dataframe_from_rpt, dataframe_from_inp, dataframe_from_bi)
1010
import swmmio
1111

@@ -257,4 +257,13 @@ def test_polygons(test_model_02):
257257

258258
assert poly1.equals(test_model_02.inp.polygons)
259259

260-
# print()
260+
261+
def test_swmmio_outfall():
262+
model = swmmio.Model(MODEL_A_PATH)
263+
outfalls = model.inp.outfalls
264+
265+
assert outfalls.loc['J3-485', 'StageOrTimeseries'] == " ", "StageOrTimeseries for J3-485 should be empty"
266+
assert outfalls.loc['J3-485', 'TideGate'] == 'NO', "TideGate for J3-485 should be 'NO'"
267+
268+
assert outfalls.loc['J4-485', 'StageOrTimeseries'] == '0', "StageOrTimeseries for J4-485 should be 0"
269+
assert outfalls.loc['J4-485', 'TideGate'] == 'NO', "TideGate for J4-485 should be 'NO'"

swmmio/utils/dataframes.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ def dataframe_from_inp(inp_path, section, additional_cols=None, quote_replace='
144144

145145
# count tokens in first non-empty line, after the header, ignoring comments
146146
# if zero tokens counted (i.e. empty line), fall back to headers dict
147-
n_tokens = len(re.sub(r"(\n)\1+", r"\1", s).split('\n')[1].split(';')[0].split())
147+
148+
lines = re.sub(r"(\n)\1+", r"\1", s).split('\n')
149+
try:
150+
n_tokens_min = min(
151+
len(line.split(';')[0].split()) for line in lines if line.strip() and len(line.split(';')[0].split()) > 1)
152+
except ValueError:
153+
n_tokens_min = 1
154+
155+
n_tokens = max(len(line.split(';')[0].split()) for line in lines)
148156
n_tokens = len(headers[sect]['columns']) if n_tokens == 0 else n_tokens
149157

150158
# and get the list of columns to use for parsing this section
@@ -157,8 +165,12 @@ def dataframe_from_inp(inp_path, section, additional_cols=None, quote_replace='
157165
return pd.read_csv(StringIO(s), delim_whitespace=False)
158166
else:
159167
try:
160-
df = pd.read_csv(StringIO(s), header=None, delim_whitespace=True,
161-
skiprows=[0], index_col=0, names=cols)
168+
if n_tokens == n_tokens_min:
169+
df = pd.read_csv(StringIO(s), header=None, delim_whitespace=True,
170+
skiprows=[0], index_col=0, names=cols, na_values=' ', usecols=range(len(cols)))
171+
else:
172+
df = pd.read_fwf(StringIO(s), header=None, delim_whitespace=True, na_values='',
173+
skiprows=[0], index_col=0, names=cols, usecols=range(len(cols)))
162174
except:
163175
raise IndexError(f'failed to parse {section} with cols: {cols}. head:\n{s[:500]}')
164176

0 commit comments

Comments
 (0)