SWE: L1B to L2 flag addition#3059
Conversation
…last-interval interpolation was used for in-flight calibration of counts.
|
@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 |
There was a problem hiding this comment.
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
SweL1bFlagsand addsinflight_cal_flagsto 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.
tmplummer
left a comment
There was a problem hiding this comment.
This looks good to me. Just two things worth checking on.
laspsandoval
left a comment
There was a problem hiding this comment.
Updates need to happen so this doesn't break I-ALiRT code.
tmplummer
left a comment
There was a problem hiding this comment.
I believe that @vineetbansal has responded to all review comments and addressed needed changes. Thanks!
|
@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. |
tech3371
left a comment
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
| 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 |
There was a problem hiding this comment.
| FIELDNAM: In-Flight Calibration Flags | |
| FIELDNAM: SWE 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. |
There was a problem hiding this comment.
Vineet, can you update description and VAR_NOTES, similar to what I did for SWAPI, https://github.com/IMAP-Science-Operations-Center/imap_processing/blob/dev/imap_processing/cdf/config/imap_swapi_variable_attrs.yaml#L52.
| VAR_TYPE: support_data | ||
| DICT_KEY: SPASE>Support>SupportQuantity:Temporal,Qualifier:Array | ||
|
|
||
| inflight_cal_flags: |
| attrs=cdf_attrs.get_variable_attributes("esa_energy"), | ||
| ) | ||
|
|
||
| science_dataset["inflight_cal_flags"] = xr.DataArray( |
There was a problem hiding this comment.
| science_dataset["inflight_cal_flags"] = xr.DataArray( | |
| science_dataset["data_quality_flags"] = xr.DataArray( |
|
@tech3371 - I've made the changes. I'm using Also added |
What you had is good. I was going to generic name too! |
f2be49d
into
IMAP-Science-Operations-Center:dev
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 newinflight_cal_flagsvariable.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)