ytree.data_structures.tree_node.TreeNode.get_leaf_nodes¶
-
TreeNode.
get_leaf_nodes
(selector=None)[source]¶ Get all leaf nodes from the tree of which this is the head.
This returns a generator of all leaf nodes belonging to this tree. A leaf node is a node that has no ancestors.
Parameters: selector (optional, str ("forest", "tree", or "prog")) – The tree selector from which leaf nodes will be found. If none given, this will be set to “forest” if the calling node is a root node and “tree” otherwise. Returns: leaf_nodes – TreeNode
objects.Return type: a generator of Examples
>>> import ytree >>> a = ytree.load("tiny_ctrees/locations.dat") >>> my_tree = a[0] >>> for leaf in my_tree.get_leaf_nodes(): ... print (leaf["mass"])