sfstoolbox/sfs-python

mirror image notebook: RuntimeWarning: divide by zero

Closed this issue · 1 comments

Currently, there are several ugly warnings in this notebook: http://python.sfstoolbox.org/en/latest/examples/mirror-image-source-model.html

That's the first bunch:

/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/latest/lib/python3.7/site-packages/sfs/mono/source.py:85: RuntimeWarning: divide by zero encountered in true_divide
  return 1 / (4*np.pi) * np.exp(-1j * k * r) / r
/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/latest/lib/python3.7/site-packages/sfs/mono/source.py:85: RuntimeWarning: invalid value encountered in true_divide
  return 1 / (4*np.pi) * np.exp(-1j * k * r) / r
/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/latest/lib/python3.7/site-packages/sfs/mono/source.py:398: RuntimeWarning: invalid value encountered in multiply
  p += strength * point(omega, position, grid, c)

And two more further down:

/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/latest/lib/python3.7/site-packages/sfs/time/source.py:82: RuntimeWarning: divide by zero encountered in true_divide
  weights = 1 / (4 * np.pi * r)
/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/latest/lib/python3.7/site-packages/sfs/time/source.py:87: RuntimeWarning: invalid value encountered in multiply
  data, left=0, right=0)

It would be nice to get rid of those warnings.

If the division by zero is justified, we should silence the warning.

One example for ignoring a warning:

sfs-python/sfs/plot.py

Lines 388 to 389 in d4ac310

with np.errstate(invalid='ignore'):
U, V = v.apply(np.true_divide, speed)

Another one:

sfs-python/sfs/util.py

Lines 366 to 367 in d4ac310

with np.errstate(divide='ignore'):
return (10 if power else 20) * np.log10(np.abs(x))

This was resolved in #139.