Skip to content

Commit b1213ff

Browse files
committed
pass extension through _load
1 parent 039f192 commit b1213ff

2 files changed

Lines changed: 22 additions & 83 deletions

File tree

jdaviz/configs/imviz/helper.py

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from astropy.utils import deprecated
88
from glue.core.link_helpers import LinkSame
99

10-
from jdaviz.core.events import SnackbarMessage, NewViewerMessage
10+
from jdaviz.core.events import NewViewerMessage
1111
from jdaviz.core.helpers import ImageConfigHelper
12-
from jdaviz.utils import (data_has_valid_wcs, get_wcs_only_layer_labels,
13-
get_reference_image_data, _wcs_only_label)
12+
from jdaviz.utils import (get_wcs_only_layer_labels,
13+
get_reference_image_data)
1414

1515
__all__ = ['Imviz']
1616

@@ -146,8 +146,6 @@ def load_data(self, data, data_label=None, show_in_viewer=True, **kwargs):
146146
"""
147147
self.app.state.dev_loaders = True
148148

149-
prev_data_labels = self.app.data_collection.labels
150-
151149
extensions = None if 'ext' not in kwargs else kwargs['ext']
152150

153151
if 'gwcs_to_fits_sip' not in kwargs and 'Orientation' in self.plugins.keys():
@@ -195,81 +193,12 @@ def load_data(self, data, data_label=None, show_in_viewer=True, **kwargs):
195193
if data_label:
196194
kw['data_label'] = data_label
197195

198-
self.loaders['object'].object = data[i, :, :]
199-
if data_label:
200-
self.loaders['object'].importer.data_label.value = data_label
201-
if extensions is not None:
202-
# Slight hack to load extensions using the ext kwarg
203-
self.loaders['object']._obj.importer.extension.selected = [f'{enum + 1}: {name}' for enum, name in enumerate(extensions)] # noqa
204-
self.loaders['object'].importer()
205-
# data_label = data_label
206-
# self._load(data[i, :, :], data_label=data_label, ext=extensions)
207-
# self.app.load_data(data[i, :, :], parser_reference='imviz-data-parser', **kw)
196+
self._load(data[i, :, :], data_label=data_label, extension=extensions)
208197

209198
else:
210199
if data_label:
211200
kwargs['data_label'] = data_label
212-
self.loaders['object'].object = data
213-
if data_label:
214-
self.loaders['object'].importer.data_label.value = data_label
215-
if extensions is not None:
216-
self.loaders['object']._obj.importer.extension.selected = [f'{enum+1}: {name}'
217-
for enum, name in
218-
enumerate(extensions)]
219-
self.loaders['object'].importer()
220-
# self._load(data, data_label=data_label, ext=extensions)
221-
# self.app.load_data(data, parser_reference='imviz-data-parser', **kwargs)
222-
return
223-
# find the current label(s) - TODO: replace this by calling default label functionality
224-
# above instead of having to refind it
225-
applied_labels = []
226-
applied_visible = []
227-
layer_is_wcs_only = []
228-
layer_has_wcs = []
229-
for data in self.app.data_collection:
230-
label = data.label
231-
if label not in prev_data_labels:
232-
applied_labels.append(label)
233-
applied_visible.append(True)
234-
layer_is_wcs_only.append(data.meta.get(_wcs_only_label, False))
235-
layer_has_wcs.append(data_has_valid_wcs(data))
236-
237-
if show_in_viewer is True:
238-
show_in_viewer = f"{self.app.config}-0"
239-
240-
if show_in_viewer:
241-
linked_by_wcs = self.app._align_by == 'wcs'
242-
if linked_by_wcs:
243-
for applied_label, visible, is_wcs_only, has_wcs in zip(
244-
applied_labels, applied_visible, layer_is_wcs_only, layer_has_wcs
245-
):
246-
if not is_wcs_only and linked_by_wcs and not has_wcs:
247-
self.app.hub.broadcast(SnackbarMessage(
248-
f"'{applied_label}' will be added to the data collection but not "
249-
f"the viewer '{show_in_viewer}', since data are aligned by WCS, but "
250-
f"'{applied_label}' has no WCS.",
251-
color="warning", timeout=8000, sender=self)
252-
)
253-
254-
if self._in_batch_load and show_in_viewer:
255-
for applied_label, is_wcs_only in zip(applied_labels, layer_is_wcs_only):
256-
if not is_wcs_only:
257-
self._delayed_show_in_viewer_labels[applied_label] = show_in_viewer
258-
259-
else:
260-
if 'Orientation' not in self.plugins.keys():
261-
# otherwise plugin will handle linking automatically with DataCollectionAddMessage
262-
self.link_data(align_by='wcs')
263-
264-
# One input might load into multiple Data objects.
265-
# NOTE: If the batch_load context manager was used, it will
266-
# handle that logic instead.
267-
if show_in_viewer:
268-
for applied_label, visible, has_wcs in zip(
269-
applied_labels, applied_visible, layer_has_wcs
270-
):
271-
if (has_wcs and linked_by_wcs) or not linked_by_wcs:
272-
self.app.add_data_to_viewer(show_in_viewer, applied_label, visible=visible)
201+
self._load(data, data_label=data_label, extension=extensions)
273202

274203
def link_data(self, align_by='pixels', wcs_fallback_scheme=None, wcs_fast_approximation=True):
275204
"""(Re)link loaded data in Imviz with the desired link type.

jdaviz/core/user_api.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,23 @@ def __setattr__(self, attr, value):
6868
if isinstance(exp_obj, UnitSelectPluginComponent) and isinstance(value, u.Unit):
6969
value = value.to_string()
7070
elif isinstance(exp_obj, SelectFileExtensionComponent):
71-
if isinstance(value, int):
72-
# allow setting by index
73-
value = exp_obj.choices[exp_obj.indices.index(value)]
74-
elif isinstance(value, str):
75-
# allow setting without index
76-
if value not in exp_obj.choices:
77-
value = exp_obj.choices[exp_obj.names.index(value)]
71+
def to_choice_single(value):
72+
if isinstance(value, int):
73+
# allow setting by index
74+
return exp_obj.choices[value]
75+
elif isinstance(value, str):
76+
# allow setting without index
77+
if value not in exp_obj.choices:
78+
return exp_obj.choices[exp_obj.names.index(value)]
79+
return value
80+
else:
81+
raise ValueError(f"Invalid value type: {type(value)}")
82+
if isinstance(value, (list, tuple)):
83+
# allow setting by list of indices or names
84+
value = [to_choice_single(v) for v in value]
85+
else:
86+
# allow setting by single index or name
87+
value = to_choice_single(value)
7888
exp_obj.selected = value
7989
return
8090
elif isinstance(exp_obj, AddResults):

0 commit comments

Comments
 (0)