-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow tweakreg to parse absolute reference catalogs with skycoord objects in them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import math | ||
import warnings | ||
from pathlib import Path | ||
|
@@ -253,14 +254,43 @@ def _parse_refcat(abs_refcat: str | Path, | |
) | ||
|
||
if Path(abs_refcat).is_file(): | ||
return Table.read(abs_refcat) | ||
return _parse_sky_centroid(Table.read(abs_refcat)) | ||
|
||
msg = (f"Invalid 'abs_refcat' value: {abs_refcat}. 'abs_refcat' must be " | ||
"a path to an existing file name or one of the supported " | ||
f"reference catalogs: {_SINGLE_GROUP_REFCAT_STR}.") | ||
raise ValueError(msg) | ||
|
||
|
||
def _parse_sky_centroid(catalog: Table) -> Table: | ||
"""Turn SkyCoord object into simple RA/DEC columns. | ||
|
||
The inclusion of SkyCoord objects via sky_centroid.ra and sky_centroid.dec | ||
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] | ||
if ("ra" in cols) and ("dec" in cols): | ||
if "sky_centroid" in cols: | ||
msg = ("Catalog contains both (RA, DEC) and sky_centroid. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"Ignoring sky_centroid.") | ||
warnings.warn(msg, stacklevel=2) | ||
catalog.remove_column("sky_centroid") | ||
return catalog | ||
if "sky_centroid" not in cols: | ||
msg = ("Absolute reference catalog contains neither RA, DEC " | ||
"nor sky_centroid.ra, sky_centroid.dec.") | ||
raise KeyError(msg) | ||
|
||
skycoord = catalog["sky_centroid"].to_table() | ||
|
||
catalog["ra"] = skycoord["ra"] | ||
catalog["dec"] = skycoord["dec"] | ||
catalog.remove_column("sky_centroid") | ||
|
||
return catalog | ||
|
||
|
||
def _is_wcs_correction_small(correctors, | ||
use2dhist=True, | ||
searchrad=2.0, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
, andra
columns at the same time? If "Yes", then I think this code should be enhanced and throw an exception if there are multiple instances ofra
incols
list. While it may never happen, we must catch something like this.There was a problem hiding this comment.
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
andDEC
are present - use those, if not tryra
anddec
, if not uselower()
and try again...There was a problem hiding this comment.
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
andra
, so that the user doesn't accidentally get unexpected results from the wrong column.