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

Loosen check on coordinate class for NDData translator to accept subclasses #101

Merged
merged 2 commits into from
Aug 1, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)