Source

2011-yt-princeton-tutorial / scripts / derived_fields.py

Full commit
from yt.mods import *

@derived_field(name = "Dinosaurs", units = "TRexPerS")
def Dinosaurs(field, data):
    return (data["Density"]**(2./3) /
            data["Temperature"]**(0.5))

pf = load("DD0023/DD0023")
dd = pf.h.all_data()

dinosaurs, = dd.quantities["TotalQuantity"](["Dinosaurs"])
print "Total T-Rexes per Second: %0.3e" % (dinosaurs)