Skip to content

Commit

Permalink
Merge pull request #101 from bmorris3/nddata-coords-bugfix
Browse files Browse the repository at this point in the history
Loosen check on coordinate class for NDData translator to accept subclasses
  • Loading branch information
dhomeier authored Aug 1, 2024
2 parents d6961bf + a2bfe9a commit 43f0315
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion glue_astronomy/translators/nddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def to_object(self, data_or_subset, attribute=None):

if isinstance(data.coords, (WCS, BaseHighLevelWCS, SpectralCoordinates)):
wcs = data.coords
elif type(data.coords) is Coordinates or data.coords is None:
elif isinstance(data.coords, Coordinates) or data.coords is None:
wcs = None
else:
raise TypeError('data.coords should be an instance of Coordinates or WCS')
Expand Down
16 changes: 15 additions & 1 deletion glue_astronomy/translators/tests/test_nddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from glue.core import Data, DataCollection
from glue.core.component import Component
from glue.core.coordinates import Coordinates
from glue.core.coordinates import Coordinates, IdentityCoordinates

WCS_CELESTIAL = WCS(naxis=2)
WCS_CELESTIAL.wcs.ctype = ['RA---TAN', 'DEC--TAN']
Expand Down Expand Up @@ -222,3 +222,17 @@ def test_meta_round_trip():
assert len(image_new.meta) == 2
assert image_new.meta['BUNIT'] == 'Jy/beam'
assert image_new.meta['some_variable'] == 10


def test_other_coords():
coords = IdentityCoordinates(n_dim=2)

flux = [[2, 3], [4, 5]] * u.Jy
ndd = NDDataArray(data=flux)

data_collection = DataCollection()

data_collection['image'] = ndd
data_collection['image'].coords = coords
round_trip_ndd = data_collection['image'].get_object(cls=NDDataArray)
assert round_trip_ndd.shape == (2, 2)

0 comments on commit 43f0315

Please sign in to comment.