CoAxLab/DeBaCl

Need a better error message for plot color nodes if a node is not valid

Closed this issue · 1 comments

The get_clusters method can return "-1" values to indicate points that are "noise" for a given cluster labeling scheme. If this "-1" label is passed directly to the color_nodes parameter it's a problem because this isn't a valid tree node ID, but the error message isn't very helpful.

>>> cluster_labels = tree.get_clusters(fill_background=True)
>>> labels = np.unique(cluster_labels[:, 1])
>>> fig = tree.plot(color_nodes=labels)[0]
KeyError                                  Traceback (most recent call last)
<ipython-input-27-8cae5ab76c06> in <module>()
----> 1 fig = tree.plot(color_nodes=labels)[0]

/home/brian/projects/DeBaCl/debacl/level_set_tree.pyc in plot(self, form, horizontal_spacing, color_nodes, colormap)
    313 
    314         for i, ix in enumerate(color_nodes):
--> 315             subtree = self._make_subtree(ix)
    316 
    317             for ix_sub in subtree.nodes.keys():

/home/brian/projects/DeBaCl/debacl/level_set_tree.pyc in _make_subtree(self, ix)
    519 
    520         T = LevelSetTree()
--> 521         T.nodes[ix] = _copy.deepcopy(self.nodes[ix])
    522         T.nodes[ix].parent = None
    523         queue = self.nodes[ix].children[:]

KeyError: -1

Fixed by pull request #53 - closing.