ytree.data_structures.tree_node_selector.add_tree_node_selector

ytree.data_structures.tree_node_selector.add_tree_node_selector(name, function)[source]

Add a TreeNodeSelector to the registry of known selectors, so they can be chosen with set_selector.

Parameters:
  • name (string) – Name of the selector.
  • function (callable) – The associated function.

Examples

>>> import ytree
>>> def max_value(ancestors, field):
...     vals = np.array([a[field] for a in ancestors])
...     return ancestors[np.argmax(vals)]
>>> ytree.add_tree_node_selector("max_field_value", max_value)
>>> a = ytree.load("tree_0_0_0.dat")
>>> a.set_selector("max_field_value", "mass")
>>> print (a[0]["prog"])