Apply myelin labels to basket cell axon

This example uses the plotting package PyVista for interactive rendering. Any rendering program that takes vertices and edges can work.

WarningVersion update

We have released a new public version 1926, as part of our quarterly release schedule. See details at Release Manifests: 1926.

However, 1926 does not have a flat segmentation. This tutorial remains pinned to v1300 as the latest major version.

import pandas as pd
import numpy as np

from caveclient import CAVEclient
import pyvista as pv
import cloudvolume 
import seaborn as sns

Query a myelinated cell

# Set version to a data release with manual myelination labels
client = CAVEclient("minnie65_public")
client.version = 1300
timestamp = client.materialize.get_version_metadata(client.version)['time_stamp']

# Load the myelin values 
myelin_df = client.materialize.tables.vortex_manual_myelination_v0().query(
    desired_resolution=[1,1,1])

# Load the nodes of Ranvier
nodes_df = client.materialize.tables.vortex_manual_nodes_of_ranvier().query(
    desired_resolution=[1,1,1])
Table Owner Notice on vortex_manual_myelination_v0: Myelination status assessed for the axon of the VALID_ID, not the pt_root_id.
Table Owner Notice on vortex_manual_nodes_of_ranvier: Nodes and myelination assessed for the VALID_ID; if pt_root_id does not match valid_id, the segment has undergone proofreading. Proceed with caution.
myelin_df.value_counts('valid_id').head(5)
valid_id
864691136724881917    22762
864691135808631069    10847
864691136210378684     7873
864691135639556411     7083
864691135162983725     4952
Name: count, dtype: int64
# select an example myelinated basket cell
original_root_id = 864691136210378684 

# update the the root at the specificed version
version_root_id = client.chunkedgraph.suggest_latest_roots(original_root_id, timestamp=timestamp)

version_root_id
864691135763975990

Load the static mesh for one cell

# Set the static segmentaiton source to the most recent flat segmentation where that root id is valid
seg_source = 'precomputed://gs://iarpa_microns/minnie/minnie65/seg_m1300'

# load from cloudvolume
cv = cloudvolume.CloudVolume(seg_source, progress=False, use_https=True)
mesh = cv.mesh.get(version_root_id, lod=2)[version_root_id]
# Render the mesh vertices for pyvista
vertices = mesh.vertices
faces = mesh.faces

# add a column of all 3s to the faces
padded_faces = np.concatenate([np.full((faces.shape[0], 1), 3), faces], axis=1)

mesh_poly = pv.PolyData(vertices, faces=padded_faces)

# Flip with y axis
mesh_poly.points[:, 1] *= -1
# Format the myelin annotations 
myelin_points = np.vstack(myelin_df.query(f"(valid_id=={original_root_id}) & (tag==True)").pt_position.to_numpy()).astype(float)
myelin_poly = pv.PolyData(myelin_points)

# Flip with y axis
myelin_poly.points[:, 1] *= -1
# Format the node annotations 
ranvier_points = np.vstack(nodes_df.query(f"(valid_id=={original_root_id})").pt_position.to_numpy()).astype(float)
ranvier_poly = pv.PolyData(ranvier_points)

# Flip with y axis
ranvier_poly.points[:, 1] *= -1

Initialize plotting object, add mesh and annotations

pv.set_jupyter_backend("client")
plotter = pv.Plotter(image_scale=10)

silhouette = dict(
    color=[.06, .48, .67],
    line_width=0.5,
)

plotter.add_mesh(mesh_poly, color=[.06, .48, .67], opacity=0.75, silhouette=silhouette)
plotter.add_mesh(myelin_poly, point_size=6, color="orange", opacity=0.5)

plotter.camera_position = 'zy'
plotter.camera.zoom(1.0)
plotter.set_background('#fbfbfb')

plotter.show()
Interactive: Myelination (yellow) annotated along basket cell axon (blue)
Back to top