Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: signal: Division by zero in lombscargle #3787

Closed
WarrenWeckesser opened this issue Jul 11, 2014 · 0 comments · Fixed by #3788
Closed

BUG: signal: Division by zero in lombscargle #3787

WarrenWeckesser opened this issue Jul 11, 2014 · 0 comments · Fixed by #3788
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.signal
Milestone

Comments

@WarrenWeckesser
Copy link
Member

This problem was reported on stackoverflow: http://stackoverflow.com/questions/24702807/lomb-scargle-vs-fft-power-spectrum-crashes-with-evenly-spaced-data/

Here's a self-contained example:

In [2]: scipy.__version__
Out[2]: '0.14.0'

In [3]: from scipy.signal import lombscargle

In [4]: t = np.linspace(0, 10, 1000, endpoint=False)

In [5]: x = np.sin(4*t)

In [6]: f = np.linspace(0, 50, 500, endpoint=False) + 0.1

In [7]: q = lombscargle(t, x, f*2*np.pi)
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-7-119dba45b118> in <module>()
----> 1 q = lombscargle(t, x, f*2*np.pi)

/Users/warren/anaconda/lib/python2.7/site-packages/scipy/signal/_spectral.so in scipy.signal._spectral.lombscargle (scipy/signal/_spectral.c:1662)()

ZeroDivisionError: float division

The problem is that lombscargle includes the calculation atan(2 * cs / (cc - ss)), but it is possible for cc - ss to be 0.

The fix is easy: replace atan(2 * cs / (cc - ss)) with atan2(2 * cs, cc - ss).

jacobcvt12 added a commit to jacobcvt12/scipy that referenced this issue Jul 12, 2014
Change calculation of tau to use atan2 function instead of atan.

closes scipygh-3787
jacobcvt12 added a commit to jacobcvt12/scipy that referenced this issue Jul 12, 2014
Change calculation of tau to use atan2 function instead of atan.

closes scipygh-3787
@rgommers rgommers added this to the 0.15.0 milestone Jul 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.signal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants