mikebannis / rascontrol Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for HEC-RAS controller. win32com based
License: GNU General Public License v3.0
Python wrapper for HEC-RAS controller. win32com based
License: GNU General Public License v3.0
Sometimes the reach codes are different in the geometry and output files in HEC-RAS. This will throw an error when accessing the output data because it assigns the incorrect node code to the incorrect reach. In order to fix this you must first grab the reach code using Geometry_GetReaches
, assign each reach its appropriate nodes, and then update the reach codes with Output_GetReaches
if the two differ. This way, you will be able to read the output file correctly. This was done by amending the River and RasController classes as follows:
River
class River(object):
def __init__(self, name, code, rc):
self.name = name # River name, string
self.code = code # River code, int - these start at 1, not 0
self.rc = rc # RasController object
self.reaches = self._get_reaches() # list of Reach objects
self._update_reach_codes()
# TODO - the reach code should probably be pulled from the rascontller, although i+1 seems to work
def _get_reaches(self):
"""
Gets list of reaches for river represented by self
:return: list of Reach objects
"""
reaches = []
reach_names = self.rc.geometry_getreaches(self.code)
for i, name in enumerate(reach_names):
new_reach = Reach(name, i+1, self)
reaches.append(new_reach)
return reaches
def _update_reach_codes(self):
"""
Sometimes the reach codes switch between the geometry and output files. This switches the codes after assigning
each reach their respective nodes
"""
if self.rc.output_getreaches(self.code)==self.rc.geometry_getreaches(self.code):
pass
else:
new_reach_codes = {}
new_reach_names = self.rc.output_getreaches(self.code)
for code, reach in enumerate(new_reach_names):
new_reach_codes[reach] = code+1
for reach in self.reaches:
updated_code = new_reach_codes[reach.name]
reach.code = updated_code
def __repr__(self):
return 'River name = "'+self.name + '", River code = "' + str(self.code)+'"'
RasController
def geometry_getreaches(self, river_num):
"""
Returns reach names in river numbered river_num using Geometry_GetReaches
:param river_num: int
:return: list of reach names
"""
_, _, reaches = self.com_rc.Geometry_GetReaches(river_num, None, None)
return reaches
def output_getreaches(self, river_num):
"""
Returns reach names in river numbered river_num using Output_GetReaches
:param river_num: int
:return: list of reach names
"""
_, _, reaches = self.com_rc.Output_GetReaches(river_num, None, None)
return reaches
If one writes a function to run rascontrol, rather than make a global variable of rascontrol, one runs into a referencing error. In run_orig in RasRunner, I changed
self.full_xs_list = rc.simple_xs_list()
self.rivers = {x.river for x in rr.full_xs_list}
self.xs_by_river = [[x for x in rr.full_xs_list if x.river == riv] for riv in self.rivers]
to
self.full_xs_list = rc.simple_xs_list()
self.rivers = {x.river for x in self.full_xs_list}
self.xs_by_river = [[x for x in self.full_xs_list if x.river == riv] for riv in self.rivers]
to fix the problem.
If your version of HEC-RAS is not 4.1, and you do not set the version in RasRunner appropriately, there is an error. Perhaps fix this with a try... catch...? The error comes up in line 232 of rascontrol.py
I installed rascontrol through git and pip as described in the rascontrol homepage. When I run the following code (given in basic usage example), it gives me the error: module 'rascontrol' has no attribute 'RasController'
import rascontrol
rc = rascontrol.RasController(version='507')
I am using Python 3.7.6 and HEC-RAS 5.0.7
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.