Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile plotter and pyswmm integration #165

Merged
merged 24 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c199624
updated requirements.txt - added geopandas
bemcdonnell Sep 27, 2022
725330b
First steps to Migrate to PySWMM as dependency
bemcdonnell Sep 28, 2022
c05fbfd
Added Network Tracer function and tests
bemcdonnell Dec 22, 2022
d9127c3
Merge branch 'master' of https://github.com/aerispaha/swmmio
bemcdonnell Dec 22, 2022
0076c19
fix merge
bemcdonnell Dec 22, 2022
58f5e3c
removed line
bemcdonnell Dec 22, 2022
5024faf
Adding profile plotting code
bemcdonnell Dec 23, 2022
13529da
added function docstrings
bemcdonnell Dec 23, 2022
e5961c1
added import error
bemcdonnell Dec 23, 2022
78e5a68
Adding unit test for profiler config info
bemcdonnell Dec 23, 2022
1a705cd
updated requiredments
bemcdonnell Dec 23, 2022
7d17665
add unit tests for and refactor run_models.run
aerispaha Dec 28, 2022
f332b05
add report to inp, use in run.py
aerispaha Dec 28, 2022
b111808
add simple test of swmmio cli
aerispaha Dec 29, 2022
3f73c42
use jerzy example model for cli test
aerispaha Dec 29, 2022
350aae9
remove unnecessary files from run_models module
aerispaha Dec 29, 2022
e8d9849
step commit before pulling changes
bemcdonnell Dec 29, 2022
148fc89
Merge branch 'profile_plotter' of https://github.com/aerispaha/swmmio…
bemcdonnell Dec 29, 2022
3c2c768
fix
bemcdonnell Dec 29, 2022
ce5215f
syntax tweaks in utils.functions
aerispaha Dec 29, 2022
1748d2c
add temp unit test duplicate using temp directory
aerispaha Dec 29, 2022
c739da8
syntax tweaks in test_functions
aerispaha Dec 29, 2022
0d0735d
rm Example1_parallel_loop.out and Example1_parallel_loop.rpt
aerispaha Dec 29, 2022
83a598d
refactor test_profile such that it doesn't leave .out and .rpt artifacts
aerispaha Dec 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed lib/linux/swmm5
Binary file not shown.
Binary file removed lib/windows/swmm5_22.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ m2r
mistune==0.8.4
# Run dependencies
pyproj>=3.0.0
geopandas
pyswmm==1.2
9 changes: 4 additions & 5 deletions swmmio/defs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
# This is the swmmio project root
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# path to the SWMM5 executable used within the run_models module
if os.name == 'posix':
SWMM_ENGINE_PATH = os.path.join(ROOT_DIR, 'lib', 'linux', 'swmm5')
else:
SWMM_ENGINE_PATH = os.path.join(ROOT_DIR, 'lib', 'windows', 'swmm5_22.exe')
# path to the Python executable used to run your version of Python
PYTHON_EXE_PATH = "python"#os.path.join(os.__file__.split("lib/")[0],"bin","python")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aerispaha can you give me some advice here? This could break someone's run if they had python pointing to py2.7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, well we officially dropped support for Python 2.x back in version 0.3.7. Do you think we need to support 2.x to have pyswmm integrated as the model run engine?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aerispaha nope! If the user is not running inside an environment, this line just calls “python” rather than the version of python you are using to execute.


# feature class name of parcels in geodatabase
PARCEL_FEATURES = r'PWD_PARCELS_SHEDS_PPORT'
Expand All @@ -25,3 +22,5 @@
BASEMAP_PATH = os.path.join(ROOT_DIR, 'swmmio', 'reporting', 'basemaps', 'index.html')
BETTER_BASEMAP_PATH = os.path.join(ROOT_DIR, 'swmmio', 'reporting', 'basemaps', 'mapbox_base.html')

# PySWMM Wrapper Path
PYSWMM_WRAPPER_PATH = os.path.join(ROOT_DIR, 'swmmio', 'wrapper', 'pyswmm_wrapper.py')
23 changes: 15 additions & 8 deletions swmmio/run_models/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
from swmmio.utils.modify_model import replace_inp_section
from swmmio.run_models import defs
from swmmio import Model
from swmmio.defs.config import SWMM_ENGINE_PATH
from swmmio.defs.config import PYTHON_EXE_PATH, PYSWMM_WRAPPER_PATH


def run_simple(inp_path, swmm_eng=SWMM_ENGINE_PATH):
def run_simple(inp_path, py_path=PYTHON_EXE_PATH, pyswmm_wrapper=PYSWMM_WRAPPER_PATH):
"""
run a model once as is.
"""
print('running {} with {}'.format(inp_path, swmm_eng))
print('running {}'.format(inp_path))
#inp_path = model.inp.path
rpt_path = os.path.splitext(inp_path)[0] + '.rpt'
out_path = os.path.splitext(inp_path)[0] + '.out'

subprocess.call([swmm_eng, inp_path, rpt_path])
# Pass Environment Info to Run
env_definition = os.environ.copy()
env_definition["PATH"] = "/usr/sbin:/sbin:" + env_definition["PATH"]

def run_hot_start_sequence(inp_path, swmm_eng=SWMM_ENGINE_PATH):
subprocess.call([py_path, pyswmm_wrapper, inp_path, rpt_path, out_path],
env=env_definition)
return 0

def run_hot_start_sequence(inp_path, py_path=PYTHON_EXE_PATH):

# inp_path = model.inp.path
model = Model(inp_path)
Expand All @@ -33,15 +40,15 @@ def run_hot_start_sequence(inp_path, swmm_eng=SWMM_ENGINE_PATH):
model = replace_inp_section(model.inp.path, '[FILES]', hot1_df)
model = replace_inp_section(model.inp.path, '[REPORT]', defs.REPORT_none)
model = replace_inp_section(model.inp.path, '[OPTIONS]', defs.OPTIONS_no_rain)
subprocess.call([swmm_eng, model.inp.path, rpt_path])
run_simple(model.inp.path)

# if os.path.exists(hotstart1) and not os.path.exists(hotstart2):
#create new model inp with params to use hotstart1 and save hotstart2
print('with params to use hotstart1 and save hotstart2')
s = pd.Series(['USE HOTSTART "{}"'.format(hotstart1), 'SAVE HOTSTART "{}"'.format(hotstart2)])
hot2_df = pd.DataFrame(s, columns=['[FILES]'])
model = replace_inp_section(model.inp.path, '[FILES]', hot2_df)
subprocess.call([swmm_eng, model.inp.path, rpt_path])
run_simple(model.inp.path)

# if os.path.exists(hotstart2):
#create new model inp with params to use hotstart2 and not save anything
Expand All @@ -53,4 +60,4 @@ def run_hot_start_sequence(inp_path, swmm_eng=SWMM_ENGINE_PATH):
model = replace_inp_section(model.inp.path, '[REPORT]', defs.REPORT_none)# defs.REPORT_nodes_links)
model = replace_inp_section(model.inp.path, '[OPTIONS]', defs.OPTIONS_normal)

subprocess.call([swmm_eng, model.inp.path, rpt_path])
run_simple(model.inp.path)
Loading