org-arl / arlpy

ARL Python Tools
BSD 3-Clause "New" or "Revised" License
119 stars 37 forks source link

Possible divide by zero in plot_rays #16

Closed rigelifland closed 5 years ago

rigelifland commented 5 years ago

The greyscale color of the ray lines in plot_rays() are calculated using

max_amp = _np.max(_np.abs(rays.bottom_bounces))
...
c = int(255*_np.abs(row.bottom_bounces)/max_amp)

In the case of no bottom bounces (which isn't uncommon for eigen rays in sufficiently close-range/deep environments), this results in a divide by zero error.

Possible fix:

#Get the range, using one less than the minimum number of bottom bounces so that the minimum doesn't plot white.
amp_range = [_np.min(_np.abs(rays.bottom_bounces)) - 1, _np.max(_np.abs(rays.bottom_bounces))]
...
c = int(_np.interp(_np.abs(row.bottom_bounces), amp_range, [0, 255])) 

Link to relevent code

mchitre commented 5 years ago

Thanks! Will fix in the upcoming release.

mchitre commented 5 years ago

Fixed.