Napari Drawing Correction Error

Hi there,

While using Napari add_labels layer on an image layer of shape TYX I am running into an error shown below:
The image is pretty standard one and the same program has worked before for images of such shapes so I do not know why it is not working now, I also explicitly mentioned to take the numpy array as uint16 but that does not help either.

Other things work just fine, just the dragging of mouse to correct the labels does not work that well! Why do you think that is?

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    116     try:
--> 117         num = operator.index(num)
    118     except TypeError:

TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/app/backends/_qt.py in mouseMoveEvent(self, ev)
    467             native=ev,
    468             pos=(ev.pos().x(), ev.pos().y()),
--> 469             modifiers=self._modifiers(ev),
    470         )
    471 

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/app/base.py in _vispy_mouse_move(self, **kwargs)
    211             kwargs['button'] = self._vispy_mouse_data['press_event'].button
    212 
--> 213         ev = self._vispy_canvas.events.mouse_move(**kwargs)
    214         self._vispy_mouse_data['last_event'] = ev
    215         return ev

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/util/event.py in __call__(self, *args, **kwargs)
    453                     continue
    454 
--> 455                 self._invoke_callback(cb, event)
    456                 if event.blocked:
    457                     break

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/util/event.py in _invoke_callback(self, cb, event)
    473             _handle_exception(self.ignore_callback_errors,
    474                               self.print_callback_errors,
--> 475                               self, cb_event=(cb, event))
    476 
    477     def _prepare_event(self, *args, **kwargs):

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/util/event.py in _invoke_callback(self, cb, event)
    469     def _invoke_callback(self, cb, event):
    470         try:
--> 471             cb(event)
    472         except Exception:
    473             _handle_exception(self.ignore_callback_errors,

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/_qt/qt_viewer.py in on_mouse_move(self, event)
    325         if layer is not None:
    326             # Line bellow needed until layer mouse callbacks are refactored
--> 327             self.layer_to_visual[layer].on_mouse_move(event)
    328             mouse_move_callbacks(layer, event)
    329 

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/_vispy/vispy_base_layer.py in on_mouse_move(self, event)
    172         self._position = list(event.pos)
    173         self.layer.position = self._transform_position(self._position)
--> 174         self.layer.on_mouse_move(event)
    175 
    176     def on_mouse_press(self, event):

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/layers/labels/labels.py in on_mouse_move(self, event)
    546             else:
    547                 interp_coord = interpolate_coordinates(
--> 548                     self._last_cursor_coord, self.coordinates, self.brush_size
    549                 )
    550             with self.events.set_data.blocker():

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/util/misc.py in interpolate_coordinates(old_coord, new_coord, brush_size)
    432     coords = [
    433         np.linspace(old_coord[i], new_coord[i], num=num_step + 1)
--> 434         for i in range(len(new_coord))
    435     ]
    436     coords = np.stack(coords).T

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/util/misc.py in <listcomp>(.0)
    432     coords = [
    433         np.linspace(old_coord[i], new_coord[i], num=num_step + 1)
--> 434         for i in range(len(new_coord))
    435     ]
    436     coords = np.stack(coords).T

<__array_function__ internals> in linspace(*args, **kwargs)

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    119         raise TypeError(
    120             "object of type {} cannot be safely interpreted as an integer."
--> 121                 .format(type(num)))
    122 
    123     if num < 0:

TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    116     try:
--> 117         num = operator.index(num)
    118     except TypeError:

TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/app/backends/_qt.py in mouseMoveEvent(self, ev)
    467             native=ev,
    468             pos=(ev.pos().x(), ev.pos().y()),
--> 469             modifiers=self._modifiers(ev),
    470         )
    471 

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/app/base.py in _vispy_mouse_move(self, **kwargs)
    211             kwargs['button'] = self._vispy_mouse_data['press_event'].button
    212 
--> 213         ev = self._vispy_canvas.events.mouse_move(**kwargs)
    214         self._vispy_mouse_data['last_event'] = ev
    215         return ev

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/util/event.py in __call__(self, *args, **kwargs)
    453                     continue
    454 
--> 455                 self._invoke_callback(cb, event)
    456                 if event.blocked:
    457                     break

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/util/event.py in _invoke_callback(self, cb, event)
    473             _handle_exception(self.ignore_callback_errors,
    474                               self.print_callback_errors,
--> 475                               self, cb_event=(cb, event))
    476 
    477     def _prepare_event(self, *args, **kwargs):

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/vispy/util/event.py in _invoke_callback(self, cb, event)
    469     def _invoke_callback(self, cb, event):
    470         try:
--> 471             cb(event)
    472         except Exception:
    473             _handle_exception(self.ignore_callback_errors,

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/_qt/qt_viewer.py in on_mouse_move(self, event)
    325         if layer is not None:
    326             # Line bellow needed until layer mouse callbacks are refactored
--> 327             self.layer_to_visual[layer].on_mouse_move(event)
    328             mouse_move_callbacks(layer, event)
    329 

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/_vispy/vispy_base_layer.py in on_mouse_move(self, event)
    172         self._position = list(event.pos)
    173         self.layer.position = self._transform_position(self._position)
--> 174         self.layer.on_mouse_move(event)
    175 
    176     def on_mouse_press(self, event):

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/layers/labels/labels.py in on_mouse_move(self, event)
    546             else:
    547                 interp_coord = interpolate_coordinates(
--> 548                     self._last_cursor_coord, self.coordinates, self.brush_size
    549                 )
    550             with self.events.set_data.blocker():

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/util/misc.py in interpolate_coordinates(old_coord, new_coord, brush_size)
    432     coords = [
    433         np.linspace(old_coord[i], new_coord[i], num=num_step + 1)
--> 434         for i in range(len(new_coord))
    435     ]
    436     coords = np.stack(coords).T

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/napari/util/misc.py in <listcomp>(.0)
    432     coords = [
    433         np.linspace(old_coord[i], new_coord[i], num=num_step + 1)
--> 434         for i in range(len(new_coord))
    435     ]
    436     coords = np.stack(coords).T

<__array_function__ internals> in linspace(*args, **kwargs)

~/miniconda3/envs/tensorflowEnv36/lib/python3.6/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    119         raise TypeError(
    120             "object of type {} cannot be safely interpreted as an integer."
--> 121                 .format(type(num)))
    122 
    123     if num < 0:

TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

Hi @kapoorlab! That looks like a bug in our usage of linspace, but one that has been fixed already! You appear to be using a pretty old version of napari since we renamed the util folder utils months ago! And we now cast num+1 to int before using linspace, which was what was causing the problem. In short, if you could upgrade napari I think your problem would go away! :crossed_fingers:

1 Like

Hi @jni, Thank you so much, yup that was it, it is fixed n new!

1 Like