Skip to content

Commit

Permalink
Merge pull request #274 from Dewberry/feature/fix-htab-warning
Browse files Browse the repository at this point in the history
Feature/fix htab warning
  • Loading branch information
sclaw authored Dec 20, 2024
2 parents 3a189b0 + 251a6ee commit 71c5122
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ripple1d/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,38 @@ def thalweg(self):
_, y = list(zip(*self.station_elevation_points))
return min(y)

@property
def has_htab_error(self):
"""Check if min htab value is less than section invert."""
if self.htab_string is None:
return False
else:
return self.htab_starting_el < self.thalweg

@property
def htab_string(self):
"""Cross section htab string."""
try:
htabstr = search_contents(self.ras_data, "XS HTab Starting El and Incr", expect_one=True)
except:
htabstr = None
return htabstr

@property
def htab_starting_el(self):
"""Cross section minimum htab."""
return float(self.htab_string.split(",")[0])

@property
def htab_increment(self):
"""Cross section minimum htab."""
return float(self.htab_string.split(",")[1])

@property
def htab_points(self):
"""Cross section minimum htab."""
return float(self.htab_string.split(",")[2])

@property
def xs_max_elevation(self):
"""Cross section maximum elevation."""
Expand Down
25 changes: 25 additions & 0 deletions ripple1d/ras.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ def __init__(self, ras_text_file_path: str, crs: str = None, new_file=False, uni
self.units = units
self.hdf_file = self._ras_text_file_path + ".hdf"

self.fix_htab_errors()

def __repr__(self):
"""Representation of the RasGeomText class."""
return f"RasGeomText({self._ras_text_file_path})"
Expand Down Expand Up @@ -856,6 +858,29 @@ def _check_layers(self):
if "River" not in layers:
raise NoRiverLayerError(f"Could not find a layer called River in {self._gpkg_path}")

def fix_htab_errors(self):
"""Update any htab values lower than the section invert to the section invert."""
working_string = "\n".join(self.contents.copy())
needs_save = False
for xs in self.cross_sections.values():
if xs.has_htab_error:
needs_save = True
logging.info(f"Fixing htab error for {xs.river_reach}")
old_htab_str = xs.htab_string
# HEC-RAS default handling:
# either 0 or 0.5 ft above section invert for the start elevation
# increment that will yield 20 pts between start and section max elevations
# We want to preserve engineer-specified increments, so we don't do that
new_htab_str = old_htab_str.replace(str(xs.htab_starting_el), str(xs.thalweg))

old_xs_str = "\n".join(xs.ras_data)
new_xs_str = old_xs_str.replace(old_htab_str, new_htab_str)
working_string = working_string.replace(old_xs_str, new_xs_str)
if needs_save:
with open(self._ras_text_file_path, "w") as f:
f.write(working_string)
self.contents = working_string.splitlines()

@property
def title(self):
"""Title of the HEC-RAS Geometry file."""
Expand Down

0 comments on commit 71c5122

Please sign in to comment.