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

ENH: Fast Lomb-Scargle Periodogram #17384

Open
jerabaul29 opened this issue Nov 10, 2022 · 5 comments
Open

ENH: Fast Lomb-Scargle Periodogram #17384

jerabaul29 opened this issue Nov 10, 2022 · 5 comments
Labels
enhancement A new feature or improvement scipy.signal

Comments

@jerabaul29
Copy link

Is your feature request related to a problem? Please describe.

The current implementation of the Lomb-Scargle Periodogram available in scipy has a number of issues / quirks; according to https://jakevdp.github.io/blog/2015/06/13/lomb-scargle-in-python/ :

The SciPy Lomb-Scargle periodogram is a C implementation of the naive O[N2] algorithm. The algorithm cannot account for noise in the data, and has some other quirks as well:

  • it requires you to center your data (by subtracting the mean) before computing the periodogram. If you do not, the results will be garbage.
  • it computes the unnormalized periodogram, which can be normalized manually as we'll see below.
  • it takes angular frequencies as the argument.

Describe the solution you'd like.

There are some faster and less quirky implementations available in other packages. However, these packages are often "subfield specific / tainted", and it would be great to have a high quality implementation that is shared across all fields and provided by scipy, rather than by a specific repo and package from the astonomy community, or the life science community, etc.

According to https://jakevdp.github.io/blog/2017/03/30/practical-lomb-scargle/ :

I'd recommend AstroPy's LombScargle in most cases today

and https://docs.astropy.org/en/stable/timeseries/lombscargle.html does look very good and detailed, with several algorithmic implementations (see "Summary" section there).

Would it be possible to pull the implementation(s) from there into scipy, and remove all astronomy specific aspects (should be none in the code itself, and come mostly from the documentation / blogs etc), to help diffuse these algorithms to a wider community?

The motivation for this is that, for many of us, scipy is the "default goto" solution, and if a method / functionality is available in scipy, we often use it and trust that it is good / high quality / as optimal as it should be and use it without digging further. Pulling the better implementations from astropy into scipy would allow people like me (and many others around me) who default to scipy when scipy provides a functionality, to have access to the better solution by default, without the need to use some hours to search the web and make their mind about what alternative solution is best.

Describe alternatives you've considered.

After some time making my mind, I think that https://docs.astropy.org/en/stable/timeseries/lombscargle.html is the best available, and I will use it for now.

Additional context (e.g. screenshots, GIFs)

No response

@jerabaul29 jerabaul29 added the enhancement A new feature or improvement label Nov 10, 2022
@jerabaul29
Copy link
Author

@jakevdp
Copy link
Member

jakevdp commented Nov 10, 2022

Thanks for raising this issue! Adding one small piece: here is how astropy wraps the scipy lombscargle function to add the various normalization schemes it supports: https://github.com/astropy/astropy/blob/main/astropy/timeseries/periodograms/lombscargle/implementations/scipy_impl.py

@jerabaul29
Copy link
Author

(and as an additional side note, https://github.com/astropy/astropy/tree/main/astropy/timeseries/periodograms/lombscargle/implementations is also where the faster implementations are available :) ).

@rkern
Copy link
Member

rkern commented Nov 10, 2022

I am broadly supportive of this, yes.

@jerabaul29
Copy link
Author

PS: and this could be a good opportunity for making sure that the API of the corresponding functionalities is as polished / easy to use / "logical" / similar to APIs for related functions such as "normal" FFT and IFFT provided by scipy as possible, to make life easier for the users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.signal
Projects
None yet
Development

No branches or pull requests

4 participants