lsmatott / ostrich-swmm

A toolset for connecting the OSTRICH optimization software toolkit with the SWMM simulation model.
GNU General Public License v2.0
29 stars 19 forks source link

NameError: name 'sys' is not defined #25

Open rarygit opened 2 years ago

rarygit commented 2 years ago

OS: Ubuntu 20.04 pip3 venv = py3swmm python=v3.9 Is there an issue using python v3.9, rather than v3.8.3?

Trying to run ostrich-swmm for the first time, so any help appreciated.

I built and installed ostrich-swmm "lsmatott" in pip3 venv (the conda setup had too many conflicts) . I am following the tutorial documentation, using the *.inp file to run this test. I received the NameError: name 'sys' is not defined I checked the listed files at their respective lines, but could not find a solution

Attached are the input and config files and the swmm5 executable. Thanks for any help in getting this to run.

test_ostrich-swmm.zip

sh ostrich-swmm.sh Traceback (most recent call last): File "/media/l1nux/SAN240/py3venv/py3swmm/bin/ostrich-swmm", line 33, in sys.exit(load_entry_point('ostrich-swmm==0.6.0', 'console_scripts', 'ostrich-swmm')()) File "/media/l1nux/SAN240/py3venv/py3swmm/lib/python3.9/site-packages/ostrich_swmm-0.6.0-py3.9.egg/ostrich_swmm/main.py", line 247, in main File "/media/l1nux/SAN240/py3venv/py3swmm/lib/python3.9/site-packages/ostrich_swmm-0.6.0-py3.9.egg/ostrich_swmm/main.py", line 116, in run_cmd File "/media/l1nux/SAN240/py3venv/py3swmm/lib/python3.9/site-packages/ostrich_swmm-0.6.0-py3.9.egg/ostrich_swmm/run.py", line 24, in perform_run File "/media/l1nux/SAN240/py3venv/py3swmm/lib/python3.9/site-packages/ostrich_swmm-0.6.0-py3.9.egg/ostrich_swmm/inject.py", line 387, in perform_injection File "/media/l1nux/SAN240/py3venv/py3swmm/lib/python3.9/site-packages/ostrich_swmm-0.6.0-py3.9.egg/ostrich_swmm/inject.py", line 171, in inject_parameters_into_input File "/media/l1nux/SAN240/py3venv/py3swmm/lib/python3.9/site-packages/ostrich_swmm-0.6.0-py3.9.egg/ostrich_swmm/inject.py", line 55, in extract_subcatchment_polygons NameError: name 'sys' is not defined

rarygit commented 2 years ago

Solution in file inject.py:

don't use:

if sys.version_info[0] == 3:

instead:

from sys import version_info
if version_info[0] == 3:

This site was helpful:

https://stackoverflow.com/questions/9079036/how-do-i-detect-the-python-version-at-runtime

So now to the next problem: ValueError: Coordinates (1082700.0, 1077400.0) not found in subcatchments.

$ ostrich-swmm run -c submodel-ostrich-swmm-config.json Traceback (most recent call last): File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/bin/ostrich-swmm", line 33, in sys.exit(load_entry_point('ostrich-swmm==0.6.0', 'console_scripts', 'ostrich-swmm')()) File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/lib/python3.9/site-packages/ostrich_swmm/main.py", line 247, in main return subcommandsargs['subcommand'] File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/lib/python3.9/site-packages/ostrich_swmm/main.py", line 116, in run_cmd run.perform_run(config) File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/lib/python3.9/site-packages/ostrich_swmm/run.py", line 24, in perform_run inject.perform_injection(config, validate=False) File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/lib/python3.9/site-packages/ostrich_swmm/inject.py", line 388, in perform_injection inject_parameters_into_input(input_parameters, input_template) File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/lib/python3.9/site-packages/ostrich_swmm/inject.py", line 173, in inject_parameters_into_input lid['location']['subcatchment'] = get_subcatchment_from_map_coords( File "/media/l1nux/SAN240/conda_envs/envs/py3swmm/lib/python3.9/site-packages/ostrich_swmm/inject.py", line 115, in get_subcatchment_from_map_coords raise ValueError( ValueError: Coordinates (1082700.0, 1077400.0) not found in subcatchments.

rarygit commented 2 years ago

Maybe start with line 351 in file inject.py

line.append(sc_names_list[i]) #need to figure out how to grab subcat coordinates