Napari Track Layer astonishing error

Hi, I am having a very very weird behavior with Napari tracks layer. I tried a very simple example on this page :

First off there is a spelling mistake in the name of the image test_im should be replaced with hubble_data for the example. But then I tried my own example:

import napari

tracks_data = [
     [1,1,41,768],
     [1,2,34,758],
     [2,3,36,761],
     [2,4,29,764]]
with napari.gui_qt():
    Tracks = napari.view_tracks(tracks_data,name='tracks')

And the error I got was:

ERROR:root:Unhandled exception:
Traceback (most recent call last):
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_qt/event_loop.py", line 79, in gui_qt
    yield app
  File "<ipython-input-2-498e4844dd1f>", line 9, in <module>
    Tracks = napari.view_tracks(tracks_data,name='tracks')
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/view_layers.py", line 9, in view_tracks
    (where <layer_type> is replaced with one of the layer types):
  File "<string>", line 3, in add_tracks
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 72, in add_layer
    self.layers.append(layer)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/list/_model.py", line 59, in append
    self.events.added(item=obj, index=len(self) - 1)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/events/event.py", line 514, in __call__
    self._invoke_callback(cb, event)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/events/event.py", line 531, in _invoke_callback
    _handle_exception(
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/utils/events/event.py", line 529, in _invoke_callback
    cb(event)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_qt/qt_viewer.py", line 323, in _add_layer
    vispy_layer = create_vispy_visual(layer)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_vispy/utils.py", line 44, in create_vispy_visual
    return visual(layer)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_vispy/vispy_tracks_layer.py", line 50, in __init__
    self._on_data_change()
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/_vispy/vispy_tracks_layer.py", line 62, in _on_data_change
    labels_text, labels_pos = self.layer.track_labels
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/layers/tracks/tracks.py", line 543, in track_labels
    padded_positions = self._pad_display_data(positions)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/napari/layers/tracks/tracks.py", line 306, in _pad_display_data
    data = np.pad(data, ((0, 0), (0, 1)), 'constant')
  File "<__array_function__ internals>", line 5, in pad
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/arraypad.py", line 748, in pad
    pad_width = _as_pairs(pad_width, array.ndim, as_index=True)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/arraypad.py", line 523, in _as_pairs
    return np.broadcast_to(x, (ndim, 2)).tolist()
  File "<__array_function__ internals>", line 5, in broadcast_to
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 182, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "/home/kapoorlab/anaconda3/envs/tensorflowGPU/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 125, in _broadcast_to
    it = np.nditer(
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (2,2) and requested shape (3,2)

I do not get it, what is wrong with my numbers??

Ah Ok second column (time) has to start from 0!

That’s certainly sub-optimal! We should certainly allow tracks layers where no tracklets start at time 0! Could you please raise an issue on github.com/napari/napari/issues?

2 Likes

Yes sure I will raise an issue on github tonight.

1 Like