Arbor.add_derived_field(name, function, units=None, dtype=None, description=None, vector_field=False, force_add=True)[source]

Add a field that is a function of other fields.

  • name (string) – Field name.
  • function (callable) – The function to be called to generate the field. This function should take two arguments, the arbor and the data structure containing the dependent fields. See below for an example.
  • units (optional, string) – The units in which the field will be returned.
  • dtype (optional, type) – The data type of the field array. If none, use the default type set by Arbor._default_dtype.
  • description (optional, string) – A short description of the field.
  • vector_field (optional, bool) – If True, field is an xyz vector. Default: False.
  • force_add (optional, bool) – If True, add field even if it already exists and warn the user and raise an exception if dependencies do not exist. If False, silently do nothing in both instances. Default: True.


>>> import ytree
>>> a = ytree.load("tree_0_0_0.dat")
>>> def _redshift(field, data):
...     return 1. / data["scale"] - 1
>>> a.add_derived_field("redshift", _redshift)
>>> print (a["redshift"])