NeurodataWithoutBorders / nwbwidgets

Explore the hierarchical structure of NWB 2.0 files and visualize data with Jupyter widgets.
https://nwb-widgets.readthedocs.io/en/latest/
Other
48 stars 21 forks source link

[Bug]: CCFWidget label_image_weights #274

Closed CodyCBakerPhD closed 2 months ago

CodyCBakerPhD commented 1 year ago

What happened?

Failed to view the CCF tab of 'electrodes'

Steps to Reproduce

import h5py
import fsspec
from fsspec.implementations.cached import CachingFileSystem
from pynwb import NWBHDF5IO

s3_url = "https://dandiarchive.s3.amazonaws.com/blobs/631/af9/631af947-1de8-4e36-83b5-8c763d9d18f5" # Brain Wide Map
cfs = CachingFileSystem(
    fs=fsspec.filesystem("http"),
    cache_storage="/home/jovyan/fsspec_cache",  # Local folder for the cache
)
file_system = cfs.open(s3_url, "rb")
file = h5py.File(file_system)
io = NWBHDF5IO(file=file, load_namespaces=True)
nwbfile = io.read()

nwb2widget(nwbfile)
--> navigate to 'electrodes'
--> navigate to 'CCF'

Traceback

TraitError                                Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:766, in Widget._handle_msg(self, msg)
    764         if 'buffer_paths' in data:
    765             _put_buffers(state, data['buffer_paths'], msg['buffers'])
--> 766         self.set_state(state)
    768 # Handle a state request.
    769 elif method == 'request_state':

File /opt/conda/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:643, in Widget.set_state(self, sync_data)
    638         self._send(msg, buffers=echo_buffers)
    640 # The order of these context managers is important. Properties must
    641 # be locked when the hold_trait_notification context manager is
    642 # released and notifications are fired.
--> 643 with self._lock_property(**sync_data), self.hold_trait_notifications():
    644     for name in sync_data:
    645         if name in self.keys:

File /opt/conda/lib/python3.10/contextlib.py:142, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    140 if typ is None:
    141     try:
--> 142         next(self.gen)
    143     except StopIteration:
    144         return False

File /opt/conda/lib/python3.10/site-packages/traitlets/traitlets.py:1502, in HasTraits.hold_trait_notifications(self)
   1500 for changes in cache.values():
   1501     for change in changes:
-> 1502         self.notify_change(change)

File /opt/conda/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:694, in Widget.notify_change(self, change)
    691     if name in self.keys and self._should_send_property(name, getattr(self, name)):
    692         # Send new state to front-end
    693         self.send_state(key=name)
--> 694 super().notify_change(change)

File /opt/conda/lib/python3.10/site-packages/traitlets/traitlets.py:1517, in HasTraits.notify_change(self, change)
   1515 def notify_change(self, change):
   1516     """Notify observers of a change event"""
-> 1517     return self._notify_observers(change)

File /opt/conda/lib/python3.10/site-packages/traitlets/traitlets.py:1564, in HasTraits._notify_observers(self, event)
   1561 elif isinstance(c, EventHandler) and c.name is not None:
   1562     c = getattr(self, c.name)
-> 1564 c(event)

File /opt/conda/lib/python3.10/site-packages/nwbwidgets/base.py:130, in lazy_tabs.<locals>.on_selected_index(change)
    128 def on_selected_index(change):
    129     if isinstance(change.owner.children[change.new], widgets.HTML):
--> 130         children[change.new] = vis2widget(tabs_spec[change.new][1](node))
    131         change.owner.children = children

File /opt/conda/lib/python3.10/site-packages/nwbwidgets/utils/dependencies.py:66, in check_widget_dependencies.<locals>.wrap.<locals>.wrapped_func(*args, **kwargs)
     64 missing = [name for name, dependency in dependencies.items() if not dependency]
     65 if not missing:
---> 66     return func(*args, **kwargs)
     67 else:
     68     txt = "This widget requires the following extra dependencies: {}"

File /opt/conda/lib/python3.10/site-packages/nwbwidgets/ecephys.py:109, in show_ccf(electrodes_table, **kwargs)
    106     input_kwargs.update(markers=markers)
    108 input_kwargs.update(kwargs)
--> 109 return ccfwidget.CCFWidget(**input_kwargs)

File /opt/conda/lib/python3.10/site-packages/ccfwidget/widget_ccf.py:122, in CCFWidget.__init__(self, tree, swc_morphologies, markers, marker_sizes, marker_opacities, marker_colors, selected_allen_ids, selected_acronyms, rotate, **kwargs)
    118 camera = np.array([[ 1.3441567e+03, -2.1723846e+04,  1.7496496e+04],
    119                    [ 6.5500000e+03,  3.9750000e+03,  5.6750000e+03],
    120                    [ 3.6606243e-01, -4.4908229e-01, -8.1506038e-01]], dtype=np.float32)
    121 size_limit_3d = [256,256,256]
--> 122 self.itk_viewer = view(image=self._image,
    123                        label_image=self._label_image,
    124                        opacity_gaussians=opacity_gaussians,
    125                        label_image_blend=0.65,
    126                        point_sets=markers.copy(),
    127                        camera=camera,
    128                        ui_collapsed=True,
    129                        shadow=False,
    130                        size_limit_3d=size_limit_3d,
    131                        background=(0.85,)*3,
    132                        units="μm",
    133                        gradient_opacity=0.1)
    134 # Todo: initialization should work
    135 self.itk_viewer.opacity_gaussians = opacity_gaussians

File /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:502, in Widget.__init__(self, **kwargs)
    500 """Public constructor"""
    501 self._model_id = kwargs.pop('model_id', None)
--> 502 super().__init__(**kwargs)
    504 Widget._call_widget_constructed(self)
    505 self.open()

File /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/site-packages/ipydatawidgets/ndarray/traits.py:40, in shape_constraints.<locals>.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

Operating System

Linux

Python Version

3.10

Package Versions

No response

Code of Conduct