jdaviz icon indicating copy to clipboard operation
jdaviz copied to clipboard

[BUG] layer state doesn't update if run in a for loop in a notebook cell

Open eteq opened this issue 2 years ago • 4 comments
trafficstars

Jdaviz component

Imviz

Description

This is a very confusing one - it seems like some of the imviz state changing behaves differently depending on how I run the code. Everything below executes, but only some of it correctly updates the UI.

How to Reproduce

  1. Create at least two new viewers, and load different data into them.
  2. Run this snippet in a notebook cell
for vnm in imviz.app.get_viewer_reference_names():
    if vnm == 'imviz-0':
        continue
    v = imviz.app.get_viewer(vnm)
    v.stretch = 'log'
    for l in v.layers:
        if hasattr(l, 'ImageLayer'):
            l.state.percentile = 99.5

Expected behavior

I expect that to set all the viewers to the 99.5 percentile stretch. But it doesn't work! Nothing happens. but if I instead do the following:

imviz.app.get_viewer('viewer-name-1').layers[0].state.percentile = 99.5

and then in a separate cell, do

imviz.app.get_viewer('viewer-name-2').layers[0].state.percentile = 99.5

That does work!

Browser

No response

Jupyter

jupyter --version

IPython          : 8.14.0
ipykernel        : 6.23.3
ipywidgets       : 8.0.6
jupyter_client   : 7.4.1
jupyter_core     : 5.3.1
jupyter_server   : 1.24.0
jupyterlab       : 3.6.5
nbclient         : 0.7.4
nbconvert        : 7.6.0
nbformat         : 5.9.0
notebook         : 6.5.4
qtconsole        : 5.4.3
traitlets        : 5.9.0

Software versions

>>> import platform; print(platform.platform())
Linux-6.4.2-arch1-1-surface-x86_64-with-glibc2.37
>>> import sys; print("Python", sys.version)
Python 3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429]
>>> import numpy; print("Numpy", numpy.__version__)
Numpy 1.25.0
>>> import astropy; print("astropy", astropy.__version__)
astropy 5.3
>>> import matplotlib; print("matplotlib", matplotlib.__version__)
matplotlib 3.7.1
>>> import scipy; print("scipy", scipy.__version__)
scipy 1.9.3
>>> import skimage; print("scikit-image", skimage.__version__)
scikit-image 0.21.0
>>> import asdf; print("asdf", asdf.__version__)
asdf 2.15.0
>>> import stdatamodels; print("stdatamodels", stdatamodels.__version__)
stdatamodels 1.7.0
>>> import gwcs; print("gwcs", gwcs.__version__)
gwcs 0.18.3
>>> import regions; print("regions", regions.__version__)
regions 0.7
>>> import specutils; print("specutils", specutils.__version__)
specutils 1.11.0
>>> import specreduce; print("specreduce", specreduce.__version__)
specreduce 1.3.0
>>> import photutils; print("photutils", photutils.__version__)
photutils 1.8.0
>>> import astroquery; print("astroquery", astroquery.__version__)
astroquery 0.4.6
>>> import yaml; print("pyyaml", yaml.__version__)
pyyaml 6.0
>>> import asteval; print("asteval", asteval.__version__)
asteval 0.9.30
>>> import idna; print("idna", idna.__version__)
idna 3.4
>>> import traitlets; print("traitlets", traitlets.__version__)
traitlets 5.9.0
>>> import bqplot; print("bqplot", bqplot.__version__)
bqplot 0.12.39
>>> import bqplot_image_gl; print("bqplot-image-gl", bqplot_image_gl.__version__)
bqplot-image-gl 1.4.11
>>> import glue; print("glue-core", glue.__version__)
glue-core 1.12.0
>>> import glue_jupyter; print("glue-jupyter", glue_jupyter.__version__)
glue-jupyter 0.17.0
>>> import glue_astronomy; print("glue-astronomy", glue_astronomy.__version__)
glue-astronomy 0.10.0
>>> import echo; print("echo", echo.__version__)
echo 0.8.0
>>> import ipyvue; print("ipyvue", ipyvue.__version__)
ipyvue 1.9.2
>>> import ipyvuetify; print("ipyvuetify", ipyvuetify.__version__)
ipyvuetify 1.8.10
>>> import ipysplitpanes; print("ipysplitpanes", ipysplitpanes.__version__)
ipysplitpanes 0.2.0
>>> import ipygoldenlayout; print("ipygoldenlayout", ipygoldenlayout.__version__)
ipygoldenlayout 0.4.0
>>> import jinja2; print("Jinja2", jinja2.__version__)
Jinja2 3.1.2
>>> import voila; print("voila", voila.__version__)
voila 0.4.1
>>> import vispy; print("vispy", vispy.__version__)
vispy 0.13.0
>>> import sidecar; print("sidecar", sidecar.__version__)
sidecar 0.5.2
>>> import jdaviz; print("Jdaviz", jdaviz.__version__)
Jdaviz 3.5.0

🐱

eteq avatar Jul 31 '23 17:07 eteq

The plot options API would be much simpler than a custom for-loop in this case. (But there might still be a bug here that we should definitely investigate and fix).

kecnry avatar Jul 31 '23 17:07 kecnry

But why are you not using Astrowidgets API here? I am shocked, Erik, shocked!

https://github.com/spacetelescope/jdaviz/blob/c3168d4dd562ba143ca86ed41178177d685fccf7/jdaviz/core/astrowidgets_api.py#L328-L344

pllim avatar Aug 01 '23 23:08 pllim

In a nutshell, you are calling the wrong layer, and none of that is considered public API fit for a user, so the solution here is for you to either use:

  1. What Kyle said above about Plot Options, or
  2. Astrowidgets API ("cuts")

Can we close this as "won't fix"?

pllim avatar Aug 01 '23 23:08 pllim

p.s. Maybe you are calling the right layer but a copy of it rather than the actual layer being rendered. 🤷

pllim avatar Aug 01 '23 23:08 pllim