Skip to main content

CI Coverage Ruff PyPI Python versions License Docs DOI OpenSSF Scorecard OpenSSF Best Practices

pre-commit Typed: Pyrefly Tested with Hypothesis

treegraphduals

This package is an extension of my Master's thesis: The Horizontal Tunnelability Graph is Dual to Level Set Trees. I have tried to keep everything as compatible as possible with other popular time series, tree, and graph libraries.

This is an early release. The sections below separate what the package computes today from what it is being built towards, so you can tell at a glance whether the piece you need is ready.

Install

pip install treegraphduals     # or: uv add treegraphduals

Requires Python 3.13+.

Quickstart

from treegraphduals.core import Tree
from treegraphduals.timeseries import TimeSeries

# Level-set tree of a time series
ts = TimeSeries.from_array([0, 3, 1, 4, 2, 5, 0])
tree = ts.to_level_set_tree()
tree  # Tree(n_nodes=6, n_leaves=3, root=0)
tree.horton_strahler_order_tree()  # 2
tree.max_horton_prunings()  # 3

# Level-set tree of a symbolic function, using exact critical points
import sympy as sp

t = sp.Symbol("t")
extrema = TimeSeries.from_function(
    (t - 1) * (t - 3) * (t - 5) * (t - 7), 1, 7, preserve_extrema=True
)
extrema.times  # [1.0, 1.764, 4.0, 6.236, 7.0]

# Hand the result to NetworkX or igraph
G = tree.to_networkx()  # DiGraph with 6 nodes and 5 edges

What the package computes today

Time series to trees

  • Level Set Trees of Time Series as Alternating Piecewise Linear Excursions with Slopes +/- 1 (Harris Paths)
  • Level Set Trees of Time Series as Alternating Piecewise Linear Excursions of Arbitrary Slope
  • Level Set Trees and Partial Trees of Arbitrary Time Series
  • Level Set Trees of Arbitrary Functions via Sympy, using exact symbolic differentiation
  • Harris Paths of Binary Trees (and Partial Trees)
  • Local extrema detection, minimal excursions, and unit-slope excursions

Trees

  • Horton-Strahler Orders of a Binary Tree, and of a tree as a whole
  • Horton Pruning of a Tree, with series reduction, and the pruning count to eliminate a tree
  • Plantedness, leaves, internal nodes, depths, subtree sizes, total length
  • Traversals: depth-first, breadth-first, left-to-right, and edge contours
  • Paths, distances, and ancestry queries between any two nodes
  • Structures: Tree, BinaryTree, Forest, DAG, Polytree, Graph, Multigraph, ErdosRenyi, GaltonWatsonTree, RealTree

Trees may be weighted or unweighted.

Interoperability — every structure converts to and from

  • NetworkX and igraph graphs
  • NumPy adjacency matrices and SciPy sparse matrices
  • Parent arrays, with left/right child information preserved for binary trees

This is the intended route to general graph-theoretic quantities for now: export to NetworkX or igraph and use their algorithms.

Visualization

  • Tree plots with disk (for duality), radial, force-directed, and hierarchical layouts
  • Coloring by Horton-Strahler order, with node and edge annotations
  • Time series, excursion, and extrema plots
  • Trees drawn side by side with their Harris path

Planned

None of the following is implemented yet. They are the roadmap, listed here because they are where the package is going, not what it does now.

Duals and visibility graphs

  • Duals of Binary Trees (Horizontal Tunnelability Graphs)
  • Duals of Binary Trees w/ Partial Trees
  • Dual of a Graph
  • Horizontal Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
  • Horizon Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
  • Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions

Further tree and time series constructions

  • Time Series Merge Trees of Arbitrary Time Series and of Arbitrary Functions
  • Chiral Merge Trees of Arbitrary Time Series and of Arbitrary Functions
  • U-shaped Segments of Arbitrary Time Series and of Arbitrary Functions
  • Hurst Exponents
  • Persistence Diagrams/Barcodes
  • Time-varying trees, and hence time-varying duals, with appropriate interpretation on time series

Native graph functionality

The graph classes are intended to become general enough to allow for:

  • Vertices with or without numerical weights as well as optional labels of arbitrary data type
  • Directed or undirected Edges with or without numerical weights and optional labels of arbitrary data type
  • Easy and efficient recall/computation of other graph representations and important quantities such as
  • Adjacency Matrix, Incidence Matrix, Adjacency List, Laplacian Matrix, Graph Distance Matrix, etc.
  • Graph Traversal Algorithms: DFS and BFS
  • Find Shortest Path, Shortest Path Function, Hamiltonian Path, Topological Sort
  • Find Graph Distances, Find Paths (Edge/Vertex Independent as well), Find Cycles (All, Eulerian, Hamiltonian, Postman, Shortest Tour)
  • Check if two Graphs are Isomorphic
  • Graph Union, Find Maximum Flow, Path Lengths, Mean Path Lengths, etc.
  • Compute Graph Polynomials: Tutte, Chromatic, Flow
  • Check if a Graph is a Subgraph of Another Graph
  • Generate Neighborhood Graphs and Subgraphs from Graphs
  • Get Connected Components of a Graph, k-Core Components, Weakly Connected Components
  • Find Cliques
  • Check if a Graph is a Tree (and if so how k-ary), if it is Acyclic, Bipartite, Planar, Loop Free, Simple, etc.
  • Graph Self-Similarity, Small-World Property, Scale-Invariance
  • Graph Metrics: Vertex and Edge Count, Vertex Degree/In and Out Degrees, Vertex Eccentricity
  • Graph Radius, Graph Diameter, Graph Center, Graph Periphery, Vertex and Edge Connectivity
  • Centrality Measures: Closeness, Betweenness, Edge Betweenness, Degree Centrality, Eigenvector Centrality, Katz Centrality, PageRank Centrality, HITS Centrality, Radiality, Status Centrality
  • Reciprocity and Transitivity Measures: Graph Reciprocity & Global, Local, and Mean Clustering Coefficients
  • Homophily, Assortative Mixing, and Similarity Measures: Assortativity, Vertex Correlation, Mean Neighbor Degree
  • Mean Degree Connectivity, Vertex Dice Similarity, Vertex Jaccard Similarity, Vertex Cosine Similarity
  • Mean Degree, Mean Path Length, Clustering Coefficients, Degree Distributions, Degree Sequences, many many other things

Documentation

Full API documentation, tutorials, and examples: https://treegraphduals.readthedocs.io

Getting help and contributing

Citing

If you use this package, please cite it via the DOI above, or see CITATION.cff. The underlying thesis is The Horizontal Tunnelability Graph is Dual to Level Set Trees (University of Nevada, Reno, 2023).

License

MIT

Metadata

Release files for treegraphduals 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treegraphduals 0.2.0
File Size Uploaded
treegraphduals-0.2.0.tar.gz 169.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for treegraphduals 0.2.0
File Interpreter ABI Platform
treegraphduals-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 213.5 kB

Release files / treegraphduals-0.2.0.tar.gz

Download URL treegraphduals-0.2.0.tar.gz
Size 169.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9ff16b7eed04e46665d8d784f67d9a3335b5fb44436b6b29562070eed7769516
BLAKE2b-256 checksum
How to use checksums
6c702579eac840919d00dd38d802b6bc4d49d77f2eec80f2971522a7ccc7d0b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / treegraphduals-0.2.0-py3-none-any.whl

Download URL treegraphduals-0.2.0-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0867cb6a4b9dc5e20045aaeeb7bbfe5d8b4183c0b8373b8353c48d2038542fa7
BLAKE2b-256 checksum
How to use checksums
7e303cf0e917b46d3ffa3c9a1899a4064134bc4f6fde69ee70a7936668589588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page