spacetelescope / jdaviz

JWST astronomical data analysis tools in the Jupyter platform
https://jdaviz.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
142 stars 74 forks source link

[BUG] Cubeviz: Can't load data from unit conversion plugin in the Cube viewer #646

Closed PatrickOgle closed 2 years ago

PatrickOgle commented 3 years ago

After running the unit conversion plugin on a cube dataset, the unit-converted data shows up with the proper units in the spectrum viewer. However, it throws an error if selected in one of the cube viewers.

To Reproduce Steps to reproduce the behavior:

  1. Load a MIRI MRS data cube in Cubeviz
  2. Use the unit conversion plugin to convert from 'm' to 'micron'
  3. Go to the data dropdown for one of the cube viewers
  4. deselect the data that is displayed
  5. Select the unit-converted copy of the data

Expected behavior Converted data should be displayed in the cube viewer

Screenshots UnitConverted_cubeviewer_bug Converted data don't show up in upper left viewer and the following traceback appears:

IndexError                                Traceback (most recent call last)
~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/image/state.py in _reference_data_changed(self, *args)
    178                     # so we do this here manually.
--> 179                     self._on_xatt_world_change()
    180                     self._on_yatt_world_change()

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/utils/matplotlib.py in wrapper(*args, **kwargs)
    159         if len(DEFER_DRAW_BACKENDS) == 0:
--> 160             return func(*args, **kwargs)
    161 

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/image/state.py in _on_xatt_world_change(self, *args)
    269                     if self.x_att_world == world_ids[-1]:
--> 270                         self.y_att_world = world_ids[-2]
    271                     else:

IndexError: list index out of range

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
~/miniconda3/envs/science/lib/python3.8/site-packages/ipyvue/VueTemplateWidget.py in _handle_event(self, _, content, buffers)
     55                 getattr(self, 'vue_' + event)(data, buffers)
     56             else:
---> 57                 getattr(self, 'vue_' + event)(data)
     58 
     59 

~/miniconda3/envs/science/lib/python3.8/site-packages/jdaviz/app.py in vue_data_item_selected(self, event)
    894                 lambda id: id != item_id, viewer_item['selected_data_items']))
    895 
--> 896         self._update_selected_data_items(viewer_id, selected_items)
    897 
    898     def vue_save_figure(self, event):

~/miniconda3/envs/science/lib/python3.8/site-packages/jdaviz/app.py in _update_selected_data_items(self, viewer_id, selected_items)
    933             [data] = [x for x in self.data_collection if x.label == label]
    934 
--> 935             viewer.add_data(data)
    936 
    937             add_data_message = AddDataMessage(data, viewer,

~/miniconda3/envs/science/lib/python3.8/site-packages/glue_jupyter/view.py in add_data(self, data, color, alpha, **layer_state)
    115         data = validate_data_argument(self._data, data)
    116 
--> 117         result = super().add_data(data)
    118 
    119         if not result:

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/common/viewer.py in add_data(self, data)
    205         # Create layer artist and add to container. First check whether any
    206         # plugins want to make a custom layer artist.
--> 207         layer = get_layer_artist_from_registry(data, self) or self.get_data_layer_artist(data)
    208 
    209         if layer is None:

~/miniconda3/envs/science/lib/python3.8/site-packages/glue_jupyter/bqplot/image/viewer.py in get_data_layer_artist(self, layer, layer_state)
     67         else:
     68             cls = BqplotImageLayerArtist
---> 69         return self.get_layer_artist(cls, layer=layer, layer_state=layer_state)
     70 
     71     def get_subset_layer_artist(self, layer=None, layer_state=None):

~/miniconda3/envs/science/lib/python3.8/site-packages/glue_jupyter/view.py in get_layer_artist(self, cls, layer, layer_state)
    140 
    141     def get_layer_artist(self, cls, layer=None, layer_state=None):
--> 142         return cls(self, self.state, layer=layer, layer_state=layer_state)
    143 
    144     def initialize_layer_options(self):

~/miniconda3/envs/science/lib/python3.8/site-packages/glue_jupyter/bqplot/scatter/layer_artist.py in __init__(self, view, viewer_state, layer_state, layer)
     26     def __init__(self, view, viewer_state, layer_state=None, layer=None):
     27 
---> 28         super(BqplotScatterLayerArtist, self).__init__(viewer_state,
     29                                                        layer_state=layer_state, layer=layer)
     30 

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/common/layer_artist.py in __init__(self, viewer_state, layer_state, layer)
     27 
     28         if self.state not in self._viewer_state.layers:
---> 29             self._viewer_state.layers.append(self.state)
     30 
     31         self.zorder = self.state.zorder

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/containers.py in append(self, value)
     50     def append(self, value):
     51         super(CallbackList, self).append(self._prepare_add(value))
---> 52         self.notify_all()
     53 
     54     def extend(self, iterable):

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/containers.py in notify_all(self, *args, **kwargs)
     43     def notify_all(self, *args, **kwargs):
     44         for callback in self.callbacks:
---> 45             callback(*args, **kwargs)
     46 
     47     def __repr__(self):

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/containers.py in __call__(self, *args, **kwargs)
    164 
    165     def __call__(self, *args, **kwargs):
--> 166         self.function(*args, **kwargs)
    167 
    168 

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/containers.py in callback(*args, **kwargs)
    187 
    188         def callback(*args, **kwargs):
--> 189             self.notify(instance, wrapped_list, wrapped_list)
    190 
    191         dcb.function = callback

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/core.py in notify(self, instance, old, new)
    123             return
    124         for cback in self._callbacks.get(instance, []):
--> 125             cback(new)
    126         for cback in self._2arg_callbacks.get(instance, []):
    127             cback(old, new)

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/image/state.py in _layers_changed(self, *args)
    192             return
    193 
--> 194         self._update_combo_ref_data()
    195         self._set_reference_data()
    196         self._update_syncing()

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/image/state.py in _update_combo_ref_data(self)
    218 
    219     def _update_combo_ref_data(self):
--> 220         self.ref_data_helper.set_multiple_data(self.layers_data)
    221 
    222     def _update_combo_att(self):

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/core/data_combo_helper.py in set_multiple_data(self, datasets)
    520         for data in unique_data_iter(datasets):
    521             self.append_data(data, refresh=False)
--> 522         self.refresh()
    523 
    524     def append_data(self, data, refresh=True):

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/core/data_combo_helper.py in refresh(self, *args)
    443 
    444     def refresh(self, *args):
--> 445         self.choices = [data for data in self._datasets]
    446         self.refresh_component_ids()
    447 

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/core/data_combo_helper.py in choices(self, choices)
     84         with delay_callback(self.state, self.selection_property):
     85             prop = getattr(type(self.state), self.selection_property)
---> 86             prop.set_choices(self.state, choices)
     87 
     88     @property

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/core.py in __exit__(self, *args)
    536 
    537         for p, args in notifications:
--> 538             p.notify(*args)
    539 
    540 

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/utils/matplotlib.py in wrapper(*args, **kwargs)
    158 
    159         if len(DEFER_DRAW_BACKENDS) == 0:
--> 160             return func(*args, **kwargs)
    161 
    162         # Don't recursively defer draws. We just check the first draw_idle

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/matplotlib/state.py in notify(self, *args, **kwargs)
     33     @defer_draw
     34     def notify(self, *args, **kwargs):
---> 35         super(DeferredDrawSelectionCallbackProperty, self).notify(*args, **kwargs)
     36 
     37 

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/core.py in notify(self, instance, old, new)
    123             return
    124         for cback in self._callbacks.get(instance, []):
--> 125             cback(new)
    126         for cback in self._2arg_callbacks.get(instance, []):
    127             cback(old, new)

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/image/state.py in _reference_data_changed(self, *args)
    178                     # so we do this here manually.
    179                     self._on_xatt_world_change()
--> 180                     self._on_yatt_world_change()
    181 
    182     def _layers_changed(self, *args):

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/core.py in __exit__(self, *args)
    536 
    537         for p, args in notifications:
--> 538             p.notify(*args)
    539 
    540 

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/utils/matplotlib.py in wrapper(*args, **kwargs)
    158 
    159         if len(DEFER_DRAW_BACKENDS) == 0:
--> 160             return func(*args, **kwargs)
    161 
    162         # Don't recursively defer draws. We just check the first draw_idle

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/matplotlib/state.py in notify(self, *args, **kwargs)
     33     @defer_draw
     34     def notify(self, *args, **kwargs):
---> 35         super(DeferredDrawSelectionCallbackProperty, self).notify(*args, **kwargs)
     36 
     37 

~/miniconda3/envs/science/lib/python3.8/site-packages/echo/core.py in notify(self, instance, old, new)
    123             return
    124         for cback in self._callbacks.get(instance, []):
--> 125             cback(new)
    126         for cback in self._2arg_callbacks.get(instance, []):
    127             cback(old, new)

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/utils/matplotlib.py in wrapper(*args, **kwargs)
    158 
    159         if len(DEFER_DRAW_BACKENDS) == 0:
--> 160             return func(*args, **kwargs)
    161 
    162         # Don't recursively defer draws. We just check the first draw_idle

~/miniconda3/envs/science/lib/python3.8/site-packages/glue/viewers/image/state.py in _on_xatt_world_change(self, *args)
    268                         world_ids = self.reference_data.pixel_component_ids
    269                     if self.x_att_world == world_ids[-1]:
--> 270                         self.y_att_world = world_ids[-2]
    271                     else:
    272                         self.y_att_world = world_ids[-1]

IndexError: list index out of range

Desktop (please complete the following information):

jupyter core : 4.6.3 jupyter-notebook : 6.0.3 qtconsole : 4.7.4 ipython : 7.14.0 ipykernel : 5.3.0 jupyter client : 6.1.11 jupyter lab : not installed nbconvert : 6.0.7 ipywidgets : 7.5.1 nbformat : 5.0.6 traitlets : 5.0.5

Package versions (please complete the following information):

macOS-10.13.6-x86_64-i386-64bit Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 07:56:27) [Clang 9.0.1 ] Numpy 1.18.5 astropy 4.2.1 specutils 1.3.dev42+g57dd2b28 spectral-cube 0.5.0 pyyaml 5.4.1 click 7.1.2 asteval 0.9.23 idna 2.10 traitlets 5.0.5 bqplot 0.12.26 bqplot-image-gl 1.3.3 glue-core 1.0.1 glue-jupyter 0.5 glue-astronomy 0.1 echo 0.5 ipyvue 1.5.0 ipyvuetify 1.6.1 ipysplitpanes 0.1.0 ipygoldenlayout 0.3.0 voila 0.2.6 vispy 0.6.6 Jdaviz 1.2.dev153+g39e1d9a

Additional context (e.g. data files) Add any other context about the problem here.

pllim commented 2 years ago

Select the unit-converted copy of the data

In Jdaviz v3.1, there is no such thing as "unit-converted copy" of a cube. Is this ticket still relevant?

camipacifici commented 2 years ago

No, this can be closed.