Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scatter Layer on Image Viewer breaks export-as-script #2457

Open
jfoster17 opened this issue Nov 1, 2023 · 5 comments
Open

Scatter Layer on Image Viewer breaks export-as-script #2457

jfoster17 opened this issue Nov 1, 2023 · 5 comments
Labels

Comments

@jfoster17
Copy link
Member

Describe the bug
The "Save Python script..." option fails for an ImageViewer with a Scatter layer on top.

To Reproduce
Steps to reproduce the behavior such as:

  1. Create an ImageViewer and add some points on top (e.g. with the W5 sample data)
  2. Use the "Save" toolbar to "Save Python script to reproduce plot"
  3. Nothing apparently happens, but an error message is thrown
Traceback (most recent call last):
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue-qt/glue_qt/viewers/common/toolbar.py", line 145, in trigger
    self.active_tool = tool
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue-qt/glue_qt/viewers/common/toolbar.py", line 79, in active_tool
    self.activate_tool(new_tool)
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue-qt/glue_qt/viewers/common/toolbar.py", line 98, in activate_tool
    tool.activate()
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue/glue/plugins/tools/python_export.py", line 24, in activate
    self.viewer.export_as_script(filename)
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue/glue/utils/matplotlib.py", line 180, in wrapper
    result = func(*args, **kwargs)
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue/glue/utils/matplotlib.py", line 175, in wrapper
    return func(*args, **kwargs)
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue/glue/viewers/common/viewer.py", line 478, in export_as_script
    imports_layer, layer_script = layer._python_exporter(layer)
  File "/Users/jfoster/Developer/glue-genes-with-mainline-glue/glue/glue/viewers/scatter/python_export.py", line 13, in python_export_scatter_layer
    polar = layer._viewer_state.using_polar
AttributeError: 'ImageViewerState' object has no attribute 'using_polar'

Details:

  • Python version (python --version): Python 3.10
  • Glue version (glue --version): 1.14
  • How you installed glue: conda

Additional context
I'm not sure when/if this previously worked. It seems like much of the logic in python_export_scatter_layer assumes that we are exporting a standalone ScatterViewer (many calls to layer._viewer_state). The hacky fix would be to disable this option for an image viewer with additional non-image layers on top.

@jfoster17
Copy link
Member Author

NB -- this will also apply to RegionScatterLayers (once they are implemented). We can fix both at once.

@Carifio24
Copy link
Member

I would guess that changing the offending line to polar = getattr(layer._viewer_state, 'using_polar', False) should be enough to fix this, but I admittedly haven't tried it.

@jfoster17
Copy link
Member Author

That would deal with this particular error, but there are other calls to layer._viewer_state in this to fix.

@Carifio24
Copy link
Member

Ah yeah, looks like there are similar calls for other scatter viewer state properties (full sphere, degrees)

@Carifio24
Copy link
Member

I don't know when exactly this broke, but this is clearly something that I didn't check on when I added the support for the full-sphere and angle unit functionality. I can confirm that doing e.g.

polar = getattr(layer._viewer_state, 'using_polar', False)
full_sphere = getattr(layer._viewer_state, 'using_full_sphere', False)
degrees = getattr(layer._viewer_state, 'using_degrees', False)

will make things work for a scatter layer in an image viewer.

I'm not sure what adding support for region layers would entail - if the behavior for those is significantly different we could use a dispatch function for the layer export. Not ideal, but we do need some kind of check on the viewer state so we can properly handle any pretransforms that the exporting viewer is using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants