[yt-svn] commit/yt-3.0: 13 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Aug 10 18:03:05 PDT 2013


13 new commits in yt-3.0:

https://bitbucket.org/yt_analysis/yt-3.0/commits/39b85cdc0db3/
Changeset:   39b85cdc0db3
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-08 20:47:17
Summary:     First go at adding a mask field to the cell traversal.
Affected #:  3 files

diff -r c7f0b4c36217f18e0b4bb4fdd763b8bab4cade69 -r 39b85cdc0db3afda94b02dc677e135c9f59a804b yt/utilities/amr_kdtree/amr_kdtree.py
--- a/yt/utilities/amr_kdtree/amr_kdtree.py
+++ b/yt/utilities/amr_kdtree/amr_kdtree.py
@@ -257,17 +257,19 @@
         else:
             dds = []
             for i, field in enumerate(self.fields):
-                vcd = grid.get_vertex_centered_data(field, smoothed=True,no_ghost=self.no_ghost).astype('float64')
+                vcd = grid.get_vertex_centered_data(field, smoothed=True, no_ghost=self.no_ghost).astype('float64')
                 if self.log_fields[i]: vcd = np.log10(vcd)
                 dds.append(vcd)
                 self.current_saved_grids.append(grid)
                 self.current_vcds.append(dds)
+        mask = np.ones(dims, dtype='uint8')
 
         data = [d[li[0]:ri[0]+1,
                   li[1]:ri[1]+1,
                   li[2]:ri[2]+1].copy() for d in dds]
 
         brick = PartitionedGrid(grid.id, data,
+                                mask,
                                 nle.copy(),
                                 nre.copy(),
                                 dims.astype('int64'))

diff -r c7f0b4c36217f18e0b4bb4fdd763b8bab4cade69 -r 39b85cdc0db3afda94b02dc677e135c9f59a804b yt/utilities/lib/grid_traversal.pxd
--- a/yt/utilities/lib/grid_traversal.pxd
+++ b/yt/utilities/lib/grid_traversal.pxd
@@ -30,6 +30,8 @@
 cdef struct VolumeContainer:
     int n_fields
     np.float64_t **data
+    # The mask has dimensions one fewer in each direction than data
+    np.uint8_t *mask
     np.float64_t left_edge[3]
     np.float64_t right_edge[3]
     np.float64_t dds[3]

diff -r c7f0b4c36217f18e0b4bb4fdd763b8bab4cade69 -r 39b85cdc0db3afda94b02dc677e135c9f59a804b yt/utilities/lib/grid_traversal.pyx
--- a/yt/utilities/lib/grid_traversal.pyx
+++ b/yt/utilities/lib/grid_traversal.pyx
@@ -60,6 +60,7 @@
 
 cdef class PartitionedGrid:
     cdef public object my_data
+    cdef public object source_mask 
     cdef public object LeftEdge
     cdef public object RightEdge
     cdef public int parent_grid_id
@@ -74,12 +75,14 @@
     @cython.cdivision(True)
     def __cinit__(self,
                   int parent_grid_id, data,
+                  mask,
                   np.ndarray[np.float64_t, ndim=1] left_edge,
                   np.ndarray[np.float64_t, ndim=1] right_edge,
                   np.ndarray[np.int64_t, ndim=1] dims,
 		  star_kdtree_container star_tree = None):
         # The data is likely brought in via a slice, so we copy it
         cdef np.ndarray[np.float64_t, ndim=3] tdata
+        cdef np.ndarray[np.uint8_t, ndim=3] mask_data
         self.container = NULL
         self.parent_grid_id = parent_grid_id
         self.LeftEdge = left_edge
@@ -96,10 +99,13 @@
             c.dds[i] = (c.right_edge[i] - c.left_edge[i])/dims[i]
             c.idds[i] = 1.0/c.dds[i]
         self.my_data = data
+        self.source_mask = mask
+        mask_data = mask
         c.data = <np.float64_t **> malloc(sizeof(np.float64_t*) * n_fields)
         for i in range(n_fields):
             tdata = data[i]
             c.data[i] = <np.float64_t *> tdata.data
+        c.mask = <np.uint8_t *> mask_data.data
         if star_tree is None:
             self.star_list = NULL
         else:
@@ -116,6 +122,7 @@
         # So we don't need to deallocate them.
         if self.container == NULL: return
         if self.container.data != NULL: free(self.container.data)
+        if self.container.mask != NULL: free(self.container.mask)
         free(self.container)
 
     @cython.boundscheck(False)
@@ -503,6 +510,10 @@
     # we assume this has vertex-centered data.
     cdef int offset = index[0] * (vc.dims[1] + 1) * (vc.dims[2] + 1) \
                     + index[1] * (vc.dims[2] + 1) + index[2]
+    cdef int cell_offset = index[0] * (vc.dims[1]) * (vc.dims[2]) \
+                    + index[1] * (vc.dims[2]) + index[2]
+    if vc.mask[cell_offset] != 1:
+        return
     cdef np.float64_t slopes[6], dp[3], ds[3]
     cdef np.float64_t dt = (exit_t - enter_t) / vri.n_samples
     cdef np.float64_t dvs[6]


https://bitbucket.org/yt_analysis/yt-3.0/commits/f592e1d2760a/
Changeset:   f592e1d2760a
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-08 23:25:40
Summary:     Change the way masks are calculated. This is way faster, and is simply a result
of me being more familiar with the selector functionality.
Affected #:  1 file

diff -r 39b85cdc0db3afda94b02dc677e135c9f59a804b -r f592e1d2760a454a55010e754ef485cec2f0418d yt/utilities/amr_kdtree/amr_kdtree.py
--- a/yt/utilities/amr_kdtree/amr_kdtree.py
+++ b/yt/utilities/amr_kdtree/amr_kdtree.py
@@ -262,7 +262,11 @@
                 dds.append(vcd)
                 self.current_saved_grids.append(grid)
                 self.current_vcds.append(dds)
-        mask = np.ones(dims, dtype='uint8')
+
+        if self.source.selector is None:
+            mask = np.ones(dims, dtype='uint8')
+        else:
+            mask = self.source.selector.fill_mask(grid)[li[0]:ri[0], li[1]:ri[1], li[2]:ri[2] ].astype('uint8')
 
         data = [d[li[0]:ri[0]+1,
                   li[1]:ri[1]+1,


https://bitbucket.org/yt_analysis/yt-3.0/commits/e3df5051e31f/
Changeset:   e3df5051e31f
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 00:29:29
Summary:     Adding a NotImplementedError for HEALpix -- the camera setup is not fixed yet
for the source rendering.  Also fixing a memory error.
Affected #:  2 files

diff -r f592e1d2760a454a55010e754ef485cec2f0418d -r e3df5051e31f43cf819a7b4051c52ecb229142e7 yt/utilities/lib/grid_traversal.pyx
--- a/yt/utilities/lib/grid_traversal.pyx
+++ b/yt/utilities/lib/grid_traversal.pyx
@@ -122,7 +122,6 @@
         # So we don't need to deallocate them.
         if self.container == NULL: return
         if self.container.data != NULL: free(self.container.data)
-        if self.container.mask != NULL: free(self.container.mask)
         free(self.container)
 
     @cython.boundscheck(False)

diff -r f592e1d2760a454a55010e754ef485cec2f0418d -r e3df5051e31f43cf819a7b4051c52ecb229142e7 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -1125,6 +1125,8 @@
                  sub_samples = 5, log_fields = None, volume = None,
                  pf = None, use_kd=True, no_ghost=False, use_light=False,
                  inner_radius = 10):
+        mylog.error('I am sorry, HEALpix Camera does not work yet in 3.0')
+        raise NotImplementedError
         ParallelAnalysisInterface.__init__(self)
         if pf is not None: self.pf = pf
         self.center = np.array(center, dtype='float64')


https://bitbucket.org/yt_analysis/yt-3.0/commits/61254ef8bbbf/
Changeset:   61254ef8bbbf
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 18:20:24
Summary:     Adding tests for volume rendering. At the moment, this tests only that the
cameras don't fail during execution. It also tests that all of the camera
movements work.  This also comes with fixes for the ProjectionCamera, pointed
out by the testing framework itself!'
Affected #:  2 files

diff -r e3df5051e31f43cf819a7b4051c52ecb229142e7 -r 61254ef8bbbf4a93c1166fe67680edef6e42bd37 yt/visualization/tests/test_vr_cameras.py
--- /dev/null
+++ b/yt/visualization/tests/test_vr_cameras.py
@@ -0,0 +1,177 @@
+"""
+Test for Volume Rendering Cameras, and their movement. 
+
+Author: Samuel Skillman <samskillman at gmail.com>
+Homepage: http://yt-project.org/
+License:
+  Copyright (C) 2013 Samuel Skillman.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+import os
+import os.path
+import tempfile
+import shutil
+from yt.testing import \
+    fake_random_pf
+import numpy as np
+from yt.mods import ColorTransferFunction, ProjectionTransferFunction
+from yt.visualization.volume_rendering.api import \
+    PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera
+from yt.visualization.tests.test_plotwindow import assert_fname
+
+use_tmpdir = False
+
+
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
+
+
+def setup_dir():
+    if use_tmpdir:
+        curdir = os.getcwd()
+        # Perform I/O in safe place instead of yt main dir
+        tmpdir = tempfile.mkdtemp()
+        os.chdir(tmpdir)
+    else:
+        curdir, tmpdir = None, None
+    return curdir, tmpdir
+
+
+def teardown_dir(curdir, tmpdir):
+    if use_tmpdir:
+        os.chdir(curdir)
+        shutil.rmtree(tmpdir)
+
+
+def setup_pf():
+    # args for off_axis_projection
+    test_pf = fake_random_pf(64)
+    c = [0.5, 0.5, 0.5]
+    norm = [0.5, 0.5, 0.5]
+    W = test_pf.domain_width
+    N = 64
+    field = "Density"
+    cam_args = [test_pf, c, norm, W, N, field]
+    return cam_args
+
+
+def setup_transfer_function(pf, camera_type):
+    if camera_type in ['perspective', 'camera', 'stereopair', 'interactive']:
+        mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
+        mi, ma = np.log10(mi), np.log10(ma)
+        tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
+        Nsamples = 4
+        tf.add_layers(Nsamples, w=0.02, col_bounds=(mi, ma),
+                      alpha=np.logspace(1.0, 2.0, Nsamples), colormap='RdBu_r')
+        #tf.map_to_colormap(mi,ma, scale=10., colormap='RdBu_r')
+        return tf
+    elif camera_type in ['healpix']:
+        return ProjectionTransferFunction()
+    else:
+        pass
+
+
+def test_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
+    cam.snapshot('camera.png')
+    assert_fname('camera.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_perspective_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = PerspectiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
+    cam.snapshot('perspective.png')
+    assert_fname('perspective.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_interactive_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = InteractiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
+    cam.snapshot('interactive.png')
+    assert_fname('interactive.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_projection_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+
+    cam = ProjectionCamera(c, L, W, N, pf=pf, field='Density')
+    cam.snapshot('projection.png')
+    assert_fname('projection.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_stereo_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
+    stereo_cam = StereoPairCamera(cam)
+    # Take image
+    cam1, cam2 = stereo_cam.split()
+    cam1.snapshot(fn='stereo1.png')
+    cam2.snapshot(fn='stereo2.png')
+    assert_fname('stereo1.png')
+    assert_fname('stereo2.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_camera_movement():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
+    cam.zoom(0.5)
+    for snap in cam.zoomin(2.0, 3):
+        snap
+    for snap in cam.move_to(np.array(c) + 0.1, 3,
+                            final_width=None, exponential=False):
+        snap
+    for snap in cam.move_to(np.array(c) - 0.1, 3,
+                            final_width=2.0*W, exponential=False):
+        snap
+    for snap in cam.move_to(np.array(c), 3,
+                            final_width=1.0*W, exponential=True):
+        snap
+    cam.rotate(np.pi/10)
+    cam.pitch(np.pi/10)
+    cam.yaw(np.pi/10)
+    cam.roll(np.pi/10)
+    for snap in cam.rotation(np.pi, 3, rot_vector=None):
+        snap
+    for snap in cam.rotation(np.pi, 3, rot_vector=np.random.random(3)):
+        snap
+    cam.snapshot('final.png')
+    assert_fname('final.png')
+    teardown_dir(curdir, tmpdir)

diff -r e3df5051e31f43cf819a7b4051c52ecb229142e7 -r 61254ef8bbbf4a93c1166fe67680edef6e42bd37 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -1157,8 +1157,8 @@
         self.light_dir = None
         self.light_rgba = None
         if volume is None:
-            volume = AMRKDTree(self.pf, fields=self.fields, no_ghost=no_ghost,
-                               log_fields=log_fields)
+            volume = AMRKDTree(self.pf, min_level=min_level,
+                               max_level=max_level, source=self.source)
         self.use_kd = isinstance(volume, AMRKDTree)
         self.volume = volume
 
@@ -2205,6 +2205,7 @@
             data = [(grid[field] * mask).astype("float64") for field in fields]
             pg = PartitionedGrid(
                 grid.id, data,
+                mask.astype('uint8'),
                 grid.LeftEdge, grid.RightEdge, grid.ActiveDimensions.astype("int64"))
             grid.clear_data()
             sampler(pg, num_threads = num_threads)


https://bitbucket.org/yt_analysis/yt-3.0/commits/7009a2cea9f3/
Changeset:   7009a2cea9f3
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 18:46:07
Summary:     Use Agg backend (important for InteractiveCamera testing), and modify the tf
and setup a bit so that the images produced are useful.  Turn on temporary dir
by default.
Affected #:  1 file

diff -r 61254ef8bbbf4a93c1166fe67680edef6e42bd37 -r 7009a2cea9f3e2dfb22a670a6f7e3da221f7fee5 yt/visualization/tests/test_vr_cameras.py
--- a/yt/visualization/tests/test_vr_cameras.py
+++ b/yt/visualization/tests/test_vr_cameras.py
@@ -32,8 +32,11 @@
 from yt.visualization.volume_rendering.api import \
     PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera
 from yt.visualization.tests.test_plotwindow import assert_fname
+import matplotlib
+matplotlib.use('Agg')
 
-use_tmpdir = False
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True 
 
 
 def setup():
@@ -62,9 +65,9 @@
 def setup_pf():
     # args for off_axis_projection
     test_pf = fake_random_pf(64)
-    c = [0.5, 0.5, 0.5]
+    c = test_pf.domain_center 
     norm = [0.5, 0.5, 0.5]
-    W = test_pf.domain_width
+    W = 1.5*test_pf.domain_width
     N = 64
     field = "Density"
     cam_args = [test_pf, c, norm, W, N, field]
@@ -74,12 +77,8 @@
 def setup_transfer_function(pf, camera_type):
     if camera_type in ['perspective', 'camera', 'stereopair', 'interactive']:
         mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
-        mi, ma = np.log10(mi), np.log10(ma)
         tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
-        Nsamples = 4
-        tf.add_layers(Nsamples, w=0.02, col_bounds=(mi, ma),
-                      alpha=np.logspace(1.0, 2.0, Nsamples), colormap='RdBu_r')
-        #tf.map_to_colormap(mi,ma, scale=10., colormap='RdBu_r')
+        tf.map_to_colormap(mi, ma, scale=10., colormap='RdBu_r')
         return tf
     elif camera_type in ['healpix']:
         return ProjectionTransferFunction()


https://bitbucket.org/yt_analysis/yt-3.0/commits/f0c3992e474d/
Changeset:   f0c3992e474d
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 18:57:35
Summary:     No testing of the InteractiveCamera snapshot. Uses pylab and thus won't work
for unit testing.'
Affected #:  1 file

diff -r 7009a2cea9f3e2dfb22a670a6f7e3da221f7fee5 -r f0c3992e474d2fac54d6035cd3e684b4ea9b64ad yt/visualization/tests/test_vr_cameras.py
--- a/yt/visualization/tests/test_vr_cameras.py
+++ b/yt/visualization/tests/test_vr_cameras.py
@@ -32,8 +32,6 @@
 from yt.visualization.volume_rendering.api import \
     PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera
 from yt.visualization.tests.test_plotwindow import assert_fname
-import matplotlib
-matplotlib.use('Agg')
 
 # This toggles using a temporary directory. Turn off to examine images.
 use_tmpdir = True 
@@ -114,8 +112,7 @@
     tf = setup_transfer_function(pf, 'camera')
 
     cam = InteractiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
-    cam.snapshot('interactive.png')
-    assert_fname('interactive.png')
+    # Can't take a snapshot here since IC uses pylab.'
     teardown_dir(curdir, tmpdir)
 
 


https://bitbucket.org/yt_analysis/yt-3.0/commits/66803ac7861e/
Changeset:   66803ac7861e
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 19:33:34
Summary:     Moving camera tests to a new tests dir in volume_rendering. Fixing up transfer
function documentation for map_to_colormap, and fixing some PEP8 stuff.
Affected #:  4 files

diff -r f0c3992e474d2fac54d6035cd3e684b4ea9b64ad -r 66803ac7861e2df56b42914f2ad783b39f0b9669 yt/visualization/tests/test_vr_cameras.py
--- a/yt/visualization/tests/test_vr_cameras.py
+++ /dev/null
@@ -1,173 +0,0 @@
-"""
-Test for Volume Rendering Cameras, and their movement. 
-
-Author: Samuel Skillman <samskillman at gmail.com>
-Homepage: http://yt-project.org/
-License:
-  Copyright (C) 2013 Samuel Skillman.  All Rights Reserved.
-
-  This file is part of yt.
-
-  yt is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 3 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
-import os
-import os.path
-import tempfile
-import shutil
-from yt.testing import \
-    fake_random_pf
-import numpy as np
-from yt.mods import ColorTransferFunction, ProjectionTransferFunction
-from yt.visualization.volume_rendering.api import \
-    PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera
-from yt.visualization.tests.test_plotwindow import assert_fname
-
-# This toggles using a temporary directory. Turn off to examine images.
-use_tmpdir = True 
-
-
-def setup():
-    """Test specific setup."""
-    from yt.config import ytcfg
-    ytcfg["yt", "__withintesting"] = "True"
-
-
-def setup_dir():
-    if use_tmpdir:
-        curdir = os.getcwd()
-        # Perform I/O in safe place instead of yt main dir
-        tmpdir = tempfile.mkdtemp()
-        os.chdir(tmpdir)
-    else:
-        curdir, tmpdir = None, None
-    return curdir, tmpdir
-
-
-def teardown_dir(curdir, tmpdir):
-    if use_tmpdir:
-        os.chdir(curdir)
-        shutil.rmtree(tmpdir)
-
-
-def setup_pf():
-    # args for off_axis_projection
-    test_pf = fake_random_pf(64)
-    c = test_pf.domain_center 
-    norm = [0.5, 0.5, 0.5]
-    W = 1.5*test_pf.domain_width
-    N = 64
-    field = "Density"
-    cam_args = [test_pf, c, norm, W, N, field]
-    return cam_args
-
-
-def setup_transfer_function(pf, camera_type):
-    if camera_type in ['perspective', 'camera', 'stereopair', 'interactive']:
-        mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
-        tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
-        tf.map_to_colormap(mi, ma, scale=10., colormap='RdBu_r')
-        return tf
-    elif camera_type in ['healpix']:
-        return ProjectionTransferFunction()
-    else:
-        pass
-
-
-def test_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
-    cam.snapshot('camera.png')
-    assert_fname('camera.png')
-    teardown_dir(curdir, tmpdir)
-
-
-def test_perspective_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = PerspectiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
-    cam.snapshot('perspective.png')
-    assert_fname('perspective.png')
-    teardown_dir(curdir, tmpdir)
-
-
-def test_interactive_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = InteractiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
-    # Can't take a snapshot here since IC uses pylab.'
-    teardown_dir(curdir, tmpdir)
-
-
-def test_projection_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-
-    cam = ProjectionCamera(c, L, W, N, pf=pf, field='Density')
-    cam.snapshot('projection.png')
-    assert_fname('projection.png')
-    teardown_dir(curdir, tmpdir)
-
-
-def test_stereo_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
-    stereo_cam = StereoPairCamera(cam)
-    # Take image
-    cam1, cam2 = stereo_cam.split()
-    cam1.snapshot(fn='stereo1.png')
-    cam2.snapshot(fn='stereo2.png')
-    assert_fname('stereo1.png')
-    assert_fname('stereo2.png')
-    teardown_dir(curdir, tmpdir)
-
-
-def test_camera_movement():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
-    cam.zoom(0.5)
-    for snap in cam.zoomin(2.0, 3):
-        snap
-    for snap in cam.move_to(np.array(c) + 0.1, 3,
-                            final_width=None, exponential=False):
-        snap
-    for snap in cam.move_to(np.array(c) - 0.1, 3,
-                            final_width=2.0*W, exponential=False):
-        snap
-    for snap in cam.move_to(np.array(c), 3,
-                            final_width=1.0*W, exponential=True):
-        snap
-    cam.rotate(np.pi/10)
-    cam.pitch(np.pi/10)
-    cam.yaw(np.pi/10)
-    cam.roll(np.pi/10)
-    for snap in cam.rotation(np.pi, 3, rot_vector=None):
-        snap
-    for snap in cam.rotation(np.pi, 3, rot_vector=np.random.random(3)):
-        snap
-    cam.snapshot('final.png')
-    assert_fname('final.png')
-    teardown_dir(curdir, tmpdir)

diff -r f0c3992e474d2fac54d6035cd3e684b4ea9b64ad -r 66803ac7861e2df56b42914f2ad783b39f0b9669 yt/visualization/volume_rendering/tests/test_vr_cameras.py
--- /dev/null
+++ b/yt/visualization/volume_rendering/tests/test_vr_cameras.py
@@ -0,0 +1,173 @@
+"""
+Test for Volume Rendering Cameras, and their movement. 
+
+Author: Samuel Skillman <samskillman at gmail.com>
+Homepage: http://yt-project.org/
+License:
+  Copyright (C) 2013 Samuel Skillman.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+import os
+import os.path
+import tempfile
+import shutil
+from yt.testing import \
+    fake_random_pf
+import numpy as np
+from yt.mods import ColorTransferFunction, ProjectionTransferFunction
+from yt.visualization.volume_rendering.api import \
+    PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera
+from yt.visualization.tests.test_plotwindow import assert_fname
+
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True 
+
+
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
+
+
+def setup_dir():
+    if use_tmpdir:
+        curdir = os.getcwd()
+        # Perform I/O in safe place instead of yt main dir
+        tmpdir = tempfile.mkdtemp()
+        os.chdir(tmpdir)
+    else:
+        curdir, tmpdir = None, None
+    return curdir, tmpdir
+
+
+def teardown_dir(curdir, tmpdir):
+    if use_tmpdir:
+        os.chdir(curdir)
+        shutil.rmtree(tmpdir)
+
+
+def setup_pf():
+    # args for off_axis_projection
+    test_pf = fake_random_pf(64)
+    c = test_pf.domain_center 
+    norm = [0.5, 0.5, 0.5]
+    W = 1.5*test_pf.domain_width
+    N = 64
+    field = "Density"
+    cam_args = [test_pf, c, norm, W, N, field]
+    return cam_args
+
+
+def setup_transfer_function(pf, camera_type):
+    if camera_type in ['perspective', 'camera', 'stereopair', 'interactive']:
+        mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
+        tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
+        tf.map_to_colormap(mi, ma, scale=10., colormap='RdBu_r')
+        return tf
+    elif camera_type in ['healpix']:
+        return ProjectionTransferFunction()
+    else:
+        pass
+
+
+def test_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
+    cam.snapshot('camera.png')
+    assert_fname('camera.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_perspective_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = PerspectiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
+    cam.snapshot('perspective.png')
+    assert_fname('perspective.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_interactive_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = InteractiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
+    # Can't take a snapshot here since IC uses pylab.'
+    teardown_dir(curdir, tmpdir)
+
+
+def test_projection_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+
+    cam = ProjectionCamera(c, L, W, N, pf=pf, field='Density')
+    cam.snapshot('projection.png')
+    assert_fname('projection.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_stereo_camera():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
+    stereo_cam = StereoPairCamera(cam)
+    # Take image
+    cam1, cam2 = stereo_cam.split()
+    cam1.snapshot(fn='stereo1.png')
+    cam2.snapshot(fn='stereo2.png')
+    assert_fname('stereo1.png')
+    assert_fname('stereo2.png')
+    teardown_dir(curdir, tmpdir)
+
+
+def test_camera_movement():
+    curdir, tmpdir = setup_dir()
+    pf, c, L, W, N, field = setup_pf()
+    tf = setup_transfer_function(pf, 'camera')
+
+    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
+    cam.zoom(0.5)
+    for snap in cam.zoomin(2.0, 3):
+        snap
+    for snap in cam.move_to(np.array(c) + 0.1, 3,
+                            final_width=None, exponential=False):
+        snap
+    for snap in cam.move_to(np.array(c) - 0.1, 3,
+                            final_width=2.0*W, exponential=False):
+        snap
+    for snap in cam.move_to(np.array(c), 3,
+                            final_width=1.0*W, exponential=True):
+        snap
+    cam.rotate(np.pi/10)
+    cam.pitch(np.pi/10)
+    cam.yaw(np.pi/10)
+    cam.roll(np.pi/10)
+    for snap in cam.rotation(np.pi, 3, rot_vector=None):
+        snap
+    for snap in cam.rotation(np.pi, 3, rot_vector=np.random.random(3)):
+        snap
+    cam.snapshot('final.png')
+    assert_fname('final.png')
+    teardown_dir(curdir, tmpdir)

diff -r f0c3992e474d2fac54d6035cd3e684b4ea9b64ad -r 66803ac7861e2df56b42914f2ad783b39f0b9669 yt/visualization/volume_rendering/transfer_functions.py
--- a/yt/visualization/volume_rendering/transfer_functions.py
+++ b/yt/visualization/volume_rendering/transfer_functions.py
@@ -636,24 +636,59 @@
                 v, w, (r,g,b,alpha)))
 
     def map_to_colormap(self, mi, ma, scale=1.0, colormap="gist_stern",
-            scale_func=None):
+                        scale_func=None):
+        r"""Map a range of values to a full colormap.
+
+        Given a minimum and maximum value in the TransferFunction, map a full
+        colormap over that range at an alpha level of `scale`.
+        Optionally specify a scale_func function that modifies the alpha as
+        a function of the transfer function value.
+
+        Parameters
+        ----------
+        mi : float
+            The start of the TransferFunction to map the colormap
+        ma : float
+            The end of the TransferFunction to map the colormap
+        scale: float, optional
+            The alpha value to be used for the height of the transfer function.
+            Larger values will be more opaque.
+        colormap : string, optional
+            An acceptable colormap.  See either yt.visualization.color_maps or
+            http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps .
+        scale_func: function(value, minval, maxval), optional
+            A user-defined function that can be used to scale the alpha channel
+            as a function of the TransferFunction field values. Function maps
+            value to somewhere between minval and maxval.
+
+        Examples
+        --------
+
+        >>> def linramp(vals, minval, maxval):
+        ...     return (vals - vals.min())/(vals.(max) - vals.min())
+        >>> tf = ColorTransferFunction( (-10.0, -5.0) )
+        >>> tf.map_to_colormap(-8.0, -6.0, scale=10.0, colormap='algae')
+        >>> tf.map_to_colormap(-6.0, -5.0, scale=10.0, colormap='algae',
+        ...                    scale_func = linramp)
+        """
+
         rel0 = int(self.nbins*(mi - self.x_bounds[0])/(self.x_bounds[1] -
-            self.x_bounds[0]))
+                                                       self.x_bounds[0]))
         rel1 = int(self.nbins*(ma - self.x_bounds[0])/(self.x_bounds[1] -
-            self.x_bounds[0]))
+                                                       self.x_bounds[0]))
         rel0 = max(rel0, 0)
         rel1 = min(rel1, self.nbins-1)
-        tomap = np.linspace(0.,1.,num=rel1-rel0)
+        tomap = np.linspace(0., 1., num=rel1-rel0)
         cmap = get_cmap(colormap)
         cc = cmap(tomap)
         if scale_func is None:
             scale_mult = 1.0
         else:
-            scale_mult = scale_func(tomap,0.0,1.0)
-        self.red.y[rel0:rel1]  = cc[:,0]*scale_mult
-        self.green.y[rel0:rel1]= cc[:,1]*scale_mult
-        self.blue.y[rel0:rel1] = cc[:,2]*scale_mult
-        self.alpha.y[rel0:rel1]= scale*cc[:,3]*scale_mult
+            scale_mult = scale_func(tomap, 0.0, 1.0)
+        self.red.y[rel0:rel1] = cc[:, 0]*scale_mult
+        self.green.y[rel0:rel1] = cc[:, 1]*scale_mult
+        self.blue.y[rel0:rel1] = cc[:, 2]*scale_mult
+        self.alpha.y[rel0:rel1] = scale*cc[:, 3]*scale_mult
 
     def add_layers(self, N, w=None, mi=None, ma=None, alpha = None,
                    colormap="gist_stern", col_bounds = None):


https://bitbucket.org/yt_analysis/yt-3.0/commits/546523af25f2/
Changeset:   546523af25f2
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 19:54:02
Summary:     Change to Using unittest.TestCase.
Affected #:  1 file

diff -r 66803ac7861e2df56b42914f2ad783b39f0b9669 -r 546523af25f253cf0a788be4968d1609976635cf yt/visualization/volume_rendering/tests/test_vr_cameras.py
--- a/yt/visualization/volume_rendering/tests/test_vr_cameras.py
+++ b/yt/visualization/volume_rendering/tests/test_vr_cameras.py
@@ -32,6 +32,7 @@
 from yt.visualization.volume_rendering.api import \
     PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera
 from yt.visualization.tests.test_plotwindow import assert_fname
+from unittest import TestCase
 
 # This toggles using a temporary directory. Turn off to examine images.
 use_tmpdir = True 
@@ -43,131 +44,126 @@
     ytcfg["yt", "__withintesting"] = "True"
 
 
-def setup_dir():
-    if use_tmpdir:
-        curdir = os.getcwd()
-        # Perform I/O in safe place instead of yt main dir
-        tmpdir = tempfile.mkdtemp()
-        os.chdir(tmpdir)
-    else:
-        curdir, tmpdir = None, None
-    return curdir, tmpdir
+class CameraTest(TestCase):
+    def setUp(self):
+        if use_tmpdir:
+            self.curdir = os.getcwd()
+            # Perform I/O in safe place instead of yt main dir
+            self.tmpdir = tempfile.mkdtemp()
+            os.chdir(self.tmpdir)
+        else:
+            self.curdir, self.tmpdir = None, None
 
+        self.pf, self.c, self.L, self.W, self.N, self.field = self.setup_pf()
 
-def teardown_dir(curdir, tmpdir):
-    if use_tmpdir:
-        os.chdir(curdir)
-        shutil.rmtree(tmpdir)
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
 
+    def setup_pf(self):
+        # args for off_axis_projection
+        test_pf = fake_random_pf(64)
+        c = test_pf.domain_center
+        norm = [0.5, 0.5, 0.5]
+        W = 1.5*test_pf.domain_width
+        N = 64
+        field = "Density"
+        cam_args = [test_pf, c, norm, W, N, field]
+        return cam_args
 
-def setup_pf():
-    # args for off_axis_projection
-    test_pf = fake_random_pf(64)
-    c = test_pf.domain_center 
-    norm = [0.5, 0.5, 0.5]
-    W = 1.5*test_pf.domain_width
-    N = 64
-    field = "Density"
-    cam_args = [test_pf, c, norm, W, N, field]
-    return cam_args
+    def setup_transfer_function(self, pf, camera_type):
+        if camera_type in ['perspective', 'camera',
+                           'stereopair', 'interactive']:
+            mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
+            tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
+            tf.map_to_colormap(mi, ma, scale=10., colormap='RdBu_r')
+            return tf
+        elif camera_type in ['healpix']:
+            return ProjectionTransferFunction()
+        else:
+            pass
 
+    def test_camera(self):
+        pf = self.pf
+        tf = self.setup_transfer_function(pf, 'camera')
+        cam = self.pf.h.camera(self.c, self.L, self.W, self.N,
+                               transfer_function=tf)
+        cam.snapshot('camera.png')
+        assert_fname('camera.png')
 
-def setup_transfer_function(pf, camera_type):
-    if camera_type in ['perspective', 'camera', 'stereopair', 'interactive']:
-        mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
-        tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
-        tf.map_to_colormap(mi, ma, scale=10., colormap='RdBu_r')
-        return tf
-    elif camera_type in ['healpix']:
-        return ProjectionTransferFunction()
-    else:
-        pass
+    def test_source_camera(self):
+        pf = self.pf
+        tf = self.setup_transfer_function(pf, 'camera')
+        source = pf.h.sphere(pf.domain_center, pf.domain_width[0]*0.5)
 
+        cam = pf.h.camera(self.c, self.L, self.W, self.N,
+                          transfer_function=tf, source=source)
+        cam.snapshot('source_camera.png')
+        assert_fname('source_camera.png')
 
-def test_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
+    def test_perspective_camera(self):
+        pf = self.pf
+        tf = self.setup_transfer_function(pf, 'camera')
 
-    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
-    cam.snapshot('camera.png')
-    assert_fname('camera.png')
-    teardown_dir(curdir, tmpdir)
+        cam = PerspectiveCamera(self.c, self.L, self.W, self.N, pf=pf,
+                                transfer_function=tf)
+        cam.snapshot('perspective.png')
+        assert_fname('perspective.png')
 
+    def test_interactive_camera(self):
+        pf = self.pf
+        tf = self.setup_transfer_function(pf, 'camera')
 
-def test_perspective_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
+        cam = InteractiveCamera(self.c, self.L, self.W, self.N, pf=pf,
+                                transfer_function=tf)
+        # Can't take a snapshot here since IC uses pylab.'
 
-    cam = PerspectiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
-    cam.snapshot('perspective.png')
-    assert_fname('perspective.png')
-    teardown_dir(curdir, tmpdir)
+    def test_projection_camera(self):
+        pf = self.pf
 
+        cam = ProjectionCamera(self.c, self.L, self.W, self.N, pf=pf,
+                               field='Density')
+        cam.snapshot('projection.png')
+        assert_fname('projection.png')
 
-def test_interactive_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
+    def test_stereo_camera(self):
+        pf = self.pf
+        tf = self.setup_transfer_function(pf, 'camera')
 
-    cam = InteractiveCamera(c, L, W, N, pf=pf, transfer_function=tf)
-    # Can't take a snapshot here since IC uses pylab.'
-    teardown_dir(curdir, tmpdir)
+        cam = pf.h.camera(self.c, self.L, self.W, self.N, transfer_function=tf)
+        stereo_cam = StereoPairCamera(cam)
+        # Take image
+        cam1, cam2 = stereo_cam.split()
+        cam1.snapshot(fn='stereo1.png')
+        cam2.snapshot(fn='stereo2.png')
+        assert_fname('stereo1.png')
+        assert_fname('stereo2.png')
 
+    def test_camera_movement(self):
+        pf = self.pf
+        tf = self.setup_transfer_function(pf, 'camera')
 
-def test_projection_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-
-    cam = ProjectionCamera(c, L, W, N, pf=pf, field='Density')
-    cam.snapshot('projection.png')
-    assert_fname('projection.png')
-    teardown_dir(curdir, tmpdir)
-
-
-def test_stereo_camera():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
-    stereo_cam = StereoPairCamera(cam)
-    # Take image
-    cam1, cam2 = stereo_cam.split()
-    cam1.snapshot(fn='stereo1.png')
-    cam2.snapshot(fn='stereo2.png')
-    assert_fname('stereo1.png')
-    assert_fname('stereo2.png')
-    teardown_dir(curdir, tmpdir)
-
-
-def test_camera_movement():
-    curdir, tmpdir = setup_dir()
-    pf, c, L, W, N, field = setup_pf()
-    tf = setup_transfer_function(pf, 'camera')
-
-    cam = pf.h.camera(c, L, W, N, transfer_function=tf)
-    cam.zoom(0.5)
-    for snap in cam.zoomin(2.0, 3):
-        snap
-    for snap in cam.move_to(np.array(c) + 0.1, 3,
-                            final_width=None, exponential=False):
-        snap
-    for snap in cam.move_to(np.array(c) - 0.1, 3,
-                            final_width=2.0*W, exponential=False):
-        snap
-    for snap in cam.move_to(np.array(c), 3,
-                            final_width=1.0*W, exponential=True):
-        snap
-    cam.rotate(np.pi/10)
-    cam.pitch(np.pi/10)
-    cam.yaw(np.pi/10)
-    cam.roll(np.pi/10)
-    for snap in cam.rotation(np.pi, 3, rot_vector=None):
-        snap
-    for snap in cam.rotation(np.pi, 3, rot_vector=np.random.random(3)):
-        snap
-    cam.snapshot('final.png')
-    assert_fname('final.png')
-    teardown_dir(curdir, tmpdir)
+        cam = pf.h.camera(self.c, self.L, self.W, self.N, transfer_function=tf)
+        cam.zoom(0.5)
+        for snap in cam.zoomin(2.0, 3):
+            snap
+        for snap in cam.move_to(np.array(self.c) + 0.1, 3,
+                                final_width=None, exponential=False):
+            snap
+        for snap in cam.move_to(np.array(self.c) - 0.1, 3,
+                                final_width=2.0*self.W, exponential=False):
+            snap
+        for snap in cam.move_to(np.array(self.c), 3,
+                                final_width=1.0*self.W, exponential=True):
+            snap
+        cam.rotate(np.pi/10)
+        cam.pitch(np.pi/10)
+        cam.yaw(np.pi/10)
+        cam.roll(np.pi/10)
+        for snap in cam.rotation(np.pi, 3, rot_vector=None):
+            snap
+        for snap in cam.rotation(np.pi, 3, rot_vector=np.random.random(3)):
+            snap
+        cam.snapshot('final.png')
+        assert_fname('final.png')


https://bitbucket.org/yt_analysis/yt-3.0/commits/a8d33200bfd8/
Changeset:   a8d33200bfd8
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 19:58:17
Summary:     Adding tests to vr setup.py
Affected #:  1 file

diff -r 546523af25f253cf0a788be4968d1609976635cf -r a8d33200bfd864c7bf726b8102905300fe9a482e yt/visualization/volume_rendering/setup.py
--- a/yt/visualization/volume_rendering/setup.py
+++ b/yt/visualization/volume_rendering/setup.py
@@ -12,4 +12,5 @@
     config = Configuration('volume_rendering', parent_package, top_path)
     config.make_config_py()  # installs __config__.py
     #config.make_svn_version_py()
+    config.add_subpackage('tests')
     return config


https://bitbucket.org/yt_analysis/yt-3.0/commits/65f953554158/
Changeset:   65f953554158
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 20:15:31
Summary:     Touching up a few things for cleanliness.
Affected #:  1 file

diff -r a8d33200bfd864c7bf726b8102905300fe9a482e -r 65f9535541584559d54a1dd7299b41b70e987a24 yt/visualization/volume_rendering/tests/test_vr_cameras.py
--- a/yt/visualization/volume_rendering/tests/test_vr_cameras.py
+++ b/yt/visualization/volume_rendering/tests/test_vr_cameras.py
@@ -54,28 +54,22 @@
         else:
             self.curdir, self.tmpdir = None, None
 
-        self.pf, self.c, self.L, self.W, self.N, self.field = self.setup_pf()
+        self.pf = fake_random_pf(64)
+        self.c = self.pf.domain_center
+        self.L = np.array([0.5, 0.5, 0.5])
+        self.W = 1.5*self.pf.domain_width
+        self.N = 64
+        self.field = "Density"
 
     def tearDown(self):
         if use_tmpdir:
             os.chdir(self.curdir)
             shutil.rmtree(self.tmpdir)
 
-    def setup_pf(self):
-        # args for off_axis_projection
-        test_pf = fake_random_pf(64)
-        c = test_pf.domain_center
-        norm = [0.5, 0.5, 0.5]
-        W = 1.5*test_pf.domain_width
-        N = 64
-        field = "Density"
-        cam_args = [test_pf, c, norm, W, N, field]
-        return cam_args
-
-    def setup_transfer_function(self, pf, camera_type):
+    def setup_transfer_function(self, camera_type):
         if camera_type in ['perspective', 'camera',
                            'stereopair', 'interactive']:
-            mi, ma = pf.h.all_data().quantities['Extrema']('Density')[0]
+            mi, ma = self.pf.h.all_data().quantities['Extrema']('Density')[0]
             tf = ColorTransferFunction((mi-1., ma+1.), grey_opacity=True)
             tf.map_to_colormap(mi, ma, scale=10., colormap='RdBu_r')
             return tf
@@ -86,7 +80,7 @@
 
     def test_camera(self):
         pf = self.pf
-        tf = self.setup_transfer_function(pf, 'camera')
+        tf = self.setup_transfer_function('camera')
         cam = self.pf.h.camera(self.c, self.L, self.W, self.N,
                                transfer_function=tf)
         cam.snapshot('camera.png')
@@ -94,7 +88,7 @@
 
     def test_source_camera(self):
         pf = self.pf
-        tf = self.setup_transfer_function(pf, 'camera')
+        tf = self.setup_transfer_function('camera')
         source = pf.h.sphere(pf.domain_center, pf.domain_width[0]*0.5)
 
         cam = pf.h.camera(self.c, self.L, self.W, self.N,
@@ -104,7 +98,7 @@
 
     def test_perspective_camera(self):
         pf = self.pf
-        tf = self.setup_transfer_function(pf, 'camera')
+        tf = self.setup_transfer_function('camera')
 
         cam = PerspectiveCamera(self.c, self.L, self.W, self.N, pf=pf,
                                 transfer_function=tf)
@@ -113,7 +107,7 @@
 
     def test_interactive_camera(self):
         pf = self.pf
-        tf = self.setup_transfer_function(pf, 'camera')
+        tf = self.setup_transfer_function('camera')
 
         cam = InteractiveCamera(self.c, self.L, self.W, self.N, pf=pf,
                                 transfer_function=tf)
@@ -129,7 +123,7 @@
 
     def test_stereo_camera(self):
         pf = self.pf
-        tf = self.setup_transfer_function(pf, 'camera')
+        tf = self.setup_transfer_function('camera')
 
         cam = pf.h.camera(self.c, self.L, self.W, self.N, transfer_function=tf)
         stereo_cam = StereoPairCamera(cam)
@@ -142,7 +136,7 @@
 
     def test_camera_movement(self):
         pf = self.pf
-        tf = self.setup_transfer_function(pf, 'camera')
+        tf = self.setup_transfer_function('camera')
 
         cam = pf.h.camera(self.c, self.L, self.W, self.N, transfer_function=tf)
         cam.zoom(0.5)


https://bitbucket.org/yt_analysis/yt-3.0/commits/780734c776b4/
Changeset:   780734c776b4
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 21:14:57
Summary:     Changing source to data_source, including in allsky projection calls.
Affected #:  3 files

diff -r 65f9535541584559d54a1dd7299b41b70e987a24 -r 780734c776b4bba00f0f06f2037aa98bebda74ef yt/utilities/amr_kdtree/amr_kdtree.py
--- a/yt/utilities/amr_kdtree/amr_kdtree.py
+++ b/yt/utilities/amr_kdtree/amr_kdtree.py
@@ -54,14 +54,14 @@
 
 class Tree(object):
     def __init__(self, pf, comm_rank=0, comm_size=1, left=None, right=None, 
-        min_level=None, max_level=None, source=None):
+        min_level=None, max_level=None, data_source=None):
 
         self.pf = pf
         self._id_offset = self.pf.h.grids[0]._id_offset
 
-        if source is None:
-            source = pf.h.all_data()
-        self.source = source
+        if data_source is None:
+            data_source = pf.h.all_data()
+        self.data_source = data_source
         if left is None:
             left = np.array([-np.inf]*3)
         if right is None:
@@ -87,8 +87,8 @@
     def build(self):
         lvl_range = range(self.min_level, self.max_level+1)
         for lvl in lvl_range:
-            #grids = self.source.select_grids(lvl)
-            grids = np.array([b for b, mask in self.source.blocks if b.Level == lvl])
+            #grids = self.data_source.select_grids(lvl)
+            grids = np.array([b for b, mask in self.data_source.blocks if b.Level == lvl])
             if len(grids) == 0: continue
             self.add_grids(grids)
 
@@ -141,7 +141,7 @@
     no_ghost = True
 
     def __init__(self, pf, min_level=None, max_level=None,
-                 source=None):
+                 data_source=None):
 
         ParallelAnalysisInterface.__init__(self)
 
@@ -158,14 +158,14 @@
         except AttributeError:
             self._id_offset = 0
 
-        if source is None:
-            source = self.pf.h.all_data()
-        self.source = source
+        if data_source is None:
+            data_source = self.pf.h.all_data()
+        self.data_source = data_source
 
         mylog.debug('Building AMRKDTree')
         self.tree = Tree(pf, self.comm.rank, self.comm.size,
                          min_level=min_level, max_level=max_level,
-                         source=source)
+                         data_source=data_source)
 
     def set_fields(self, fields, log_fields, no_ghost):
         self.fields = fields
@@ -263,10 +263,10 @@
                 self.current_saved_grids.append(grid)
                 self.current_vcds.append(dds)
 
-        if self.source.selector is None:
+        if self.data_source.selector is None:
             mask = np.ones(dims, dtype='uint8')
         else:
-            mask = self.source.selector.fill_mask(grid)[li[0]:ri[0], li[1]:ri[1], li[2]:ri[2] ].astype('uint8')
+            mask = self.data_source.selector.fill_mask(grid)[li[0]:ri[0], li[1]:ri[1], li[2]:ri[2] ].astype('uint8')
 
         data = [d[li[0]:ri[0]+1,
                   li[1]:ri[1]+1,

diff -r 65f9535541584559d54a1dd7299b41b70e987a24 -r 780734c776b4bba00f0f06f2037aa98bebda74ef yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -164,7 +164,7 @@
                  log_fields = None,
                  sub_samples = 5, pf = None,
                  min_level=None, max_level=None, no_ghost=True,
-                 source=None,
+                 data_source=None,
                  use_light=False):
         ParallelAnalysisInterface.__init__(self)
         if pf is not None: self.pf = pf
@@ -196,13 +196,13 @@
         if self.no_ghost:
             mylog.info('Warning: no_ghost is currently True (default). This may lead to artifacts at grid boundaries.')
 
-        if source is None:
-            source = self.pf.h.all_data()
-        self.source = source
+        if data_source is None:
+            data_source = self.pf.h.all_data()
+        self.data_source = data_source
 
         if volume is None:
             volume = AMRKDTree(self.pf, min_level=min_level, 
-                               max_level=max_level, source=self.source)
+                               max_level=max_level, data_source=self.data_source)
         self.volume = volume        
 
     def _setup_box_properties(self, width, center, unit_vectors):
@@ -1158,7 +1158,7 @@
         self.light_rgba = None
         if volume is None:
             volume = AMRKDTree(self.pf, min_level=min_level,
-                               max_level=max_level, source=self.source)
+                               max_level=max_level, data_source=self.data_source)
         self.use_kd = isinstance(volume, AMRKDTree)
         self.volume = volume
 
@@ -1965,7 +1965,7 @@
             yield self.snapshot()
 
 def allsky_projection(pf, center, radius, nside, field, weight = None,
-                      inner_radius = 10, rotation = None, source = None):
+                      inner_radius = 10, rotation = None, data_source = None):
     r"""Project through a parameter file, through an allsky-method
     decomposition from HEALpix, and return the image plane.
 
@@ -2000,8 +2000,8 @@
         If supplied, the vectors will be rotated by this.  You can construct
         this by, for instance, calling np.array([v1,v2,v3]) where those are the
         three reference planes of an orthogonal frame (see ortho_find).
-    source : data container, default None
-        If this is supplied, this gives the data source from which the all sky
+    data_source : data container, default None
+        If this is supplied, this gives the data data_source from which the all sky
         projection pulls its data from.
 
     Returns
@@ -2046,16 +2046,16 @@
     positions += inner_radius * dx * vs
     vs *= radius
     uv = np.ones(3, dtype='float64')
-    if source is not None:
-        grids = source._grids
+    if data_source is not None:
+        grids = data_source._grids
     else:
         grids = pf.h.sphere(center, radius)._grids
     sampler = ProjectionSampler(positions, vs, center, (0.0, 0.0, 0.0, 0.0),
                                 image, uv, uv, np.zeros(3, dtype='float64'))
     pb = get_pbar("Sampling ", len(grids))
     for i,grid in enumerate(grids):
-        if source is not None:
-            data = [grid[field] * source._get_cut_mask(grid) * \
+        if data_source is not None:
+            data = [grid[field] * data_source._get_cut_mask(grid) * \
                 grid.child_mask.astype('float64')
                 for field in fields]
         else:
@@ -2199,9 +2199,9 @@
                     np.minimum(mi, this_point, mi)
                     np.maximum(ma, this_point, ma)
         # Now we have a bounding box.
-        source = pf.h.region(self.center, mi, ma)
+        data_source = pf.h.region(self.center, mi, ma)
 
-        for i, (grid, mask) in enumerate(source.blocks):
+        for i, (grid, mask) in enumerate(data_source.blocks):
             data = [(grid[field] * mask).astype("float64") for field in fields]
             pg = PartitionedGrid(
                 grid.id, data,

diff -r 65f9535541584559d54a1dd7299b41b70e987a24 -r 780734c776b4bba00f0f06f2037aa98bebda74ef yt/visualization/volume_rendering/tests/test_vr_cameras.py
--- a/yt/visualization/volume_rendering/tests/test_vr_cameras.py
+++ b/yt/visualization/volume_rendering/tests/test_vr_cameras.py
@@ -86,15 +86,15 @@
         cam.snapshot('camera.png')
         assert_fname('camera.png')
 
-    def test_source_camera(self):
+    def test_data_source_camera(self):
         pf = self.pf
         tf = self.setup_transfer_function('camera')
-        source = pf.h.sphere(pf.domain_center, pf.domain_width[0]*0.5)
+        data_source = pf.h.sphere(pf.domain_center, pf.domain_width[0]*0.5)
 
         cam = pf.h.camera(self.c, self.L, self.W, self.N,
-                          transfer_function=tf, source=source)
-        cam.snapshot('source_camera.png')
-        assert_fname('source_camera.png')
+                          transfer_function=tf, data_source=data_source)
+        cam.snapshot('data_source_camera.png')
+        assert_fname('data_source_camera.png')
 
     def test_perspective_camera(self):
         pf = self.pf


https://bitbucket.org/yt_analysis/yt-3.0/commits/ab94f85a5e1a/
Changeset:   ab94f85a5e1a
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 21:18:52
Summary:     Adding docstrings for data_source usage.
Affected #:  1 file

diff -r 780734c776b4bba00f0f06f2037aa98bebda74ef -r ab94f85a5e1a33344415d3f63c89708ba60777a6 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -121,6 +121,10 @@
         accuracy/smoothness in resulting image.  The effects are
         less notable when the transfer function is smooth and
         broad. Default: True
+    data_source: YTRegion, optional
+        Optionally specify an arbitrary data source to the volume rendering.
+        All cells not included in the data source will be ignored during ray
+        casting. By default this will get set to pf.h.all_data().
 
     Examples
     --------


https://bitbucket.org/yt_analysis/yt-3.0/commits/ba1e3aff8f58/
Changeset:   ba1e3aff8f58
Branch:      yt-3.0
User:        samskillman
Date:        2013-08-09 21:19:49
Summary:     Quick fix to docstrings.
Affected #:  1 file

diff -r ab94f85a5e1a33344415d3f63c89708ba60777a6 -r ba1e3aff8f58a620904c3fae89358470e2e04b26 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -121,7 +121,7 @@
         accuracy/smoothness in resulting image.  The effects are
         less notable when the transfer function is smooth and
         broad. Default: True
-    data_source: YTRegion, optional
+    data_source: data container, optional
         Optionally specify an arbitrary data source to the volume rendering.
         All cells not included in the data source will be ignored during ray
         casting. By default this will get set to pf.h.all_data().
@@ -2005,7 +2005,7 @@
         this by, for instance, calling np.array([v1,v2,v3]) where those are the
         three reference planes of an orthogonal frame (see ortho_find).
     data_source : data container, default None
-        If this is supplied, this gives the data data_source from which the all sky
+        If this is supplied, this gives the data source from which the all sky
         projection pulls its data from.
 
     Returns

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

--

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