Source

yt.workshop2012.fields / scripts / field_parameters.py

Full commit
from yt.mods import *

@derived_field(name = "delta_Velocity",
               validators = [ValidateParameter("bulk_velocity")])
def delta_Velocity(field, data):
    bv = data.get_field_parameter("bulk_velocity")
    delta_v = ((data["x-velocity"] - bv[0])**2.0
            +  (data["y-velocity"] - bv[1])**2.0
            +  (data["z-velocity"] - bv[2])**2.0)**0.5
    return delta_v

pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")

sp_small = pf.h.sphere("max", (0.01, 'mpc'))
bv = sp_small.quantities["BulkVelocity"]()

sp = pf.h.sphere("max", (1.0, 'mpc'))
sp.set_field_parameter("bulk_velocity", bv)

print sp["delta_Velocity"].min()
print sp["delta_Velocity"].max()