spacetelescope / jdaviz

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

[BUG] Cubeviz: Fails to retrieve regions when "remove" tool was used #957

Open rosteen opened 2 years ago

rosteen commented 2 years ago

Describe the bug Retrieving spatial subsets from the flux viewer fails if the "remove" tool was used to remove part of the subset, due to a NotImplementedError in glue-astronomy. Looks like we need to implement that...

To Reproduce Steps to reproduce the behavior:

  1. Create a subset in the flux viewer.
  2. Change selector behavior to "remove"
  3. Attempt to retrieve the subset with app.get_subsets_from_viewer

Expected behavior You can get your spatial subset back. I'm not familiar with the astropy support for these sorts of regions, it may not exist.

Traceback

NotImplementedError                       Traceback (most recent call last)
/var/folders/ds/q5jd1xq53l9djq7lcc029d240002hz/T/ipykernel_16543/3290163830.py in <module>
----> 1 viz.app.get_subsets_from_viewer("flux-viewer")

~/projects/jdaviz/jdaviz/app.py in get_subsets_from_viewer(self, viewer_reference, data_label, subset_type)
    680                 # **Note** that the y values in this region object are not
    681                 #  useful, only the x values are.
--> 682                 region = subset_group.subsets[0].data.get_selection_definition(
    683                     format='astropy-regions')
    684                 regions[key] = region

~/opt/anaconda3/envs/viz_dev/lib/python3.9/site-packages/glue/core/data.py in get_selection_definition(self, subset_id, format, **kwargs)
    371         handler = subset_state_translator.get_handler_for(format)
    372 
--> 373         return handler.to_object(subset, **kwargs)
    374 
    375 

~/opt/anaconda3/envs/viz_dev/lib/python3.9/site-packages/glue_astronomy/translators/regions.py in to_object(self, subset)
    134             temp_sub2 = Subset(data=data)
    135             temp_sub2.subset_state = subset_state.state2
--> 136             return self.to_object(temp_sub1) & self.to_object(temp_sub2)
    137 
    138         elif isinstance(subset_state, OrState):

~/opt/anaconda3/envs/viz_dev/lib/python3.9/site-packages/glue_astronomy/translators/regions.py in to_object(self, subset)
    160 
    161         else:
--> 162             raise NotImplementedError("Subset states of type {0} are not supported"
    163                                       .format(subset_state.__class__.__name__))

NotImplementedError: Subset states of type InvertState are not supported
rosteen commented 2 years ago

Apparently Imviz will catch this error, see #898.

pllim commented 2 years ago

Yes, @camipacifici wanted a snackbar error instead of traceback for Imviz. See implementation at #906 .