StingraySoftware / stingray

Anything can happen in the next half hour (including spectral timing made easy)!
https://stingray.science/stingray
MIT License
172 stars 141 forks source link

NaN errors in the lag-energy spectrum #741

Closed matteolucchini1 closed 8 months ago

matteolucchini1 commented 1 year ago

By pure coincidence I am working on the same NICER data as the spectral/timing tutorial, so I thought I would try to replicate the results on the documentation but using my own event file produced with nicerl2 (https://www.dropbox.com/scl/fo/0j0or7wwioeagx0xmc3ig/h?rlkey=97vf5yd6g9lup70uuslge7jtm&dl=0 has both the event file and jupyter notebook I used).

The issue I'm having is that I am getting a few runtime warnings when computing the cross spectrum: RuntimeWarning: invalid value encountered in sqrt so I imagine some weird is happening with the real/imaginary parts of the cross spectrum. The result is that the error bars on the lag-energy spectrum from 0.1 to 1 Hz are NaN. Otherwise, I recover nearly identical results for the PSD, cross spectrum, lag frequency spectrum, coherence, and the lag energy spectrum at higher frequency.

mgullik commented 1 year ago

Hi @matteolucchini1, thank you for pointing this out. The problem is that the segment size is 10 seconds, so 0.1 Hz frequency is at the edge of the minimum frequency boundary. For example, if you try 0.101 Hz as the minimum frequency of your boundary, the errors on the lag are computed correctly.

We are going to fix this issue of the minimum frequency, but you can solve your issue by either choosing a 0.101 Hz boundary or using a longer segment size, for instance, 100 seconds.

matteolucchini1 commented 1 year ago

Hi @mgullik ,

That makes sense, thanks! In that case you also should change the documentation though, it also uses 10s segments and a minimum frequency of 0.1 Hz.

vedant-z commented 1 year ago

@mgullik May I help in fixing documentation like @matteolucchini1 suggested? I was looking for a starter issue to start contributing to Stingray.

mgullik commented 1 year ago

Hi @vedant-z, surely you can help fix this tutorial. You can start changing the segment size to either 50 or 100 and check that the results are similar. If you feel you want to contribute more, you can also compute the raw coherence and intrinsic coherence which are not in the tutorial now.