Skip to content

Commit

Permalink
Merge pull request #897 from NOAA-OWP/hand-fim-2.1.7-hotfix
Browse files Browse the repository at this point in the history
Calculating stage values from the hydrotables were failing when certain hydrotable values returned a NaN value. Added a catch to ignore those values.
  • Loading branch information
nickchadwick-noaa authored Sep 30, 2024
2 parents 850e475 + da01e87 commit 94f9c05
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,21 +608,27 @@ def interpolate_stage(df_row, df_hydro):

# Get the interpolated stage by using the discharge forecast value against the arrays
interpolated_stage = round(np.interp(forecast, discharges, stages), 2)


if np.isnan(interpolated_stage):
print(f"WARNING: Interpolated stage is NaN where hydro_id == {hydro_id}")
return np.nan

# Get the upper and lower values of the 1-ft hydrotable array that the current forecast / interpolated stage is at
hydrotable_index = np.searchsorted(discharges, forecast, side='right')

# If streamflow exceeds the rating curve max, just use the max value
exceeds_max = False
if hydrotable_index >= len(stages):
exceeds_max = True
hydrotable_index = hydrotable_index - 1

hydrotable_previous_index = hydrotable_index-1
if CACHE_FIM_RESOLUTION_FT == 1:
if CACHE_FIM_RESOLUTION_FT == 1 or exceeds_max:
rounded_stage = stages[hydrotable_index]
else:
rounded_stage = round_m_to_nearest_ft_resolution(interpolated_stage, CACHE_FIM_RESOLUTION_FT, CACHE_FIM_RESOLUTION_ROUNDING)
rc_previous_stage = stages[hydrotable_previous_index]
rc_discharge = discharges[hydrotable_index]
rc_previous_discharge = discharges[hydrotable_previous_index]

return interpolated_stage, rounded_stage, rc_previous_stage, rc_discharge, rc_previous_discharge
return interpolated_stage, rounded_stage, rc_previous_stage, rc_discharge, rc_previous_discharge

0 comments on commit 94f9c05

Please sign in to comment.