Closed ubless607 closed 11 months ago
version: 1.0a36, 1.0a35
I've clean-installed on WSL2, not working.
import itk from itkwidgets import view from urllib.request import urlretrieve import os # Download data file_name = '005_32months_T2_RegT1_Reg2Atlas_ManualBrainMask_Stripped.nrrd' if not os.path.exists(file_name): url = 'https://data.kitware.com/api/v1/file/564a5b078d777f7522dbfaa6/download' urlretrieve(url, file_name) image = itk.imread(file_name) view(image, rotate=True, axes=True, vmin=4000, vmax=17000, gradient_opacity=0.9)
--------------------------------------------------------------------------- TraitError Traceback (most recent call last) Cell In[2], line 12 10 urlretrieve(url, file_name) 11 image = itk.imread(file_name) ---> 12 view(image, rotate=True, axes=True, vmin=4000, vmax=17000, gradient_opacity=0.9) File [~/mambaforge/envs/itk/lib/python3.11/site-packages/itkwidgets/widget_viewer.py:1090](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/itkwidgets/widget_viewer.py:1090), in view(image, label_image, label_image_names, label_image_weights, label_image_blend, cmap, lut, select_roi, interpolation, gradient_opacity, opacity_gaussians, channels, slicing_planes, shadow, blend_mode, point_sets, point_set_colors, point_set_opacities, point_set_representations, point_set_sizes, geometries, geometry_colors, geometry_opacities, ui_collapsed, rotate, annotations, axes, mode, **kwargs) 1087 if image is None and len(images): # only one image is rendered 1088 image = images[0] -> 1090 viewer = Viewer(image=image, 1091 label_image=label_image, 1092 label_image_names=label_image_names, 1093 label_image_blend=label_image_blend, 1094 label_image_weights=label_image_weights, 1095 cmap=cmap, 1096 lut=lut, 1097 select_roi=select_roi, 1098 interpolation=interpolation, 1099 gradient_opacity=gradient_opacity, 1100 opacity_gaussians=opacity_gaussians, 1101 slicing_planes=slicing_planes, 1102 shadow=shadow, blend_mode=blend_mode, 1103 point_sets=point_sets, 1104 point_set_colors=point_set_colors, 1105 point_set_opacities=point_set_opacities, 1106 point_set_representations=point_set_representations, 1107 point_set_sizes=point_set_sizes, 1108 geometries=geometries, geometry_colors=geometry_colors, 1109 geometry_opacities=geometry_opacities, 1110 rotate=rotate, ui_collapsed=ui_collapsed, 1111 annotations=annotations, axes=axes, mode=mode, 1112 **kwargs) 1113 return viewer File [~/mambaforge/envs/itk/lib/python3.11/site-packages/itkwidgets/widget_viewer.py:369](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/itkwidgets/widget_viewer.py:369), in Viewer.__init__(self, **kwargs) 365 if have_label_image: 366 # Interpolation is not currently supported with label maps 367 kwargs['interpolation'] = False --> 369 super(Viewer, self).__init__(**kwargs) 371 if not self.image and not self.label_image: 372 return File [~/mambaforge/envs/itk/lib/python3.11/site-packages/ipywidgets/widgets/widget.py:478](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/ipywidgets/widgets/widget.py:478), in Widget.__init__(self, **kwargs) 476 """Public constructor""" 477 self._model_id = kwargs.pop('model_id', None) --> 478 super(Widget, self).__init__(**kwargs) 480 Widget._call_widget_constructed(self) 481 self.open() File [~/mambaforge/envs/itk/lib/python3.11/site-packages/traitlets/traitlets.py:1362](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/traitlets/traitlets.py:1362), in HasTraits.__init__(self, *args, **kwargs) 1360 for key in changed: 1361 value = self._traits[key]._cross_validate(self, getattr(self, key)) -> 1362 self.set_trait(key, value) 1363 changes[key]['new'] = value 1364 self._cross_validation_lock = False File [~/mambaforge/envs/itk/lib/python3.11/site-packages/traitlets/traitlets.py:1742](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/traitlets/traitlets.py:1742), in HasTraits.set_trait(self, name, value) 1740 raise TraitError(f"Class {cls.__name__} does not have a trait named {name}") 1741 else: -> 1742 getattr(cls, name).set(self, value) File [~/mambaforge/envs/itk/lib/python3.11/site-packages/traittypes/traittypes.py:108](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/traittypes/traittypes.py:108), in Array.set(self, obj, value) 107 def set(self, obj, value): --> 108 new_value = self._validate(obj, value) 109 old_value = obj._trait_values.get(self.name, self.default_value) 110 obj._trait_values[self.name] = new_value File [~/mambaforge/envs/itk/lib/python3.11/site-packages/traitlets/traitlets.py:738](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/traitlets/traitlets.py:738), in TraitType._validate(self, obj, value) 736 return value 737 if hasattr(self, "validate"): --> 738 value = self.validate(obj, value) 739 if obj._cross_validation_lock is False: 740 value = self._cross_validate(obj, value) File [~/mambaforge/envs/itk/lib/python3.11/site-packages/ipydatawidgets/ndarray/traits.py:25](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/ipydatawidgets/ndarray/traits.py:25), in NDArray.validate(self, obj, value) 24 def validate(self, obj, value): ---> 25 value = super(NDArray, self).validate(obj, value) 26 if value is None or value is Undefined: 27 return value File [~/mambaforge/envs/itk/lib/python3.11/site-packages/traittypes/traittypes.py:105](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/traittypes/traittypes.py:105), in Array.validate(self, obj, value) 103 except (ValueError, TypeError) as e: 104 raise TraitError(e) --> 105 return super(Array, self).validate(obj, value) File [~/mambaforge/envs/itk/lib/python3.11/site-packages/traittypes/traittypes.py:76](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/traittypes/traittypes.py:76), in SciType.validate(self, obj, value) 74 try: 75 for validator in self.validators: ---> 76 value = validator(self, value) 77 return value 78 except (ValueError, TypeError) as e: File [~/mambaforge/envs/itk/lib/python3.11/site-packages/ipydatawidgets/ndarray/traits.py:40](https://untitled+.vscode-resource.vscode-cdn.net/~/mambaforge/envs/itk/lib/python3.11/site-packages/ipydatawidgets/ndarray/traits.py:40), in shape_constraints..validator(trait, value) 38 return value 39 if len(value.shape) != len(args): ---> 40 raise TraitError('%s shape expected to have %s components, but got %s components' % ( 41 trait.name, len(args), value.shape)) 42 for i, constraint in enumerate(args): 43 if constraint is not None: TraitError: label_image_weights shape expected to have 1 components, but got () components
You might need to use traitlets < 5.7, which is a requirement in itkwidgets >= 0.32.5, cf. https://github.com/InsightSoftwareConsortium/itkwidgets/issues/588.
选择 traitlets==5.5.0,itkwidgets==0.32.6,就可以运行了。
version: 1.0a36, 1.0a35
I've clean-installed on WSL2, not working.