create_gti_mask drops valid points after empty GTIs and crashes with min_length > 0 and dt

Open
#1,044 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@Rohan-Dedhia is already working on this.

Since Nov 30, 2026.

  • #1045 by @Rohan-Dedhia — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
numpy, python
Domain
data

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:

  1. Silent data loss across empty GTIs: create_gti_mask_jit advances gti_el += 1 at most once per timestamp (if i == 0 or t > gtis[gti_el, 1] or next_gti). When time skips over an empty GTI, the first valid timestamp in the next populated GTI is silently dropped (False), whereas create_gti_mask_complete keeps it (True). Similarly, hitting a GTI shorter than min_length executes continue without checking the current timestamp against subsequent GTIs.
  2. TypeError / AxisError when min_length > 0 and dt is given: good = lengths >= np.max(min_length, dt) passes dt as the axis argument of np.max. Passing a float dt raises TypeError, integer dt >= 1 raises AxisError, and an iterable dt raises TypeError.
  3. safe_interval + min_length mismatch: min_length is checked before safe_interval is subtracted, and create_gti_mask_jit receives min_length - 2 * (1 + epsilon) * dt even though gtis_to_mask has length (limmax - limmin) - (1 - 2 * epsilon) * dt. This lets GTIs shortened below min_length by safe_interval pass on the Numba path while failing create_gti_mask_complete.
  4. return_new_gtis=True & unsorted time:
    • When no GTIs satisfy min_length, create_gti_mask returns mask alone instead of (mask, empty_gtis) even when return_new_gtis=True.
    • When time ends before trailing GTIs, create_gti_mask_jit stops early and omits valid trailing GTIs from new_gtis.
    • Unsorted time inputs fail silently in the Numba path while working in create_gti_mask_complete.
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

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.