Skip to content

Commit

Permalink
Merge pull request #73 from aerispaha/dev
Browse files Browse the repository at this point in the history
Update networkx, autorelease to PyPi
  • Loading branch information
aerispaha authored Oct 25, 2019
2 parents 3cdbaf3 + 9f83c67 commit daccb37
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 56 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
language: python
python:
- "2.7"
- "3.6"
- "3.7"

# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs
matrix:
include:
- python: 3.7
dist: xenial
sudo: true
# command to install dependencies
install:
- pip install -r requirements.txt
Expand Down
39 changes: 15 additions & 24 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
#matrix:
# fast_finish: true

#branches:
# only:
# - master
# - /dev-.*/

environment:
matrix:
# For Python versions available on Appveyor, see
# For Python versions available on Appveyor, see
# http://www.appveyor.com/docs/installed-software#python
# The list here is complete (excluding Python 2.6, which
# isn't covered by this document) at the time of writing.
- PYTHON: "C:\\Python27"
- PYTHON: "C:\\Python36"
- PYTHON: "C:\\Python37"

install:
- "%PYTHON%\\python setup.py develop"
Expand All @@ -22,17 +12,18 @@ install:
build: off

test_script:

- "%PYTHON%\\Scripts\\pytest %APPVEYOR_BUILD_FOLDER%"

# Asserting pep8 formatting checks (using autopep8 tool)
# - ps: |
# $output = C:\\Python36\\Scripts\\autopep8 -d --recursive .
# if($output)
# {
# echo $output;
# $host.SetShouldExit(1)
# Write-Host "autopep8 failed:
# Please this command locally:
# 'autopep8 -i -a -r .'"
# }

on_success:
- >
IF "%APPVEYOR_REPO_BRANCH%" == "master"
(
IF "%APPVEYOR_REPO_TAG%" == "true"
(
%PYTHON%\\python.exe -m pip install wheel
%PYTHON%\\python.exe setup.py bdist_wheel
%PYTHON%\\python.exe -m pip install twine &&
%PYTHON%\\python.exe -m twine upload dist/* -u %PYPI_USERNAME% -p %PYPI_PASSWORD%
)
)
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Build dependencies
#python
pytest
pillow==6.0.0
numpy==1.16.4
pandas==0.24.2
pillow>=6.2.0
numpy>=1.16.4
pandas>=0.24.2
pyshp==2.1.0
geojson==2.4.1
networkx==2.1
networkx>=2.4
# Run dependencies
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def get_description():
AUTHOR_EMAIL = '[email protected]'

install_requires = [
'Pillow==6.0.0',
'numpy==1.16.4',
'pandas==0.24.2',
'Pillow>=6.2.0',
'numpy>=1.16.4',
'pandas>=0.24.2',
'pyshp==2.1.0',
'geojson==2.4.1',
'networkx>=2.4',
]

tests_require = [
Expand Down
2 changes: 1 addition & 1 deletion swmmio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'''Python SWMM Input/Output Tools'''


VERSION_INFO = (0, 3, 6, 'dev0')
VERSION_INFO = (0, 3, 6, 'dev1')
__version__ = '.'.join(map(str, VERSION_INFO))
__author__ = 'Adam Erispaha'
__copyright__ = 'Copyright (c) 2016'
Expand Down
23 changes: 21 additions & 2 deletions swmmio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import math
from swmmio.utils import spatial
from swmmio.utils import functions
from swmmio.utils.dataframes import create_dataframeINP, create_dataframeRPT, get_link_coords
from swmmio.utils.dataframes import create_dataframeINP, create_dataframeRPT, get_link_coords, \
create_dataframe_multi_index
from swmmio.defs.config import *
from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH, MODEL_FULL_FEATURES_XY
import warnings
Expand Down Expand Up @@ -540,6 +541,7 @@ def __init__(self, file_path):
self._subareas_df = None
self._infiltration_df = None
self._headers = None
self._curves_df = None

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

Expand All @@ -559,6 +561,7 @@ def __init__(self, file_path):
'[SUBAREAS]',
'[INFILTRATION]',
'[COORDINATES]'
'[CURVES]'
]

def save(self, target_path=None):
Expand Down Expand Up @@ -924,7 +927,23 @@ def polygons(self):
@polygons.setter
def polygons(self, df):
"""Set inp.polygons DataFrame."""
self._polygons_df = df
self._curves_df = df

@property
def curves(self):
"""
get/set curves section of model
:return: multi-index dataframe of model curves
"""
if self._curves_df is not None:
return self._curves_df
self._curves_df = create_dataframe_multi_index(self.path, '[CURVES]', comment_cols=False)
return self._curves_df

@curves.setter
def curves(self, df):
"""Set inp.polygons DataFrame."""
self._curves_df = df


def drop_invalid_model_elements(inp):
Expand Down
3 changes: 2 additions & 1 deletion swmmio/defs/section_headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"[Polygons]": ["Name", "X", "Y"],
"[REPORT]": ["Param", "Status"],
"[TAGS]": ["ElementType", "Name", "Tag"],
"[MAP]": ["x1", "y1", "x2", "y2"]
"[MAP]": ["x1", "y1", "x2", "y2"],
"[CURVES]": ["Name", "Type", "X-Value", "Y-Value"]
},
"infiltration_cols": {
"HORTON": ["Subcatchment", "MaxRate", "MinRate", "Decay", "DryTime", "MaxInfil"],
Expand Down
4 changes: 2 additions & 2 deletions swmmio/defs/sectionheaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
'[Polygons]':'Name X Y',
'[REPORT]':'Param Status',
'[TAGS]':'ElementType Name Tag',
'[MAP]': 'x1 y1 x2 y2'
#'[CURVES]':'Name Type X-Value Y-Value',
'[MAP]': 'x1 y1 x2 y2',
'[CURVES]': 'Name Type X-Value Y-Value',
#'[TIMESERIES]':'Name Date Time Value'
}

Expand Down
28 changes: 28 additions & 0 deletions swmmio/tests/data/model_full_features_network_xy.inp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,36 @@ J1 FLOW "" FLOW 1.0 1 1
[CURVES]
;;Name Type X-Value Y-Value
;;-------------- ---------- ---------- ----------
;control curve
control-curve Control 0 0
control-curve 1 0.5
control-curve 10 1.0
;
diversion-curve Diversion 0 0
diversion-curve 1 10
;
P1_Curve Pump4 0 10
P1_Curve 5 20
;
P2_Curve Pump4 0 10
P2_Curve 1 20
P2_Curve 3 30
;
;tenk sotrage curve
tenk-sturage Shape 0 0
tenk-sturage 1 10
tenk-sturage 2 30
tenk-sturage 3 60
tenk-sturage 10 60
;
storage-curve Storage 0 0
storage-curve 1 100
storage-curve 10 100
;
tidal-curve Tidal 0 1
tidal-curve 6 1.5
tidal-curve 12 2
tidal-curve 23 1

[TIMESERIES]
;;Name Date Time Value
Expand Down
4 changes: 2 additions & 2 deletions swmmio/tests/test_dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_model_to_networkx():

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

links = m.links()
assert(len(links) == len(G.edges()))
Expand Down Expand Up @@ -139,4 +139,4 @@ def pumps_old_method(model):
pumps_old_method = pumps_old_method(m)
pumps = m.pumps()

assert(pumps_old_method.equals(pumps))
assert(pumps_old_method.equals(pumps))
12 changes: 10 additions & 2 deletions swmmio/tests/test_model_elements.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from swmmio.tests.data import MODEL_FULL_FEATURES__NET_PATH
from swmmio.tests.data import MODEL_FULL_FEATURES_XY, MODEL_FULL_FEATURES__NET_PATH
from swmmio import Model
from swmmio.elements import ModelSection
from swmmio.utils import functions
import pytest



@pytest.fixture
def test_model():
return Model(MODEL_FULL_FEATURES__NET_PATH)
return Model(MODEL_FULL_FEATURES_XY)


def test_model_section(test_model):
Expand All @@ -31,3 +32,10 @@ def test_complete_headers(test_model):
'[SYMBOLS]'
]
assert (all(section in headers['headers'] for section in sections_in_inp))


def test_get_set_curves(test_model):

curves = test_model.inp.curves

print (curves)
32 changes: 32 additions & 0 deletions swmmio/utils/dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ def create_dataframeINP(inp_path, section='[CONDUITS]', ignore_comments=True,
return df.rename(index=str)


def create_dataframe_multi_index(inp_path, section='[CURVES]', ignore_comments=True,
comment_str=';', comment_cols=True, headers=None):
# find all the headers and their defs (section title with cleaned one-liner column headers)
headerdefs = funcs.complete_inp_headers(inp_path)
# create temp file with section isolated from inp file
tempfilepath = txt.extract_section_from_inp(inp_path, section,
headerdefs=headerdefs,
ignore_comments=ignore_comments,
skipheaders=True)

headerlist = HEADERS['inp_sections'][section]

with open(tempfilepath, 'r') as f:
data = []
for line in f.readlines():
items = line.strip().split()
if len(items) == 3:
items = [items[0], None, items[1], items[2]]
if len(items) == 4:
data.append(items)

# df = pd.read_csv(tempfilepath, header=None, delim_whitespace=True, skiprows=[0],
# index_col=[0,1], names=headerlist, comment=comment_str)

df = pd.DataFrame(data=data, columns=headerlist)
df = df.set_index(['Name', 'Type'])


# os.startfile(tempfilepath)
os.remove(tempfilepath)
return df

def get_link_coords(row, nodexys, verticies):
"""for use in an df.apply, to get coordinates of a conduit/link """

Expand Down
11 changes: 3 additions & 8 deletions swmmio/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import deque
import pandas as pd
from swmmio.tests.data import MODEL_FULL_FEATURES_INVALID
import networkx as nx


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

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

conduits = model.conduits()
links = pd.concat([conduits, model.orifices(), model.weirs(), model.pumps()], sort=True)
links = model.links()
links['facilityid'] = links.index

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

if drop_cycles:
# remove cycles
Expand Down

0 comments on commit daccb37

Please sign in to comment.