[yt-svn] commit/cookbook: MatthewTurk: Updating a bunch of recipes to use newer coding practices.

Bitbucket commits-noreply at bitbucket.org
Wed May 23 20:06:03 PDT 2012


1 new commit in cookbook:


https://bitbucket.org/yt_analysis/cookbook/changeset/d0bda19b351e/
changeset:   d0bda19b351e
user:        MatthewTurk
date:        2012-05-24 05:05:45
summary:     Updating a bunch of recipes to use newer coding practices.
affected #:  18 files

diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 do_all.sh
--- a/do_all.sh
+++ b/do_all.sh
@@ -2,6 +2,7 @@
 for i in recipes/*.py
 #for i in recipes/simple_volume_rendering.py
 #for i in recipes/thin_slice_projection.py
+#for i in recipes/find_clumps.py
 do
     rname=`basename ${i}`
     rname=${rname%%.py}


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/aligned_cutting_plane.py
--- a/recipes/aligned_cutting_plane.py
+++ b/recipes/aligned_cutting_plane.py
@@ -10,22 +10,14 @@
 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.
+# take the angular momentum.  We create a sphere centered at this most dense
+# point.  We also want to make the radius 5.0 Mpc.
+sp = pf.h.sphere("max", (5.0, "mpc"))
+# Now we have an object which contains all of the data within 5 (radial)
+# 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)


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/arbitrary_vectors_on_slice.py
--- a/recipes/arbitrary_vectors_on_slice.py
+++ b/recipes/arbitrary_vectors_on_slice.py
@@ -6,15 +6,12 @@
 from yt.mods import * # set up our namespace
 
 fn = "RedshiftOutput0005" # parameter file to load
-ax = 0 # x-axis
 
 pf = load(fn) # load data
 pc = PlotCollection(pf) # defaults to center at most dense point
-p = pc.add_slice("Density", ax) 
-v1 = "%s-velocity" % (axis_names[x_dict[ax]])
-v2 = "%s-velocity" % (axis_names[y_dict[ax]])
-# This takes a few arguments, but we'll use the defaults here.  The third
-# argument is the 'skip' factor -- every how-many pixels to put a vector.
-p.modify["quiver"](v1, v2, 16)
+p = pc.add_slice("Density", "x") 
+# This takes a few arguments, but we'll use the defaults here.  The argument is
+# the 'skip' factor -- every how-many pixels to put a vector.
+p.modify["velocity"](16)
 pc.set_width(2.5, 'mpc') # change width of all plots in pc
 pc.save(fn) # save all plots


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/average_value.py
--- a/recipes/average_value.py
+++ b/recipes/average_value.py
@@ -16,7 +16,7 @@
                      # 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)
+        field, weight)
 
 print "Average %s (weighted by %s) is %0.5e" % (field, weight, average_value)
 


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/global_phase_plots.py
--- a/recipes/global_phase_plots.py
+++ b/recipes/global_phase_plots.py
@@ -14,14 +14,11 @@
 
 # We plot the average x-velocity (mass-weighted) in our object as a function of
 # Density and Temperature
-plot=pc.add_phase_object(dd, ["Density","Temperature","x-velocity"],
-                lazy_reader = True)
+plot=pc.add_phase_object(dd, ["Density","Temperature","x-velocity"])
 
 # We now plot the average value of x-velocity as a function of temperature
-plot=pc.add_profile_object(dd, ["Temperature", "x-velocity"],
-                lazy_reader = True)
+plot=pc.add_profile_object(dd, ["Temperature", "x-velocity"])
 
 # Finally, the velocity magnitude as a function of density
-plot=pc.add_profile_object(dd, ["Density", "VelocityMagnitude"],
-                lazy_reader = True)
+plot=pc.add_profile_object(dd, ["Density", "VelocityMagnitude"])
 pc.save() # save all plots


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/halo_particle_plotting.py
--- a/recipes/halo_particle_plotting.py
+++ b/recipes/halo_particle_plotting.py
@@ -9,8 +9,8 @@
 pf = load(fn) # load data
 halos = HaloFinder(pf)
 
-pc = PlotCollection(pf, [0.5, 0.5, 0.5])
-p = pc.add_projection("Density", 0)
+pc = PlotCollection(pf, "c")
+p = pc.add_projection("Density", "x")
 p.modify["hop_circles"](halos) # We like the circles for framing
 
 # Only plot the first 100 halos.  Also, by default the particles are


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/halo_plotting.py
--- a/recipes/halo_plotting.py
+++ b/recipes/halo_plotting.py
@@ -9,8 +9,8 @@
 pf = load(fn) # load data
 halos = HaloFinder(pf)
 
-pc = PlotCollection(pf, [0.5, 0.5, 0.5])
-p = pc.add_projection("Density", 0)
+pc = PlotCollection(pf, "c")
+p = pc.add_projection("Density", "x")
 p.modify["hop_circles"](halos)
 
 pc.save()


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/multi_plot.py
--- a/recipes/multi_plot.py
+++ b/recipes/multi_plot.py
@@ -21,16 +21,16 @@
 fig, axes, colorbars = get_multi_plot( 2, 1, colorbar=orient, bw = 4)
 
 # We'll use a plot collection, just for convenience's sake
-pc = PlotCollection(pf, center=[0.5, 0.5, 0.5])
+pc = PlotCollection(pf, "c")
 
 # Now we add a slice and set the colormap of that slice, but note that we're
 # feeding it an axes -- the zeroth row, the zeroth column, and telling the plot
 # "Don't make a colorbar."  We'll make one ourselves.
-p = pc.add_slice("Density", 0, figure = fig, axes = axes[0][0], use_colorbar=False)
+p = pc.add_slice("Density", "x", figure = fig, axes = axes[0][0], use_colorbar=False)
 p.set_cmap("bds_highcontrast") # this is our colormap
 
 # We do this again, but this time we take the 1-index column.
-p = pc.add_slice("Temperature", 0, figure=fig, axes=axes[0][1], use_colorbar=False)
+p = pc.add_slice("Temperature", "x", figure=fig, axes=axes[0][1], use_colorbar=False)
 p.set_cmap("hot") # a different colormap
 
 pc.set_width(5.0, 'mpc') # change width of both plots


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/multi_plot_3x2.py
--- a/recipes/multi_plot_3x2.py
+++ b/recipes/multi_plot_3x2.py
@@ -21,7 +21,7 @@
 fig, axes, colorbars = get_multi_plot( 2, 3, colorbar=orient, bw = 4)
 
 # We'll use a plot collection, just for convenience's sake
-pc = PlotCollection(pf, center=[0.5, 0.5, 0.5])
+pc = PlotCollection(pf, "c")
 
 # Now we follow the method of "multi_plot.py" but we're going to iterate
 # over the columns, which will become axes of slicing.


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/multi_plot_3x2_FRB.py
--- a/recipes/multi_plot_3x2_FRB.py
+++ b/recipes/multi_plot_3x2_FRB.py
@@ -18,9 +18,8 @@
 pf = load(fn) # load data
 
 # set up our Fixed Resolution Buffer parameters: a width, resolution, and center
-width = 7./pf['mpc']
+width = (7.0, "mpc")
 res = [1000, 1000]
-c = pf.h.find_max('Density')[1]
 #  get_multi_plot returns a containing figure, a list-of-lists of axes
 #   into which we can place plots, and some axes that we'll put
 #   colorbars.  
@@ -38,7 +37,7 @@
 # over the columns, which will become axes of slicing.
 plots = []
 for ax in range(3):
-    sli = pf.h.slice(ax,c[ax])
+    sli = pf.h.slice(ax, c[ax])
     frb = sli.to_frb(width, res, center=c, periodic=True)
     den_axis = axes[ax][0]
     temp_axis = axes[ax][1]


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/multi_width_save.py
--- a/recipes/multi_width_save.py
+++ b/recipes/multi_width_save.py
@@ -8,7 +8,7 @@
 fn = "RedshiftOutput0005" # parameter file to load
 pf = load(fn) # load data
 
-pc = PlotCollection(pf, center=[0.5, 0.5, 0.5]) # We get our Plot Collection object
+pc = PlotCollection(pf, "c") # We get our Plot Collection object
 
 # Note that when we save, we will be using string formatting to change all of
 # the bits in here.  You can add more, or remove some, if you like.
@@ -20,8 +20,8 @@
 #  widths += [ ... ]
 
 # Now we add a slice for x and y.
-pc.add_slice("Density", 0)
-pc.add_slice("Density", 1)
+pc.add_slice("Density", "x")
+pc.add_slice("Density", "y")
 
 # So for all of our widths, we will set the width of the plot and then make
 # sure that our limits for the colorbar are the min/max across the three plots.


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/overplot_particles.py
--- a/recipes/overplot_particles.py
+++ b/recipes/overplot_particles.py
@@ -8,12 +8,12 @@
 fn = "RedshiftOutput0005" # parameter file to load
 
 pf = load(fn) # load data
-pc = PlotCollection(pf, center=[0.5,0.5,0.5]) # defaults to center at most dense point
-p = pc.add_projection("Density", 0) # 0 = x-axis
+pc = PlotCollection(pf, "c") # center at middle of domain
+p = pc.add_projection("Density", "x")
 p.modify["particles"](1.0) # 1.0 is the 'width' we want for our slab of
                             # particles -- this governs the allowable locations
                             # of particles that show up on the image
                             # NOTE: we can also supply a *ptype* to cut based
                             # on a given (integer) particle type
-pc.set_width(1.0, '1') # change width of our plot to the full domain
+pc.set_width(1.0, 'unitary') # change width of our plot to the full domain
 pc.save(fn) # save all plots


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/simple_projection.py
--- a/recipes/simple_projection.py
+++ b/recipes/simple_projection.py
@@ -10,8 +10,8 @@
 
 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.add_projection("Density", "x", weight_field="Density") # 0 = x-axis
+pc.add_projection("Density", "y", weight_field="Density") # 1 = y-axis
+pc.add_projection("Density", "z", 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


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/simple_slice.py
--- a/recipes/simple_slice.py
+++ b/recipes/simple_slice.py
@@ -9,8 +9,8 @@
 
 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.add_slice("Density", "x") # 0 = x-axis
+pc.add_slice("Density", "y") # 1 = y-axis
+pc.add_slice("Density", "z") # 2 = z-axis
 pc.set_width(1.5, 'mpc') # change width of all plots in pc
 pc.save(fn) # save all plots


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/sum_mass_in_sphere.py
--- a/recipes/sum_mass_in_sphere.py
+++ b/recipes/sum_mass_in_sphere.py
@@ -10,11 +10,10 @@
 fn = "RedshiftOutput0005" # parameter file to load
 
 pf = load(fn) # load data
-v, c = pf.h.find_max("Density")
-sp = pf.h.sphere(c, 1.0/pf["mpc"])
+sp = pf.h.sphere("max", (1.0, "mpc"))
 
 baryon_mass, particle_mass = sp.quantities["TotalQuantity"](
-        ["CellMassMsun", "ParticleMassMsun"], lazy_reader=True)
+        ["CellMassMsun", "ParticleMassMsun"])
 
 print "Total mass in sphere is %0.5e (gas = %0.5e / particles = %0.5e)" % \
             (baryon_mass + particle_mass, baryon_mass, particle_mass)


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/thin_slice_projection.py
--- a/recipes/thin_slice_projection.py
+++ b/recipes/thin_slice_projection.py
@@ -15,5 +15,5 @@
 # fully covers the domain in y and z, but only a portion of it in x.
 region = pf.h.region([0.3, 0.5, 0.5], [0.1, 0.0, 0.0], [0.5, 1.0, 1.0])
 
-pc.add_projection("Density", 0, weight_field="Density", data_source = region) # 0 = x-axis
+pc.add_projection("Density", "x", weight_field="Density", data_source = region) # 0 = x-axis
 pc.save(fn) # save all plots


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/time_series_phase.py
--- a/recipes/time_series_phase.py
+++ b/recipes/time_series_phase.py
@@ -13,12 +13,12 @@
     # We create a plot collection to hold our plot
     # If we don't specify the center, it will look for one -- but we don't
     # really care where it's centered for this plot.
-    pc = PlotCollection(pf, center=[0.5, 0.5, 0.5])
+    pc = PlotCollection(pf, "c")
 
     # Now we add a phase plot of a sphere with radius 1.0 in code units.
     # If your domain is not 0..1, then this may not cover it completely.
     p = pc.add_phase_sphere(1.0, '1', ["Density", "Temperature", "CellMassMsun"],
-                        weight=None, lazy_reader=True,
+                        weight=None,
                         x_bins=128, x_bounds = (1e-32, 1e-24),
                         y_bins=128, y_bounds = (1e2, 1e7))
     # We've over-specified things -- but this will help ensure we have constant


diff -r da7039602d04bec1b7e3724a3be4456e7edafece -r d0bda19b351eed6ba34d63682975946d34b00a68 recipes/zoomin_frames.py
--- a/recipes/zoomin_frames.py
+++ b/recipes/zoomin_frames.py
@@ -11,14 +11,13 @@
               # this is used.
 min_dx = 40   # This is the minimum size in smallest_dx of our last frame.
               # Usually it should be set to something like 400, but for THIS
-              # dataset, we actually don't have that great of resolution.
+              # dataset, we actually don't have that great of resolution.:w
 
 pf = load(fn) # load data
 frame_template = "frame_%05i" # Template for frame filenames
 
-pc = PlotCollection(pf, center=[0.5, 0.5, 0.5]) # We make a plot collection that defaults to being
-                        # centered at the most dense point.
-p = pc.add_slice("Density", 2) # Add our slice, along z
+pc = PlotCollection(pf, "c")
+p = pc.add_slice("Density", "z") # Add our slice, along z
 p.modify["contour"]("Temperature") # We'll contour in temperature -- this kind
                                     # of modification can't be done on the command
                                     # line, so that's why we have the recipe!

Repository URL: https://bitbucket.org/yt_analysis/cookbook/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list