[yt-svn] commit/cookbook: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Mon Dec 12 10:12:12 PST 2011


3 new commits in cookbook:


https://bitbucket.org/yt_analysis/cookbook/changeset/30db0cca1f78/
changeset:   30db0cca1f78
user:        samskillman
date:        2011-12-12 19:09:43
summary:     Updating simple_volume_rendering cookbook to use camera interface.
affected #:  1 file

diff -r 3ec812af8bca7aa390922f61adcfe9513cfda982 -r 30db0cca1f78bdc5afb01a5a8d6c8e1524773700 recipes/simple_volume_rendering.py
--- a/recipes/simple_volume_rendering.py
+++ b/recipes/simple_volume_rendering.py
@@ -1,15 +1,13 @@
 """
-This recipe shows how to volume render a dataset.  There are a number of
-twiddles, and rough edges, and the process is still very much in beta.
-See :ref:`volume_rendering` for more information.  In particular, this
-interface will do some things very easily, but it provides almost no
-customizability.  The Camera interface is recommended.
+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.
 """
 from yt.mods import * # set up our namespace
-
+   
 fn = "RedshiftOutput0005" # parameter file to load
 
 pf = load(fn) # load data
@@ -52,10 +50,15 @@
 # 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.
-vp = pf.h.volume_rendering(L, W, c, Nvec, tf, whole_box=True)
+cam = pf.h.camera(L, W, c, Nvec, tf)
 
-# Now we tell the volume rendering object to cast the rays
-vp.ray_cast()
+# Now we tell the camera object to take a snapshot, casting the rays
+image = cam.snapshot()
 
-# And now, we call our direct image saver.  
-write_bitmap(vp.image, "%s_volume_rendered.png" % pf)
+# 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)
+



https://bitbucket.org/yt_analysis/cookbook/changeset/589f3f219427/
changeset:   589f3f219427
user:        samskillman
date:        2011-12-12 19:10:05
summary:     Adding a cookbook of how to use the camera movement functionality.
affected #:  1 file

diff -r 30db0cca1f78bdc5afb01a5a8d6c8e1524773700 -r 589f3f219427dcff96d29a6c4780f8af11d1dcbd recipes/camera_movement.py
--- /dev/null
+++ b/recipes/camera_movement.py
@@ -0,0 +1,51 @@
+"""
+This recipe shows how to use the movement functions hanging off of the Camera
+object.  See :ref:`volume_rendering` for more information.  
+
+Additionally, for the purposes of the recipe, we have simplified the image
+considerably.
+"""
+from yt.mods import * # set up our namespace
+   
+# Follow the simple_volume_rendering cookbook for the first part of this.
+fn = "RedshiftOutput0005" # parameter file to load
+pf = load(fn) # load data
+dd = pf.h.all_data()
+mi, ma = dd.quantities["Extrema"]("Density")[0]
+
+# Set up transfer function
+tf = ColorTransferFunction((na.log10(mi), na.log10(ma)))
+tf.add_layers(6, w=0.05)
+
+# Set up camera paramters
+c = [0.5, 0.5, 0.5] # Center
+L = [1, 1, 1] # Normal Vector
+W = 1.0 # Width
+Nvec = 512 # Pixels on a side
+
+# Specify a north vector, which helps with rotations.
+north_vector = [0.,0.,1.]
+
+# Find the maximum density location, store it in max_c
+v,max_c = pf.h.find_max('Density')
+
+# Initialize the Camera
+cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf, north_vector=north_vector)
+frame = 0
+
+# Do a rotation
+for i, snapshot in enumerate(cam.rotation(na.pi, 30)):
+    write_bitmap(snapshot, 'camera_movement_%04i.png' % frame)
+    frame += 1
+
+# Move to the maximum density location
+for i, snapshot in enumerate(cam.move_to(max_c, 10)):
+    write_bitmap(snapshot, 'camera_movement_%04i.png' % frame)
+    frame += 1
+
+# Zoom in
+for i, snapshot in enumerate(cam.zoomin(10.0, 10)):
+    write_bitmap(snapshot, 'camera_movement_%04i.png' % frame)
+    frame += 1
+
+



https://bitbucket.org/yt_analysis/cookbook/changeset/5fae7bd246f7/
changeset:   5fae7bd246f7
user:        samskillman
date:        2011-12-12 19:10:23
summary:     Merging.
affected #:  4 files

diff -r 589f3f219427dcff96d29a6c4780f8af11d1dcbd -r 5fae7bd246f7bbcdabb55c302a55d39c3752aa71 recipes/boolean_data_objects.py
--- /dev/null
+++ b/recipes/boolean_data_objects.py
@@ -0,0 +1,31 @@
+"""
+Below shows the creation of a number of boolean data objects, which
+are built upon previously-defined data objects. The boolean
+data ojbects can be used like any other, except for a few cases.
+Please see :ref:`boolean_data_objects` for more information.
+"""
+from yt.mods import * # set up our namespace
+
+fn = "RedshiftOutput0005" # parameter file to load
+
+pf = load(fn) # load data
+# Make a few data ojbects to start.
+re1 = pf.h.region([0.5, 0.5, 0.5], [0.4, 0.4, 0.4], [0.6, 0.6, 0.6])
+re2 = pf.h.region([0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6])
+sp1 = pf.h.sphere([0.5, 0.5, 0.5], 0.05)
+sp2 = pf.h.sphere([0.1, 0.2, 0.3], 0.1)
+# The "AND" operator. This will make a region identical to re2.
+bool1 = pf.h.boolean([re1, "AND", re2])
+xp = bool1["particle_position_x"]
+# The "OR" operator. This will make a region identical to re1.
+bool2 = pf.h.boolean([re1, "OR", re2])
+# The "NOT" operator. This will make a region like re1, but with the corner
+# that re2 covers cut out.
+bool3 = pf.h.boolean([re1, "NOT", re2])
+# Disjoint regions can be combined with the "OR" operator.
+bool4 = pf.h.boolean([sp1, "OR", sp2])
+# Find oddly-shaped overlapping regions.
+bool5 = pf.h.boolean([re2, "AND", sp1])
+# Nested logic with parentheses.
+# This is re1 with the oddly-shaped region cut out.
+bool6 = pf.h.boolean([re1, "NOT", "(", re1, "AND", sp1, ")"])


diff -r 589f3f219427dcff96d29a6c4780f8af11d1dcbd -r 5fae7bd246f7bbcdabb55c302a55d39c3752aa71 recipes/halo_finding.py
--- a/recipes/halo_finding.py
+++ b/recipes/halo_finding.py
@@ -1,5 +1,5 @@
 """
-This script shows the simples way of getting halo information.  For more
+This script shows the simplest way of getting halo information.  For more
 information, see :ref:`halo_finding`.
 """
 from yt.mods import * # set up our namespace


diff -r 589f3f219427dcff96d29a6c4780f8af11d1dcbd -r 5fae7bd246f7bbcdabb55c302a55d39c3752aa71 recipes/make_light_ray.py
--- /dev/null
+++ b/recipes/make_light_ray.py
@@ -0,0 +1,56 @@
+import os
+import sys
+
+from yt.mods import *
+from yt.analysis_modules.halo_profiler.api import *
+from yt.analysis_modules.light_ray.api import *
+
+# Get the simulation parameter file from the command line.
+par_file = sys.argv[1]
+
+# Instantiate a ray object from z = 0 to z = 0.1 using the 
+# minimum number of datasets.
+lr = LightRay(par_file, 0.0, 0.1, use_minimum_datasets=True)
+
+# The next four variables are used when get_nearest_galaxy is set to True.
+# This option will calculate the distance and mass of the halo nearest to 
+# each element of the ray.
+# The light ray tool accomplishes this by using the HaloProfiler.
+# Here we are providing the LightRay with instructions to give the HaloProfiler.
+# This is a dictionary of standard halo profiler keyword arguments and values.
+halo_profiler_kwargs = {'halo_list_format': {'id':0, 'center':[4, 5, 6], 
+                                             'TotalMassMsun':1},
+                        'halo_list_file': 'HopAnalysis.out'}
+# This is a list of actions we want the HaloProfiler to perform.
+# Note that each list item is a dictionary with the following three 
+# entries: 'function', 'args', and 'kwargs'.
+# These are the function to be called, the arguments to that function, and 
+# any keyword arguments.
+halo_profiler_actions = [{'function': make_profiles,
+                          'args': None,
+                          'kwargs': {'filename': 'VirializedHalos.out'}},
+                         {'function': add_halo_filter,
+                          'args': VirialFilter,
+                          'kwargs': {'overdensity_field': 'ActualOverdensity',
+                                     'virial_overdensity': 200,
+                                     'virial_filters': [['TotalMassMsun','>=','1e14']],
+                                     'virial_quantities': ['TotalMassMsun','RadiusMpc']}}]
+# This option can only be 'all' or 'filtered' and tells the HaloProfiler to 
+# use either the full halo list or the filtered list made after calling make_profiles.
+halo_list = 'filtered'
+
+# This is the name of the field from the halo list that represents the halo mass.
+halo_mass_field = 'TotalMassMsun_200'
+
+# Make the ray and get the Density and Temperature fields, the nearest galaxy information, and 
+# the line of sight velocity.
+lr.make_light_ray(seed=8675309, 
+                  solution_filename='lightraysolution.txt',
+                  data_filename='lightray.h5',
+                  fields=['Temperature', 'Density'],
+                  get_nearest_galaxy=True, 
+                  halo_profiler_kwargs=halo_profiler_kwargs,
+                  halo_profiler_actions=halo_profiler_actions, 
+                  halo_list=halo_list,
+                  halo_mass_field=halo_mass_field,
+                  get_los_velocity=True)


diff -r 589f3f219427dcff96d29a6c4780f8af11d1dcbd -r 5fae7bd246f7bbcdabb55c302a55d39c3752aa71 recipes/multi_plot_3x2_FRB.py
--- /dev/null
+++ b/recipes/multi_plot_3x2_FRB.py
@@ -0,0 +1,73 @@
+"""
+This is a simple recipe to illustrate the
+:func:`~yt.visualization.plot_collection.get_multi_plot`
+functionality. It produces a series of slices of multiple fields with
+different color maps and zlimits, and makes use of the
+FixedResolutionBuffer. While this is more complex than the equivalent
+plot collection-based solution, it allows for a *lot* more
+flexibility. Every part of the script uses matplotlib commands,
+allowing its full power to be exercised.
+"""
+from yt.mods import * # set up our namespace
+import matplotlib.colorbar as cb
+from matplotlib.colors import LogNorm
+
+fn = "RedshiftOutput0005" # parameter file to load
+
+
+pf = load(fn) # load data
+
+# set up our Fixed Resolution Buffer parameters: a width, resolution, and center
+width = 7./pf['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.  
+
+#  it accepts: # of x-axis plots, # of y-axis plots, and how the
+#  colorbars are oriented (this also determines where they go: below
+#  in the case of 'horizontal', on the right in the case of
+#  'vertical'), bw is the base-width in inches (4 is about right for
+#  most cases)
+
+orient = 'horizontal'
+fig, axes, colorbars = get_multi_plot( 2, 3, colorbar=orient, bw = 6)
+
+# Now we follow the method of "multi_plot.py" but we're going to iterate
+# over the columns, which will become axes of slicing.
+plots = []
+for ax in range(3):
+    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]
+
+    # here, we turn off the axes labels and ticks, but you could
+    # customize further.
+    for ax in (den_axis, temp_axis):
+        ax.xaxis.set_visible(False)
+        ax.yaxis.set_visible(False)
+
+    plots.append(den_axis.imshow(frb['Density'], norm=LogNorm()))
+    plots[-1].set_clim((5e-32, 1e-29))
+    plots[-1].set_cmap("bds_highcontrast")
+
+    plots.append(temp_axis.imshow(frb['Temperature'], norm=LogNorm()))
+    plots[-1].set_clim((1e3, 3e4))
+    plots[-1].set_cmap("hot")
+    
+# Each 'cax' is a colorbar-container, into which we'll put a colorbar.
+# the zip command creates triples from each element of the three lists
+# .  Note that it cuts off after the shortest iterator is exhausted,
+# in this case, titles.
+titles=[r'$\mathrm{Density}\ (\mathrm{g\ cm^{-3}})$', r'$\mathrm{Temperature}\ (\mathrm{K})$']
+for p, cax, t in zip(plots, colorbars,titles):
+    # Now we make a colorbar, using the 'image' we stored in plots
+    # above. note this is what is *returned* by the imshow method of
+    # the plots.
+    cbar = fig.colorbar(p, cax=cax, orientation=orient)
+    cbar.set_label(t)
+
+# And now we're done!  
+fig.savefig("%s_3x2" % pf)

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