AveragedCrossspectrum returns zeros when using simulated light curves with input_counts=False.
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
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
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from StingraySoftware/stingray
-
create_gti_mask drops valid points after empty GTIs and crashes with min_length > 0 and dtPossibly taken @Rohan-Dedhia claimed this 5 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
StingraySoftware/stingray#1044 ·
Maintainers usually reply within 3 days
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
StingraySoftware/stingray#1042 · 1 comment ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
StingraySoftware/stingray#1039 · 1 comment ·
Maintainers usually reply within 3 days
-
stingray: arbitrary code execution reading a pickle-format data product (read fmt=pickle) (CWE-502)May be free again @yash-8923 claimed this 11 days ago, and no pull request is open. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
StingraySoftware/stingray#1037 · 3 comments ·
Maintainers usually reply within 3 days
-
Difficulty 5/5 Over a week Newbie friendliness 32/100
StingraySoftware/stingray#925 · 13 comments · 1 reaction ·
Maintainers usually reply within 3 days
All issues in StingraySoftware/stingray
Similar issues
-
accepted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
future-agi/future-agi#6392 ·
Maintainers usually reply within 1 day
-
memmapped_arange ignores the start value and drops the last point above the memmap thresholdPossibly taken @prathameshfuke claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
StingraySoftware/HENDRICS#213 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
bot-triaged module: decompositions module: edge cases module: int overflow module: primTorch oncall: pt2 triage review
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day