"""
This is a recipe to show how to open a dataset, calculate the angular momentum
vector in a sphere, and then use that to take an oblique slice.  See
:ref:`derived-quantities` and :ref:`methods-cutting-planes` for more information.
"""
from yt.mods import * # set up our namespace

fn = "RedshiftOutput0005" # parameter file to load

pf = load(fn) # load data

# Now let's create a data object that describes the region of which we wish to
# take the angular momentum.

# First find the most dense point, which will serve as our center.  We get the
# most dense value for free, too!  This is an operation on the 'hierarchy',
# rather than the parameter file.
v, c = pf.h.find_max("Density")
print "Found highest density of %0.3e at %s" % (v, c)
# Now let's get a sphere centered at this most dense point, c.  We have to
# convert '5' into Mpc, which means we have to use unit conversions provided by
# the parameter file.  To convert *into* code units, we divide.  (To convert
# back, we multiply.)
sp = pf.h.sphere(c, 5.0 / pf["mpc"])
# Now we have an object which contains all of the data within 5 megaparsecs of
# the most dense point.  So we want to calculate the angular momentum vector of
# this 5 Mpc set of gas, and yt provides the facility for that inside a
# "derived quantity" property.  So we use that, and it returns a vector.
L = sp.quantities["AngularMomentumVector"]()

print "Angular momentum vector: %s" % (L)

pc = PlotCollection(pf, center=c) # Make a new plot holder
pc.add_cutting_plane("Density", L) # Add our oblique slice
pc.set_width(2.5, 'mpc') # change the width
pc.save(fn) # save out with the pf as a prefix to the image name
