Skip to content

Fix FITS bug for list-type metadata#748

Merged
melanieclarke merged 3 commits into
spacetelescope:mainfrom
melanieclarke:list_metadata
May 28, 2026
Merged

Fix FITS bug for list-type metadata#748
melanieclarke merged 3 commits into
spacetelescope:mainfrom
melanieclarke:list_metadata

Conversation

@melanieclarke

@melanieclarke melanieclarke commented May 27, 2026

Copy link
Copy Markdown
Contributor

Toward JP-4313

To produce accurate rate values, some multistripe modes will require explicit read times for all readout frames in each group. See #739 for the draft implementation to support this, which stores the read time values in a list of lists inside meta.exposure.read_times. This is similar to the meta.exposure.read_pattern metadata stored for Roman datamodels: https://github.com/spacetelescope/rad/blob/b7879d2c36bdac7006a57c9971b8ae8dbb157ee4/src/rad/resources/schemas/meta/exposure-1.2.0.yaml#L197

Using this draft implementation, I noticed that RampModels saved as FITS files with meta.exposure.read_times set generated many extra FITS extensions, mostly empty. I tracked it down to the _fits_item_recurse validator, which sets a sequence index whenever it encounters list-type attributes. This is appropriate for lists of objects, like slits or spectra, since this is how it knows to start a new extension version for a new slit or spectrum. It is not appropriate for list-type primary metadata: when encountered, the update to the sequence index makes any metadata defined later in the schema think it's supposed to go into a new primary header extension.

The fix here is to update the sequence index only if the list-type item contains an object. This works for the use case I need it for, and shouldn't break any other existing JWST schemas, but it may be fragile to other kinds of stored metadata. I'm open to alternate fixes if anyone can think of a more general one, or a better way to store the necessary metadata in #739.

Tasks

  • update or add relevant tests
  • update relevant docstrings and / or docs/ page
  • Does this PR change any API used downstream? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • run jwst regression tests with this branch installed ("git+https://github.com/<fork>/stdatamodels@<branch>")
news fragment change types...
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.misc.rst: infrastructure or miscellaneous change

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.71%. Comparing base (e99448e) to head (df8e130).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #748   +/-   ##
=======================================
  Coverage   90.70%   90.71%           
=======================================
  Files          99       99           
  Lines        4595     4597    +2     
=======================================
+ Hits         4168     4170    +2     
  Misses        427      427           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@melanieclarke

melanieclarke commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@melanieclarke melanieclarke marked this pull request as ready for review May 27, 2026 20:26
@melanieclarke melanieclarke requested a review from a team as a code owner May 27, 2026 20:26
Comment thread src/stdatamodels/fits_support.py Outdated
Co-authored-by: Brett Graham <brettgraham@gmail.com>

@braingram braingram left a comment

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.

Thanks for finding and fixing the bug!

@melanieclarke melanieclarke merged commit db6da31 into spacetelescope:main May 28, 2026
22 checks passed
@melanieclarke melanieclarke deleted the list_metadata branch May 28, 2026 12:46
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.

2 participants