spacetelescope / jdaviz

JWST astronomical data analysis tools in the Jupyter platform
https://jdaviz.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
136 stars 72 forks source link

Line list: traceback when using available lists #1994

Open Jdaviz-Triage-Bot opened 1 year ago

Jdaviz-Triage-Bot commented 1 year ago

Reporter: Camilla Pacifici

---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)
File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/ipyvue/VueTemplateWidget.py:60, in Events._handle_event(self, _, content, buffers)
     58     getattr(self, "vue_" + event)(data, buffers)
     59 else:
---> 60     getattr(self, "vue_" + event)(data)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/jdaviz/configs/default/plugins/line_lists/line_lists.py:733, in LineListTool.vue_change_visible(self, data)
    730 self.list_contents = list_contents
    732 if show:
--> 733     self._viewer.plot_spectral_line(name_rest)
    734 else:
    735     self._viewer.erase_spectral_lines(name_rest=name_rest)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/jdaviz/configs/specviz/plugins/viewers.py:373, in SpecvizProfileView.plot_spectral_line(self, line, plot_units, **kwargs)
    370 if plot_units is None:
    371     plot_units = self.data()[0].spectral_axis.unit
--> 373 line_mark = SpectralLine(self,
    374                          line['rest'].to(plot_units).value,
    375                          self.redshift,
    376                          name=line["linename"],
    377                          table_index=line["name_rest"],
    378                          colors=[line["colors"]], **kwargs)
    380 # Erase this line if it already existed, to avoid duplication
    381 self.erase_spectral_lines(name_rest=line["name_rest"])

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/jdaviz/core/marks.py:119, in SpectralLine.__init__(self, viewer, rest_value, redshift, name, **kwargs)
    114 self.redshift = redshift
    116 viewer.session.hub.subscribe(self, LineIdentifyMessage,
    117                              handler=self._process_identify_change)
--> 119 super().__init__(viewer=viewer, x=self.obs_value, stroke_width=1,
    120                  fill='none', close_path=False, **kwargs)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/jdaviz/core/marks.py:75, in BaseSpectrumVerticalLine.__init__(self, viewer, x, **kwargs)
     72 scales = viewer.scales
     74 # Lines.__init__ will set self.x
---> 75 super().__init__(x=[x, x], y=[0, 1],
     76                  scales={'x': scales['x'], 'y': LinearScale(min=0, max=1)},
     77                  **kwargs)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/bqplot/marks.py:242, in Mark.__init__(self, **kwargs)
    241 def __init__(self, **kwargs):
--> 242     super(Mark, self).__init__(**kwargs)
    243     self._hover_handlers = CallbackDispatcher()
    244     self._click_handlers = CallbackDispatcher()

File ~/opt/miniconda3/envs/jdaviz3.2.1/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/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:1347, in HasTraits.__init__(self, *args, **kwargs)
   1345 for key, value in kwargs.items():
   1346     if self.has_trait(key):
-> 1347         setattr(self, key, value)
   1348         changes[key] = Bunch(
   1349             name=key,
   1350             old=None,
   (...)
   1353             type="change",
   1354         )
   1355     else:
   1356         # passthrough args that don't set traits to super

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:732, in TraitType.__set__(self, obj, value)
    730     raise TraitError('The "%s" trait is read-only.' % self.name)
    731 else:
--> 732     self.set(obj, value)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:3022, in List.set(self, obj, value)
   3020     return super().set(obj, [value])
   3021 else:
-> 3022     return super().set(obj, value)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:706, in TraitType.set(self, obj, value)
    705 def set(self, obj, value):
--> 706     new_value = self._validate(obj, value)
    707     try:
    708         old_value = obj._trait_values[self.name]

File ~/opt/miniconda3/envs/jdaviz3.2.1/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/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:2871, in Container.validate(self, obj, value)
   2868 if value is None:
   2869     return value
-> 2871 value = self.validate_elements(obj, value)
   2873 return value

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:3016, in List.validate_elements(self, obj, value)
   3013 if length < self._minlen or length > self._maxlen:
   3014     self.length_error(obj, value)
-> 3016 return super().validate_elements(obj, value)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:2883, in Container.validate_elements(self, obj, value)
   2881     v = self._trait._validate(obj, v)
   2882 except TraitError as error:
-> 2883     self.error(obj, v, error)
   2884 else:
   2885     validated.append(v)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:823, in TraitType.error(self, obj, value, error, info)
    812         else:
    813             error.args = (
    814                 "The '%s' trait contains %s which "
    815                 "expected %s, not %s."
   (...)
    821                 ),
    822             )
--> 823     raise error
    824 else:
    825     # this trait caused an error
    826     if self.name is None:
    827         # this is not the root trait

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:2881, in Container.validate_elements(self, obj, value)
   2879 for v in value:
   2880     try:
-> 2881         v = self._trait._validate(obj, v)
   2882     except TraitError as error:
   2883         self.error(obj, v, error)

File ~/opt/miniconda3/envs/jdaviz3.2.1/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/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/ipywidgets/widgets/trait_types.py:50, in Color.validate(self, obj, value)
     46     if (value.lower() in _color_names or _color_hex_re.match(value) or
     47         _color_hexa_re.match(value) or _color_rgbhsl_re.match(value)):
     48         return value
---> 50 self.error(obj, value)

File ~/opt/miniconda3/envs/jdaviz3.2.1/lib/python3.10/site-packages/traitlets/traitlets.py:828, in TraitType.error(self, obj, value, error, info)
    824 else:
    825     # this trait caused an error
    826     if self.name is None:
    827         # this is not the root trait
--> 828         raise TraitError(value, info or self.info(), self)
    829     else:
    830         # this is the root trait
    831         if obj is not None:

TraitError: The 'colors' trait of a SpectralLine instance contains a Color of a List which expected a valid HTML color, not the Column <Column name='colors' dtype='str9' length=2>
#FF0000FF
#FF0000FF.

DISCLAIMER: This issue was autocreated by the Jdaviz Issue Creation Bot on behalf of the reporter. If any information is incorrect, please contact Duy Nguyen

pllim commented 1 year ago

This looks confusing to me:

https://github.com/spacetelescope/jdaviz/blob/78ad5791c70ff0ec5bf911e497f1e89eea88831f/jdaviz/configs/specviz/plugins/viewers.py#L387

https://github.com/spacetelescope/jdaviz/blob/78ad5791c70ff0ec5bf911e497f1e89eea88831f/jdaviz/configs/specviz/plugins/viewers.py#L394-L398

colors=["blue"] is in the method signature. But it is completely ignored if "colors" column is detected in the self.spectral_lines (presumably an astropy.table.Table), unless the column does not exist and the length mismatches, then it is suddenly a list, and not a astropy.table.Column. What was the original intention here?