Skip to content

Hi L1B DE: carry last_spin_num into output and add BADSPIN ccsds_qf flag#2754

Merged
subagonsouth merged 7 commits intodevfrom
copilot/carry-last-spin-num-to-l1b
Feb 24, 2026
Merged

Hi L1B DE: carry last_spin_num into output and add BADSPIN ccsds_qf flag#2754
subagonsouth merged 7 commits intodevfrom
copilot/carry-last-spin-num-to-l1b

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

last_spin_num was being dropped from L1A→L1B DE processing, and there was no quality flag to signal packets containing events from invalid spins.

Changes Made

  • quality_flags.py: Added BADSPIN = ENAFlags.BADSPIN (bit 2, value 4) to ImapHiL1bDeFlags, reusing the existing shared ENAFlags.BADSPIN flag rather than a custom flag.
  • hi_l1b.py:
    • Removed last_spin_num from drop_vars — it now passes through to L1B with unchanged variable attributes.
    • de_ccsds_qf(): sets BADSPIN flag (bitwise OR) on any packet where spin_invalids != 0; check is placed before the early-return guard so it applies even when no valid direct events exist.
  • imap_hi_variable_attrs.yaml: Updated VAR_NOTES for hi_de_ccsds_qf to document both flags — Bit 0 (PACKET_FULL) and Bit 2 (BADSPIN).
  • test_hi_l1b.py: Added spin_invalids to existing test datasets; added two new test methods using np.testing.assert_array_equal; updated data_vars count assertions from 17 to 18.
Original prompt

This section details on the original issue you should resolve

<issue_title>Hi L1B DE - carry last_spin_num into L1B and add spin_invalid quality flag</issue_title>
<issue_description>### Algorithm Description:
Simplifying dependencies for goodtimes, I want to carry the L1A DE last_spin_num into L1B DE. I also want to add a ccsds_qf for invalid spin that uses the spin_invalids flag to populate the value.

Details:

  • Carry the last_spin_num into L1B DE. The variable attributes should be the same as in the L1A DE.
  • Add a new quality flag to the ImapHiL1bDeFlags in quality_flags.py named SPIN_INVALID. Set that flag in hi_l1b.py for any L1A DE packet that has a nonzero value in the spin_invalids variable.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…flag

Co-authored-by: subagonsouth <16110870+subagonsouth@users.noreply.github.com>
Copilot AI changed the title [WIP] Carry last_spin_num into L1B and add spin_invalid quality flag Hi L1B DE: carry last_spin_num into output and add SPIN_INVALID ccsds_qf flag Feb 23, 2026
Copilot AI requested a review from subagonsouth February 23, 2026 18:52
Comment on lines +770 to +772
assert result["ccsds_qf"].values[0] == 0
assert result["ccsds_qf"].values[1] == ImapHiL1bDeFlags.SPIN_INVALID
assert result["ccsds_qf"].values[2] == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert result["ccsds_qf"].values[0] == 0
assert result["ccsds_qf"].values[1] == ImapHiL1bDeFlags.SPIN_INVALID
assert result["ccsds_qf"].values[2] == 0
np.testing.assert_equal(result["ccsds_qf"].values, [0, ImapHiL1bDeFlags.SPIN_INVALID, 0])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 0c9b170.

Comment on lines +803 to +805
expected = ImapHiL1bDeFlags.PACKET_FULL | ImapHiL1bDeFlags.SPIN_INVALID
assert result["ccsds_qf"].values[0] == expected
assert result["ccsds_qf"].values[1] == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expected = ImapHiL1bDeFlags.PACKET_FULL | ImapHiL1bDeFlags.SPIN_INVALID
assert result["ccsds_qf"].values[0] == expected
assert result["ccsds_qf"].values[1] == 0
np.testing.assert_array_equal(
result["ccsds_qf"].values,
[ImapHiL1bDeFlags.PACKET_FULL | ImapHiL1bDeFlags.SPIN_INVALID, 0],
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 0c9b170.

Copy link
Contributor

@subagonsouth subagonsouth left a comment

Choose a reason for hiding this comment

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

@copilot please see my comments and fix the issues that I identified.

Co-authored-by: subagonsouth <16110870+subagonsouth@users.noreply.github.com>
Copy link
Contributor

@subagonsouth subagonsouth left a comment

Choose a reason for hiding this comment

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

@copilot, please evaluate if np.testing.assert_equal, or np.testing.assert_array_equal should be used and make both cases use the same.

Co-authored-by: subagonsouth <16110870+subagonsouth@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 23, 2026

@copilot, please evaluate if np.testing.assert_equal, or np.testing.assert_array_equal should be used and make both cases use the same.

Both cases now use np.testing.assert_array_equal consistently (b803706).

Copilot AI requested a review from subagonsouth February 23, 2026 19:05
@subagonsouth subagonsouth marked this pull request as ready for review February 23, 2026 19:07
@subagonsouth
Copy link
Contributor

pre-commit.ci autofix

Copy link
Contributor

@subagonsouth subagonsouth left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@laspsandoval laspsandoval left a comment

Choose a reason for hiding this comment

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

Looks good. A couple of things to think about.

@subagonsouth
Copy link
Contributor

@copilot, please make two changes based on reviews.

  • modify ImapHiL1bDeFlags to inherit from ENAFlags and use ENAFlags existing BADSPIN flag.
  • Update the VAR_NOTES attribute in imap_hi_variable_attrs.yaml to include the new flag description.

Co-authored-by: subagonsouth <16110870+subagonsouth@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 23, 2026

@copilot, please make two changes based on reviews.

  • modify ImapHiL1bDeFlags to inherit from ENAFlags and use ENAFlags existing BADSPIN flag.
  • Update the VAR_NOTES attribute in i...

Done in da732c2. ImapHiL1bDeFlags now uses BADSPIN = ENAFlags.BADSPIN (bit 2) following the same pattern as ImapHkUltraFlags and ImapLoFlags (direct inheritance is not possible in Python 3.12 for enums with existing members). The VAR_NOTES for hi_de_ccsds_qf in imap_hi_variable_attrs.yaml now includes the Bit 2 / BADSPIN description.

Copilot AI changed the title Hi L1B DE: carry last_spin_num into output and add SPIN_INVALID ccsds_qf flag Hi L1B DE: carry last_spin_num into output and add BADSPIN ccsds_qf flag Feb 23, 2026
Copilot AI requested a review from subagonsouth February 23, 2026 21:18
@subagonsouth
Copy link
Contributor

pre-commit.ci autofix

@subagonsouth subagonsouth merged commit 67cf8d8 into dev Feb 24, 2026
14 checks passed
@subagonsouth subagonsouth deleted the copilot/carry-last-spin-num-to-l1b branch February 24, 2026 16:33
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.

Hi L1B DE - carry last_spin_num into L1B and add spin_invalid quality flag

3 participants