2742 hi goodtimes statistical filter 2#2763
Conversation
Move DE_CLOCK_TICK constants inot HiConstants
There was a problem hiding this comment.
Pull request overview
This pull request implements Statistical Filter 2 from the IMAP-Hi Algorithm Document Section 2.3.2.3, which detects and removes short-lived "pulses" of qualified counts that may be temporally correlated between sensors. These pulses are typically visible only at the highest few energy steps and are not caught by Statistical Filter 1.
Changes:
- Added
mark_statistical_filter_2function and helper functions (_find_event_clusters,_compute_bins_for_cluster) to detect event clusters and mark affected spin bins - Added Statistical Filter 2 tuning parameters (min_events, max_time_delta, bin_padding) to HiConstants in utils.py
- Refactored DE_CLOCK_TICK constants from hi_l1a.py to HiConstants class for centralized access
- Added comprehensive test coverage for cluster detection, bin computation with wrapping, and filter integration
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| imap_processing/hi/hi_goodtimes.py | Implements Statistical Filter 2 with vectorized cluster detection, bin computation with wraparound, and marking of affected spin bins across 8-spin sets |
| imap_processing/hi/utils.py | Adds Statistical Filter 2 constants and consolidates DE_CLOCK_TICK constants from hi_l1a.py |
| imap_processing/hi/hi_l1a.py | Refactors to use DE_CLOCK_TICK constants from HiConstants |
| imap_processing/hi/hi_l1b.py | Updates to use HiConstants.HALF_CLOCK_TICK_S instead of local constant |
| imap_processing/hi/hi_l1c.py | Updates to use HiConstants clock tick constants instead of importing from hi_l1a |
| imap_processing/tests/hi/test_hi_l1c.py | Updates tests to use HiConstants.DE_CLOCK_TICK_S |
| imap_processing/tests/hi/test_hi_goodtimes.py | Adds comprehensive tests for cluster detection, bin computation, and filter integration including edge cases like boundary wrapping |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| List of (start_idx, end_idx) tuples marking cluster boundaries | ||
| in the input array. Indices are inclusive. | ||
| """ | ||
| if len(event_times) < min_events: |
There was a problem hiding this comment.
Isnt this a duplicate of lines 1697 and 1698?
|
|
||
| # Find transitions: +1 = start of group, -1 = end of group | ||
| diff = np.diff(padded.astype(int)) | ||
| starts = np.flatnonzero(diff == 1) |
There was a problem hiding this comment.
why do you need flatnonzero? Isnt diff 1d?
There was a problem hiding this comment.
flatnonzero returns the array of indices directly instead of a tuple of array of indices. So, it avoids having to add the [0] on the end to index the first returned element.
| bin_padding=2, | ||
| ) | ||
|
|
||
| cull_flags = goodtimes_for_filter2["cull_flags"].sel(met=1000.0).values |
There was a problem hiding this comment.
is it worth checking that the last bins arent flagged as well?
6044bf1
into
IMAP-Science-Operations-Center:dev
Change Summary
Summary
Implements Statistical Filter 2 from the IMAP-Hi Algorithm Document Section 2.3.2.3, which detects and removes short-lived "pulses" of qualified counts that may be temporally correlated between sensors.
Changes
hi_goodtimes.py (+250 lines)
mark_statistical_filter_2: Main filter function that:
_find_event_clusters: Vectorized helper that finds time clusters using:
_compute_bins_for_cluster: Computes spin bins to cull with:
utils.py (+29 lines)
Added to HiConstants:
hi_l1a.py, hi_l1b.py, hi_l1c.py, test_hi_l1c.py
test_hi_goodtimes.py (+465 lines)
Closes: #2742