Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting marker colors yields error #29

Open
rcpeene opened this issue Nov 28, 2022 · 7 comments
Open

Setting marker colors yields error #29

rcpeene opened this issue Nov 28, 2022 · 7 comments
Assignees

Comments

@rcpeene
Copy link

rcpeene commented Nov 28, 2022

I'm attempting to render neuropixel probes with ccfwidgets and set the marker colors within a jupyter notebook. This yields an error an itk widgets.

Here is my code;

colors = [(1.00, 0, 0.5) for i in range(len(points))]
ccf = CCFWidget(markers=[points])
ccf.marker_colors = colors

where points is a numpy array with shape (2304, 3)

Here is the traceback;

IndexError                                Traceback (most recent call last)
Cell In [49], line 2
      1 ccf = CCFWidget(markers=[points])
----> 2 ccf.marker_colors = colors

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:715, in TraitType.__set__(self, obj, value)
    713     raise TraitError('The "%s" trait is read-only.' % self.name)
    714 else:
--> 715     self.set(obj, value)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:2865, in List.set(self, obj, value)
   2863     return super().set(obj, [value])
   2864 else:
-> 2865     return super().set(obj, value)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:689, in TraitType.set(self, obj, value)
    688 def set(self, obj, value):
--> 689     new_value = self._validate(obj, value)
    690     try:
    691         old_value = obj._trait_values[self.name]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:723, in TraitType._validate(self, obj, value)
    721     value = self.validate(obj, value)  # type:ignore[attr-defined]
    722 if obj._cross_validation_lock is False:
--> 723     value = self._cross_validate(obj, value)
    724 return value

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:729, in TraitType._cross_validate(self, obj, value)
    727 if self.name in obj._trait_validators:
    728     proposal = Bunch({"trait": self, "value": value, "owner": obj})
--> 729     value = obj._trait_validators[self.name](obj, proposal)
    730 elif hasattr(obj, "_%s_validate" % self.name):
    731     meth_name = "_%s_validate" % self.name

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:1132, in EventHandler.__call__(self, *args, **kwargs)
   1130 """Pass `*args` and `**kwargs` to the handler's function if it exists."""
   1131 if hasattr(self, "func"):
-> 1132     return self.func(*args, **kwargs)
   1133 else:
   1134     return self._init_call(*args, **kwargs)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\ccfwidget\widget_ccf.py:289, in CCFWidget._validate_marker_colors(self, proposal)
    286 @validate('marker_colors')
    287 def _validate_marker_colors(self, proposal):
    288     value = proposal['value']
--> 289     self.itk_viewer.point_set_colors = [(1.0, 0.0, 0.0),]*len(self.swc_point_sets) + value
    290     return value

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:715, in TraitType.__set__(self, obj, value)
    713     raise TraitError('The "%s" trait is read-only.' % self.name)
    714 else:
--> 715     self.set(obj, value)

File ~\AppData\Local\Programs\Python\Python39\lib\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 ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:723, in TraitType._validate(self, obj, value)
    721     value = self.validate(obj, value)  # type:ignore[attr-defined]
    722 if obj._cross_validation_lock is False:
--> 723     value = self._cross_validate(obj, value)
    724 return value

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:729, in TraitType._cross_validate(self, obj, value)
    727 if self.name in obj._trait_validators:
    728     proposal = Bunch({"trait": self, "value": value, "owner": obj})
--> 729     value = obj._trait_validators[self.name](obj, proposal)
    730 elif hasattr(obj, "_%s_validate" % self.name):
    731     meth_name = "_%s_validate" % self.name

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\traitlets.py:1132, in EventHandler.__call__(self, *args, **kwargs)
   1130 """Pass `*args` and `**kwargs` to the handler's function if it exists."""
   1131 if hasattr(self, "func"):
-> 1132     return self.func(*args, **kwargs)
   1133 else:
   1134     return self._init_call(*args, **kwargs)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\itkwidgets\widget_viewer.py:633, in Viewer._validate_point_set_colors(self, proposal)
    631 result = np.zeros((n_colors, 3), dtype=np.float32)
    632 for index, color in enumerate(value):
--> 633     result[index, :] = matplotlib.colors.to_rgb(color)
    634 if len(value) < n_colors:
    635     for index in range(len(value), n_colors):

IndexError: index 1 is out of bounds for axis 0 with size 1

I looked in the examples and found no documentation about the usage of setting marker_colors, so I'm not 100% my usage is correct. The same error is given when passing marker_colors in the ccf constructor. Is this a problem with itkwidgets?

@rcpeene
Copy link
Author

rcpeene commented Feb 7, 2023

Any insight would be useful here so I can add colored points.

@bendichter
Copy link
Contributor

@rpeene can you try using either the keys or the values of this dict?

{'tab:blue': '#1f77b4',
'tab:orange': '#ff7f0e',
'tab:green': '#2ca02c',
'tab:red': '#d62728',
'tab:purple': '#9467bd',
'tab:brown': '#8c564b',
'tab:pink': '#e377c2',
'tab:gray': '#7f7f7f',
'tab:olive': '#bcbd22',
'tab:cyan': '#17becf'}

@rcpeene
Copy link
Author

rcpeene commented Feb 8, 2023

TraitError: could not convert string to float: '#1f77b4'
This error for both keys and values.
It was my understanding that marker_colors ought to be an n x 3 array of floats where n is the number of points.

@rcpeene
Copy link
Author

rcpeene commented Jul 25, 2023

Any updates here? Would love to have this feature working for the databook.

@bendichter
Copy link
Contributor

@thewtex , any idea what might be going on here?

@arjunsridhar12345
Copy link

arjunsridhar12345 commented Nov 16, 2023

hello, are there any updates on this? would very much like to add colored points to the widget. I am able to pass in a list of colors but the colors do not appear on the widget (all the points are the same color)

@bendichter
Copy link
Contributor

Sorry I am not really able to support this feature myself as I am not that familiar with the itkwidgets package. I think this would rest on @thewtex to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants