AveragedCrossspectrum returns zeros when using simulated light curves with input_counts=False.

Open
#977 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@VrtxOmega is already working on this.

Since Jun 11, 2026.

  • #978 by @VrtxOmega — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
numpy, python
Domain
data

Research direction

Start with AveragedCrossspectrum and the warnings pointing to stingray/fourier.py:1800, then inspect the cross-spectrum path used when Lightcurve is created with input_counts=False. Add a regression test using the supplied identical simulated light curves and verify that the complex cross-power matches the powerspectrum instead of returning zeros.

Written by the indexing model from the issue text.

Description

bug help wanted
Description of the Bug

When I generate simulated light curves with arbitrary flux values (neither counts nor rate, and with zero errors), then convert to a Stingray light curve with input_counts=False, AveragedCrossspectrum returns zeros for the complex cross-power, while AveragedPowerspectrum for both light curves returns correct values of power. AveragedCrossspectrum works correctly if input_counts=True, but this is inconsistent with the nature of the simulated light curves (which are not integer valued counts/bin). This is problematic when using Stingray to analyse the results of simulated model light curves which are generally not in counts units.

Steps/Code to Replicate the Bug

import stingray
import numpy as np
from stingray import Lightcurve, AveragedPowerspectrum, AveragedCrossspectrum
from stingray.simulator import simulator

simulate light curve

sim = simulator.Simulator(N=2566464, mean=0.5, dt=1/64, rms=0.1)
lc = sim.simulate(1)

Cross identical light curves so the cs should equal the pds!

lc1_sr = Lightcurve(lc.time, lc.counts, input_counts=False, err=np.zeros_like(lc.counts), err_dist="gauss")
lc2_sr = Lightcurve(lc.time, lc.counts, input_counts=False, err=np.zeros_like(lc.counts), err_dist="gauss")
cs = AveragedCrossspectrum(lc1_sr, lc2_sr, segment_size=256)
print(cs.power)
pds1 = AveragedPowerspectrum(lc1_sr, segment_size=256)
pds2 = AveragedPowerspectrum(lc2_sr, segment_size=256)
print(pds1.power)
print(pds2.power)

lc1_sr = Lightcurve(lc.time, lc.counts, input_counts=True, err=np.zeros_like(lc.counts), err_dist="gauss")
lc2_sr = Lightcurve(lc.time, lc.counts, input_counts=True, err=np.zeros_like(lc.counts), err_dist="gauss")
cs = AveragedCrossspectrum(lc1_sr, lc2_sr, segment_size=256)
print(cs.power)
pds1 = AveragedPowerspectrum(lc1_sr, segment_size=256)
pds2 = AveragedPowerspectrum(lc2_sr, segment_size=256)
print(pds1.power)
print(pds2.power)

Expected Results

[2.13120629e-01+5.52870986e-19j 9.76108709e-02+1.86354329e-19j
6.76512062e-02+1.89344839e-19j ... 2.14848891e-05-5.64316284e-23j
1.88156560e-05+6.23546759e-24j 2.35543903e-05+1.20486477e-23j]
64it [00:00, 1474.14it/s]
64it [00:00, 1573.48it/s]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]
64it [00:00, 791.17it/s]
[2.13120629e-01+5.52870986e-19j 9.76108709e-02+1.86354329e-19j
6.76512062e-02+1.89344839e-19j ... 2.14848891e-05-5.64316284e-23j
1.88156560e-05+6.23546759e-24j 2.35543903e-05+1.20486477e-23j]
64it [00:00, 1618.21it/s]
64it [00:00, 1575.81it/s]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]

Actual Results

/Users/philuttley/opt/anaconda3/lib/python3.13/site-packages/stingray/utils.py:492: UserWarning: SIMON says: Stingray only uses poisson err_dist at the moment. All analysis in the light curve will assume Poisson errors. Sorry for the inconvenience.
warnings.warn("SIMON says: {0}".format(message), **kwargs)
64it [00:00, 317.28it/s]
/Users/philuttley/opt/anaconda3/lib/python3.13/site-packages/numba/np/ufunc/dufunc.py:288: RuntimeWarning: divide by zero encountered in _raw_coherence
return super().call(*args, **kws)
/Users/philuttley/opt/anaconda3/lib/python3.13/site-packages/stingray/fourier.py:1800: RuntimeWarning: invalid value encountered in divide
dphi = np.sqrt((1 - gsq) / (2 * gsq * n_ave))
[0.+0.j 0.+0.j 0.+0.j ... 0.+0.j 0.+0.j 0.+0.j]
64it [00:00, 1474.14it/s]
64it [00:00, 1573.48it/s]
/Users/philuttley/opt/anaconda3/lib/python3.13/site-packages/stingray/utils.py:492: UserWarning: SIMON says: Stingray only uses poisson err_dist at the moment. All analysis in the light curve will assume Poisson errors. Sorry for the inconvenience.
warnings.warn("SIMON says: {0}".format(message), **kwargs)
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]
64it [00:00, 791.17it/s]
/Users/philuttley/opt/anaconda3/lib/python3.13/site-packages/stingray/fourier.py:1800: RuntimeWarning: invalid value encountered in sqrt
dphi = np.sqrt((1 - gsq) / (2 * gsq * n_ave))
[2.13120629e-01+5.52870986e-19j 9.76108709e-02+1.86354329e-19j
6.76512062e-02+1.89344839e-19j ... 2.14848891e-05-5.64316284e-23j
1.88156560e-05+6.23546759e-24j 2.35543903e-05+1.20486477e-23j]
64it [00:00, 1618.21it/s]
64it [00:00, 1575.81it/s]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]
[2.13120629e-01 9.76108709e-02 6.76512062e-02 ... 2.14848891e-05
1.88156560e-05 2.35543903e-05]

Dominant language
Python
Stars
229
Forks
196
Avg merge
4d 12h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StingraySoftware/stingray

All issues in StingraySoftware/stingray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.