[yt-svn] commit/yt: 4 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Nov 9 11:22:02 PST 2015


4 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/514a98bcd672/
Changeset:   514a98bcd672
Branch:      yt
User:        atmyers
Date:        2015-11-07 03:08:21+00:00
Summary:     filling in VR example notebook
Affected #:  1 file

diff -r 9f560b7f279cd6e3abffb105bd64b80946333c94 -r 514a98bcd672145f857eea22f064f90626a9bc83 doc/source/visualizing/volume_rendering.rst
--- a/doc/source/visualizing/volume_rendering.rst
+++ b/doc/source/visualizing/volume_rendering.rst
@@ -352,16 +352,6 @@
 a bit more work, but we will also provide several helper functions that attempt
 to create satisfactory default volume renderings.
 
-***needs ipython notebook with two examples here: one high-level one using the 
-yt.volume_render() functionality and the other detailed example using 
-yt.create_scene() to generate a base scene, then modifying all of the 
-components, adding some opaque sources, changing the camera position, 
-transfer function, lens, etc.  Then using "print scene" to display the
-useful __repr__ output for the scene and other VR classes.  The text below
-could be useful too.  Right now, we cannot use ipython notebooks with
-the VR infrastructure because there is no Scene.show() method.  Once it is
-introduced we should be able to do this.***
-
 When the 
 :func:`~yt.visualization.volume_rendering.volume_rendering.volume_render` 
 function is called, first an empty 
@@ -398,10 +388,23 @@
 the scene will loop through all of the
 :class:`~yt.visualization.volume_rendering.render_source.RenderSource` objects
 that have been added and integrate the radiative transfer equations through the
-volume. Finally, the image and scene object is returned to the user.
+volume. Finally, the image and scene object is returned to the user. An example
+script the uses the high-level :func:`~yt.visualization.volume_rendering.volume_rendering.volume_render`
+function to quickly set up defaults is:
 
-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.
+.. python-script::
+
+  import yt
+  # load the data
+  ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+
+  # volume render the 'density' field, and save the resulting image
+  im, sc = yt.volume_render(ds, 'density', fname='rendering.png')
+
+  # im is the image array generated. it is also saved to 'rendering.png'.
+  # sc is an instance of a Scene object, which allows you to further refine
+  # your renderings and later save them.
+
 
 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, 
@@ -418,26 +421,8 @@
   sc = yt.create_scene(ds, 'density')
 
 
-
-If you're eager to just see what a volume rendering of your simulation looks
-like, there is the high-level function 
-:func:`~yt.visualization.volume_rendering.volume_rendering.volume_render` 
-that can set up several defaults and provide you with an rendered image
-quickly:
-
-.. python-script::
-
-  import yt
-  # load the data
-  ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-
-  # volume render the 'density' field, and save the resulting image
-  im, sc = yt.volume_render(ds, 'density', fname='rendering.png')
-
-  # im is the image array generated. it is also saved to 'rendering.png'.
-  # sc is an instance of a Scene object, which allows you to further refine
-  # your renderings and later save them.
-
+For a more in-depth tutorial on how to create a Scene and modify its contents,
+see this annotated :ref:`volume-rendering-tutorial`.
 
 
 .. _volume-rendering-method:


https://bitbucket.org/yt_analysis/yt/commits/1832b0180e16/
Changeset:   1832b0180e16
Branch:      yt
User:        atmyers
Date:        2015-11-07 03:16:32+00:00
Summary:     don't set the lens until after the camera is constructed
Affected #:  3 files

diff -r 514a98bcd672145f857eea22f064f90626a9bc83 -r 1832b0180e16d97202d8daa9dcc9eef9399abd6f doc/source/visualizing/Volume_Rendering_Tutorial.ipynb
--- /dev/null
+++ b/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb
@@ -0,0 +1,272 @@
+{
+ "metadata": {
+  "name": "",
+  "signature": "sha256:16b0b0137841594b135cb8e07f6029e0cd646630816929435e584cbbf10555b4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "This notebook shows how to use the new (in version 3.3) Scene interface to create custom volume renderings. To begin, we load up a dataset and use the yt.create_scene method to set up a basic Scene. We store the Scene in a variable called 'sc' and render the default ('gas', 'density') field."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "import yt\n",
+      "import numpy as np\n",
+      "from yt.visualization.volume_rendering.transfer_function_helper import TransferFunctionHelper\n",
+      "from yt.visualization.volume_rendering.api import Scene, Camera, VolumeSource\n",
+      "\n",
+      "ds = yt.load(\"IsolatedGalaxy/galaxy0030/galaxy0030\")\n",
+      "sc = yt.create_scene(ds)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Now we can look at some information about the Scene we just created using the python print keyword:"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "print sc"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "This prints out information about the Sources, Camera, and Lens associated with this Scene. Each of these can also be printed individually. For example, to print only the information about the first (and currently, only) Source, we can do:"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "print sc.get_source(0)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "We can see that the yt.create_source has created a VolumeSource with default values for the center, bounds, and transfer function. Now, let's see what this Scene looks like. In the notebook, we can do this by calling sc.show(). "
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "sc.show()"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "That looks okay, but it's a little too zoomed-out. To fix this, let's modify the Camera associated with our Scene. This next bit of code will zoom in the camera (i.e. decrease the width of the view) by a factor of 3."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "sc.camera.zoom(3.0)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Now when we print the Scene, we see that the Camera width has decreased by a factor of 3:"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "print sc"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "To see what this looks like, we re-render the image and display the scene again. Note that we don't actually have to call sc.show() here - we can just have Ipython evaluate the Scene and that will display it automatically."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "sc.render()\n",
+      "sc"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "That's better! The image looks a little washed-out though, so we use the sigma_clip argument to sc.show() to improve the contrast:"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "sc.show(sigma_clip=4.0)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Next, we demonstrate how to change the mapping between the field values and the colors in the image. We use the TransferFunctionHelper to create a new transfer function using the \"gist_rainbow\" colormap, and then re-create the image as follows:"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "# Set up a custom transfer function using the TransferFunctionHelper. \n",
+      "# We use 10 Gaussians evenly spaced logarithmically between the min and max\n",
+      "# field values.\n",
+      "tfh = TransferFunctionHelper(ds)\n",
+      "tfh.set_field('density')\n",
+      "tfh.set_log(True)\n",
+      "tfh.set_bounds()\n",
+      "tfh.build_transfer_function()\n",
+      "tfh.tf.add_layers(10, colormap='gist_rainbow')\n",
+      "\n",
+      "# Grab the first render source and set it to use the new transfer function\n",
+      "render_source = sc.get_source(0)\n",
+      "render_source.transfer_function = tfh.tf\n",
+      "\n",
+      "sc.render()\n",
+      "sc.show(sigma_clip=4.0)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Now, let's try using a different lens type. We can give a sense of depth to the image by using the perspective lens. To do, we create a new Camera below. We also demonstrate how to switch the camera to a new position and orientation."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "cam = Camera(ds, lens_type='perspective')\n",
+      "\n",
+      "# Standing at (x=0.05, y=0.5, z=0.5), we look at the area of x>0.05 (with some open angle\n",
+      "# specified by camera width) along the positive x direction.\n",
+      "cam.position = ds.arr([0.05, 0.5, 0.5], 'code_length')\n",
+      "\n",
+      "normal_vector = [1., 0., 0.]\n",
+      "north_vector = [0., 0., 1.]\n",
+      "cam.switch_orientation(normal_vector=normal_vector,\n",
+      "                       north_vector=north_vector)\n",
+      "\n",
+      "# The width determines the opening angle\n",
+      "cam.set_width(ds.domain_width * 0.5)\n",
+      "\n",
+      "sc.camera = cam\n",
+      "print sc.camera"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "The resulting image looks like:"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "sc.render()\n",
+      "sc.show(sigma_clip=4.0)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Finally, the next cell restores the lens and the transfer function to the defaults, moves the camera, and adds an opaque source  that shows the axes of the simulation coordinate system."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "# set the lens type back to plane-parallel\n",
+      "sc.camera.set_lens('plane-parallel')\n",
+      "\n",
+      "# move the camera to the left edge of the domain\n",
+      "sc.camera.set_position(ds.domain_left_edge)\n",
+      "sc.camera.switch_orientation()\n",
+      "\n",
+      "# reset the transfer function to the default\n",
+      "render_source = sc.get_source(0)\n",
+      "render_source.build_default_transfer_function()\n",
+      "\n",
+      "# add an opaque source to the scene\n",
+      "sc.annotate_axes()\n",
+      "\n",
+      "sc.render()\n",
+      "sc.show(sigma_clip=4.0)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
\ No newline at end of file

diff -r 514a98bcd672145f857eea22f064f90626a9bc83 -r 1832b0180e16d97202d8daa9dcc9eef9399abd6f doc/source/visualizing/volume_rendering_tutorial.rst
--- /dev/null
+++ b/doc/source/visualizing/volume_rendering_tutorial.rst
@@ -0,0 +1,6 @@
+.. _volume-rendering-tutorial:
+
+Volume Rendering Tutorial
+=========================
+
+.. notebook:: Volume_Rendering_Tutorial.ipynb

diff -r 514a98bcd672145f857eea22f064f90626a9bc83 -r 1832b0180e16d97202d8daa9dcc9eef9399abd6f yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -93,7 +93,6 @@
         self._width = np.array([1.0, 1.0, 1.0])
         self._focus = np.array([0.0]*3)
         self._position = np.array([1.0]*3)
-        self.set_lens(lens_type)
         if data_source is not None:
             data_source = data_source_or_all(data_source)
             self._focus = data_source.ds.domain_center
@@ -107,6 +106,8 @@
         super(Camera, self).__init__(self.focus - self.position,
                                      self.north_vector, steady_north=False)
 
+        self.set_lens(lens_type)
+
         # This should be run on-demand if certain attributes are not set.
         self.lens.setup_box_properties(self)
 


https://bitbucket.org/yt_analysis/yt/commits/ee238a4e5898/
Changeset:   ee238a4e5898
Branch:      yt
User:        atmyers
Date:        2015-11-07 03:17:22+00:00
Summary:     call setup_box_properties whenever the lens is set
Affected #:  1 file

diff -r 1832b0180e16d97202d8daa9dcc9eef9399abd6f -r ee238a4e5898a15519f80b04f7220faa938724a9 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -108,9 +108,6 @@
 
         self.set_lens(lens_type)
 
-        # This should be run on-demand if certain attributes are not set.
-        self.lens.setup_box_properties(self)
-
     def position():
         doc = '''The position is the location of the camera in
                the coordinate system of the simulation. This needs
@@ -220,7 +217,7 @@
             mylog.error("Lens type not available")
             raise RuntimeError()
         self.lens = lenses[lens_type]()
-        self.lens.camera = self
+        self.lens.set_camera(self)
 
     def set_defaults_from_data_source(self, data_source):
         """Resets the camera attributes to their default values"""


https://bitbucket.org/yt_analysis/yt/commits/c2ac99552d56/
Changeset:   c2ac99552d56
Branch:      yt
User:        atmyers
Date:        2015-11-07 05:43:06+00:00
Summary:     adding the volume rendering tutorial to the list of example notebooks
Affected #:  1 file

diff -r ee238a4e5898a15519f80b04f7220faa938724a9 -r c2ac99552d5659b13d4af7749090adde8f1d0a12 doc/source/cookbook/index.rst
--- a/doc/source/cookbook/index.rst
+++ b/doc/source/cookbook/index.rst
@@ -51,3 +51,4 @@
    fits_xray_images
    tipsy_notebook
    halo_analysis_example
+   ../visualizing/volume_rendering_tutorial

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