From 53563ff99953d93b9e1fec51f66cd8ee84522a2d Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Tue, 30 Jul 2024 17:35:59 -0400 Subject: [PATCH 1/2] loosen check on coordinate class for nddata translator --- glue_astronomy/translators/nddata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glue_astronomy/translators/nddata.py b/glue_astronomy/translators/nddata.py index fc7104c..6ff883e 100644 --- a/glue_astronomy/translators/nddata.py +++ b/glue_astronomy/translators/nddata.py @@ -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') From a2bfe9a90b41460be4409913fa22e70e3c2c69fe Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Wed, 31 Jul 2024 12:34:58 -0400 Subject: [PATCH 2/2] add test for nddata translation with non-WCS coords --- glue_astronomy/translators/tests/test_nddata.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/glue_astronomy/translators/tests/test_nddata.py b/glue_astronomy/translators/tests/test_nddata.py index e55a557..26a4dbc 100644 --- a/glue_astronomy/translators/tests/test_nddata.py +++ b/glue_astronomy/translators/tests/test_nddata.py @@ -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'] @@ -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)