A Toolkit for Persistent Homology Computation and 3D Visualization
TopoFlow is a Python toolkit for computing Vietoris-Rips persistent homology from point cloud data and rendering the results as animated 3D visualizations. It provides implementations of core TDA (Topological Data Analysis) operations alongside interactive graphics capabilities for exploring topological features across filtration scales.
pip install -e .Dependencies: NumPy, SciPy, Matplotlib, scikit-learn (optional), Ripser (optional), GUDHI (optional)
Persistent homology is a method in topological data analysis that studies the multi-scale topological structure of data. Given a point cloud sampled from a topological space, we construct a nested sequence of simplicial complexes (a filtration) and track how topological features—connected components (H₀), loops (H₁), voids (H₂)—appear and disappear across scales.
Given a point cloud
As
- H₀ features (connected components): merge at the distances connecting points
- H₁ features (loops/cycles): form when edges create triangular cycles
- H₂ features (voids): form when tetrahedra enclose empty regions
Each topological feature has a birth scale (when it appears) and a death scale (when it is filled in). The persistence of a feature is
- Persistence barcode: each feature as an interval [birth, death)
- Persistence diagram: points (birth, death) in the plane; features on the diagonal have zero persistence
The Betti numbers
-
$\beta_0$ : number of connected components -
$\beta_1$ : number of independent loops/cycles -
$\beta_2$ : number of enclosed voids
The persistence landscape, introduced by Bubenik (2015), is a piecewise-linear function representation of persistence that enables statistical analysis. The
TopoFlow computes persistent homology via:
-
Distance matrix computation:
$O(n^2)$ pairwise distances - Filtration construction: Sort all edge pairs by distance
- Homology computation: Uses Ripser (default), GUDHI, or a union-find fallback
- Visualization rendering: 3D bar charts, surface plots, and animated GIFs
# Compute persistent homology and render barcode as 3D chart
topoflow render --input points.csv --output barcode.png --type barcode
# Run demo with torus point cloud
topoflow demo --output demo.gif
# Generate random point cloud and visualize VR complex
topoflow random --n-points 100 --distribution torus --type complex --output vr_complex.png
# Compute and display topological summary
topoflow summary --input points.csv
# Generate persistence landscape animation
topoflow landscape --input points.csv --output landscape.gif| Distribution | Description |
|---|---|
sphere |
Uniform random points on unit sphere surface |
torus |
Random points on torus (R=2.0, r=0.8) |
cube |
Uniform random points in [-1,1]³ |
circle |
Uniform random points on unit circle |
barcode: 3D bar chart of persistence intervals by homology dimensionsurface: 3D surface rendering of persistence landscapecomplex: 3D VR complex mesh with edges colored by filtration valuebetti: 2D Betti curves (count vs. filtration value)diagram: Standard persistence diagram (birth vs. death)collapse: Animated GIF showing VR complex building across filtrationlandscape: Animated GIF of persistence landscape construction
from topoflow.topology import (
generate_random_point_cloud,
read_point_cloud,
compute_persistent_homology,
compute_betti_curves,
compute_persistence_landscape,
get_topological_summary,
)
from topoflow.render import create_persistence_diagram, create_3d_barcode_chart
# Load or generate point cloud
points = read_point_cloud("data.csv")
# or: points = generate_random_point_cloud(n_points=100, distribution="torus")
# Compute persistent homology
result = compute_persistent_homology(points, max_dim=1, max_edge_length=2.0)
# Access results
dgms = result["dgms"] # List of persistence diagrams per dimension
betti_nums = result["betti_numbers"] # [β₀, β₁, ...] at max filtration
# Compute derived quantities
betti_curves = compute_betti_curves(result)
landscape = compute_persistence_landscape(result)
# Get complete topological summary
summary = get_topological_summary(points)
# Contains: n_points, betti_numbers, barcodes, betti_curves,
# persistence_landscape, total_persistence
# Visualize
fig = create_persistence_diagram(summary["barcodes"])
fig.savefig("diagram.png")| Format | Description |
|---|---|
| PNG | Static visualizations (barcode chart, diagram, curves) |
| GIF | Animated visualizations (collapse, landscape, demo) |
- Primary TDA backend: Ripser (via
ripserPython package)—fast C++ implementation - Fallback: Custom union-find algorithm for H₀ and triangle-based H₁ approximation
- Optional backend: GUDHI library support via
library="gudhi"argument - Visualization: Matplotlib with mpl_toolkits.mplot3d for 3D rendering
- Bubenik, P. (2015). Statistical topological data analysis using persistence landscapes. JMLR, 16(1), 77–102.
- Edelsbrunner, H., & Harer, J. (2008). Persistent homology—a survey. Surveys on Discrete and Computational Geometry, 453, 257–282.
- Edelsbrunner, H., Letscher, D., & Zomorodian, A. (2002). Topological persistence and simplification. Discrete & Computational Geometry, 28(4), 511–533.
MIT License - Copyright (c) 2026 Teerth Sharma