Skip to content

Commit

Permalink
Merge pull request #105 from jennwuu/bug_fix
Browse files Browse the repository at this point in the history
Address issue #103 and #102
  • Loading branch information
aerispaha authored Sep 28, 2020
2 parents 412e1ce + d97e396 commit 889c6e3
Show file tree
Hide file tree
Showing 15 changed files with 1,386 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:
# Useful for debugging any issues with conda
- conda info -a
# create test environment with geopandas installed
- conda create -q -n test-env python=$TRAVIS_PYTHON_VERSION geopandas
- conda create -q -n test-env python=$TRAVIS_PYTHON_VERSION geopandas==0.6.1
- conda activate test-env
- pip install -r requirements.txt
# command to run tests
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install:
# Useful for debugging any issues with conda
- "conda info -a"
# create test environment with geopandas installed
- "conda create -q -n test-env python=%PYTHON_VERSION% geopandas"
- "conda create -q -n test-env python=%PYTHON_VERSION% geopandas==0.6.1"
- "activate test-env"

- "python setup.py develop"
Expand Down
34 changes: 10 additions & 24 deletions swmmio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# coding:utf-8

from time import ctime
import re
import os
import pandas as pd
import glob
Expand All @@ -15,7 +16,7 @@
from swmmio.defs import INP_OBJECTS, INFILTRATION_COLS, RPT_OBJECTS, COMPOSITE_OBJECTS

from swmmio.utils.functions import trim_section_to_nodes
from swmmio.utils.text import get_inp_sections_details, get_rpt_sections_details
from swmmio.utils.text import get_inp_sections_details, get_rpt_sections_details, get_rpt_metadata

pd.set_option('max_columns', 5)

Expand Down Expand Up @@ -444,34 +445,19 @@ class rpt(SWMMIOFile):
>>> spruce.rpt.link_results
"""


def __init__(self, filePath):

SWMMIOFile.__init__(self, filePath)

with open(filePath) as f:
for line in f:
if "Starting Date" in line:
simulationStart = line.split(".. ")[1].replace("\n", "")
if "Ending Date" in line:
simulationEnd = line.split(".. ")[1].replace("\n", "")
if "Report Time Step ........." in line:
timeStepMin = int(line.split(":")[1].replace("\n", ""))
break

self.simulationStart = simulationStart
self.simulationEnd = simulationEnd
self.timeStepMin = timeStepMin
self._rpt_section_details = None
# grab the date of analysis
with open(filePath) as f:
f.seek(self.file_size - 500) # jump to 500 bytes before the end of file
for line in f:
if "Analysis begun on" in line:
date = line.split("Analysis begun on: ")[1].replace("\n", "")

self.dateOfAnalysis = date
meta_data = get_rpt_metadata(filePath)

self.swmm_version = meta_data['swmm_version']
self.simulationStart = meta_data['simulation_start']
self.simulationEnd = meta_data['simulation_end']
self.timeStepMin = meta_data['time_step_min']
self.dateOfAnalysis = meta_data['analysis_date']
self.elementByteLocations = {"Link Results": {}, "Node Results": {}}
self._rpt_section_details = None

@property
def headers(self):
Expand Down
3 changes: 2 additions & 1 deletion swmmio/defs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

INP_OBJECTS = normalize_inp_config(_inp_sections_conf_raw['inp_file_objects'])
RPT_OBJECTS = normalize_inp_config(HEADERS_YML['rpt_sections'])
SWMM5_VERSION = HEADERS_YML['swmm5_version']
INP_SECTION_TAGS = _inp_sections_conf_raw['inp_section_tags']
INFILTRATION_COLS = _inp_sections_conf_raw['infiltration_cols']
COMPOSITE_OBJECTS = HEADERS_YML['composite']
INFILTRATION_KEY = 'INFILTRATION'
INFILTRATION_KEY = 'INFILTRATION'
17 changes: 16 additions & 1 deletion swmmio/defs/section_headers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ conduits:
inp_sections: ['[CONDUITS]', '[XSECTIONS]']
rpt_sections: [Link Flow Summary]


rpt_sections:
Cross Section Summary:
- Name
Expand Down Expand Up @@ -134,6 +133,22 @@ rpt_sections:
- RainGage
- Outlet

swmm5_version:
1.13:
rpt_sections:
Subcatchment Runoff Summary:
- Name
- TotalPrecip
- TotalRunon
- TotalEvap
- TotalInfil
- ImpervRunoff
- PervRunoff
- TotalRunoffIn
- TotalRunoffMG
- PeakRunoff
- RunoffCoeff

composite:
nodes:
inp_sections: [junctions, outfalls, storage]
Expand Down
3 changes: 1 addition & 2 deletions swmmio/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ def __call__(self):
# add conduit coordinates
xys = df.apply(lambda r: get_link_coords(r, self.inp.coordinates, self.inp.vertices), axis=1)
df = df.assign(coords=xys.map(lambda x: x[0]))

# make inlet/outlet node IDs string type
df.InletNode = df.InletNode.astype(str)
df.OutletNode = df.OutletNode.astype(str)

elif self.geomtype == 'polygon':
p = self.inp.polygons

p.index = p.index.map(str)
# take stacked coordinates and orient in list of tuples,
xys = p.groupby(by=p.index).apply(lambda r: [(xy['X'], xy['Y']) for ix, xy in r.iterrows()])
# copy the first point to the last position
Expand Down
Loading

0 comments on commit 889c6e3

Please sign in to comment.