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

Fix a bug in NDData constructor where WCS was not validated correctly #11985

Merged
merged 4 commits into from Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion astropy/nddata/ccddata.py
Expand Up @@ -224,7 +224,7 @@ def wcs(self):

@wcs.setter
def wcs(self, value):
if not isinstance(value, WCS):
if value is not None and not isinstance(value, WCS):
raise TypeError("the wcs must be a WCS instance.")
self._wcs = value

Expand Down
3 changes: 2 additions & 1 deletion astropy/nddata/nddata.py
Expand Up @@ -227,7 +227,8 @@ def __init__(self, data, uncertainty=None, mask=None, wcs=None,
# Store the attributes
self._data = data
self.mask = mask
self._wcs = wcs
self._wcs = None
self.wcs = wcs
self.meta = meta # TODO: Make this call the setter sometime
self._unit = unit
# Call the setter for uncertainty to further check the uncertainty
Expand Down
7 changes: 7 additions & 0 deletions astropy/nddata/tests/test_nddata.py
Expand Up @@ -518,3 +518,10 @@ def test_nddata_wcs_setter_with_low_level_wcs():
ndd.wcs = low_level

assert isinstance(ndd.wcs, BaseHighLevelWCS)


def test_nddata_init_with_low_level_wcs():
wcs = WCS()
low_level = SlicedLowLevelWCS(wcs, 5)
ndd = NDData(np.ones((5, 5)), wcs=low_level)
assert isinstance(ndd.wcs, BaseHighLevelWCS)
2 changes: 2 additions & 0 deletions docs/changes/nddata/11985.bugfix.rst
@@ -0,0 +1,2 @@
Ensure that the ``wcs=`` argument to ``NDData`` is always parsed into a high
level WCS object.