Skip to content

Commit

Permalink
Catches NaN hydrotable values before calculating stage value
Browse files Browse the repository at this point in the history
  • Loading branch information
nickchadwick-noaa committed Sep 27, 2024
1 parent 850e475 commit da01e87
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 da01e87

Please sign in to comment.