Skip to content

Commit 16bc94f

Browse files
committed
handle appending "extensions" for NDData
1 parent 63523f8 commit 16bc94f

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

jdaviz/configs/imviz/helper.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
from astropy.io import fits
88
from astropy.utils import deprecated
9-
from astropy.nddata import NDData
109
from glue.core.link_helpers import LinkSame
1110

1211
from jdaviz.core.events import NewViewerMessage
@@ -193,19 +192,15 @@ def load_data(self, data, data_label=None, show_in_viewer=True, **kwargs):
193192

194193
self._load(data[i, :, :],
195194
format='Image',
196-
data_label=data_label+'[DATA]',
195+
data_label=data_label,
197196
extension=extensions)
198197
else:
199-
# extensions is None or a single extension
200-
if isinstance(data, NDData):
198+
# extensions is None or a single extension or data is NDData and importer will handle
199+
# appending the extension
200+
if isinstance(data, fits.hdu.image.ImageHDU):
201201
if data_label is not None and not data_label.endswith(']'):
202-
# NOTE: for backwards compatibility with previous load_data behavior
203-
# in .load() the data_label will not be appended
204-
data_label = data_label + '[DATA]'
205-
elif isinstance(data, fits.hdu.image.ImageHDU):
206-
if data_label is not None and not data_label.endswith(']'):
207-
# NOTE: for backwards compatibility with previous load_data behavior
208-
# in .load() the data_label will not be appended
202+
# NOTE: for backwards compatibility with previous load_data behavior.
203+
# In .load() the data_label will not be appended
209204
data_label = data_label + f'[{data.name},{data.ver}]'
210205

211206
self._load(data,

jdaviz/core/loaders/importers/image/image.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def _set_default_data_label(self, *args):
108108
# only show the prefix and append the extension later during import
109109
self.data_label_default = prefix
110110
self.data_label_is_prefix = True
111+
elif isinstance(self.input, NDData):
112+
# will append with [DATA]/[UNCERTAINTY]/[MASK] later
113+
# TODO: allow user to select extensions and include in same logic as HDUList
114+
self.data_label_default = prefix
115+
self.data_label_is_prefix = True
111116
else:
112117
self.data_label_default = prefix
113118
self.data_label_is_prefix = False
@@ -136,10 +141,22 @@ def __call__(self, show_in_viewer=True):
136141
# self.output is always a list of Data objects
137142
outputs = self.output
138143

139-
exts = self.extension.selected_name if self.input_hdulist else [None] * len(outputs)
140-
hdus = self.extension.selected_hdu if self.input_hdulist else [None] * len(outputs)
144+
if self.input_hdulist:
145+
exts = self.extension.selected_name
146+
hdus = self.extension.selected_hdu
147+
elif isinstance(self.input, NDData):
148+
exts = ['DATA', 'MASK', 'UNCERTAINTY'] # must match order in _nddata_to_glue_data
149+
hdus = [None] * len(outputs)
150+
else:
151+
exts = [None] * len(outputs)
152+
hdus = [None] * len(outputs)
141153

142154
for output, ext, hdu in zip(outputs, exts, hdus):
155+
if output is None:
156+
# needed for NDData where one of the "extensions" might
157+
# not be present. Remove this once users can select
158+
# which to import.
159+
continue
143160
if self.data_label_is_prefix:
144161
# If data_label is a prefix, we need to append the extension
145162
# to the data label.
@@ -226,6 +243,7 @@ def _nddata_to_glue_data(ndd):
226243
for attrib in ('data', 'mask', 'uncertainty'):
227244
arr = getattr(ndd, attrib)
228245
if arr is None:
246+
returned_data.append(None)
229247
continue
230248
comp_label = attrib.upper()
231249
cur_data = Data()

0 commit comments

Comments
 (0)