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

[BUG] Imviz API triggering IndexError from Glue #2638

Closed
rosteen opened this issue Dec 26, 2023 · 4 comments · Fixed by #2641
Closed

[BUG] Imviz API triggering IndexError from Glue #2638

rosteen opened this issue Dec 26, 2023 · 4 comments · Fixed by #2641
Labels
bug Something isn't working imviz

Comments

@rosteen
Copy link
Collaborator

rosteen commented Dec 26, 2023

Jdaviz component

Imviz

Description

I've now hit a couple instances where the using the Imviz API leads to an IndexError from Glue core. The traceback copied below resulted from running the viewer.offset_by(0.5 * u.arcsec, -1.5 * u.arcsec) cell in the ImvizExample notebook, but I also have seen the same error from running the command to add markers. It seems like this only happens if the cell to load_regions in the notebook has been run.

Traceback (most recent call last):
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/tornado/ioloop.py", line 750, in _run_callback
    ret = callback()
          ^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue_jupyter/utils.py", line 121, in debounced_execute
    f(*args, **kwargs)
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue_jupyter/bqplot/image/frb_mark.py", line 48, in debounced_update
    return self.update(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue_jupyter/bqplot/image/frb_mark.py", line 95, in update
    image = self.array_maker(bounds=bounds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue/viewers/image/layer_artist.py", line 250, in __call__
    mask = self.layer_state.get_sliced_data(bounds=bounds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue/viewers/image/state.py", line 456, in get_sliced_data
    image = self.layer.data.compute_fixed_resolution_buffer(full_view, target_data=self.viewer_state.reference_data,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue/core/data.py", line 2030, in compute_fixed_resolution_buffer
    return compute_fixed_resolution_buffer(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue/core/fixed_resolution_buffer.py", line 280, in compute_fixed_resolution_buffer
    array = data.get_mask(subset_state, view=translated_coords)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue/core/data.py", line 1437, in get_mask
    return subset_state.to_mask(self, view=view)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.11/site-packages/glue/core/subset.py", line 1286, in to_mask
    result = self.mask[tuple(vals)]
             ~~~~~~~~~^^^^^^^^^^^^^
IndexError: index 4735 is out of bounds for axis 1 with size 4735

How to Reproduce

Execute the ImvizExample notebook, see that this error does not get raised if you skip the load_regions cell.

Expected behavior

Imviz API calls do not raise this error after loading regions through the API.

Browser

No response

Jupyter

IPython : 8.18.1
ipykernel : 6.27.1
ipywidgets : 8.1.1
jupyter_client : 8.6.0
jupyter_core : 5.5.0
jupyter_server : 2.11.1
jupyterlab : 4.0.9
nbclient : 0.7.4
nbconvert : 7.11.0
nbformat : 5.9.2
notebook : 7.0.6
qtconsole : 5.5.1
traitlets : 5.14.0

Software versions

macOS-10.16-x86_64-i386-64bit
Python 3.11.5 (main, Sep 11 2023, 08:19:27) [Clang 14.0.6 ]
Numpy 1.26.2
astropy 6.0.0
matplotlib 3.8.2
scipy 1.11.4
scikit-image 0.22.0
asdf 3.0.1
stdatamodels 1.8.3
gwcs 0.20.0
regions 0.8
specutils 1.12.0
specreduce 1.3.0
photutils 1.10.0
astroquery 0.4.6
pyyaml 6.0.1
asteval 0.9.31
idna 3.6
traitlets 5.14.0
bqplot 0.12.42
bqplot-image-gl 1.4.11
glue-core 1.17.1
glue-jupyter 0.20.0
glue-astronomy 0.10.0
echo 0.8.0
ipyvue 1.10.1
ipyvuetify 1.8.10
ipysplitpanes 0.2.0
ipygoldenlayout 0.4.0
Jinja2 3.1.2
voila 0.4.3
vispy 0.14.1
sidecar 0.7.0
Jdaviz 3.8.1.dev47+g8f4292a1.d20231207

🐱

@rosteen rosteen added bug Something isn't working needs-triage Issue opened via template and needs triaging labels Dec 26, 2023
@pllim pllim added the imviz label Dec 26, 2023
@pllim
Copy link
Contributor

pllim commented Jan 2, 2024

Interesting... looks like you only see this traceback when images are linked by WCS, not when linked by pixel.

@pllim
Copy link
Contributor

pllim commented Jan 2, 2024

IndexError: index 4735 is out of bounds for axis 1 with size 4735

Might be some off-by-one error somewhere in the calculations.

A shape: (4718, 4735)
B shape: (2265, 2269)

@pllim
Copy link
Contributor

pllim commented Jan 2, 2024

This is triggered by the my_mask defined in the mentioned example notebook. I think when linked by WCS, there is some translation uncertainty somewhere in MaskSubsetState.to_mask (https://github.com/glue-viz/glue/blob/5f38baf8d22aef572b3269149208089199c4512d/glue/core/subset.py#L1275) that ties into https://github.com/glue-viz/glue/blob/5f38baf8d22aef572b3269149208089199c4512d/glue/core/fixed_resolution_buffer.py#L97 . Since we're passing in an actual boolean mask that encompasses the entire data shape, an index that was right at the edge probably gets translated to sky, to the second data index, back to sky, and then back to original data index but at the last step something that was 4734 before is now 4735, which crashes.

Interestingly enough, when you run the same workflow in ImvizDitheredExample , I think it goes through the same logic route but viewer.offset_by(...) does not crash. So maybe it comes down to FITS WCS vs GWCS differences in roundtripping quality.

Before we jump into any rabbit hole, keep in mind that no one really creates a subset like this. That was just a fun example. Since it works in ImvizDitheredExample , we can keep it there. But for this ImvizExample notebook, I say we just remove my_mask and move on with our lives.

@pllim
Copy link
Contributor

pllim commented Jan 3, 2024

Upstream issue opened at glue-viz/glue#2474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working imviz
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants