-
Notifications
You must be signed in to change notification settings - Fork 144
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
Implement Lomb-Scargle Versions of Fourier algorithms for various products #689
Comments
The Lomb-Scargle periodogram is a widely used method for analyzing unevenly sampled time series data. It is particularly useful in astronomy, where observations may not be taken at regular intervals due to the orbital motion of telescopes or other factors. One possible project for implementing Lomb-Scargle versions of Fourier algorithms would be to adapt existing Fourier-based algorithms in various scientific products to use Lomb-Scargle periodograms instead. This would involve developing new code or modifying existing code to use Lomb-Scargle periodograms as a substitute for traditional Fourier methods. Some examples of scientific products that could benefit from Lomb-Scargle versions of Fourier algorithms include: Signal processing tools: Many signal processing tools use Fourier analysis to extract features from signals. By implementing Lomb-Scargle versions of these algorithms, these tools could be extended to handle unevenly sampled data. Astronomy software: As mentioned earlier, astronomy is a field where unevenly sampled data is common. By implementing Lomb-Scargle versions of Fourier algorithms in astronomy software packages, researchers could more easily analyze astronomical time series data. Machine learning libraries: Machine learning algorithms often require regular time series data as input. By developing Lomb-Scargle versions of Fourier algorithms for use in machine learning libraries, researchers could more easily analyze unevenly sampled time series data. Overall, implementing Lomb-Scargle versions of Fourier algorithms in various scientific products could greatly expand the capabilities of these tools and make them more useful for analyzing real-world data. |
Here's an example implementation of the Lomb-Scargle periodogram algorithm in Python:
''' Here, t and y are the time and flux values of the light curve, respectively, and freq is an array of frequency values at which to compute the Lomb-Scargle periodogram. The function returns an array of periodogram values corresponding to each frequency value. Note that this implementation assumes evenly spaced time values. To handle unevenly spaced time values, you would need to compute the Lomb-Scargle periodogram using a more general algorithm that accounts for the time spacing of the data. There are several Python packages that implement such algorithms, such as AstroML's LombScargle class and the gatspy.periodic.LombScargle class in the gatspy package. |
@dhuppenkothen would be happy to contribute for your organization ! |
Hi @ranjan2829 Thank you for your contribution! This is great start! We are indeed mainly interested in the LSP for unevenly sampled data. For this project, we'd like to explore whether we can reuse existing implementations for example in For now, if you're interested in contribution, I'd suggest to take a look at the issues labelled |
Hi! It sounds like an exciting project, and I'm glad to hear that my contribution was a good start. I understand that the project is more involved than initially suggested and that you have specific requirements for the implementation, such as normalizing the LSP and following the existing class structure. Reusing existing implementations, such as those in astropy, could be a good starting point, but it may also require some modifications to fit your specific needs. I'm sure there are several ways to approach this project, and I hope that I can assist you in finding the best solution. Let me know if you have any questions or if there is anything else I can help you with! |
Hi @dhuppenkothen I have a simple implementation of the I generated a time series and got this result (was just exploring how the library works):
After a bit of research I implemented it for PSD like this (just a single line of implementation, however I was mainly learning about what PSD actually is :P):
I wanted some more information on where exactly I should start for this project on your github repo. Also, is there a preferred place (discord/slack etc) for me to continue the discussion? |
Hi @SethiAbhinav welcome! Our slack is indeed a good place to join the discussion! You can find the link on our documentation website (stingray.science). For this project, the main objective will be to implement a Lomb-Scargle periodogram in such a way that it matches the normalisations and the structure of existing Stingray functionality. This probably means implementing a new |
Got it, thank you! |
Hi @dhuppenkothen. I was writing my proposal and decided to give this code a try. This is just a rough code with fake data. I have written the code according to my proposal. Let me know how I can improve my logic in this code. How does this look?
|
Also related to: #368 |
please tell me about some good first issue |
1 similar comment
please tell me about some good first issue |
Hello
|
Hi, @dhuppenkothen. Our team is trying to make power spectrum out of my data from Swift/XRT, which is an X-ray afterglow lightcurve from a long Gamma-ray Burst. Things went pretty well since we initially used Lomb-Scargle Periodogram (LSP) and Weighted Wavelet Z-transform (WWZ) to make power spectrum and dynamical power spectrum. Then we try to use Stingray to do the same work, but we are stucked this time. Whenever we make power spectrum using Powerspectrum.from_lightcurve as https://docs.stingray.science/index.html has shown, 'AssertionError: No GTIs are equal to or longer than segment_size' will be received. I have read as much discussion between you and others around this issue as I can find, and I suspect this error occurs import numpy as np
import matplotlib.pyplot as plt
from stingray import Lightcurve
from stingray import Powerspectrum
data=np.loadtxt("data.txt")
t=data[:,0]#first column in 'data.txt' is time series (units:s)
y=data[:,1]#second column in 'data.txt' is count rate (units:erg/cm^2/s)
#the 3 & 4 column will not be used in this work
gti_1=[[93.66592081,102.21053878],[110.4575,517.4115]]#the XRT is not working between 101.924742938783s & 110.37s
#we take the beginning and the end of gti_1 by -/+ dt/2
lc=Lightcurve(t,y,gti=gti_1)
lc.plot(marker = 'k',labels=('Time', "Flux"))
plt.loglog()
plt.show()
ps = Powerspectrum.from_lightcurve(lc, norm="leahy")#here is where the very error occurs
print(ps) |
@Oliver-Graz indeed, Stingray has very limited support for unbinned data, and only for the multi-taper periodogram: https://docs.stingray.science/notebooks/Multitaper/multitaper_example.html#Time-series-with-uneven-temporal-sampling:-Multitaper-Lomb-Scargle |
@matteobachetti thank you very much for your valuable reply. I have just made a simple test on our data using multi-taper periodogram, and got result similar to what we've got from our own Lomb-Scargle Periodogram code, which makes me feel at ease a little. Just for curious, is there another way to make PSD out of the unevenly-binned data (like the data I've sent in my last comment ) using Stingray (I mean, a Stingray method without using Lomb-Scargle) ? Looking forward to your next reply! |
@Oliver-Graz not at the moment, but @pupperemeritus is working on it (#737) and we should have something ready in the next release (by the end of the summer). |
@matteobachetti , thank you for your help, I will keep on focusing on the project you mentioned, best wishes. |
Resolved by #737 |
Including the PSD, the Crossspectrum and the Dynamical Powerspectrum. This is also related to #533.
The text was updated successfully, but these errors were encountered: