Skip to content

Instantly share code, notes, and snippets.

@lyralemos
Created September 2, 2019 17:56
Show Gist options
  • Save lyralemos/5981639d9573a85b9794711fe061ad1b to your computer and use it in GitHub Desktop.
Save lyralemos/5981639d9573a85b9794711fe061ad1b to your computer and use it in GitHub Desktop.
# Example to extract the persistence diagram from a neuronal tree
# Step 1: Import the tmd module
import tmd
# Step 2: Load your morphology
filename = './test_data/valid/C010398B-P2.CNG.swc'
neu = tmd.io.load_neuron(filename)
# Step 3: Extract the ph diagram of a tree
tree = neu.neurites[0]
ph = tmd.methods.get_persistence_diagram(tree)
# Step 4: Extract the ph diagram of a neuron's trees
ph_neu = tmd.methods.get_ph_neuron(neu)
# Step 5: Extract the ph diagram of a neuron's trees,
# depending on the neurite_type
ph_apical = tmd.methods.get_ph_neuron(neu, neurite_type='apical')
ph_axon = tmd.methods.get_ph_neuron(neu, neurite_type='axon')
ph_basal = tmd.methods.get_ph_neuron(neu, neurite_type='basal')
# Step 6: Plot the extracted topological data with three different ways
from tmd.view import view, plot
# Visualize the neuron
figure,mplot = view.neuron(neu)
figure.savefig('neuron.png')
# Visualize a selected neurite type or multiple of them
figure,mplot = view.neuron(neu, neurite_type=['apical'])
figure.savefig('neuron1.png')
# Visualize the persistence diagram
figure,mplot = plot.diagram(ph_apical)
figure.savefig('diagram.png')
# Visualize the persistence barcode
figure,mplot = plot.barcode(ph_apical)
figure.savefig('barcode.png')
# Visualize the persistence image
result = plot.persistence_image(ph_apical)
result[1][0].savefig('figure.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment