Skip to content

Commit e59127b

Browse files
committed
Make handling of extra and global coords by NDCube.to_nddata more general.
And docstring fix.
1 parent 361f887 commit e59127b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ndcube/ndcube.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ def to_nddata(self,
15001500
Metadata object of new instance. Default is to use data of this instance.
15011501
psf: Any, optional
15021502
PSF object of new instance. Default is to use data of this instance.
1503-
extra_coords: `ndcubeextra_coords.ExtraCoordsABC`, optional
1503+
extra_coords: `ndcube.extra_coords.ExtraCoordsABC`, optional
15041504
Extra coords object of new instance. Default is to use data of this instance.
15051505
global_coords: `ndcube.global_coords.GlobalCoordsABC`, optional
15061506
WCS object of new instance. Default is to use data of this instance.
@@ -1540,14 +1540,13 @@ def to_nddata(self,
15401540
"psf": psf,
15411541
"extra_coords": extra_coords,
15421542
"global_coords": global_coords}
1543+
extra_coords = self._extra_coords if user_kwargs["extra_coords"] is COPY else None
1544+
global_coords = self._global_coords if user_kwargs["global_coords"] is COPY else None
15431545
user_kwargs = {key: value for key, value in user_kwargs.items() if value is not COPY}
15441546
user_kwargs.update(kwargs)
15451547
all_kwargs = {key.strip("_"): value for key, value in self.__dict__.items()}
15461548
all_kwargs.update(user_kwargs)
15471549
extra_coords, global_coords = None, None
1548-
if nddata_type is NDCube:
1549-
extra_coords = all_kwargs.pop("extra_coords")
1550-
global_coords = all_kwargs.pop("global_coords")
15511550
# Inspect call signature of new_nddata class and
15521551
# remove unsupported items from new_kwargs.
15531552
nddata_sig = inspect.signature(nddata_type).parameters.keys()
@@ -1557,11 +1556,12 @@ def to_nddata(self,
15571556
del all_kwargs[key]
15581557
# Construct and return new instance.
15591558
new_nddata = nddata_type(**all_kwargs)
1560-
if extra_coords:
1561-
extra_coords._ndcube = new_nddata
1562-
new_nddata._extra_coords = extra_coords
1563-
if global_coords:
1564-
new_nddata._global_coords = global_coords
1559+
if isinstance(new_nddata, NDCubeBase):
1560+
if extra_coords:
1561+
extra_coords._ndcube = new_nddata
1562+
new_nddata._extra_coords = extra_coords
1563+
if global_coords:
1564+
new_nddata._global_coords = global_coords
15651565
return new_nddata
15661566

15671567

0 commit comments

Comments
 (0)