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

AL-850: adding tweakreg into stcal #267

Merged
merged 38 commits into from
Jul 25, 2024
Merged

Conversation

emolter
Copy link
Collaborator

@emolter emolter commented Jul 1, 2024

Resolves AL-850
Partially resolves JP-3668

This PR moves the majority of the tweakreg functionality from JWST into stcal, such that it can be used by both Roman and JWST without needing to be maintained in both places. This relates to the alignment between images and to an absolute source catalog only, but not to finding sources within images - this is handled differently by the two observatories, and is split into its own step for Roman.

Several WCS-related utilities have also been moved into alignment or modified therein. These should also eventually be called by JWST and Roman from stcal and removed in those repositories.

Checklist

  • added entry in CHANGES.rst (either in Bug Fixes or Changes to API)
  • updated relevant tests
  • updated relevant documentation
  • updated relevant milestone(s)
  • added relevant label(s)

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

Attention: Patch coverage is 85.60794% with 58 lines in your changes missing coverage. Please review.

Project coverage is 84.01%. Comparing base (5772579) to head (37ea975).
Report is 196 commits behind head on main.

Files with missing lines Patch % Lines
src/stcal/tweakreg/tweakreg.py 68.64% 37 Missing ⚠️
src/stcal/alignment/util.py 79.48% 8 Missing ⚠️
src/stcal/tweakreg/utils.py 63.15% 7 Missing ⚠️
src/stcal/tweakreg/astrometric_utils.py 90.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #267      +/-   ##
==========================================
+ Coverage   83.79%   84.01%   +0.22%     
==========================================
  Files          35       39       +4     
  Lines        6998     7345     +347     
==========================================
+ Hits         5864     6171     +307     
- Misses       1134     1174      +40     

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

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jul 8, 2024
@emolter emolter marked this pull request as ready for review July 11, 2024 15:16
@emolter emolter requested a review from a team as a code owner July 11, 2024 15:16
@emolter emolter requested review from braingram and mcara July 11, 2024 15:21
tox.ini Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
emolter and others added 2 commits July 19, 2024 11:35
Co-authored-by: Brett Graham <[email protected]>
Co-authored-by: Brett Graham <[email protected]>
Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this.

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

One more change. @emolter would you change the "unreleased" CHANGES.rst version to 1.8.0 for this PR?

@emolter
Copy link
Collaborator Author

emolter commented Jul 23, 2024

Do not merge at this time. somehow one of the last small changes broke s_region values in jwst. looking into it

@emolter
Copy link
Collaborator Author

emolter commented Jul 23, 2024

Long story short, isinstance(wcsinfo, Wcsinfo) returns False for JWST wcsinfo objects, of type ObjectNode. However, if I do

for attr in ["ra_ref", "dec_ref", ...]:
    assert hasattr(wcsinfo, attr)

all of the assert statements pass. The documentation and other snooping I've done seem to indicate that a runtime_checkable protocol should be basically shorthand for all the hasattr statements, so I'm pretty confused about what's happening there. My only idea (based on PEP 544) is that these ObjectNode objects are not initialized until called explicitly, but I don't know enough about those objects to be sure.

I tried updating all the JWST code to pass in wcsinfo as a dict in all cases (using wcsinfo.instance), but this leads to the issue that updating keywords in the wcsinfo object via e.g. update_s_region_keyword becomes cumbersome and IMO unnecessarily verbose (it becomes necessary to reassign all the values from the dict to the wcsinfo object after the fact).

While perhaps not perfect, changing back to if not isinstance(wcsinfo, dict): achieves the desired behavior. While technically the not would make possible passing any other type through, the type hint (still using the custom Wcsinfo protocol but no longer runtime checkable) specifies what attributes a wcsinfo object needs to have for these routines to run properly. Let me know if that solution sounds ok to you @braingram.

edit: still please do not merge until fully tested with jwst regtests

@emolter
Copy link
Collaborator Author

emolter commented Jul 24, 2024

Ok, all the regression tests for the JWST repo are now passing. It may be prudent to wait for more approvals of that PR, just in case changes are requested that require updating the stcal side for some reason. Other than that, this is ready to merge. @zacharyburnett what is the status of the romancal release - is it now safe to merge into stcal? @braingram are you happy with the changes now, and if so, can you remove the "changes requested" status?

mypy
types-requests
commands =
mypy src/stcal --config-file pyproject.toml
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice addition!

@@ -71,6 +71,9 @@ def _create_wcs_and_datamodel(fiducial_world, shape, pscale):


class WcsInfo:
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

This object (and DataModel) isn't added by this PR but I think could be removed with the changes in this PR. I'm not suggesting that we remove these as part of this PR. I opened an issue to track their removal: #273

@braingram braingram self-requested a review July 25, 2024 15:00
Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

Thanks!

pyproject.toml Outdated Show resolved Hide resolved


def reproject(wcs1, wcs2):
def reproject(wcs1: gwcs.wcs.WCS, wcs2: gwcs.wcs.WCS) -> Callable:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this function needs to replicate what the jwst version does, which is the most general way. The use case that this is missing is passing sliced_wcs.SlicedLowLevelWCS object. It's a JWST use case, that was requested by external users. There are tests for this in jwst:
https://github.com/spacetelescope/jwst/blob/master/jwst/resample/tests/test_utils.py#L191
Were they not moved to stcal or am I not seeing them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@nden Thanks for the comment. I think the first link goes to something unrelated, unless I'm missing something. There are two reproject functions in jwst, one in assign_wcs.util and one in resample.resample_utils. The one in resample is not affected by this PR, and is the one that those tests cover.

In my opinion, consolidating these functions falls under the scope of this issue and does not need to be done here. But I can work on changing it if you like

Co-authored-by: Nadia Dencheva <[email protected]>
@emolter emolter merged commit 5fbabf6 into spacetelescope:main Jul 25, 2024
24 of 26 checks passed
@emolter emolter deleted the AL-850 branch July 25, 2024 20:04
Copy link
Collaborator

@mairanteodoro mairanteodoro left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks, @emolter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants