From c7c6800d8261402042d33010cfebfd67f8ec0c02 Mon Sep 17 00:00:00 2001 From: Rage Lopez Date: Thu, 11 Jun 2026 08:52:41 -0500 Subject: [PATCH 1/2] Fix AveragedCrossspectrum for countrate light curves --- docs/changes/977.bugfix.rst | 1 + stingray/crossspectrum.py | 4 ++-- stingray/tests/test_crossspectrum.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 docs/changes/977.bugfix.rst diff --git a/docs/changes/977.bugfix.rst b/docs/changes/977.bugfix.rst new file mode 100644 index 000000000..e869c3270 --- /dev/null +++ b/docs/changes/977.bugfix.rst @@ -0,0 +1 @@ +Fixed averaged cross spectra for light curves initialized with ``input_counts=False``. diff --git a/stingray/crossspectrum.py b/stingray/crossspectrum.py index 2e96f574e..16d4f0a3a 100644 --- a/stingray/crossspectrum.py +++ b/stingray/crossspectrum.py @@ -3068,12 +3068,12 @@ def crossspectrum_from_lightcurve( error_flux_attr = None if lc1.err_dist == "gauss": - error_flux_attr = "_counts_err" + error_flux_attr = "counts_err" return crossspectrum_from_timeseries( lc1, lc2, - "_counts", + "counts", error_flux_attr=error_flux_attr, segment_size=segment_size, norm=norm, diff --git a/stingray/tests/test_crossspectrum.py b/stingray/tests/test_crossspectrum.py index a47154ab7..1dcaeb5f8 100644 --- a/stingray/tests/test_crossspectrum.py +++ b/stingray/tests/test_crossspectrum.py @@ -1071,6 +1071,19 @@ def test_lc_keyword_deprecation(self): assert np.allclose(cs1.power, cs2.power) assert np.allclose(cs1.freq, cs2.freq) + def test_input_countrate_matches_pds_for_identical_lightcurves(self): + dt = 1 / 64 + time = np.arange(0.5 * dt, 64, dt) + countrate = 100 + 3 * np.sin(2 * np.pi * 4 * time) + 2 * np.cos(2 * np.pi * 7 * time) + err = np.zeros_like(countrate) + lc = Lightcurve(time, countrate, input_counts=False, err=err, err_dist="gauss", dt=dt) + + cs = AveragedCrossspectrum(lc, lc, segment_size=1, norm="frac", silent=True) + pds = AveragedPowerspectrum(lc, segment_size=1, norm="frac", silent=True) + + assert not np.allclose(cs.power, 0) + assert np.allclose(cs.power.real, pds.power) + def test_make_empty_crossspectrum(self): cs = AveragedCrossspectrum() assert cs.freq is None From c16b3f1c1ad566533814990a89e7f7e6483e0a81 Mon Sep 17 00:00:00 2001 From: Rage Lopez Date: Fri, 19 Jun 2026 20:12:18 -0500 Subject: [PATCH 2/2] Fix changelog fragment number --- docs/changes/{977.bugfix.rst => 978.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/changes/{977.bugfix.rst => 978.bugfix.rst} (100%) diff --git a/docs/changes/977.bugfix.rst b/docs/changes/978.bugfix.rst similarity index 100% rename from docs/changes/977.bugfix.rst rename to docs/changes/978.bugfix.rst