Skip to content

SWE: L1B to L2 flag addition#3059

Merged
tech3371 merged 9 commits into
IMAP-Science-Operations-Center:devfrom
vineetbansal:vb/issue2950
Apr 29, 2026
Merged

SWE: L1B to L2 flag addition#3059
tech3371 merged 9 commits into
IMAP-Science-Operations-Center:devfrom
vineetbansal:vb/issue2950

Conversation

@vineetbansal
Copy link
Copy Markdown
Collaborator

Change Summary

Addresses issue #2950

Overview

Added a per-epoch SWE L1B quality flag indicating when in-flight calibration uses the final calibration interval (agreed to be set "far" into the future).

File changes

  • imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml - Added CDF metadata for the new inflight_cal_flags variable.
  • imap_processing/quality_flags.py - Added an SweL1bFlags enum for SWE L1B quality flags.
  • imap_processing/swe/l1b/swe_l1b.py - Returns per-epoch inflight calibration flags and adds them to the L1B dataset.

Testing

  • imap_processing/tests/swe/lut/imap_swe_l1b-in-flight-cal_20240510_20260716_v000.csv - Added an additional calibration time entry needed to test “last interval” behavior. The second to last entry encompasses acquisition time tested in existing tests, so no changes are needed to existing tests.
  • imap_processing/tests/swe/test_swe_l1b.py - Added a new unit test for the flag logic.
  • imap_processing/tests/swe/test_swe_l2.py - Added an assertion to an existing test that L1B epochs are not flagged for the L2 test data (since all tested data is outside the last cal interval)

@tech3371
Copy link
Copy Markdown
Contributor

@laspsandoval can you double check if I-ALiRT will be impacted by this change because I remember you were using this function for it too

@tech3371 tech3371 self-requested a review April 21, 2026 15:38
@tech3371 tech3371 added the Ins: SWE Related to the SWE instrument label Apr 21, 2026
Copy link
Copy Markdown
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

Adds a new SWE L1B per-epoch quality flag that indicates when in-flight calibration is being interpolated using the final (“far future”) calibration interval, with accompanying metadata and unit test updates.

Changes:

  • Introduces SweL1bFlags and adds inflight_cal_flags to the SWE L1B dataset as a per-epoch bitmask.
  • Updates SWE in-flight calibration application to return both corrected counts and per-epoch flags.
  • Extends SWE test LUT and adds/updates tests to exercise and assert the new flag behavior.

Reviewed changes

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

Show a summary per file
File Description
imap_processing/swe/l1b/swe_l1b.py Returns per-epoch in-flight cal flags from calibration application and writes them into the L1B dataset.
imap_processing/quality_flags.py Adds the SweL1bFlags IntFlag enum for SWE L1B.
imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml Adds CDF metadata for the new inflight_cal_flags variable.
imap_processing/tests/swe/lut/imap_swe_l1b-in-flight-cal_20240510_20260716_v000.csv Adds an additional calibration entry to enable “last interval” test coverage.
imap_processing/tests/swe/test_swe_l1b.py Updates existing calibration test for new return signature and adds a new unit test for flag logic.
imap_processing/tests/swe/test_swe_l2.py Adds an assertion that L1B epochs are not flagged for the L2 test data.
Comments suppressed due to low confidence (1)

imap_processing/tests/swe/test_swe_l1b.py:87

  • test_in_flight_calibration_factor still calls apply_in_flight_calibration() with counts shaped (N_ESA_STEPS, N_ANGLE_SECTORS, N_CEMS) and acquisition_time shaped (N_ESA_STEPS, N_ANGLE_SECTORS), but the function now returns per-epoch flags and documents an epoch axis. Updating this test to use an explicit single-epoch shape (e.g., add a leading epoch dimension and then index [0] for assertions) will keep it aligned with the updated API and avoid silently exercising the wrong flag-shape behavior.
    calibrated_count, _ = apply_in_flight_calibration(
        one_full_cycle_data,
        acquisition_time,
        in_flight_cal_files,
    )

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

Comment thread imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml Outdated
Comment thread imap_processing/swe/l1b/swe_l1b.py Outdated
Comment thread imap_processing/tests/swe/test_swe_l1b.py Outdated
Comment thread imap_processing/tests/swe/test_swe_l1b.py
Comment thread imap_processing/tests/swe/test_swe_l2.py
Copy link
Copy Markdown
Contributor

@tmplummer tmplummer left a comment

Choose a reason for hiding this comment

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

This looks good to me. Just two things worth checking on.

Comment thread imap_processing/quality_flags.py
Comment thread imap_processing/cdf/config/imap_swe_l2_variable_attrs.yaml Outdated
Copy link
Copy Markdown
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.

Updates need to happen so this doesn't break I-ALiRT code.

Comment thread imap_processing/swe/l1b/swe_l1b.py
Copy link
Copy Markdown
Contributor

@tmplummer tmplummer left a comment

Choose a reason for hiding this comment

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

I believe that @vineetbansal has responded to all review comments and addressed needed changes. Thanks!

Copy link
Copy Markdown
Contributor

@tech3371 tech3371 left a comment

Choose a reason for hiding this comment

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

Minor comments!

Comment thread imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml Outdated
Comment thread imap_processing/swe/l1b/swe_l1b.py Outdated
Comment thread imap_processing/quality_flags.py Outdated
@tech3371
Copy link
Copy Markdown
Contributor

@vineetbansal once this PR is merge, it will be good to check with Ruth or Jon if that's file contains what they expected. Let me or @jtniehof know if you need help.

My initial recommendation is to go to this line, https://github.com/IMAP-Science-Operations-Center/imap_processing/blob/dev/imap_processing/tests/swe/test_swe_l2.py#L449 and save L2 file to your local machine and sent to Ruth and Menlo for validation. That test will produce file with your changes in it. If they say it looks good, then we can push code to prod.

Comment thread imap_processing/cdf/config/imap_swe_l1b_variable_attrs.yaml Outdated
Comment thread imap_processing/cdf/config/imap_swe_l2_variable_attrs.yaml Outdated
Copy link
Copy Markdown
Contributor

@tech3371 tech3371 left a comment

Choose a reason for hiding this comment

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

minor rename of CDF variable based on discussion in email thread.

I like this idea and will make adding other flags easier in the future if we make variable name general.

FORMAT: I5
VALIDMAX: 65535

inflight_cal_flags:
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.

Suggested change
inflight_cal_flags:
data_quality_flags:

In-flight calibration quality flags. Bit 2 (LAST_CAL_INTERVAL): set if any
acquisition time in this cycle was extrapolated using the last two entries
in the calibration table.
FIELDNAM: In-Flight Calibration Flags
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.

Suggested change
FIELDNAM: In-Flight Calibration Flags
FIELDNAM: SWE data quality flags

Comment on lines +326 to +328
In-flight calibration quality flags. Bit 2 (LAST_CAL_INTERVAL): set if any
acquisition time in this cycle was extrapolated using the last two entries
in the calibration table.
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.

VAR_TYPE: support_data
DICT_KEY: SPASE>Support>SupportQuantity:Temporal,Qualifier:Array

inflight_cal_flags:
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.

same update here

Comment thread imap_processing/swe/l1b/swe_l1b.py Outdated
attrs=cdf_attrs.get_variable_attributes("esa_energy"),
)

science_dataset["inflight_cal_flags"] = xr.DataArray(
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.

Suggested change
science_dataset["inflight_cal_flags"] = xr.DataArray(
science_dataset["data_quality_flags"] = xr.DataArray(

@vineetbansal
Copy link
Copy Markdown
Collaborator Author

@tech3371 - I've made the changes. I'm using data_quality instead of data_quality_flags like you suggested because that's the name of an existing flag for codice that they're using, so I wanted to avoid making a new name. Hope that's okay - if you really want data_quality_flags let me know and I'll make the change.

Also added VAR_NOTES.

@tech3371
Copy link
Copy Markdown
Contributor

@tech3371 - I've made the changes. I'm using data_quality instead of data_quality_flags like you suggested because that's the name of an existing flag for codice that they're using, so I wanted to avoid making a new name. Hope that's okay - if you really want data_quality_flags let me know and I'll make the change.

Also added VAR_NOTES.

What you had is good. I was going to generic name too!

@tech3371 tech3371 merged commit f2be49d into IMAP-Science-Operations-Center:dev Apr 29, 2026
14 checks passed
maxinelasp pushed a commit to maxinelasp/imap_processing that referenced this pull request May 1, 2026
lacoak21 pushed a commit to lacoak21/imap_processing that referenced this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ins: SWE Related to the SWE instrument

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants