pyapp-kit / ndv

Simple, fast-loading, n-dimensional array viewer with minimal dependencies.
BSD 3-Clause "New" or "Revised" License
33 stars 5 forks source link

bug: ZeroDivisionError when altering clims for uniform image. #42

Open gselzer opened 1 week ago

gselzer commented 1 week ago

Description

It would seem that SceneCanvas.elements_at (naturally) throws a ZeroDivisionError, crashing python, when the contrast range is zero. This can happen when the dataset only contains a single value (example below). As this method is called from data interrogation (during hovering), this can cause unexpected crashes.

I'm not sure whether this is a vispy bug, or whether it's something we should handle here. I lean towards the former but would appreciate others' opinions.

What I Did

Here's the code for a minimal example:

import ndv
import numpy as np

img = np.ones((256, 256)) * 128
ndv.imshow(img)

Steps to reproduce the crash:

  1. Set the contrast limits to the same value.
  2. Hover over a part of the image.
tlambert03 commented 1 week ago

This actually will be fixed in the next vispy release... see https://github.com/vispy/vispy/pull/2621

(Maybe? Is your error on that same line?)

gselzer commented 1 week ago

Heh, you beat me to it! Great! :dash: