Skip to content

Commit

Permalink
Hotfix: Prevent div-by-zero in dynamic ratio colorbar range
Browse files Browse the repository at this point in the history
gcpy/plot/six_plot.py
- In routine "compute_vmin_vmax_for_ratio_plots":
  - If vmin is nonzero, compute vmax = 1.0 / vmin
  - If vmin is zero, then
    - Set vmax = np.abs(np.nanmax(plot_val)
    - Set vmin = 1.0 / vmax
  - Values will be swapped (as before) if vmin > vmax

This fix is necessary in order potential div-by-zero errors in
the computation of the dynamic ratio colorbar limits vmin & vmax.

Signed-off-by: Bob Yantosca <[email protected]>
  • Loading branch information
yantosca committed Oct 15, 2024
1 parent acb8626 commit 3b70af8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gcpy/plot/six_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,13 @@ def vmin_vmax_for_ratio_plots(
vmin = np.min(
[np.abs(np.nanmin(plot_val)), np.abs(np.nanmax(plot_val))]
)
vmax = 1.0 / vmin
if np.abs(vmin) > 0.0: # If vmin > 0, compute
vmax = 1.0 / vmin # vmax as its reciprocal
else:
vmax = np.abs(np.nanmax(plot_val)) # Otherwise compute vmin
vmin = 1.0 / vmax # as reciprocal of vmax
if vmin > vmax:
vmin, vmax = vmax, vmin
vmin, vmax = vmax, vmin # Swap values if needed
verbose_print(verbose, rowcol, vmin, vmax)
return vmin, vmax

Expand Down

0 comments on commit 3b70af8

Please sign in to comment.