[yt-svn] commit/yt: xarthisius: Merged in chummels/yt (pull request #1800)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Oct 15 10:57:38 PDT 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/562b253b734a/
Changeset:   562b253b734a
Branch:      yt
User:        xarthisius
Date:        2015-10-15 17:57:26+00:00
Summary:     Merged in chummels/yt (pull request #1800)

[experimental] new create_scene() function
Affected #:  14 files

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 doc/source/cookbook/camera_movement.py
--- a/doc/source/cookbook/camera_movement.py
+++ b/doc/source/cookbook/camera_movement.py
@@ -3,7 +3,7 @@
 
 # Follow the simple_volume_rendering cookbook for the first part of this.
 ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")  # load data
-im, sc = yt.volume_render(ds)
+sc = yt.create_scene(ds)
 cam = sc.camera
 cam.resolution = (512, 512)
 cam.set_width(ds.domain_width/20.0)

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 doc/source/cookbook/custom_camera_volume_rendering.py
--- a/doc/source/cookbook/custom_camera_volume_rendering.py
+++ b/doc/source/cookbook/custom_camera_volume_rendering.py
@@ -4,8 +4,7 @@
 ds = yt.load("Enzo_64/DD0043/data0043")
 
 # Create a volume rendering
-# NOTE: This should use yt.create_scene once that exists
-im, sc = yt.volume_render(ds, field=('gas', 'density'))
+sc = yt.create_scene(ds, field=('gas', 'density'))
 
 # Now increase the resolution
 sc.camera.resolution = (1024, 1024)

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 doc/source/cookbook/custom_transfer_function_volume_rendering.py
--- a/doc/source/cookbook/custom_transfer_function_volume_rendering.py
+++ b/doc/source/cookbook/custom_transfer_function_volume_rendering.py
@@ -5,8 +5,7 @@
 ds = yt.load("Enzo_64/DD0043/data0043")
 
 # Create a volume rendering
-# NOTE: This should use yt.create_scene once that exists
-im, sc = yt.volume_render(ds, field=('gas', 'density'))
+sc = yt.create_scene(ds, field=('gas', 'density'))
 
 # Modify the transfer function
 

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 doc/source/cookbook/rendering_with_box_and_grids.py
--- a/doc/source/cookbook/rendering_with_box_and_grids.py
+++ b/doc/source/cookbook/rendering_with_box_and_grids.py
@@ -4,7 +4,7 @@
 
 # Load the dataset.
 ds = yt.load("Enzo_64/DD0043/data0043")
-im, sc = yt.volume_render(ds, ('gas','density'))
+sc = yt.create_scene(ds, ('gas','density'))
 sc.get_source(0).transfer_function.grey_opacity=True
 
 sc.annotate_domain(ds)

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -592,6 +592,7 @@
    :toctree: generated/
 
    ~yt.visualization.volume_rendering.volume_rendering.volume_render
+   ~yt.visualization.volume_rendering.volume_rendering.create_scene
    ~yt.visualization.volume_rendering.off_axis_projection.off_axis_projection
    ~yt.visualization.volume_rendering.scene.Scene
    ~yt.visualization.volume_rendering.camera.Camera

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 doc/source/visualizing/volume_rendering.rst
--- a/doc/source/visualizing/volume_rendering.rst
+++ b/doc/source/visualizing/volume_rendering.rst
@@ -60,6 +60,7 @@
 Here is a working example for rendering the IsolatedGalaxy dataset.
 
 .. python-script::
+
   import yt
   # load the data
   ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
@@ -70,10 +71,10 @@
   # sc is an instance of a Scene object, which allows you to further refine
   # your renderings.
 
-When the volume_render function is called, first an empty
-:class:`~yt.visualization.volume_rendering.scene.Scene` object is
-created. Next, a 
-:class:`~yt.visualization.volume_rendering.api.VolumeSource`
+When the :func:`~yt.visualization.volume_rendering.volume_render` function 
+is called, first an empty 
+:class:`~yt.visualization.volume_rendering.scene.Scene` object is created. 
+Next, a :class:`~yt.visualization.volume_rendering.api.VolumeSource`
 object is created, which decomposes the volume elements
 into a tree structure to provide back-to-front rendering of fixed-resolution
 blocks of data.  (If the volume elements are grids, this uses a
@@ -106,6 +107,21 @@
 In this example, we don't add on any non-volume rendering sources; however, if
 such sources are added, they will be integrated as well.
 
+Alternatively, if you don't want to immediately generate an image of your
+volume rendering, and you just want access to the default scene object, 
+you can skip this expensive operation by just running the
+:func:`~yt.visualization.volume_rendering.create_scene` function in lieu of the
+:func:`~yt.visualization.volume_rendering.volume_render` function. Example:
+
+.. python-script::
+
+  import yt
+  # load the data
+  ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+  # volume render the 'density' field 
+  sc = yt.create_scene(ds, 'density')
+
+
 Modifying the Scene
 -------------------
 

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 yt/__init__.py
--- a/yt/__init__.py
+++ b/yt/__init__.py
@@ -154,7 +154,7 @@
     ParticleProjectionPlot, ParticleImageBuffer, ParticlePlot
 
 from yt.visualization.volume_rendering.api import \
-    volume_render, ColorTransferFunction, TransferFunction, \
+    volume_render, create_scene, ColorTransferFunction, TransferFunction, \
     off_axis_projection
 import yt.visualization.volume_rendering.api as volume_rendering
 #    TransferFunctionHelper, MultiVariateTransferFunction

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -112,6 +112,7 @@
 class Dataset(object):
 
     default_fluid_type = "gas"
+    default_field = ("gas", "density")
     fluid_types = ("gas", "deposit", "index")
     particle_types = ("io",) # By default we have an 'all'
     particle_types_raw = ("io",)

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -67,6 +67,9 @@
     def __str__(self):
         return "Could not find field '%s' in %s." % (self.fname, self.ds)
 
+class YTSceneFieldNotFound(YTException):
+    pass
+
 class YTCouldNotGenerateField(YTFieldNotFound):
     def __str__(self):
         return "Could field '%s' in %s could not be generated." % (self.fname, self.ds)

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 yt/visualization/volume_rendering/api.py
--- a/yt/visualization/volume_rendering/api.py
+++ b/yt/visualization/volume_rendering/api.py
@@ -27,7 +27,7 @@
 #    SphericalCamera, StereoSphericalCamera
 from .camera import Camera
 from .transfer_function_helper import TransferFunctionHelper
-from .volume_rendering import volume_render
+from .volume_rendering import volume_render, create_scene
 from .off_axis_projection import off_axis_projection
 from .scene import Scene
 from .render_source import VolumeSource, OpaqueSource, LineSource, \

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 yt/visualization/volume_rendering/tests/simple_scene_creation.py
--- /dev/null
+++ b/yt/visualization/volume_rendering/tests/simple_scene_creation.py
@@ -0,0 +1,17 @@
+"""
+Create a simple scene object
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2014, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+import yt
+from yt.testing import \
+    fake_random_ds
+
+ds = fake_random_ds(32)
+sc = yt.create_scene(ds)

diff -r 3735cc557a7aafa02a3cc69ec65bd3f5c107b136 -r 562b253b734a3abc182b712fb9009034ea3b36c6 yt/visualization/volume_rendering/volume_rendering.py
--- a/yt/visualization/volume_rendering/volume_rendering.py
+++ b/yt/visualization/volume_rendering/volume_rendering.py
@@ -17,8 +17,59 @@
 from .render_source import VolumeSource
 from .utils import data_source_or_all
 from yt.funcs import mylog
+from yt.utilities.exceptions import YTSceneFieldNotFound
 
 
+def create_scene(data_source, field=None):
+    r""" Set up a scene object with sensible defaults for use in volume 
+    rendering.
+
+    A helper function that creates a default camera view, transfer
+    function, and image size. Using these, it returns an instance 
+    of the Scene class, allowing one to further modify their rendering.
+
+    This function is the same as volume_render() except it doesn't render
+    the image.
+
+    Parameters
+    ----------
+    data_source : :class:`yt.data_objects.data_containers.AMR3DData`
+        This is the source to be rendered, which can be any arbitrary yt
+        3D object
+    field: string, tuple, optional
+        The field to be rendered. If unspecified, this will use the 
+        default_field for your dataset's frontend--usually ('gas', 'density').
+        A default transfer function will be built that spans the range of 
+        values for that given field, and the field will be logarithmically 
+        scaled if the field_info object specifies as such.
+
+    Returns
+    -------
+    sc: Scene
+        A :class:`yt.visualization.volume_rendering.scene.Scene` object
+        that was constructed during the rendering. Useful for further
+        modifications, rotations, etc.
+
+    Example:
+    >>> import yt
+    >>> ds = yt.load("Enzo_64/DD0046/DD0046")
+    >>> sc = yt.create_scene(ds)
+    """
+    data_source = data_source_or_all(data_source)
+    sc = Scene()
+    if field is None:
+        field = data_source.ds.default_field
+        if field not in data_source.ds.derived_field_list:
+            raise YTSceneFieldNotFound("""Could not find field '%s' in %s. 
+                  Please specify a field in create_scene()""" % \
+                  (field, data_source.ds))
+        mylog.info('Setting default field to %s' % field.__repr__())
+
+    vol = VolumeSource(data_source, field=field)
+    sc.add_source(vol)
+    sc.camera = Camera(data_source)
+    return sc
+
 def volume_render(data_source, field=None, fname=None, sigma_clip=None):
     r""" Create a simple volume rendering of a data source.
 
@@ -33,18 +84,19 @@
         This is the source to be rendered, which can be any arbitrary yt
         3D object
     field: string, tuple, optional
-        The field to be rendered. By default, this will use the first
-        field in data_source.ds.field_list.  A default transfer function
-        will be built that spans the range of values for that given field,
-        and the field will be logarithmically scaled if the field_info
-        object specifies as such.
+        The field to be rendered. If unspecified, this will use the 
+        default_field for your dataset's frontend--usually ('gas', 'density').
+        A default transfer function will be built that spans the range of 
+        values for that given field, and the field will be logarithmically 
+        scaled if the field_info object specifies as such.
     fname: string, optional
         If specified, the resulting rendering will be saved to this filename
         in png format.
-    sigma_clip: float
-        The resulting image will be clipped before saving, using a threshold
-        based on `sigma_clip` multiplied by the standard deviation of the pixel
-        values. Recommended values are between 2 and 6. Default: None
+    sigma_clip: float, optional
+        If specified, the resulting image will be clipped before saving,
+        using a threshold based on sigma_clip multiplied by the standard
+        deviation of the pixel values. Recommended values are between 2 and 6.
+        Default: None
 
     Returns
     -------
@@ -58,29 +110,8 @@
     Example:
     >>> import yt
     >>> ds = yt.load("Enzo_64/DD0046/DD0046")
-    >>> im, sc = yt.volume_render(ds, fname='test.png')
+    >>> im, sc = yt.volume_render(ds, fname='test.png', sigma_clip=4.0)
     """
-    data_source = data_source_or_all(data_source)
-    sc = Scene()
-    if field is None:
-        data_source.ds.index
-        for ftype, f in sorted(data_source.ds.field_list):
-            if ftype == "all":
-                continue
-            if f == 'Density':
-                field = (ftype, f)
-            elif f == 'density':
-                field = (ftype, f)
-            elif ftype != 'index' and 'particle' not in f:
-                field = (ftype, f)
-                break
-        else:
-            raise RuntimeError("Could not find default field." +
-                               " Please set explicitly in volume_render call")
-        mylog.info('Setting default field to %s' % field.__repr__())
-
-    vol = VolumeSource(data_source, field=field)
-    sc.add_source(vol)
-    sc.camera = Camera(data_source)
+    sc = create_scene(data_source, field=field)
     im = sc.render(fname=fname, sigma_clip=sigma_clip)
     return im, sc

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

--

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