Skip to content

Commit daccb37

Browse files
authored
Merge pull request #73 from aerispaha/dev
Update networkx, autorelease to PyPi
2 parents 3cdbaf3 + 9f83c67 commit daccb37

13 files changed

+125
-56
lines changed

.travis.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
language: python
22
python:
3-
- "2.7"
43
- "3.6"
4+
- "3.7"
55

6-
# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs
7-
matrix:
8-
include:
9-
- python: 3.7
10-
dist: xenial
11-
sudo: true
126
# command to install dependencies
137
install:
148
- pip install -r requirements.txt

appveyor.yml

+15-24
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
#matrix:
2-
# fast_finish: true
3-
4-
#branches:
5-
# only:
6-
# - master
7-
# - /dev-.*/
8-
91
environment:
102
matrix:
11-
# For Python versions available on Appveyor, see
3+
# For Python versions available on Appveyor, see
124
# http://www.appveyor.com/docs/installed-software#python
13-
# The list here is complete (excluding Python 2.6, which
14-
# isn't covered by this document) at the time of writing.
15-
- PYTHON: "C:\\Python27"
165
- PYTHON: "C:\\Python36"
6+
- PYTHON: "C:\\Python37"
177

188
install:
199
- "%PYTHON%\\python setup.py develop"
@@ -22,17 +12,18 @@ install:
2212
build: off
2313

2414
test_script:
25-
2615
- "%PYTHON%\\Scripts\\pytest %APPVEYOR_BUILD_FOLDER%"
2716

28-
# Asserting pep8 formatting checks (using autopep8 tool)
29-
# - ps: |
30-
# $output = C:\\Python36\\Scripts\\autopep8 -d --recursive .
31-
# if($output)
32-
# {
33-
# echo $output;
34-
# $host.SetShouldExit(1)
35-
# Write-Host "autopep8 failed:
36-
# Please this command locally:
37-
# 'autopep8 -i -a -r .'"
38-
# }
17+
18+
on_success:
19+
- >
20+
IF "%APPVEYOR_REPO_BRANCH%" == "master"
21+
(
22+
IF "%APPVEYOR_REPO_TAG%" == "true"
23+
(
24+
%PYTHON%\\python.exe -m pip install wheel
25+
%PYTHON%\\python.exe setup.py bdist_wheel
26+
%PYTHON%\\python.exe -m pip install twine &&
27+
%PYTHON%\\python.exe -m twine upload dist/* -u %PYPI_USERNAME% -p %PYPI_PASSWORD%
28+
)
29+
)

requirements.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Build dependencies
22
#python
33
pytest
4-
pillow==6.0.0
5-
numpy==1.16.4
6-
pandas==0.24.2
4+
pillow>=6.2.0
5+
numpy>=1.16.4
6+
pandas>=0.24.2
77
pyshp==2.1.0
88
geojson==2.4.1
9-
networkx==2.1
9+
networkx>=2.4
1010
# Run dependencies

setup.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ def get_description():
3232
AUTHOR_EMAIL = '[email protected]'
3333

3434
install_requires = [
35-
'Pillow==6.0.0',
36-
'numpy==1.16.4',
37-
'pandas==0.24.2',
35+
'Pillow>=6.2.0',
36+
'numpy>=1.16.4',
37+
'pandas>=0.24.2',
3838
'pyshp==2.1.0',
3939
'geojson==2.4.1',
40+
'networkx>=2.4',
4041
]
4142

4243
tests_require = [

swmmio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'''Python SWMM Input/Output Tools'''
66

77

8-
VERSION_INFO = (0, 3, 6, 'dev0')
8+
VERSION_INFO = (0, 3, 6, 'dev1')
99
__version__ = '.'.join(map(str, VERSION_INFO))
1010
__author__ = 'Adam Erispaha'
1111
__copyright__ = 'Copyright (c) 2016'

swmmio/core.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import math
88
from swmmio.utils import spatial
99
from swmmio.utils import functions
10-
from swmmio.utils.dataframes import create_dataframeINP, create_dataframeRPT, get_link_coords
10+
from swmmio.utils.dataframes import create_dataframeINP, create_dataframeRPT, get_link_coords, \
11+
create_dataframe_multi_index
1112
from swmmio.defs.config import *
1213
from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH, MODEL_FULL_FEATURES_XY
1314
import warnings
@@ -540,6 +541,7 @@ def __init__(self, file_path):
540541
self._subareas_df = None
541542
self._infiltration_df = None
542543
self._headers = None
544+
self._curves_df = None
543545

544546
SWMMIOFile.__init__(self, file_path) # run the superclass init
545547

@@ -559,6 +561,7 @@ def __init__(self, file_path):
559561
'[SUBAREAS]',
560562
'[INFILTRATION]',
561563
'[COORDINATES]'
564+
'[CURVES]'
562565
]
563566

564567
def save(self, target_path=None):
@@ -924,7 +927,23 @@ def polygons(self):
924927
@polygons.setter
925928
def polygons(self, df):
926929
"""Set inp.polygons DataFrame."""
927-
self._polygons_df = df
930+
self._curves_df = df
931+
932+
@property
933+
def curves(self):
934+
"""
935+
get/set curves section of model
936+
:return: multi-index dataframe of model curves
937+
"""
938+
if self._curves_df is not None:
939+
return self._curves_df
940+
self._curves_df = create_dataframe_multi_index(self.path, '[CURVES]', comment_cols=False)
941+
return self._curves_df
942+
943+
@curves.setter
944+
def curves(self, df):
945+
"""Set inp.polygons DataFrame."""
946+
self._curves_df = df
928947

929948

930949
def drop_invalid_model_elements(inp):

swmmio/defs/section_headers.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"[Polygons]": ["Name", "X", "Y"],
4343
"[REPORT]": ["Param", "Status"],
4444
"[TAGS]": ["ElementType", "Name", "Tag"],
45-
"[MAP]": ["x1", "y1", "x2", "y2"]
45+
"[MAP]": ["x1", "y1", "x2", "y2"],
46+
"[CURVES]": ["Name", "Type", "X-Value", "Y-Value"]
4647
},
4748
"infiltration_cols": {
4849
"HORTON": ["Subcatchment", "MaxRate", "MinRate", "Decay", "DryTime", "MaxInfil"],

swmmio/defs/sectionheaders.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
'[Polygons]':'Name X Y',
2727
'[REPORT]':'Param Status',
2828
'[TAGS]':'ElementType Name Tag',
29-
'[MAP]': 'x1 y1 x2 y2'
30-
#'[CURVES]':'Name Type X-Value Y-Value',
29+
'[MAP]': 'x1 y1 x2 y2',
30+
'[CURVES]': 'Name Type X-Value Y-Value',
3131
#'[TIMESERIES]':'Name Date Time Value'
3232
}
3333

swmmio/tests/data/model_full_features_network_xy.inp

+28
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,36 @@ J1 FLOW "" FLOW 1.0 1 1
137137
[CURVES]
138138
;;Name Type X-Value Y-Value
139139
;;-------------- ---------- ---------- ----------
140+
;control curve
141+
control-curve Control 0 0
142+
control-curve 1 0.5
143+
control-curve 10 1.0
144+
;
145+
diversion-curve Diversion 0 0
146+
diversion-curve 1 10
147+
;
140148
P1_Curve Pump4 0 10
141149
P1_Curve 5 20
150+
;
151+
P2_Curve Pump4 0 10
152+
P2_Curve 1 20
153+
P2_Curve 3 30
154+
;
155+
;tenk sotrage curve
156+
tenk-sturage Shape 0 0
157+
tenk-sturage 1 10
158+
tenk-sturage 2 30
159+
tenk-sturage 3 60
160+
tenk-sturage 10 60
161+
;
162+
storage-curve Storage 0 0
163+
storage-curve 1 100
164+
storage-curve 10 100
165+
;
166+
tidal-curve Tidal 0 1
167+
tidal-curve 6 1.5
168+
tidal-curve 12 2
169+
tidal-curve 23 1
142170

143171
[TIMESERIES]
144172
;;Name Date Time Value

swmmio/tests/test_dataframes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_model_to_networkx():
8787

8888
assert (G['J2']['J3']['C2.1']['Length'] == 666)
8989
assert (G['J1']['J2']['C1:C2']['Length'] == 244.63)
90-
assert (round(G.node['J2']['InvertElev'], 3) == 13.0)
90+
assert (round(G.nodes['J2']['InvertElev'], 3) == 13.0)
9191

9292
links = m.links()
9393
assert(len(links) == len(G.edges()))
@@ -139,4 +139,4 @@ def pumps_old_method(model):
139139
pumps_old_method = pumps_old_method(m)
140140
pumps = m.pumps()
141141

142-
assert(pumps_old_method.equals(pumps))
142+
assert(pumps_old_method.equals(pumps))

swmmio/tests/test_model_elements.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH
1+
from swmmio.tests.data import MODEL_FULL_FEATURES_XY, MODEL_FULL_FEATURES__NET_PATH
22
from swmmio import Model
33
from swmmio.elements import ModelSection
44
from swmmio.utils import functions
55
import pytest
66

77

8+
89
@pytest.fixture
910
def test_model():
10-
return Model(MODEL_FULL_FEATURES__NET_PATH)
11+
return Model(MODEL_FULL_FEATURES_XY)
1112

1213

1314
def test_model_section(test_model):
@@ -31,3 +32,10 @@ def test_complete_headers(test_model):
3132
'[SYMBOLS]'
3233
]
3334
assert (all(section in headers['headers'] for section in sections_in_inp))
35+
36+
37+
def test_get_set_curves(test_model):
38+
39+
curves = test_model.inp.curves
40+
41+
print (curves)

swmmio/utils/dataframes.py

+32
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,38 @@ def create_dataframeINP(inp_path, section='[CONDUITS]', ignore_comments=True,
8181
return df.rename(index=str)
8282

8383

84+
def create_dataframe_multi_index(inp_path, section='[CURVES]', ignore_comments=True,
85+
comment_str=';', comment_cols=True, headers=None):
86+
# find all the headers and their defs (section title with cleaned one-liner column headers)
87+
headerdefs = funcs.complete_inp_headers(inp_path)
88+
# create temp file with section isolated from inp file
89+
tempfilepath = txt.extract_section_from_inp(inp_path, section,
90+
headerdefs=headerdefs,
91+
ignore_comments=ignore_comments,
92+
skipheaders=True)
93+
94+
headerlist = HEADERS['inp_sections'][section]
95+
96+
with open(tempfilepath, 'r') as f:
97+
data = []
98+
for line in f.readlines():
99+
items = line.strip().split()
100+
if len(items) == 3:
101+
items = [items[0], None, items[1], items[2]]
102+
if len(items) == 4:
103+
data.append(items)
104+
105+
# df = pd.read_csv(tempfilepath, header=None, delim_whitespace=True, skiprows=[0],
106+
# index_col=[0,1], names=headerlist, comment=comment_str)
107+
108+
df = pd.DataFrame(data=data, columns=headerlist)
109+
df = df.set_index(['Name', 'Type'])
110+
111+
112+
# os.startfile(tempfilepath)
113+
os.remove(tempfilepath)
114+
return df
115+
84116
def get_link_coords(row, nodexys, verticies):
85117
"""for use in an df.apply, to get coordinates of a conduit/link """
86118

swmmio/utils/functions.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from collections import deque
33
import pandas as pd
44
from swmmio.tests.data import MODEL_FULL_FEATURES_INVALID
5+
import networkx as nx
56

67

78
def random_alphanumeric(n=6):
@@ -16,11 +17,6 @@ def model_to_networkx(model, drop_cycles=True):
1617
Networkx MultiDiGraph representation of the model
1718
'''
1819
from geojson import Point, LineString
19-
try:
20-
import networkx as nx
21-
except ImportError:
22-
raise ImportError('networkx module needed. get this package here: ',
23-
'https://pypi.python.org/pypi/networkx')
2420

2521
def multidigraph_from_edges(edges, source, target):
2622
'''
@@ -52,8 +48,7 @@ def multidigraph_from_edges(edges, source, target):
5248
model.rpt.path, "Node Inflow Summary")[inflow_cols]
5349
nodes = nodes.join(flows)
5450

55-
conduits = model.conduits()
56-
links = pd.concat([conduits, model.orifices(), model.weirs(), model.pumps()], sort=True)
51+
links = model.links()
5752
links['facilityid'] = links.index
5853

5954
# create a nx.MultiDiGraph from the combined model links, add node data, set CRS
@@ -66,7 +61,7 @@ def multidigraph_from_edges(edges, source, target):
6661
G[u][v][k]['geometry'] = LineString(coords)
6762
for n, coords in G.nodes(data='coords'):
6863
if coords:
69-
G.node[n]['geometry'] = Point(coords[0])
64+
G.nodes[n]['geometry'] = Point(coords[0])
7065

7166
if drop_cycles:
7267
# remove cycles

0 commit comments

Comments
 (0)