Skip to content

Fix fill_bad_time_intervals#968

Merged
matteobachetti merged 8 commits intomainfrom
better_gti_filling
Feb 27, 2026
Merged

Fix fill_bad_time_intervals#968
matteobachetti merged 8 commits intomainfrom
better_gti_filling

Conversation

@matteobachetti
Copy link
Member

As reported at Lorentz Center, this function had a few problems When multiple short BTIs were present, it often failed to measure a robust count rate. It did not reject events from the bad intervals before filling them, adding events to the existing ones and overestimating the number of counts. Also, it was very slow in problematic NICER datasets.

Filtered_lc_old

The new function:

  1. Eliminates sequences of very short GTI/BTIs, as those intervals are problematic anyway.
  2. Eliminates the existing counts from BTIs, avoiding duplication.
    The decrease of the number of BTIs is sufficient to greatly speed up the computation in the Spectral Timing tutorial.
    The result is below:

Filtered_lc_new

The green shows the filled event list, the black is the raw one. Notice how the intervals that were incorrectly filled in the old version (e.g. the large drop at time ~3320) are now marked as BTIs (a feature, not a bug; simply, a very bad time interval that should not be trusted). Also, when filled, the light curve has a slightly lower value than before, closer to the average count rate that should be considered the stable flux of the source.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes multiple issues with the fill_bad_time_intervals function that were reported at the Lorentz Center. The main problems addressed are:

  1. Failure to measure robust count rates when multiple short Bad Time Intervals (BTIs) were present
  2. Incorrect addition of events from bad intervals to existing ones, causing overestimation
  3. Very slow performance on problematic NICER datasets

Changes:

  • Added new eliminate_short_gtis function to remove sequences of very short GTIs that are problematic
  • Modified fill_bad_time_intervals to eliminate existing counts from BTIs before filling, and to skip sequences of short GTIs
  • Improved analyze_segments to use consistent even-sampling detection logic

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
stingray/gti.py Added eliminate_short_gtis function to filter out problematic short GTI sequences
stingray/base.py Fixed fill_bad_time_intervals to properly handle BTIs, updated buffer size calculation, added GTI filtering, sorted random events, changed BTI visualization, and improved analyze_segments even-sampling detection
stingray/tests/test_base.py Updated tests to use explicit max_length and buffer_size parameters
docs/changes/968.bugfix.rst Added changelog entry for the bug fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.18%. Comparing base (79b8f9b) to head (9b56019).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #968      +/-   ##
==========================================
- Coverage   96.21%   96.18%   -0.03%     
==========================================
  Files          48       48              
  Lines        9949     9987      +38     
==========================================
+ Hits         9572     9606      +34     
- Misses        377      381       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matteobachetti
Copy link
Member Author

Changes included here for inspection: StingraySoftware/notebooks#127

Copy link
Collaborator

@eleonorav89 eleonorav89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment on my side. Thanks for your work!

@matteobachetti matteobachetti added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 86b1681 Feb 27, 2026
15 of 17 checks passed
@matteobachetti matteobachetti deleted the better_gti_filling branch February 27, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants