Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCAL-833 Recursively convert all meta attributes during model casting #352

Merged
merged 11 commits into from
Jun 3, 2024

Conversation

stscieisenhamer
Copy link
Collaborator

@stscieisenhamer stscieisenhamer commented May 23, 2024

Resolves RCAL-833

This PR addresses issues found while trying to convert TVAC raw/level 1 data into a RampModel.

The issue is that the meta update was using dict.update, which doesn't transcribe/copy all the attributes. This left attributes with TVAC tags, producing validation warnings when the RampModel is produced.

Solution is to recursively traverse the meta tree, equating/converting each item.

Checklist

stscieisenhamer and others added 6 commits May 21, 2024 10:48
The method, as written, was unused throughout the code base.
Since the DQInitStep code was in active use, and had just a few
modifications, just simply moved that code to the method.
This is needed to ensure tagged scalars get their
tags changed to the "more generic" tag.
@stscieisenhamer
Copy link
Collaborator Author

Attention Reviewers: This is one method; the other is presented in PR #353

This implementation is fixing the previously implemented way of creating the ramp node, update the node with the values from the input model, then create the RampModel from that node. The previous version of this code suffered conversion issues due to the whole of the meta tree was simply using dict.update, essentially not touching any of the items. The solution here does the recursive walk through the attributes, touching all items. Doing so found another special case involving lists/Lnodes.

The implementation in #353 does everything, but directly on the RampModel and not the Ramp stnode. #353 does solve the issue experienced. However, extra keys, such as filename and model_type also get modified. To rectify that, the meta update will also need to become recursive to filter out such keys.

@schlafly
Copy link
Collaborator

@PaulHuwe , can I ask you to take a look at these? Following a discussion with Jonathan, I think either of these are good. I have a vague, poorly defined preference for avoiding any code that knows about nodes, driven mostly by my not really understanding what these are good for, which would argue for #353. On the other hand, I haven't figured out where the existing code avoids updating model_type, so there is some hidden magic via that approach as well---I'm happy either way. Take a look and then we'll let Jonathan decide? Thanks!

Copy link
Collaborator

@PaulHuwe PaulHuwe left a comment

Choose a reason for hiding this comment

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

I prefer this version. Comments added.

if isinstance(model, cls):
return model
if not isinstance(model, (ScienceRawModel, TvacModel)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should RampModel be in this list to match the comments?

Also, I think FpsModel should be allowed in this function as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RampModel is implicitly checked for in the preceding statement. However, no issue with adding here also.

def test_rampmodel_from_science_raw(model_class):
"""Test creation of RampModel from raw science/tvac"""
model = utils.mk_datamodel(model_class)
ramp = datamodels.RampModel.from_science_raw(model)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a line where you set a value and confirm the set value is properly propagated?

@stscieisenhamer stscieisenhamer marked this pull request as ready for review May 31, 2024 02:58
@stscieisenhamer stscieisenhamer requested a review from a team as a code owner May 31, 2024 02:58
Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.55%. Comparing base (087a60d) to head (fbd184f).
Report is 42 commits behind head on main.

Files with missing lines Patch % Lines
src/roman_datamodels/datamodels/_datamodels.py 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #352      +/-   ##
==========================================
- Coverage   97.56%   97.55%   -0.01%     
==========================================
  Files          30       36       +6     
  Lines        2788     3349     +561     
==========================================
+ Hits         2720     3267     +547     
- Misses         68       82      +14     

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

@stscieisenhamer
Copy link
Collaborator Author

Regression attempt #1

Copy link
Collaborator

@PaulHuwe PaulHuwe 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
Collaborator

@ddavis-stsci ddavis-stsci left a comment

Choose a reason for hiding this comment

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

LGTM

@ddavis-stsci ddavis-stsci merged commit b23b8ed into spacetelescope:main Jun 3, 2024
14 of 16 checks passed
@nden nden added this to the 14Q4_B15 milestone Jul 19, 2024
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.

5 participants