Project notes

Fixing Branch Connections in TreeQSM

TreeQSM sometimes gets branch connections wrong on orchard trees. I built a tool to repair those connections so the models could be used to measure tree structure.

My role

I built the repair tool, from reconstructing the branch graph to exporting corrected TreeQSM files and 3D views for checking the results.

Stack

PythonTreeQSMNetworkXNumPyPandasPlotly

About the project

TreeQSM represents a tree as a set of cylinders. While working with orchard trees, I found that their shapes could look reasonable even when the branch connections were wrong. I built a tool that reconstructs those connections, identifies the trunk and branch orders, and writes the corrected structure back into the same file format.

How it works

  • 1Builds a branch graph from cylinder centerlines and detects and removes cycles.
  • 2Finds the shared trunk and separates it from the main branches.
  • 3Uses branch length and radius to decide which path continues a branch.
  • 4Writes corrected connections and branch orders in a TreeQSM-compatible format.
  • 5Processes batches of CSV files and saves a 3D view of each result for inspection.

At a glance

  • →Reached about 90% agreement with the expected branch structure in internal checks on open-vase trees.
  • →Exported corrected CSV files and interactive 3D views for use in other tree research projects.

Why this project

The open-vase trees I was studying spread out from a short trunk, which gave TreeQSM trouble. Cylinders could end up assigned to the wrong branch or parent. That made measurements based on branch order unreliable and left a lot of manual cleanup before the models were useful.

The approach

I rebuilt each tree as a directed graph using the cylinder centerlines. Existing parent fields provide the connections where available; otherwise, the tool connects nearby endpoints while checking their direction. It follows long paths to identify the main branches, with a preference for a competing branch when its radius is at least twice as large. The shared part of those paths becomes the trunk. From there, it assigns higher branch orders and rewrites the parent, branch, extension, and position fields.

Results and notes

The tool produces a cleaned_fixed.csv file for each tree and a Plotly view showing the trunk and branch orders. It can process a directory of trees at once and export the graph assignments for debugging. The useful lesson here was that a plausible-looking 3D model can still have incorrect connections, so inspecting the branch structure matters as much as inspecting the shape.

Links