morphometry_pipeline module provides tools for measuring geometric properties of subcellular neural structures. It is designed to analyze components like dendritic spines, axonal boutons, and other small structures on neuron meshes.
Overview
The morphometry pipeline measures detailed geometric properties for each component:- Volume - Estimated using winding number and Monte Carlo sampling
- Surface area - Computed from mesh vertex areas
- Sphericity - Shape measure comparing volume to surface area
- Principal components - Orientation and elongation of structures
- Distance transform - Distance from interior points to surface
- Spatial location - Centroid position of each component
Functions
component_morphometry_pipeline
Compute morphometric measurements for labeled components on a mesh.The input mesh as (vertices, faces). Vertices should be in nanometers.
Array of labels for each vertex, indicating which component it belongs to. Same length as vertices.
The label value to analyze. Only components with this label are measured (e.g., label for “spine” or “bouton”).
Array mapping synapse IDs to mesh vertex indices. If provided, counts the number of synapses on each component.
Additional per-vertex features to include in analysis (currently not used in measurements).
Type of Laplacian to use for component splitting. Currently only “graph” is supported.
Threshold for Fiedler eigenvalue. Components with eigenvalue below this are split into two. If None, no splitting occurs.
Minimum number of vertices required for each split component. Prevents over-splitting.
Maximum bounding box volume in μm³. Components with larger bounding boxes are skipped (prevents measuring large artifacts).
Show progress bar during computation.
(results_df, corrected_components) where:
results_df: DataFrame with one row per component and columns for all measurementscorrected_components: Array of component labels after splitting, same length as vertices
Output Columns
The results DataFrame contains the following columns:Geometric Measurements
Estimated volume in nm³ using winding number method.
Surface area in nm² computed from mesh.
Shape measure from 0 to 1, where 1 is a perfect sphere. Computed as π^(1/3) * (6V)^(2/3) / A.
Spatial Features
X coordinate of component centroid (medoid of interior points) in nm.
Y coordinate of component centroid in nm.
Z coordinate of component centroid in nm.
Principal Component Analysis
First principal component singular value. Indicates elongation along primary axis.
Second principal component singular value.
Third principal component singular value. pca_val_1/pca_val_3 ratio indicates elongation.
Distance Transform
Maximum distance from any interior point to the surface in nm. Indicates thickness.
Mean distance from interior points to surface in nm.
Topology
Second smallest eigenvalue of the graph Laplacian (Fiedler value). Lower values indicate elongated or multi-part structures.
Number of vertices in the component mesh.
Number of faces in the component mesh.
Connectivity
Number of postsynaptic inputs on this component (only if post_synapse_mappings provided).
Diagnostics
Number of Monte Carlo sample points that fell inside the component.
Total number of Monte Carlo sample points generated.
Volume of axis-aligned bounding box in μm³.
Time in seconds to process this component.
Component Splitting
The pipeline can automatically split components that appear to be multiple structures merged together:- Computes the graph Laplacian for each component
- Calculates the Fiedler vector (second eigenvector)
- If the Fiedler eigenvalue is below
split_threshold, bisects the component - Each half becomes a new component if it meets
split_min_size - Process repeats recursively until no more splits occur
Volume Estimation
Volume is estimated using the winding number method:- Compute axis-aligned bounding box around the component
- Generate uniform random sample points within the box
- Compute winding number for each point (inside if > 0.5)
- Estimate volume as: (fraction inside) × (bounding box volume)
Best Practices
- Component size: Works best for structures between 100-10,000 vertices
- Bounding threshold: Set
bound_volume_thresholdto exclude large artifacts (typically 50-100 μm³) - Splitting: Use
split_threshold=0.1-0.2for spines, higher values for more conservative splitting - Synapse mapping: Provides
n_post_synapsescount when analyzing postsynaptic structures - Missing values: Components that fail measurements are excluded from results
Performance
Processing time per component depends on:- Bounding box volume (determines sample points)
- Number of vertices in component
- Whether splitting occurs
- Small spines (< 1 μm³): 0.01-0.1 seconds
- Medium boutons (1-10 μm³): 0.1-0.5 seconds
- Large components (> 10 μm³): 0.5-2 seconds
verbose=True to monitor progress with a progress bar.
Notes
- All spatial measurements are in nanometers (nm)
- Volume/area measurements assume vertex coordinates are in nm
- Components with fewer than 10 vertices are automatically skipped
- The algorithm filters autapses when counting synapses
- Rows with any NaN values are dropped from results
- Component IDs are preserved in the DataFrame index as
component_id