question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Negative powers in Lomb-Scargle periodogram

See original GitHub issue

I’ve been using Astropy’s Lomb-Scargle periodogram for some time but just run into an unexpected scenario. I’ve attached a simple series of 19440 points of Gaussian noise (WN_1000_timeseries.txt), generated using 1000*numpy.random.randn(19440). When I compute the Lomb-Scargle periodogram, however, the second-last element has negative power. I was under the impression that this wasn’t possible but I appreciate that I may well be wrong, in which case this issue can be resolved by me understanding the LS periodogram better!

The timeseries is attached and this snippet of code produces the negative value for me.

import numpy as np
from astropy.stats import LombScargle

y = np.loadtxt('WN_1000_timeseries.txt')
f, p = LombScargle(np.arange(len(y), dtype=float), y, center_data=False).autopower(normalization='psd', samples_per_peak=1, nyquist_factor=1)
print(p[-2]) # -2493.908823582499

I’m running Python 3.7.2 on Fedora 29, with NumPy 1.16.0 and Astropy 3.1.2.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jakevdpcommented, Feb 25, 2019

The default computational approach is an approximation that speeds the algorithm from O[N^2] to O[N log N], at the expense of not producing exact results. For values close to zero, this approximation can lead to negative powers.

If exact results are important to you, you can specify the method argument of the autopower function to something other than "fast".

1reaction
jakevdpcommented, Feb 26, 2019

For what it’s worth, I don’t think 1% inaccuracies at high frequencies are worth worrying about. In practice, the signal at such frequencies is so dominated by aliasing effects that a 1% inaccuracy is not going to make any substantive difference in the interpretation of periodograms.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding the Lomb–Scargle Periodogram - IOPscience
The Lomb–Scargle periodogram is a method that allows efficient computation of a Fourier-like power spectrum estimator from such unevenly sampled data, ...
Read more >
Lomb-Scargle Periodograms
The Lomb-Scargle periodogram fits a sinusoidal model to the data at each frequency, with a larger power reflecting a better fit. With this...
Read more >
Introduction To The Lomb-Scargle Periodogram (Lecture III)
LSSTC DSFP Session 13 Introduction to the Lomb-Scargle Periodogram. ... The Periodogram for Power Spectrum Estimation. Barry Van Veen.
Read more >
Application of the Lomb-Scargle Periodogram to ... - NCBI
This paper examines the effect of common preprocessing methods on the Lomb–Scargle power spectral density estimate using both real and synthetic ...
Read more >
Significance of periodogram peaks and a pulsation mode ...
Equivalently, a power value PX(ω) > z0 has probability 1 −p0 of being due to pure noise alone. This test is primitive and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found