stingray icon indicating copy to clipboard operation
stingray copied to clipboard

Crossspectrum.power only returning real component

Open scotthgn opened this issue 3 years ago • 5 comments

Hi,

I'm having an issue where the Crossspectrum object is only returning the real part of the CS, while I would quite like to also see the imaginary part. Looking at the source code it would seem that passing 'none' to norm should retain the full complex number, however on my version (1.0) this is not the case - still only receiving the real part.

Code to re-produce:

import numpy as np from stingray import Lightcurve, Crossspectrum

#Generating mock light-curves dt = 0.5 ts = np.arange(0, 200, 0.5)

l1 = 80 * np.sin(np.pi*ts/10) + 100 l2 = 20 * np.sin(np.pi*ts/10 + np.pi/2) + 10

l1_noise = np.random.poisson(l1 * dt) l2_noise = np.random.poisson(l2 * dt)

lc1 = Lightcurve(ts, l1_noise, skip_checks=True, dt=dt) lc2 = Lightcurve(ts, l2_noise, skip_checks=True, dt=dt)

cs_s = Crossspectrum(lc1, lc2, norm='none') print(cs_s.power.imag)

I think that some option in Crossspectrum to return the full complex number would be nice :)

Cheers, Scott

scotthgn avatar Mar 04 '22 10:03 scotthgn

@scotthgn thanks for the Issue. The way to get the full powers is specifying power_type="all":

cs_s = Crossspectrum(lc1, lc2, norm='none', power_type="all")

I realize this can be misleading, since the cross spectrum is a complex quantity, and indeed when you create the cross spectrum with the new interface (Crossspectrum.from_lightcurve(lc1, lc2, norm='none')) the default is to have the full complex information.

@dhuppenkothen We use power_type="all" by default in the new methods, but I did not change the default behavior in the legacy interface, for API compatibility issues. This, however, can be misleading, as in this Issue. Should we change the default behavior? It should not be a major disruption for anyone, finding that the powers are suddenly complex in the cross spectrum.

matteobachetti avatar Mar 04 '22 13:03 matteobachetti

Ah, yes that works!! Thank you @matteobachetti !

scotthgn avatar Mar 04 '22 13:03 scotthgn

@scotthgn Glad it worked! @dhuppenkothen I'll leave this open, to remind ourselves to discuss this issue and make a decision before 1.0 is out

matteobachetti avatar Mar 04 '22 14:03 matteobachetti

@matteobachetti @dhuppenkothen Decision made?

abigailStev avatar Mar 26 '22 23:03 abigailStev

My vote is to leave the default as-is but note it more in the docstrings.

abigailStev avatar Mar 26 '22 23:03 abigailStev

I think this has been resolved some time ago. For lags etc., which is the default use of cross spectra, we needed the complex powers, so eventually we decided for power_type="all" as default.

matteobachetti avatar Jan 08 '24 13:01 matteobachetti