"""
This recipe finds the average value of a quantity through the entire box.  (See
:ref:`derived-quantities`.)  Note that this recipe will take advantage of
multiple CPUs if executed with mpirun and supplied the --parallel command line
argument.
"""
from yt.mods import *

fn = "RedshiftOutput0005" # parameter file to load
pf = load(fn) # load data

field = "Temperature"  # The field to average
weight = "CellMassMsun" # The weight for the average

dd = pf.h.all_data() # This is a region describing the entire box,
                     # but note it doesn't read anything in yet!
# We now use our 'quantities' call to get the average quantity
average_value = dd.quantities["WeightedAverageQuantity"](
        field, weight, lazy_reader=True)

print "Average %s (weighted by %s) is %0.5e" % (field, weight, average_value)

