dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 36 forks source link

Interactive viewer crashes when dendrogram is loaded from file #106

Closed tomr-stargazer closed 10 years ago

tomr-stargazer commented 10 years ago

Hi, When I save a dendrogram object to a file, and then load it back, I have the following bug. I call up the viewer, then click on the intensity map, and get these errors:

In [8]: d
Out[8]: <astrodendro.dendrogram.Dendrogram at 0x106435f90>
In [9]: d.save_to('saved_dendrogram_test.hdf5')
In [12]: d2 = astrodendro.Dendrogram.load_from('saved_dendrogram_test.hdf5')
In [13]: d2.viewer()
# Then I interactively click on the map in the viewer and the following occurs:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/tsrice/anaconda/lib/python2.7/site-packages/matplotlib/cbook.pyc in process(self, s, *args, **kwargs)
    525                     del self.callbacks[s][cid]
    526                 else:
--> 527                     proxy(*args, **kwargs)
    528
    529

/Users/tsrice/anaconda/lib/python2.7/site-packages/matplotlib/cbook.pyc in __call__(self, *args, **kwargs)
    403             mtd = self.func
    404         # invoke the callable and return the result
--> 405         return mtd(*args, **kwargs)
    406
    407     def __eq__(self, other):

/Users/tsrice/Documents/Code/astrodendro/astrodendro/viewer.pyc in select_from_map(self, event)
    219             # Select the structure
    220             structure = self.dendrogram.structure_at(indices)
--> 221             self.hub.select(input_key, structure)
    222
    223             # Re-draw

/Users/tsrice/Documents/Code/astrodendro/astrodendro/viewer.pyc in select(self, id, structure)
     51         self.selections[id] = structure
     52         for cb in self._callbacks:
---> 53             cb(id)
     54
     55

/Users/tsrice/Documents/Code/astrodendro/astrodendro/viewer.pyc in _on_selection_change(self, selection_id)
    178     def _on_selection_change(self, selection_id):
    179         self._update_lines(selection_id)
--> 180         self.update_contours()
    181
    182     def update_vmin(self, vmin):

/Users/tsrice/Documents/Code/astrodendro/astrodendro/viewer.pyc in update_contours(self)
    312             if struct is None:
    313                 continue
--> 314             mask = struct.get_mask(subtree=True)
    315             if self.array.ndim == 3:
    316                 mask = mask[self.slice, :, :]

/Users/tsrice/Documents/Code/astrodendro/astrodendro/structure.pyc in get_mask(self, shape, subtree)
    476         """
    477         if shape is None:
--> 478             shape = self._dendrogram.data.shape
    479         indices = self.indices(subtree=True) if subtree else self.indices
    480         mask = np.zeros(shape, dtype=bool)

AttributeError: 'NoneType' object has no attribute 'data'

I assume this is a bug in how the dendrogram object is reconstructed when loading from a file, or perhaps the .viewer() method should have a way of handling this case?

tomr-stargazer commented 10 years ago

I can confirm that when I call up d.viewer() (the original dendrogram) in the same session and click on it, I don't get the same crash -- it works as expected, unlike d2 which was loaded-from-file.

tomr-stargazer commented 10 years ago

Also, I noticed this behavior about a month ago, before we started merging in pull request #105, but I'm only calling it out now.

tomr-stargazer commented 10 years ago

I asked @ChrisBeaumont to see if he'd be able to address this one -- just flagging it here for posterity.

tomr-stargazer commented 10 years ago

I checked this code out and it appears to have fixed the bug!