Commits

Britton Smith committed 8715d11

Updating simple recipes and moving to .py files.

Comments (0)

Files changed (15)

source/cookbook/simple_pdf.inc

-.. _cookbook-simple_pdf:
-
-Simple pdf
-----------
-
-If you would like to create a phase plot such that the mass
-distribution represents the fraction of the total mass rather than
-absolute mass, you must include the "fractional" keyword.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_pdf.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-   
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   pc = PlotCollection(pf) # defaults to center at most dense point
-   pc.add_phase_sphere(10.0, "mpc", # how many of which unit at pc.center
-      ["Density", "Temperature", "CellMassMsun"], # our fields: x, y, color
-      weight=None, # don't take the average value in a cell, just sum them up
-      fractional=True)  #return fractional mass values rather than absolute
-   pc.save(fn) # save all plots
-   
-
-.. rubric:: Sample Output
-
-.. image:: _simple_pdf/simple_pdf_RedshiftOutput0005_Profile2D_0_Density_Temperature_CellMassMsun.png
-   :width: 240
-   :target: ../_images/simple_pdf_RedshiftOutput0005_Profile2D_0_Density_Temperature_CellMassMsun.png
-
-

source/cookbook/simple_pdf.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# This is identical to the simple profile, except we
+# add the fractional keyword to divide the values in
+# each bin by the sum of all bins.
+pc.add_phase_sphere(10.0, "mpc",
+   ["Density", "Temperature", "CellMassMsun"],
+   weight=None,
+   fractional=True)
+
+# Save the image.
+# Optionally, give a string as an argument
+# to name files with a keyword.
+pc.save()

source/cookbook/simple_phase.inc

-.. _cookbook-simple_phase:
-
-Simple phase
-------------
-
-This is a simple recipe to show how to open a dataset and then plot a phase
-plot showing mass distribution in the rho-T plane.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_phase.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-   
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   pc = PlotCollection(pf) # defaults to center at most dense point
-   pc.add_phase_sphere(10.0, "mpc", # how many of which unit at pc.center
-       ["Density", "Temperature", "CellMassMsun"], # our fields: x, y, color
-       weight=None) # don't take the average value in a cell, just sum them up
-   pc.save(fn) # save all plots
-   
-
-.. rubric:: Sample Output
-
-.. image:: _simple_phase/simple_phase_RedshiftOutput0005_Profile2D_0_Density_Temperature_CellMassMsun.png
-   :width: 240
-   :target: ../_images/simple_phase_RedshiftOutput0005_Profile2D_0_Density_Temperature_CellMassMsun.png
-
-

source/cookbook/simple_phase.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# Create a 2D profile within a sphere of radius 10 Mpc
+# of the total mass in bins of density and temperature.
+# Setting weight to None will calculate a sum.
+# Setting weight to a field will calculate an average
+# weighted by that field.
+pc.add_phase_sphere(10.0, "mpc",
+    ["Density", "Temperature", "CellMassMsun"],
+    weight=None)
+
+# Save the image.
+# Optionally, give a string as an argument
+# to name files with a keyword.
+pc.save()
+

source/cookbook/simple_profile.inc

-.. _cookbook-simple_profile:
-
-Simple profile
---------------
-
-This is a simple recipe to show how to open a dataset and then plot a 
-profile showing mass-weighted average Temperature as a function of Density
-inside a sphere.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_profile.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-   
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   pc = PlotCollection(pf) # defaults to center at most dense point
-   pc.add_profile_sphere(10.0, "mpc", # how many of which unit at pc.center
-       ["Density", "Temperature"], weight="CellMassMsun") # x, y, weight
-   pc.save(fn) # save all plots
-   
-
-.. rubric:: Sample Output
-
-.. image:: _simple_profile/simple_profile_RedshiftOutput0005_Profile1D_0_Density_Temperature.png
-   :width: 240
-   :target: ../_images/simple_profile_RedshiftOutput0005_Profile1D_0_Density_Temperature.png
-
-

source/cookbook/simple_profile.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# Create a 1D profile within a sphere of radius 10 Mpc
+# of the average temperature vs. density, weighted by mass.
+pc.add_profile_sphere(10.0, "mpc",
+    ["Density", "Temperature"], weight="CellMassMsun")
+
+# Save the image.
+# Optionally, give a string as an argument
+# to name files with a keyword.
+pc.save()

source/cookbook/simple_projection.inc

-.. _cookbook-simple_projection:
-
-Simple projection
------------------
-
-This is a simple recipe to show how to open a dataset and then take a
-weighted-average projection through it, centered at its most dense point. 
-This will only project along grid axes (i.e. x,y,z).  In order to do 
-project along arbitrary projection angles, see the entry for Offaxis Projections. For more information see :ref:`methods-projections`.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_projection.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-   
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   pc = PlotCollection(pf) # defaults to center at most dense point
-   pc.add_projection("Density", 0, weight_field="Density") # 0 = x-axis
-   pc.add_projection("Density", 1, weight_field="Density") # 1 = y-axis
-   pc.add_projection("Density", 2, weight_field="Density") # 2 = z-axis
-   pc.set_width(1.5, 'mpc') # change width of all plots in pc
-   pc.save(fn) # save all plots
-   
-
-.. rubric:: Sample Output
-
-.. image:: _simple_projection/simple_projection_RedshiftOutput0005_Projection_x_Density_Density.png
-   :width: 240
-   :target: ../_images/simple_projection_RedshiftOutput0005_Projection_x_Density_Density.png
-.. image:: _simple_projection/simple_projection_RedshiftOutput0005_Projection_y_Density_Density.png
-   :width: 240
-   :target: ../_images/simple_projection_RedshiftOutput0005_Projection_y_Density_Density.png
-.. image:: _simple_projection/simple_projection_RedshiftOutput0005_Projection_z_Density_Density.png
-   :width: 240
-   :target: ../_images/simple_projection_RedshiftOutput0005_Projection_z_Density_Density.png
-
-

source/cookbook/simple_projection.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# Create projections of the density-weighted mean density.
+pc.add_projection("Density", "x", weight_field="Density")
+pc.add_projection("Density", "y", weight_field="Density")
+pc.add_projection("Density", "z", weight_field="Density")
+
+# Change the width of the image.
+pc.set_width(1.5, 'mpc')
+
+# Save the image.
+# Optionally, give a string as an argument
+# to name files with a keyword.
+pc.save()

source/cookbook/simple_radial_profile.inc

-.. _cookbook-simple_radial_profile:
-
-Simple radial profile
----------------------
-
-This is a simple recipe to show how to open a dataset and then plot a radial
-profile showing mass-weighted average Density inside a sphere.  For more
-information, see :ref:`methods-profiles`.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_radial_profile.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-   
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   pc = PlotCollection(pf) # defaults to center at most dense point
-   pc.add_profile_sphere(10.0, "mpc", # how many of which unit at pc.center
-       ["RadiusMpc", "Density"], weight="CellMassMsun", # x, y, weight
-        x_bounds = (1e-3, 10.0))  # cut out zero-radius and tiny-radius cells
-       # But ... weight defaults to CellMassMsun, so we're being redundant here!
-   pc.save(fn) # save all plots
-   
-
-.. rubric:: Sample Output
-
-.. image:: _simple_radial_profile/simple_radial_profile_RedshiftOutput0005_Profile1D_0_RadiusMpc_Density.png
-   :width: 240
-   :target: ../_images/simple_radial_profile_RedshiftOutput0005_Profile1D_0_RadiusMpc_Density.png
-
-

source/cookbook/simple_radial_profile.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# Create a 1D profile within a sphere of radius 10 Mpc
+# of the average density vs. radius, weighted by mass.
+# We will also manually set the radius bounds.
+pc.add_profile_sphere(10.0, "mpc",
+    ["RadiusMpc", "Density"], weight="CellMassMsun",
+     x_bounds = (1e-3, 10.0))
+
+# Save the image.
+# Optionally, give a string as an argument
+# to name files with a keyword.
+pc.save()

source/cookbook/simple_slice.inc

-.. _cookbook-simple_slice:
-
-Simple slice
-------------
-
-This is a simple recipe to show how to open a dataset and then plot a slice
-through it, centered at its most dense point.  For more information, see
-:ref:`methods-slices`.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_slice.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-   
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   pc = PlotCollection(pf) # defaults to center at most dense point
-   pc.add_slice("Density", 0) # 0 = x-axis
-   pc.add_slice("Density", 1) # 1 = y-axis
-   pc.add_slice("Density", 2) # 2 = z-axis
-   pc.set_width(1.5, 'mpc') # change width of all plots in pc
-   pc.save(fn) # save all plots
-   
-
-.. rubric:: Sample Output
-
-.. image:: _simple_slice/simple_slice_RedshiftOutput0005_Slice_x_Density.png
-   :width: 240
-   :target: ../_images/simple_slice_RedshiftOutput0005_Slice_x_Density.png
-.. image:: _simple_slice/simple_slice_RedshiftOutput0005_Slice_y_Density.png
-   :width: 240
-   :target: ../_images/simple_slice_RedshiftOutput0005_Slice_y_Density.png
-.. image:: _simple_slice/simple_slice_RedshiftOutput0005_Slice_z_Density.png
-   :width: 240
-   :target: ../_images/simple_slice_RedshiftOutput0005_Slice_z_Density.png
-
-

source/cookbook/simple_slice.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# Create density slices in all three axes.
+pc.add_slice("Density", "x")
+pc.add_slice("Density", "y")
+pc.add_slice("Density", "z")
+
+# Change the width of the image.
+pc.set_width(1.5, 'mpc')
+
+# Save the image.
+# Optionally, give a string as an argument
+# to name files with a keyword.
+pc.save()

source/cookbook/simple_volume_rendering.inc

-.. _cookbook-simple_volume_rendering:
-
-Simple volume rendering
------------------------
-
-This recipe shows how to volume render a dataset. 
-See :ref:`volume_rendering` for more information, as there is considerably more
-functionality than is demonstrated here.
-
-Additionally, for the purposes of the recipe, we have simplified the image
-considerably.
-
-The latest version of this recipe can be downloaded here: http://hg.yt-project.org/cookbook/raw/tip/recipes/simple_volume_rendering.py .
-
-.. code-block:: python
-
-   from yt.mods import * # set up our namespace
-      
-   fn = "RedshiftOutput0005" # parameter file to load
-   
-   pf = load(fn) # load data
-   
-   dd = pf.h.all_data()
-   
-   # Get the bounds of density
-   mi, ma = dd.quantities["Extrema"]("Density")[0]
-   
-   # We supply the min/max we want the function to cover, in log.
-   # For this dataset it's -31 and -27.
-   tf = ColorTransferFunction((na.log10(mi), na.log10(ma)))
-   
-   # Now we add some Gaussians on.  Work is underway to transform this into a
-   # graphical user interface, and the initial steps can be found in
-   # transfer_function_widget.py .
-   
-   # We now just add a couple gaussians, sampled inside the colormap "gist_stern"
-   # at equally-spaced locations in the transfer function.  We make them a bit
-   # wider, too.
-   tf.add_layers(6, w=0.02)
-   
-   # Now we need a center of our volume to render.  Here we'll just use
-   # 0.5,0.5,0.5, because volume renderings are not periodic.
-   c = [0.5, 0.5, 0.5]
-   
-   # Our image plane will be normal to some vector.  For things like collapsing
-   # objects, you could set it the way you would a cutting plane -- but for this
-   # dataset, we'll just choose an off-axis value at random.  This gets normalized
-   # automatically.
-   L = [0.5, 0.2, 0.7]
-   
-   # Our "width" is the width of the image plane as well as the depth -- so we set
-   # it to be 1.0 so we get the whole domain.
-   W = 1.0
-   
-   # Now we decide how big an image we want.  512x512 should be sufficient.
-   Nvec = 512
-   
-   # Now we call the ray caster, which handles the rest.
-   # Note that we feed whole_box, which means that it won't apply any cuts to the
-   # considered grids.  This may be unnecessary for most appliations.
-   cam = pf.h.camera(L, W, c, Nvec, tf)
-   
-   # Now we tell the camera object to take a snapshot, casting the rays
-   image = cam.snapshot()
-   
-   # If we want to save the image when we take this snapshot, we can use the
-   # keyword fn= :
-   # image = cam.snapshot("%s_volume_rendering.png" % pf)
-   
-   # Othwerwise, we can then write out the image using our direct bitmap writer
-   write_bitmap(image, "%s_volume_rendered.png" % pf)
-   
-   
-
-
-

source/cookbook/simple_volume_rendering.py

+from yt.mods import *
+
+# Load the dataset.
+pf = load("RedshiftOutput0005")
+
+# Create a plot collection for the dataset.
+# With no additional arguments, the center will be
+# the densest point in the box.
+pc = PlotCollection(pf)
+
+# Create a data container (like a sphere or region) that
+# represents the entire domain.
+dd = pf.h.all_data()
+
+# Get the minimum and maximum densities.
+mi, ma = dd.quantities["Extrema"]("Density")[0]
+
+# Create a transfer function to map field values to colors.
+tf = ColorTransferFunction((na.log10(mi), na.log10(ma)))
+
+# Add six guassians, evenly spaced between the min and
+# max specified above with widths of 0.02 and using the
+# gist_stern colormap.
+tf.add_layers(6, w=0.02, colormap="gist_stern")
+
+# Choose a center for the render.
+c = [0.5, 0.5, 0.5]
+
+# Choose a vector representing the viewing direction.
+L = [0.5, 0.2, 0.7]
+
+# Set the width of the image.
+# Decreasing or increasing this value
+# results in a zoom in or out.
+W = 1.0
+
+# The number of pixels along one side of the image.
+# The final image will have Npixel^2 pixels.
+Npixels = 512
+
+# Create a camera object.
+# This object creates the images and
+# can be moved and rotated.
+cam = pf.h.camera(c, L, W, Npixels, tf)
+
+# Create a snapshot.
+# Here, snapshot is an array representing the image.
+image = cam.snapshot()
+
+# Write out the final image and give it a name
+# relating to what our dataset is called.
+write_bitmap(image, "%s_volume_rendered.png" % pf)
+

source/cookbook/simplest_slice.inc

-Simplest slice
---------------
-
-This is a script to show the absolute simplest way to make a slice of an
-object.  It's not fancy, but it's short!
-
-The latest version of this recipe can be downloaded `here <http://hg.yt-project.org/cookbook/raw-file/tip/recipes/simplest_slice.py>`_.
-
-.. code-block:: python
-
-   
-   from yt.mods import *
-   
-   
-
-
-