create_gti_mask drops valid points after empty GTIs and crashes with min_length > 0 and dt
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with create_gti_mask and create_gti_mask_jit in stingray/gti.py, then compare their behavior with create_gti_mask_complete. Reproduce the listed cases, including empty GTIs, min_length with dt and safe_interval, and unsorted times; add regression tests for each discrepancy. Done means the Numba path matches the complete implementation for these cases and returns the expected mask and GTIs; pull request #1045 is already open against this issue.
Written by the indexing model from the issue text.
Description
Description of the Bug
create_gti_mask (with Numba enabled) has several bugs that cause silent data loss, crashes, and silent divergence from create_gti_mask_complete:
- Silent data loss across empty GTIs:
create_gti_mask_jitadvancesgti_el += 1at most once per timestamp (if i == 0 or t > gtis[gti_el, 1] or next_gti). Whentimeskips over an empty GTI, the first valid timestamp in the next populated GTI is silently dropped (False), whereascreate_gti_mask_completekeeps it (True). Similarly, hitting a GTI shorter thanmin_lengthexecutescontinuewithout checking the current timestamp against subsequent GTIs. TypeError/AxisErrorwhenmin_length > 0anddtis given:good = lengths >= np.max(min_length, dt)passesdtas theaxisargument ofnp.max. Passing a floatdtraisesTypeError, integerdt >= 1raisesAxisError, and an iterabledtraisesTypeError.safe_interval+min_lengthmismatch:min_lengthis checked beforesafe_intervalis subtracted, andcreate_gti_mask_jitreceivesmin_length - 2 * (1 + epsilon) * dteven thoughgtis_to_maskhas length(limmax - limmin) - (1 - 2 * epsilon) * dt. This lets GTIs shortened belowmin_lengthbysafe_intervalpass on the Numba path while failingcreate_gti_mask_complete.return_new_gtis=True& unsortedtime:- When no GTIs satisfy
min_length,create_gti_maskreturnsmaskalone instead of(mask, empty_gtis)even whenreturn_new_gtis=True. - When
timeends before trailing GTIs,create_gti_mask_jitstops early and omits valid trailing GTIs fromnew_gtis. - Unsorted
timeinputs fail silently in the Numba path while working increate_gti_mask_complete.
- When no GTIs satisfy
Steps/Code to Replicate the Bug
import numpy as np
from stingray.gti import create_gti_mask, create_gti_mask_complete
# 1. Silent data loss after an empty GTI (and Numba vs non-Numba divergence)
t = np.array([5.0, 45.0, 46.0])
gti = np.array([[0.0, 10.0], [20.0, 30.0], [40.0, 50.0]])
print(create_gti_mask(t, gti, dt=0.0)) # [ True False True]
print(create_gti_mask_complete(t, gti, dt=0.0)) # [ True True True]
# 2. Crash when passing dt with min_length > 0
create_gti_mask(np.array([1.0, 2.0, 3.0]), np.array([[0.0, 10.0]]), min_length=1, dt=0.5)
# TypeError: 'float' object cannot be interpreted as an integer
# 3. safe_interval + min_length divergence
t3 = np.array([1.5, 2.0])
g3 = np.array([[0.0, 3.5]])
print(create_gti_mask(t3, g3, safe_interval=1.0, min_length=2.0, return_new_gtis=True))
# (array([ True, True]), array([[1. , 2.5]])) # post-safe length is 1.5 < 2.0!
print(create_gti_mask_complete(t3, g3, safe_interval=1.0, min_length=2.0, return_new_gtis=True))
# [array([False, False]), array([], shape=(0, 2), dtype=float64)]
# 4. return_new_gtis omits trailing valid GTIs when time ends early
t4 = np.array([0.5, 1.5])
g4 = np.array([[0.0, 4.0], [10.0, 20.0]])
print(create_gti_mask(t4, g4, dt=0.0, return_new_gtis=True)[1]) # [[0., 4.]]
print(create_gti_mask_complete(t4, g4, dt=0.0, return_new_gtis=True)[1]) # [[0., 4.], [10., 20.]]
- 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
-
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
-
AveragedCrossspectrum returns zeros when using simulated light curves with input_counts=False.Possibly taken @VrtxOmega claimed this 176 days ago. Openbug help wanted
Difficulty 4/5 3-5 days Newbie friendliness 52/100
StingraySoftware/stingray#977 · 1 comment ·
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