royerlab / ultrack

Cell tracking and segmentation software
https://royerlab.github.io/ultrack
BSD 3-Clause "New" or "Revised" License
95 stars 12 forks source link

error in viewer.add_labels(detection, visible=True).contour = 2 of notebook tribolium_cartograph.ipynb #161

Closed jazberna1 closed 2 weeks ago

jazberna1 commented 2 weeks ago

Hi,

I have encountered and error when running the following line of the tribolium_cartograph.ipynb

detection = create_zarr(image.shape, bool, "detection.zarr", overwrite=True)

The error (full traceback at the end says):

File ~\miniconda3\envs\ultrack\Lib\site-packages\zarr\util.py:91, in normalize_shape(shape)
     89 # normalize
     90 shape = cast(Tuple[int, ...], shape)
---> 91 shape = tuple(int(s) for s in shape)
     92 return shape

TypeError: 'type' object is not iterable

The error seems to be related to zarr package. In case it helps my version of zarr is 2.18.3

This is the full traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 viewer.add_labels(detection, visible=True).contour = 2
      3 nbscreenshot(viewer)

File ~\miniconda3\envs\ultrack\Lib\site-packages\napari\utils\add_layer.py_tmpl:7, in add_labels(self, data, affine, axis_labels, blending, cache, colormap, depiction, experimental_clipping_planes, features, iso_gradient_mode, metadata, multiscale, name, opacity, plane, projection_mode, properties, rendering, rotate, scale, shear, translate, units, visible)
      5 for name in getattr({cls_name}.__init__, "_deprecated_constructor_args", []):
      6     pos_kwargs[name] = kwargs.pop(name, None)
----> 7 layer = {cls_name}(**kwargs)
      8 for name, value in pos_kwargs.items():
      9     if value is not None:

File ~\miniconda3\envs\ultrack\Lib\site-packages\napari\layers\base\base.py:114, in PostInit.__call__(self, *args, **kwargs)
    113 def __call__(self, *args, **kwargs):
--> 114     obj = super().__call__(*args, **kwargs)
    115     obj._post_init()
    116     return obj

File ~\miniconda3\envs\ultrack\Lib\site-packages\napari\layers\labels\labels.py:340, in Labels.__init__(self, data, affine, axis_labels, blending, cache, colormap, depiction, experimental_clipping_planes, features, iso_gradient_mode, metadata, multiscale, name, opacity, plane, projection_mode, properties, rendering, rotate, scale, shear, translate, units, visible)
    337 self._show_selected_label = False
    338 self._contour = 0
--> 340 data = self._ensure_int_labels(data)
    342 super().__init__(
    343     data,
    344     affine=affine,
   (...)
    362     visible=visible,
    363 )
    365 self.events.add(
    366     brush_shape=Event,
    367     brush_size=Event,
   (...)
    379     show_selected_label=Event,
    380 )

File ~\miniconda3\envs\ultrack\Lib\site-packages\napari\layers\labels\labels.py:665, in Labels._ensure_int_labels(self, data)
    658     raise TypeError(
    659         trans._(
    660             'Only integer types are supported for Labels layers, but data contains {data_level_type}.',
    661             data_level_type=data_level.dtype,
    662         )
    663     )
    664 if data_level.dtype == bool:
--> 665     int_data.append(data_level.view(np.uint8))
    666 else:
    667     int_data.append(data_level)

File ~\miniconda3\envs\ultrack\Lib\site-packages\zarr\core.py:2888, in Array.view(self, shape, chunks, dtype, fill_value, filters, read_only, synchronizer)
   2886     shape = self._shape
   2887 else:
-> 2888     shape = normalize_shape(shape)
   2889     a._shape = shape
   2890 if chunks is not None:

File ~\miniconda3\envs\ultrack\Lib\site-packages\zarr\util.py:91, in normalize_shape(shape)
     89 # normalize
     90 shape = cast(Tuple[int, ...], shape)
---> 91 shape = tuple(int(s) for s in shape)
     92 return shape

TypeError: 'type' object is not iterable

Any help to fix the error will be much appreciated.

Thanks Jorge

jazberna1 commented 2 weeks ago

I got it to work by coverting the zarr array as numpy

detection = np.asarray(detection).astype('uint8')

Jorge