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

Fixes to dynamical power spectrum + Dynamical Cross spectrum #779

Merged
merged 21 commits into from
Nov 16, 2023

Conversation

matteobachetti
Copy link
Member

@matteobachetti matteobachetti commented Oct 26, 2023

  • Improves performance and consistency when using events (uses the internals already tested in AveragePowerspectrum to create light curves dynamically for each segment, rather than allocating the full light curve on the spot)
  • Resolves a bug when rebinning in time (it relied on dt, which was calculated in a weird manner)
  • Makes tests a little more understandable, I hope

BONUS: added Dynamical Cross spectrum, because why not

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (68453c6) 96.17% compared to head (36c5c0c) 96.18%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #779      +/-   ##
==========================================
+ Coverage   96.17%   96.18%   +0.01%     
==========================================
  Files          43       43              
  Lines        7999     8020      +21     
==========================================
+ Hits         7693     7714      +21     
  Misses        306      306              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matteobachetti matteobachetti marked this pull request as draft October 26, 2023 14:30
@matteobachetti matteobachetti marked this pull request as ready for review October 26, 2023 19:16
@matteobachetti matteobachetti changed the title Fixes to dynamical power spectrum Fixes to dynamical power spectrum + Dynamical Cross spectrum Oct 30, 2023
Copy link
Collaborator

@mgullik mgullik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @matteobachetti,

it's great that you updated this tool for the spectral-timing analysis.

I was wondering if it's worth adding dt as a parameter in the docstring of DynamicalCrossspectrum, specifying that dt needs to be an input in the case data1 and data2 are two EventList objects

Before calling _make_mastrix should init call the cross_gtis function? Or are we assuming that the gtis of data1 and data2 are the same?
Maybe AveragedCrossspectrum calls cross_gtis already, right?

The rebin_time function is a bit confusing.
If I had to think of rebinning in time the dynamical cross-spectrum I would think of changing the segment_size and not the dt, but maybe it's just me. However, it needs to be clearer in the docstring that the rebin_time function changes the Nyquist frequency and not the time axis of the dynamical cross-spectrum.
Actually, looking at the code, I'm not sure the rebin_data does the correct job, right?

The tests look good, but I'll check them more carefully next round.

stingray/crossspectrum.py Outdated Show resolved Hide resolved
stingray/crossspectrum.py Outdated Show resolved Hide resolved
stingray/crossspectrum.py Outdated Show resolved Hide resolved
stingray/powerspectrum.py Show resolved Hide resolved
stingray/crossspectrum.py Show resolved Hide resolved
@matteobachetti
Copy link
Member Author

@mgullik yes, there is a confusion between two different meanings of dt (+segment_size), but rebin_time does what you say, not a rebinning of the light curve. I should have addressed your comments now, including renaming the input dt -> sample_time, which clears up at least part of the confusion.

Copy link
Collaborator

@mgullik mgullik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @matteobachetti,

the review is completed, I suggested one last change to the docstring of the rebin_time. Sorry, probably too picky there

One thing, since you were so thorough in implementing the DynamicalCrossspectrum I'm wondering why don't you implement an option to output a complex matrix with real and imaginary parts instead of the normalized squared absolute values of Fourier amplitudes? In this way, it's even possible to create a dynamic lag frequency spectrum (boom!) However, not something to hold this PR longer.

Another very small thing about the tests, I noticed is that you always run the tests on DynamicalCrossspectrum with the same lightcurves for data1 and data2. Does it make sense to test it with two different light curves?

stingray/crossspectrum.py Outdated Show resolved Hide resolved
@matteobachetti
Copy link
Member Author

As far as I can see, I'm not using the squared amplitudes anywhere, and indeed, the Dynamical Cross spectrum has complex values when you feed it with different light curves in the two channels. I added a test to show explicitly that

@matteobachetti matteobachetti added this pull request to the merge queue Nov 16, 2023
Merged via the queue into main with commit 424fa59 Nov 16, 2023
15 checks passed
@matteobachetti matteobachetti deleted the fix_dyn_spec branch November 16, 2023 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants