-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Allow single inputs to find_optimal_celestial_wcs and add ability to specify HDU #344
Merged
astrofrog
merged 8 commits into
astropy:main
from
astrofrog:find_optimal_celestial_wcs_hdu
Mar 3, 2023
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ece1b05
Improve test coverage for input types for find_optimal_celestial_wcs …
astrofrog 1b62162
Updated minimum version of astropy
astrofrog ebe141a
Don't do exact comparison for header
astrofrog f91a6c6
Added support for APE 14 WCSes with array_shape defined
astrofrog ac23464
Refactor valid celestial inputs into a pytest fixture
astrofrog cb2729f
More test simplification with fixtures
astrofrog de5f9fa
Remove whitespace
astrofrog 702e76a
Removed extraneous elif and tidied params
astrofrog 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
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
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
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
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
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import numpy as np | ||
from astropy import units as u | ||
from astropy.coordinates import SkyCoord, frame_transform_graph | ||
from astropy.io.fits import Header | ||
from astropy.utils import isiterable | ||
from astropy.wcs import WCS | ||
from astropy.wcs.utils import ( | ||
celestial_frame_to_wcs, | ||
|
@@ -18,7 +20,13 @@ | |
|
||
|
||
def find_optimal_celestial_wcs( | ||
input_data, frame=None, auto_rotate=False, projection="TAN", resolution=None, reference=None | ||
input_data, | ||
hdu_in=None, | ||
frame=None, | ||
auto_rotate=False, | ||
projection="TAN", | ||
resolution=None, | ||
reference=None, | ||
): | ||
""" | ||
Given one or more images, return an optimal WCS projection object and | ||
|
@@ -44,7 +52,15 @@ def find_optimal_celestial_wcs( | |
* A tuple where the first element is a `~numpy.ndarray` and the | ||
second element is either a `~astropy.wcs.WCS` or a | ||
`~astropy.io.fits.Header` object | ||
* An `~astropy.nddata.NDData` object from which the ``.data`` and | ||
``.wcs`` attributes will be used as the input data. | ||
|
||
If only one input data needs to be provided, it is also possible to | ||
pass it in without including it in an iterable. | ||
Comment on lines
+58
to
+59
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 the added complexity really worth this? 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. Absolutely 😄 |
||
|
||
hdu_in : int or str, optional | ||
If ``input_data`` is a FITS file or an `~astropy.io.fits.HDUList` | ||
instance, specifies the HDU to use. | ||
frame : str or `~astropy.coordinates.BaseCoordinateFrame` | ||
The coordinate system for the final image (defaults to the frame of | ||
the first image specified) | ||
|
@@ -75,7 +91,25 @@ def find_optimal_celestial_wcs( | |
if isinstance(frame, str): | ||
frame = frame_transform_graph.lookup_name(frame)() | ||
|
||
input_shapes = [parse_input_shape(shape) for shape in input_data] | ||
# Determine whether an iterable of input values was given or a single | ||
# input data. | ||
|
||
if isinstance(input_data, str): | ||
# Handle this explicitly as isiterable(str) is True | ||
iterable = False | ||
elif isiterable(input_data): | ||
if len(input_data) == 2 and isinstance(input_data[1], (WCS, Header)): | ||
# Since 2-element tuples are valid single inputs we need to check for this | ||
iterable = False | ||
else: | ||
iterable = True | ||
else: | ||
iterable = False | ||
|
||
if iterable: | ||
input_shapes = [parse_input_shape(shape, hdu_in=hdu_in) for shape in input_data] | ||
else: | ||
input_shapes = [parse_input_shape(input_data, hdu_in=hdu_in)] | ||
|
||
# We start off by looping over images, checking that they are indeed | ||
# celestial images, and building up a list of all corners and all reference | ||
|
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
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,8 +1,19 @@ | ||
from astropy.io import fits | ||
from numpy.testing import assert_allclose | ||
|
||
|
||
def array_footprint_to_hdulist(array, footprint, header): | ||
hdulist = fits.HDUList() | ||
hdulist.append(fits.PrimaryHDU(array, header)) | ||
hdulist.append(fits.ImageHDU(footprint, header, name="footprint")) | ||
return hdulist | ||
|
||
|
||
def assert_header_allclose(header1, header2, **kwargs): | ||
assert sorted(header1) == sorted(header2) | ||
|
||
for key1, value1 in header1.items(): | ||
if isinstance(value1, str): | ||
assert value1 == header2[key1] | ||
else: | ||
assert_allclose(value1, header2[key1], **kwargs) |
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.
This is in this elif twice?
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.
Fixed