Derived Quantities

Derived quantities are a way of operating on a collection of cells and returning a set of values that is fewer in number than the number of cells – for instance yt already knows about several.

Using Derived Quantities

Every 3D data object (see Using and Manipulating Objects and Fields and Object Methodology) provides a mechanism for access to derived quantities. These can be accessed via the quantities interface, like so:

pf = load("my_data")
dd = pf.h.all_data()
dd.quantities["AngularMomentumVector"]()

The following quantities are available via the quantities interface.

AngularMomentumVector():

(This is a proxy for yt.lagos._AngularMomentumVector().) This function returns the mass-weighted average angular momentum vector.

BaryonSpinParameter():

(This is a proxy for yt.lagos._BaryonSpinParameter().) This function returns the spin parameter for the baryons, but it uses the particles in calculating enclosed mass.

BulkVelocity():

(This is a proxy for yt.lagos._BulkVelocity().) This function returns the mass-weighted average velocity in the object.

CenterOfMass():

(This is a proxy for yt.lagos._CenterOfMass().) This function takes no arguments and returns the location of the center of mass of the non-particle data in the object.

Extrema(fields):

(This is a proxy for yt.lagos._Extrema().) This function returns the extrema of a set of fields :param fields: A field name, or a list of field names

IsBound(truncate=True, include_thermal_energy=False):

(This is a proxy for yt.lagos._IsBound().) This returns whether or not the object is gravitationally bound. :param truncate: Should the calculation stop once the ratio of gravitational:kinetic is 1.0? :param include_thermal_energy: Should we add the energy from ThermalEnergy on to the kinetic energy to calculate binding energy?

MaxLocation(field):

(This is a proxy for yt.lagos._MaxLocation().) This function returns the location of the maximum of a set of fields.

ParticleSpinParameter():

(This is a proxy for yt.lagos._ParticleSpinParameter().) This function returns the spin parameter for the baryons, but it uses the particles in calculating enclosed mass.

TotalMass():

(This is a proxy for yt.lagos._TotalMass().) This function takes no arguments and returns the sum of cell masses and particle masses in the object.

TotalQuantity(fields):

(This is a proxy for yt.lagos._TotalQuantity().) This function sums up a given field over the entire region. :param fields: The fields to sum up

WeightedAverageQuantity(field, weight):

(This is a proxy for yt.lagos._WeightedAverageQuantity().) This function returns an averaged quantity. :param field: The field to average :param weight: The field to weight by

Creating Derived Quantities

The basic idea is that you need to be able to operate both on a set of data, and a set of sets of data. (If this is not possible, the quantity needs to be added with the force_unlazy option.)

Two functions are necessary. One will operate on arrays of data, either fed from each grid individually or fed from the entire data object at once. The second one takes the results of the first, either as lists of arrays or as single arrays, and returns the final values. For an example, we look at the TotalMass function:

def _TotalMass(data):
    baryon_mass = data["CellMassMsun"].sum()
    particle_mass = data["ParticleMassMsun"].sum()
    return baryon_mass, particle_mass
def _combTotalMass(data, baryon_mass, particle_mass):
    return baryon_mass.sum() + particle_mass.sum()
add_quantity("TotalMass", function=_TotalMass,
             combine_function=_combTotalMass, n_ret = 2)

Once the two functions have been defined, we then call add_quantity() to tell it the function that defines the data, the collator function, and the number of values that get passed between them. In this case we return both the particle and the baryon mass, so we have two total values passed from the main function into the collator.

Table Of Contents

Previous topic

Advanced yt Usage

Next topic

Plot Modification Mechanisms

This Page