ytree.data_structures.arbor.Arbor.add_derived_field¶
-
Arbor.
add_derived_field
(name, function, units=None, description=None, vector_field=False, force_add=True)[source]¶ Add a field that is a function of other fields.
Parameters: - 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.
- 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.
Examples
>>> 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"])