MAG L1D index error fix#3159
Open
maxinelasp wants to merge 3 commits intoIMAP-Science-Operations-Center:devfrom
Open
MAG L1D index error fix#3159maxinelasp wants to merge 3 commits intoIMAP-Science-Operations-Center:devfrom
maxinelasp wants to merge 3 commits intoIMAP-Science-Operations-Center:devfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a rare IndexError in MAG L1D spin-offset computation by skipping over chunk windows that unexpectedly contain no epochs, preventing downstream indexing into an empty chunk_epoch.
Changes:
- Add an empty-chunk guard in
calculate_spin_offsets()to skip processing whenchunk_epochis empty. - Emit a warning when an empty chunk is encountered to aid debugging/traceability.
Comments suppressed due to low confidence (1)
imap_processing/mag/l1d/mag_l1d_data.py:542
np.nanmeanis computed before the validity checks; when a chunk is all-NaN this still triggers RuntimeWarnings ("Mean of empty slice") even though the values are later discarded/replaced. Consider moving thenanmeancalls to after the valid-count/size checks (or guarding them) to avoid noisy warnings and unnecessary work.
# Check if more than half of the chunk data is NaN before processing
x_valid_count: int = int(np.sum(~np.isnan(chunk_vectors[:, 0])))
y_valid_count: int = int(np.sum(~np.isnan(chunk_vectors[:, 1])))
total_points = len(chunk_vectors)
# average the x and y axes (z is fixed, as the spin axis)
avg_x = np.nanmean(chunk_vectors[:, 0])
avg_y = np.nanmean(chunk_vectors[:, 1])
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
Addresses #2832. Just adds a check in the chunk generation to see if it's empty before continuing. I think the chunk can very rarely be empty in some cases if the spin inputs aren't what we expected. If the chunk is empty, it should be fine to skip past it and continue on. We already skip past chunks with too many NaNs, so it's an expected use case.
Overview
Just added a simple if and continue flow if the expected epoch list is empty.
File changes