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

ACF_scargle fails #74

Open
stephtdouglas opened this issue Aug 4, 2015 · 9 comments
Open

ACF_scargle fails #74

stephtdouglas opened this issue Aug 4, 2015 · 9 comments

Comments

@stephtdouglas
Copy link

I'm trying to run the example from http://www.astroml.org/book_figures/chapter10/fig_autocorrelation.html, but the ACF_scargle function is failing and returning all NaNs. The issue seems to be coming up when computing the power of the window function, which returns all infs. I tried computing a similar periodogram (random times, y=1 everywhere), and had similar results from the astroML and gatspy functions:

from astroML import time_series
from gatspy import periodic

t = np.sort(1000*np.random.random_sample(100))
y = np.ones(100)
dy = y * 0.1

pw = time_series.lomb_scargle(t,y,dy,np.arange(0.1,100),generalized=False,subtract_mean=False)

pw = periodic.lomb_scargle.LombScargle(center_data=False).fit(t,y,dy)
pw.score(np.arange(0.1,100))

Those yield an array of infs and an array of NaNs, respectively. Is this coming from the functions themselves, or the inputs?

I'm using astroML v. 0.3 and gatspy version 0.2, for reference.

@jakevdp
Copy link
Member

jakevdp commented Aug 5, 2015

Hi – it's failing for you when you run the example code directly, or just when you use your own data?

If you're getting bad results from the window function, I imagine it's because the data is being centered first. This application is why both astroML and gatspy have an option to turn-off centering when computing the periodogram (in gatpsy, set center_data=False)

Let me know if that fixes your issue.

@stephtdouglas
Copy link
Author

Hi Jake - it fails in both cases, running the example script or calling the lomb_scargle functions separately. I had set center_data=False for the gatspy call and subtract_mean=False for the astroML call.

The example code was failing to produce an ACF with the scargle method. This is the figure that results from running the example code; all I changed was usetex=False.

acf_fig_orig_code

I started poking around to see if I could figure out where the issue was, which is how I ended up with the set of commands I pasted above (which don't center the data). The astroML call is exactly the same as the one in the ACF_scargle function. Here are the outputs from those snippets.
screenshot from 2015-08-05 15 08 42
I also tried
pw = time_series.lomb_scargle(t,y,dy,np.arange(0.1,100),generalized=True,subtract_mean=False)
and the only difference is that it outputs NaNs instead of infs

Thanks,
Stephanie

@jakevdp
Copy link
Member

jakevdp commented Aug 5, 2015

Strange... are you on Python 2 or 3? It might be due to some sort of division truncation error, but I'm not sure. I'm stumped right now.

@stephtdouglas
Copy link
Author

I'm using Python 2.7.9, Anaconda 2.2.0, 64-bit.

On actual data the lomb_scargle functions run just fine, it's just in this particular case with all ones that it's failing, if that helps at all

@jakevdp
Copy link
Member

jakevdp commented Aug 7, 2015

I can't reproduce this. I ran the following on all versions of Python with all versions of the libraries:

import numpy as np
from astroML.time_series import lomb_scargle

N = 100

t = np.sort(1000 * np.random.random(N))
y = np.ones(N)
dy = 0.1 * np.ones(N)

omega = np.linspace(0.1, 100)

P = lomb_scargle(t, y, dy, omega, generalized=False, subtract_mean=False)
print(P)

The result contains no NANs or infs. Is there any way you can use a debugger to figure out exactly where the infs are entering the calculation?

@bsipocz
Copy link
Member

bsipocz commented Aug 17, 2015

@jakevdp - I have the same problem on python2.7 (with setups of 2.7.6 on Ubuntu 14 and 2.7.10 on Yosemite). However it only occurs when astroML_addons is also present, and it runs and gives realistic results when I uninstall the addons.

In your example also fails (with the addons):

In [9]: print(P)
[ inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf
  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf
  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf
  inf  inf  inf  inf  inf]

@jakevdp
Copy link
Member

jakevdp commented Aug 18, 2015

Ah... thanks @bsipocz! It must be some issue in the cython code in addons. I'll try to figure it out.

@jakevdp
Copy link
Member

jakevdp commented Aug 18, 2015

Actually, I think that this might already be fixed in this commit: astroML/astroML_addons@300297c

@bsipocz
Copy link
Member

bsipocz commented Aug 18, 2015

@jakevdp - I should have had mention that I've tried it with the latest addons (both master and 0.2.2), and also with the previous 0.2.1 version. All versions have this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants