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

Imviz Line Profile crashes when default viewer is empty #1238

Open Jdaviz-Triage-Bot opened 2 years ago

Jdaviz-Triage-Bot commented 2 years ago

Reporter: pllim

Workflow to reproduce:

  1. Load data in Imviz example notebook.
  2. Create a new (second) viewer.
  3. Select data in new viewer.
  4. Deselect all data in default (first) viewer.
  5. Open up Line Profile plugin.
  6. Press "l" on a star in second viewer. See plots.
  7. In the viewer dropdown, change to "imviz-0". See traceback.

Expectation: Plots will not show but also no traceback.

.../jdaviz/configs/imviz/plugins/line_profile_xy/line_profile_xy.py in vue_draw_plot(self, *args, **kwargs)
     52 
     53         viewer = self.app.get_viewer_by_id(self.selected_viewer)
---> 54         i = get_top_layer_index(viewer)
     55         data = viewer.state.layers[i].layer
     56 

.../jdaviz/configs/imviz/helper.py in get_top_layer_index(viewer)
    487 
    488     """
--> 489     return [i for i, lyr in enumerate(viewer.layers)
    490             if lyr.visible and layer_is_image_data(lyr.layer)][-1]
    491 

IndexError: list index out of range

🐱


DISCLAIMER: This issue was autocreated by the Jdaviz Issue Creation Bot on behalf of the reporter. If any information is incorrect, please contact Duy Nguyen

kecnry commented 2 years ago

Should the line profile have a data dropdown instead of a viewer? If not, this should be as simple as using the new viewer dropdown and adding a filter (which is coming soon for viewers dropdowns but not yet in main) to only allow non-empty viewers so the get_top_layer won't ever fail. Or we could go the direction of metadata-viewer and still show the item in the dropdown but replace the UI with a message saying there are no visible layers. Either way, if the plot is shown and then the top-layer is removed from a viewer, the results should then also clear.

pllim commented 2 years ago

Should the line profile have a data dropdown instead of a viewer?

No. It grabs the top visible layer like Blink. This behavior is mainly because of the key stroke functionality.

Or we could go the direction of metadata-viewer

That would be my preference but I could be swayed.