TMD icon indicating copy to clipboard operation
TMD copied to clipboard

KeyError for a neuron while computing persistence diagram

Open dokato opened this issue 1 year ago • 3 comments

When calling get_persistence_diagram on my neuron ( swc file attached) that looks like this:

Screenshot 2022-11-02 at 17 18 16

I get the following error:

In [18]: perd = tmd.methods.get_persistence_diagram(neuron.neurites[0])
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [18], in <cell line: 1>()
----> 1 perd = tmd.methods.get_persistence_diagram(neuron.neurites[0])

File ~/anaconda3/envs/testnavis/lib/python3.9/site-packages/tmd/Topology/methods.py:102, in get_persistence_diagram(tree, feature, **kwargs)
    100 def get_persistence_diagram(tree, feature='radial_distances', **kwargs):
    101     '''Method to extract ph from tree that contains mutlifurcations'''
--> 102     ph, _ = tree_to_property_barcode(
    103         tree,
    104         filtration_function=_filtration_function(feature, **kwargs),
    105         property_class=NoProperty
    106     )
    107     return ph

File ~/anaconda3/envs/testnavis/lib/python3.9/site-packages/tmd/Topology/methods.py:62, in tree_to_property_barcode(tree, filtration_function, property_class)
     59 while len(alives) > 1:
     60     for alive in alives:
---> 62         p = parents[alive]
     63         c = children[p]
     65         if np.alltrue(active[c]):
KeyError: 15

In fact this is a neuron exported from the navis library.

> import navis
> n = navis.example_neurons(1)
> navis.write_swc(n,'nrn.swc')

nrn.swc.zip

dokato avatar Nov 02 '22 17:11 dokato