ytree.data_structures.tree_node.TreeNode.get_node

TreeNode.get_node(selector, index)[source]

Get a single TreeNode from a tree.

Use this to get the nth TreeNode from a forest, tree, or progenitor list.

For forest selection, the index value is absolute and refers to the entire forest in which the node belongs.

For tree and prog selection, the index refers to the tree for which the calling TreeNode is the head.

Parameters:
  • selector (str ("forest", "tree", or "prog")) – The tree selector from which to get the TreeNode. This should be “forest”, “tree”, or “prog”.

  • index (int) – The index of the desired TreeNode in the forest, tree, or progenitor list.

Returns:

node

Return type:

TreeNode

Examples

>>> import ytree
>>> a = ytree.load("tiny_ctrees/locations.dat")
>>> my_tree = a[0]
>>> # get 6th TreeNode in the progenitor list
>>> my_node = my_tree.get_node('prog', 5)