Commits

Matthew Turk  committed 3101a9b Merge

Merged in samskillman/yt-doc (pull request #81)

Rendering, ImageArray docs.

  • Participants
  • Parent commits 2bc0ca9, dcd1336

Comments (0)

Files changed (8)

File source/api/api.rst

    ~yt.data_objects.field_info_container.ValidateProperty
    ~yt.data_objects.field_info_container.ValidateSpatial
 
+Image Handling
+--------------
+
+For volume renderings and fixed resolution buffers the image object returned is
+an ``ImageArray`` object, which has useful functions for image saving and 
+writing to bitmaps.
+
+.. autosummary::
+   :toctree: generated/
+
+   ~yt.data_objects.image_array.ImageArray
+   ~yt.data_objects.image_array.ImageArray.write_png
+   ~yt.data_objects.image_array.ImageArray.write_hdf5
+
 Extension Types
 ---------------
 

File source/changelog.rst

    Notebook to enable better integration.
  * Metallicity-dependent X-ray fields have now been added.
  * Grid lines can now be added to volume renderings.
- * Volume renderings now have alpha blending
+ * Volume rendering backend has been updated to use an alpha channel, fixing
+   parallel opaque volume renderings.  This also enables easier blending of 
+   multiple images and annotations to the rendering. Users are encouraged
+   to look at the capabilities of the ``ImageArray`` for writing out renders,
+   as updated in the cookbook examples. Volume renders can now be saved with
+   an arbitrary background color.
  * Periodicity, or alternately non-periodicity, is now a part of radius
    calculations.
- * AMRKDTree has been rewritten to allow for sub-region selection.
+ * The AMRKDTree has been rewritten.  This allows parallelism with other than 
+   power-of-2 MPI processes, arbitrary sets of grids, and splitting of
+   unigrids. 
+ * Fixed Resolution Buffers and volume rendering images now utilize a new 
+   ImageArray class that stores information such as data source, field names,
+   and other information in a .info dictionary. See the ``ImageArray``
+   docstrings for more information on how they can be used to save to a bitmap
+   or hdf5 file.
 
 Version 2.4
 -----------

File source/cookbook/camera_movement.py

 
 # Do a rotation over 5 frames
 for i, snapshot in enumerate(cam.rotation(np.pi, 5, clip_ratio = 8.0)):
-    write_bitmap(snapshot, 'camera_movement_%04i.png' % frame)
+    snapshot.write_png('camera_movement_%04i.png' % frame)
     frame += 1
 
 # Move to the maximum density location over 5 frames
 for i, snapshot in enumerate(cam.move_to(max_c, 5, clip_ratio = 8.0)):
-    write_bitmap(snapshot, 'camera_movement_%04i.png' % frame)
+    snapshot.write_png('camera_movement_%04i.png' % frame)
     frame += 1
 
 # Zoom in by a factor of 10 over 5 frames
 for i, snapshot in enumerate(cam.zoomin(10.0, 5, clip_ratio = 8.0)):
-    write_bitmap(snapshot, 'camera_movement_%04i.png' % frame)
+    snapshot.write_png('camera_movement_%04i.png' % frame)
     frame += 1
 
 

File source/cookbook/image_background_colors.py

+from yt.mods import *
+
+# This shows how to save ImageArray objects, such as those returned from 
+# volume renderings, to pngs with varying backgrounds.
+
+# Lets make a fake "rendering" that has 4 channels and looks like a linear
+# gradient from the bottom to top.
+im = np.zeros([64,128,4])
+for i in xrange(im.shape[0]):
+    for k in xrange(im.shape[2]):
+        im[i,:,k] = np.linspace(0.,10.*k, im.shape[1])
+im_arr = ImageArray(im)
+
+# in this case you would have gotten im_arr from something like:
+# im_arr = cam.snapshot() 
+
+# To save it with the default settings, we can just use write_png, where it 
+# rescales the image and uses a black background.
+im_arr.write_png('standard.png')
+ 
+# write_png accepts a background keyword argument that defaults to 'black'.
+# Other choices include:
+# black (0.,0.,0.,1.)
+# white (1.,1.,1.,1.)
+# None  (0.,0.,0.,0.) <-- Transparent!
+# any rgba list/array: [r,g,b,a], bounded by 0..1
+im_arr.write_png('black_bg.png', background='black')
+im_arr.write_png('white_bg.png', background='white')
+im_arr.write_png('green_bg.png', background=[0.,1.,0.,1.])
+im_arr.write_png('transparent_bg.png', background=None)
+
+
+
+
+

File source/cookbook/rendering_with_box_and_grids.py

 im = cam.snapshot("%s_volume_rendered.png" % pf, clip_ratio=8.0)
 
 # Add the domain edges, with an alpha blending of 0.3:
-cam.draw_domain(im, alpha=0.3)
-write_image(im, '%s_vr_domain.png' % pf)
+nim = cam.draw_domain(im, alpha=0.3)
+nim.write_png('%s_vr_domain.png' % pf)
 
 # Add the grids, colored by the grid level with the algae colormap
-cam.draw_grids(im, alpha=0.3, cmap='algae')
-write_image(im, '%s_vr_grids.png' % pf)
+nim = cam.draw_grids(im, alpha=0.3, cmap='algae')
+nim.write_png('%s_vr_grids.png' % pf)
 
 

File source/cookbook/simple_plots.rst

 
 .. yt_cookbook:: simple_volume_rendering.py
 
+Image Background Colors
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Here we see how to take an image and save it using different background colors. 
+
+.. yt_cookbook:: image_background_colors.py
+

File source/cookbook/simple_volume_rendering.py

 
 # Create a transfer function to map field values to colors.
 # We bump up our minimum to cut out some of the background fluid
-tf = ColorTransferFunction((np.log10(mi)+2.0, np.log10(ma)))
+tf = ColorTransferFunction((np.log10(mi)+1, np.log10(ma)))
 
 # Add three guassians, evenly spaced between the min and
 # max specified above with widths of 0.02 and using the
 # gist_stern colormap.
-tf.add_layers(3, w=0.02, colormap="gist_stern")
+tf.add_layers(5, w=0.02, colormap="spectral")
 
 # Choose a center for the render.
 c = [0.5, 0.5, 0.5]

File source/visualizing/volume_rendering.rst

 Here is a working example for the IsolatedGalaxy dataset from the 2012 yt workshop.
 
 .. code-block:: python
+    from yt.mods import *
 
-    from yt.mods import *
-    
-    pf = load("galaxy0030/galaxy0030")
+    pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
     # Choose a field
     field = 'Density'
     # Do you want the log of the field?
     use_log = True
-    
+
     # Find the bounds in log space of for your field
     dd = pf.h.all_data()
     mi, ma = dd.quantities["Extrema"](field)[0]
-    
+
     if use_log:
         mi,ma = np.log10(mi), np.log10(ma)
-    
+
     # Instantiate the ColorTransferfunction.
     tf = ColorTransferFunction((mi, ma))
-    
+
     # Set up the camera parameters: center, looking direction, width, resolution
     c = (pf.domain_right_edge + pf.domain_left_edge)/2.0
     L = np.array([1.0, 1.0, 1.0])
     W = 0.3 / pf["unitary"]
     N = 256 
-    
+
     # Create a camera object
     cam = pf.h.camera(c, L, W, N, tf, fields = [field], log_fields = [use_log])
-    
-    # Set up the filename using pf and field.
-    fn = "%s_%s_rendering.png" % (pf, field)
-    
-    # Now let's add some isocontours, and take a snapshot.
+
+    # Now let's add some isocontours, and take a snapshot, saving the image
+    # to a file.
     tf.add_layers(10, 0.01, colormap = 'RdBu_r')
-    im = cam.snapshot('test_rendering.png',clip_ratio=6.0)
-    
-    # Take a snapshot, saving the image to file fn.
-    im = cam.snapshot(fn)
-    
+    im = cam.snapshot('test_rendering.png')
+
     # To add the domain box to the image:
-    cam.draw_domain(im)
-    write_bitmap(im, 'test_rendering_with_domain.png')
+    nim = cam.draw_domain(im)
+    nim.write_png('test_rendering_with_domain.png')
 
     # To add the grid outlines to the image:
-    cam.draw_grids(im)
-    write_bitmap(im, 'test_rendering_with_grids.png')
+    nim = cam.draw_grids(im)
+    nim.write_png('test_rendering_with_grids.png')
 
 Method
 ------