Skip to content

Hit l1a: Allow sectored counts calculation to process with dropped frames - #3590

Closed
lacoak21 wants to merge 4 commits into
IMAP-Science-Operations-Center:devfrom
lacoak21:hit_l1a_drop_incomplete_livetimes
Closed

lacoak21 wants to merge 4 commits into
IMAP-Science-Operations-Center:devfrom
lacoak21:hit_l1a_drop_incomplete_livetimes

Conversation

@lacoak21

@lacoak21 lacoak21 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Change Summary

closes #3578

Overview

HIT l1b sectored rates jobs failed on 20260606. This was due to a dropped frame. The l1a calculation correctly dropped the whole set but never handled the dropped livetime values. This then created a dimension error at l1b because we had 9 more livetime values (full set- 1 dropped frame).

Curent problem example:

Set 1: complete counts, complete livetime. Kept.
Set 2: one frame missing, so incomplete counts. Dropped (current behavior).
Set 3: complete counts, but its livetime comes from the 10 minutes when set 2 was transmitted, and one of those minutes is the lost frame leaving 9 of 10 livetime values.

To fix this, the HIT team desires the following outcome:

Set 1:      Keep
Set 2:      Each minute of sector data includes a separate element/energy and so, if a frame is missed, we would like to keep the other nine minutes and just drop the minute with the missed frame.
Set 3:      Multiplying the livetime by 10/9 (or more accurately 10/(10 - # of missed frames) is fine (scaling the livetime).

This was a pretty large change and touches a significant amount of l1a sectored counts code to fix only one date in the release range. I would like to check with them to see if they have a dropped packets problem and this fix does need to be added or maybe if they dont expect it to happen again we can skip this.

claude helped me catch these bugs and with some of the numpy vectorization. I wish I could say I did all of it!

File changes

Testing

Fixed old tests and added new tests to check dropped frame logic

@lacoak21
lacoak21 requested a balanced review from Copilot October 27, 2026 16:24
@lacoak21 lacoak21 self-assigned this Oct 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical issues can merge integration sets, produce incorrect livetime-based rates, and break L2 bin conversion, while incompatible test assertions and invalid fixtures remain.

5 open issues

Review effort: Balanced

# The set_ids would be [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1]
# A set can be incomplete if a frame was dropped so we can not just look for
# complete sets [0-9].
ids: np.ndarray = np.cumsum(np.diff(mod_10, prepend=0) < 0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a todo for this and sent an email to the HIT team trying to get more context about this very valid issue.

Comment thread imap_processing/hit/l1a/hit_l1a.py Resolved
Comment thread imap_processing/hit/l1a/hit_l1a.py Resolved
Comment on lines +343 to +345
# Sum livetime for each set and scale for missing frames
livetime_sum = np.bincount(livetime_set_ids, weights=livetime.values)
livetime_sum = livetime_sum * (10 / livetime_counts)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a smart way to handle the missing frames. Nice work!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a threshold for the HIT team where the livetime_counts would be too low to apply this scaling in a meaningful way? It might be worth double checking to make sure this will work if there's a case where 9 out of 10 frames are dropped/missing in the set

-------
np.ndarray
Indices in mod_vals where the complete pattern [0, 1, ..., 9] starts.
Set id for each frame in the dataset, starting at 0.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using set ids is a nice improvement

@lacoak21

lacoak21 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

This PR grew in scope by a lot. I didnt realize to the extent how much of l1a - l2 processing relies on complete sets of 10.
Sorry for the big PR!!

data_i = macropixel_dataset[var].values[species_i::10, energy_i]
transformed_dataset[var].values[:, energy_i] = data_i
species_i += 1
for var in species_variables:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@leowerneck, Veronica alerted me to the fact that you had just made this change to 10 min chunks so I added you as a reviewer for this code. Since the HIT team wants to process data with incomplete sets, this needed to change.

@lacoak21
lacoak21 force-pushed the hit_l1a_drop_incomplete_livetimes branch from aa2bb3f to 1c7ea6c Compare November 5, 2026 19:13
@lacoak21

Copy link
Copy Markdown
Contributor Author

After a conversation with Eric Christian we decided to table this.

Missing 10 minutes worth of data (for the set that has a missing frame) is not worth the effort and people may use the data not knowing that there was a dropped frame.

If anyone needs that data they can get it on their own from the l0 packet.

@lacoak21 lacoak21 closed this Nov 10, 2026
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.

BUG - Hit l1a. When incomplete sets are dropped, the corresponding livetime is not.

3 participants