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

JP-3686: Allow tweakreg to parse skycoord objects in absolute refcat #333

Merged
merged 4 commits into from
Jan 27, 2025

Conversation

emolter
Copy link
Collaborator

@emolter emolter commented Jan 21, 2025

Resolves JP-3686

Closes spacetelescope/jwst#8639

This PR allows the tweakreg step to parse absolute reference catalogs that resemble the output from the JWST source_catalog step. That step reports absolute RA, DEC in columns called sky_centroid.ra and sky_centroid.dec which are parsed by into an astropy Table as a single column containing a SkyCoord. This PR adds the functionality to re-cast this into RA/DEC columns as expected by tweakwcs.align_wcs.

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 regression tests with this branch installed ("git+https://github.com/<fork>/stcal@<branch>")
news fragment change types...
  • changes/<PR#>.apichange.rst: change to public API
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.general.rst: infrastructure or miscellaneous change

@emolter emolter requested a review from mcara January 21, 2025 22:49
@emolter
Copy link
Collaborator Author

emolter commented Jan 21, 2025

@mcara this isn't ready for formal review yet, but I'm wondering whether you'd like this change (or a version of it) in tweakwcs instead, or if here is the best place for it in your opinion.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.99%. Comparing base (35726e9) to head (8cdc19b).
Report is 5 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #333       +/-   ##
===========================================
+ Coverage   29.57%   86.99%   +57.41%     
===========================================
  Files          36       49       +13     
  Lines        7949     9012     +1063     
===========================================
+ Hits         2351     7840     +5489     
+ Misses       5598     1172     -4426     

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

@emolter
Copy link
Collaborator Author

emolter commented Jan 22, 2025

Regression tests for jwst started here: https://github.com/spacetelescope/RegressionTests/actions/runs/12911371129

Regression tests for romancal started here: https://github.com/spacetelescope/RegressionTests/actions/runs/12911410864

Failing downstream unit tests for romancal appear to be unrelated.

@emolter emolter marked this pull request as ready for review January 22, 2025 15:23
@emolter emolter requested a review from a team as a code owner January 22, 2025 15:23
permits the use of catalogs directly from the jwst source_catalog step.
No action is taken if the catalog already contains RA and DEC columns.
"""
cols = [name.lower() for name in catalog.colnames]
Copy link
Member

Choose a reason for hiding this comment

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

Can a table contain RA, rA, Ra, and ra columns at the same time? If "Yes", then I think this code should be enhanced and throw an exception if there are multiple instances of ra in cols list. While it may never happen, we must catch something like this.

Copy link
Member

Choose a reason for hiding this comment

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

Or, maybe implement a logic like: if RA and DEC are present - use those, if not try ra and dec, if not use lower() and try again...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good suggestion, this is changed in the most recent version. I think it's best for the step to fail if it sees e.g. RA and ra, so that the user doesn't accidentally get unexpected results from the wrong column.

cols = [name.lower() for name in catalog.colnames]
if ("ra" in cols) and ("dec" in cols):
if "sky_centroid" in cols:
msg = ("Catalog contains both (RA, DEC) and sky_centroid. "
Copy link
Member

Choose a reason for hiding this comment

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

is it contains both (RA, DEC) or maybe contains both (ra, dEc)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the error message a bit, let me know if you are ok with the change

@mcara
Copy link
Member

mcara commented Jan 22, 2025

@mcara this isn't ready for formal review yet, but I'm wondering whether you'd like this change (or a version of it) in tweakwcs instead, or if here is the best place for it in your opinion.

I prefer to keep things simple. It is documented what tweakwcs expects and supporting various column names only complicates things. Obviously JWST source_catalog step was not designed with reusability of those catalogs (by tweakreg). I wonder if that could be changed instead of the tweakreg step. In any case, I think any changes should go to stcal and/or individual pipelines.

@emolter
Copy link
Collaborator Author

emolter commented Jan 22, 2025

I prefer to keep things simple. It is documented what tweakwcs expects and supporting various column names only complicates things. Obviously JWST source_catalog step was not designed with reusability of those catalogs (by tweakreg). I wonder if that could be changed instead of the tweakreg step. In any case, I think any changes should go to stcal and/or individual pipelines.

In that case, I think this is the best place for it. I think changing the output format of the source catalog step would be more disruptive, e.g., if users have already written workflows that ingest this information. Changing the columns in the output to source catalog would also make it less Astropy-integrated, which isn't necessarily desired either.

This is a special case and should be the only "custom" format we need to support.

@mcara
Copy link
Member

mcara commented Jan 22, 2025

Another suggestion for rare cases such as this and maybe setting sky background, etc. is to have jwst/tools or something like that with scripts or functions that can be called and rename table columns or set sky background on a list of files, etc.

@emolter emolter requested a review from tapastro January 27, 2025 15:51
Copy link
Collaborator

@tapastro tapastro 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 - happy to see our steps work together more coherently.

@emolter emolter merged commit c9a45dd into spacetelescope:main Jan 27, 2025
26 checks passed
@emolter emolter deleted the JP-3686 branch January 27, 2025 16:57
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.

Make source_catalog output compatible with tweakreg
4 participants