Skip to content

fix(mag): align L2 vector and quality metadata#3230

Open
davidt0x wants to merge 3 commits into
IMAP-Science-Operations-Center:devfrom
davidt0x:fix/istp_mag_l2_metadata
Open

fix(mag): align L2 vector and quality metadata#3230
davidt0x wants to merge 3 commits into
IMAP-Science-Operations-Center:devfrom
davidt0x:fix/istp_mag_l2_metadata

Conversation

@davidt0x
Copy link
Copy Markdown
Collaborator

Summary

Fix MAG L2 vector and quality metadata so the written CDF metadata matches the serialized variable types.

This PR is one small part of the broader ISTP / metadata cleanup tracked in issue #2577. Within that larger effort, this branch addresses the remaining MAG L2 metadata mismatches that were still showing up in the written normal-rate products.

Scope:

  • imap_mag_l2_norm-srf
  • shared MAG L2 vector metadata used by the other frame variants as well

Why

During the broader file-level metadata cleanup under #2577, two MAG-specific issues remained:

  1. the shared MAG vector attribute template still inherited unrealistic defaults, which caused SPDF width / range problems on b_srf
  2. quality_flags and quality_bitmask were assigned the wrong attribute templates in MAG L2 dataset generation

The underlying science values were not the problem here. The issue was that the metadata applied to the written CDF variables did not correctly describe the product semantics and serialized types.

What Changed

Fix shared MAG vector metadata

Update the shared MAG L2 vector attribute template so the written metadata matches the floating-point magnetic-field vectors that are actually emitted.

Changes:

  • keep CDF_FLOAT
  • keep floating FILLVAL = -1.0e31
  • set:
    • FORMAT = F13.5
    • VALIDMIN = -1.0e5
    • VALIDMAX = 1.0e5

This flows through the shared vector attrs used by:

  • b_srf
  • b_gse
  • b_gsm
  • b_rtn
  • b_dsrf

Fix quality metadata mapping

In MAG L2 dataset generation, swap the attr-template assignment so:

  • quality_flags uses the qf attrs
  • quality_bitmask uses the qf_bitmask attrs

This keeps:

  • variable names unchanged
  • data values unchanged

and only corrects the metadata applied to the written outputs.

Testing

Extended the written-CDF MAG regression coverage to verify:

  • representative MAG vector vars are written as CDF_FLOAT
  • the vector FILLVAL, FORMAT, VALIDMIN, and VALIDMAX match the updated metadata
  • quality_flags and quality_bitmask keep their values but now carry the correct written CDF attrs

Validated locally with:

pytest -q imap_processing/tests/mag/test_mag_l2.py
pre-commit run --files \
  imap_processing/cdf/config/imap_mag_l2_variable_attrs.yaml \
  imap_processing/mag/l2/mag_l2_data.py \
  imap_processing/tests/mag/test_mag_l2.py

FILLVAL: -1.0e31
FORMAT: F13.5
LABL_PTR_1: direction_label
VALIDMAX: 1.0e+5
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Are these good values? These vector VALIDMIN/MAX values were inferred from the existing MAG magnitude metadata, which already used VALIDMAX = 1.0e5 nT. The goal was to replace the inherited int64 defaults with physically meaningful float bounds and keep the vector metadata consistent with magnitude.

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.

1 participant