Skip to content

Commit

Permalink
Merge pull request #58 from pllim/imviz-nddata-gwcs
Browse files Browse the repository at this point in the history
Return NDData for GWCS
  • Loading branch information
astrofrog authored Dec 7, 2021
2 parents 25d7711 + e54b08c commit 7f3229d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions glue_astronomy/translators/ccddata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from astropy.wcs import WCS
from astropy.nddata import CCDData
from astropy.wcs.wcsapi import BaseHighLevelWCS
from astropy.nddata import CCDData, NDData
from astropy import units as u

from glue.config import data_translator
Expand Down Expand Up @@ -37,8 +38,13 @@ def to_object(self, data_or_subset, attribute=None):
subset_state = None

if isinstance(data.coords, WCS):
has_fitswcs = True
wcs = data.coords
elif isinstance(data.coords, BaseHighLevelWCS):
has_fitswcs = False
wcs = data.coords
elif type(data.coords) is Coordinates or data.coords is None:
has_fitswcs = True # For backward compatibility
wcs = None
else:
raise TypeError('data.coords should be an instance of Coordinates or WCS')
Expand Down Expand Up @@ -73,4 +79,10 @@ def to_object(self, data_or_subset, attribute=None):

values = values * u.Unit(component.units)

return CCDData(values, mask=mask, wcs=wcs, meta=data.meta)
if has_fitswcs:
result = CCDData(values, mask=mask, wcs=wcs, meta=data.meta)
else:
# https://github.com/astropy/astropy/issues/11727
result = NDData(values, mask=mask, wcs=wcs, meta=data.meta)

return result

0 comments on commit 7f3229d

Please sign in to comment.