Skip to content

Commit

Permalink
Merge pull request #11985 from Cadair/nddata_wcs_init
Browse files Browse the repository at this point in the history
Fix a bug in NDData constructor where WCS was not validated correctly
  • Loading branch information
pllim committed Oct 20, 2021
2 parents d07b143 + effb97f commit 660bc14
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
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.

0 comments on commit 660bc14

Please sign in to comment.