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

ccf.marker_colors not available if not set in __init__ #26

Open
bendichter opened this issue Aug 27, 2020 · 0 comments
Open

ccf.marker_colors not available if not set in __init__ #26

bendichter opened this issue Aug 27, 2020 · 0 comments
Assignees

Comments

@bendichter
Copy link
Contributor

If you construct without marker_colors,

ccf = CCFWidget()
ccf.markers=[np.random.randn(20,3)*1000 for _ in range(5)]

you get markers with the colors automatically assigned:

image

however, if you try to access these colors:

ccf.marker_colors

you get an error

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in get(self, obj, cls)
    527         try:
--> 528             value = obj._trait_values[self.name]
    529         except KeyError:

KeyError: 'marker_colors'

During handling of the above exception, another exception occurred:

TraitError                                Traceback (most recent call last)
<ipython-input-18-3627e74d660e> in <module>
      1 ccf = CCFWidget()
      2 ccf.markers = [np.random.randn(20, 3) * 1000 for _ in range(5)]
----> 3 ccf.marker_colors
      4 
      5 #= [(1, 0, 0)] * 5

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in __get__(self, obj, cls)
    554             return self
    555         else:
--> 556             return self.get(obj, cls)
    557 
    558     def set(self, obj, value):

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in get(self, obj, cls)
    533                 raise TraitError("No default value found for %s trait of %r"
    534                                  % (self.name, obj))
--> 535             value = self._validate(obj, dynamic_default())
    536             obj._trait_values[self.name] = value
    537             return value

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in _validate(self, obj, value)
    591             value = self.validate(obj, value)
    592         if obj._cross_validation_lock is False:
--> 593             value = self._cross_validate(obj, value)
    594         return value
    595 

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in _cross_validate(self, obj, value)
    597         if self.name in obj._trait_validators:
    598             proposal = Bunch({'trait': self, 'value': value, 'owner': obj})
--> 599             value = obj._trait_validators[self.name](obj, proposal)
    600         elif hasattr(obj, '_%s_validate' % self.name):
    601             meth_name = '_%s_validate' % self.name

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in __call__(self, *args, **kwargs)
    905         """Pass `*args` and `**kwargs` to the handler's function if it exists."""
    906         if hasattr(self, 'func'):
--> 907             return self.func(*args, **kwargs)
    908         else:
    909             return self._init_call(*args, **kwargs)

~/opt/anaconda3/lib/python3.7/site-packages/ccfwidget/widget_ccf.py in _validate_marker_colors(self, proposal)
    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
    291 

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in __set__(self, obj, value)
    583             raise TraitError('The "%s" trait is read-only.' % self.name)
    584         else:
--> 585             self.set(obj, value)
    586 
    587     def _validate(self, obj, value):

~/opt/anaconda3/lib/python3.7/site-packages/traittypes/traittypes.py in set(self, obj, value)
    106 
    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

~/opt/anaconda3/lib/python3.7/site-packages/traitlets/traitlets.py in _validate(self, obj, value)
    589             return value
    590         if hasattr(self, 'validate'):
--> 591             value = self.validate(obj, value)
    592         if obj._cross_validation_lock is False:
    593             value = self._cross_validate(obj, value)

~/opt/anaconda3/lib/python3.7/site-packages/ipydatawidgets/ndarray/traits.py in validate(self, obj, value)
     23 
     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

~/opt/anaconda3/lib/python3.7/site-packages/traittypes/traittypes.py in validate(self, obj, value)
    103         except (ValueError, TypeError) as e:
    104             raise TraitError(e)
--> 105         return super(Array, self).validate(obj, value)
    106 
    107     def set(self, obj, value):

~/opt/anaconda3/lib/python3.7/site-packages/traittypes/traittypes.py in 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:

~/opt/anaconda3/lib/python3.7/site-packages/ipydatawidgets/ndarray/traits.py in validator(trait, 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: point_set_colors shape expected to have 2 components, but got (0,) components

Setting ccf.marker_colors works as expected, this is just an issue with getting the attr

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

2 participants