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

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


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/ab8ab5788661/
Changeset:   ab8ab5788661
Branch:      yt
User:        chummels
Date:        2015-10-15 17:38:03+00:00
Summary:     Merged in atmyers/yt (pull request #1796)

[Experimental] Perform the VR tests in temporary directories if they do file IO
Affected #:  7 files

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 yt/visualization/volume_rendering/tests/test_composite.py
--- a/yt/visualization/volume_rendering/tests/test_composite.py
+++ b/yt/visualization/volume_rendering/tests/test_composite.py
@@ -10,55 +10,82 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
-import yt
+import os
+import tempfile
+import shutil
 from yt.testing import fake_random_ds
-from yt.visualization.volume_rendering.api import Scene, Camera, ZBuffer, \
-    VolumeSource, OpaqueSource, LineSource, BoxSource
-from yt.utilities.lib.misc_utilities import lines
+from yt.visualization.volume_rendering.api import Scene, Camera, \
+    VolumeSource, LineSource, BoxSource
 from yt.data_objects.api import ImageArray
 import numpy as np
+from unittest import TestCase
+
 np.random.seed(0)
 
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True
 
-def test_composite_vr():
-    ds = fake_random_ds(64)
-    dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
-    ds.field_info[ds.field_list[0]].take_log=False
 
-    sc = Scene()
-    cam = Camera(ds)
-    cam.resolution = (512,512)
-    sc.camera = cam
-    vr = VolumeSource(dd, field=ds.field_list[0])
-    vr.transfer_function.clear()
-    vr.transfer_function.grey_opacity=True
-    vr.transfer_function.map_to_colormap(0.0, 1.0, scale=3.0, colormap="Reds")
-    sc.add_source(vr)
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
 
-    cam.set_width( 1.8*ds.domain_width )
-    cam.lens.setup_box_properties(cam)
 
-    # DRAW SOME LINES
-    npoints = 100
-    vertices = np.random.random([npoints, 2, 3])
-    colors = np.random.random([npoints, 4])
-    colors[:, 3] = 0.10
+class CompositeVRTest(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
 
-    box_source = BoxSource(ds.domain_left_edge, ds.domain_right_edge, color=[1.,1.,1.,1.0])
-    sc.add_source(box_source)
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
 
-    box_source = BoxSource(ds.domain_left_edge + np.array([0.1,0.,0.3])*ds.domain_left_edge.uq,
-            ds.domain_right_edge-np.array([0.1,0.2,0.3])*ds.domain_left_edge.uq,
-            color=np.array([0.0, 1.0, 0.0, 0.10]))
-    sc.add_source(box_source)
+    def test_composite_vr(self):
+        ds = fake_random_ds(64)
+        dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
+        ds.field_info[ds.field_list[0]].take_log=False
 
-    line_source = LineSource(vertices, colors)
-    sc.add_source(line_source)
+        sc = Scene()
+        cam = Camera(ds)
+        cam.resolution = (512, 512)
+        sc.camera = cam
+        vr = VolumeSource(dd, field=ds.field_list[0])
+        vr.transfer_function.clear()
+        vr.transfer_function.grey_opacity=True
+        vr.transfer_function.map_to_colormap(0.0, 1.0, scale=3.0, colormap="Reds")
+        sc.add_source(vr)
 
-    im = sc.render()
-    im = ImageArray(im.d)
-    im.write_png("composite.png")
-    return im
+        cam.set_width( 1.8*ds.domain_width )
+        cam.lens.setup_box_properties(cam)
 
-if __name__ == "__main__":
-    im = test_composite_vr()
+        # DRAW SOME LINES
+        npoints = 100
+        vertices = np.random.random([npoints, 2, 3])
+        colors = np.random.random([npoints, 4])
+        colors[:, 3] = 0.10
+
+        box_source = BoxSource(ds.domain_left_edge, 
+                               ds.domain_right_edge, 
+                               color=[1.0, 1.0, 1.0, 1.0])
+        sc.add_source(box_source)
+
+        LE = ds.domain_left_edge + np.array([0.1,0.,0.3])*ds.domain_left_edge.uq
+        RE = ds.domain_right_edge-np.array([0.1,0.2,0.3])*ds.domain_left_edge.uq
+        color = np.array([0.0, 1.0, 0.0, 0.10])
+        box_source = BoxSource(LE, RE, color=color)
+        sc.add_source(box_source)
+
+        line_source = LineSource(vertices, colors)
+        sc.add_source(line_source)
+
+        im = sc.render()
+        im = ImageArray(im.d)
+        im.write_png("composite.png")
+        return im

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 yt/visualization/volume_rendering/tests/test_lenses.py
--- a/yt/visualization/volume_rendering/tests/test_lenses.py
+++ b/yt/visualization/volume_rendering/tests/test_lenses.py
@@ -9,102 +9,125 @@
 #
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
-import yt
+
+import os
+import tempfile
+import shutil
 from yt.testing import fake_random_ds
 from yt.visualization.volume_rendering.api import Scene, Camera, VolumeSource
-from time import time
 import numpy as np
+from unittest import TestCase
 
-field = ("gas", "density")
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True
 
-def test_perspective_lens():
-    #ds = fake_random_ds(32, fields = field)
-    ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-    sc = Scene()
-    cam = Camera(ds, lens_type='perspective')
-    cam.position = ds.arr(np.array([1.0, 1.0, 1.0]), 'code_length')
-    vol = VolumeSource(ds, field=field)
-    tf = vol.transfer_function
-    tf.grey_opacity = True
-    sc.camera = cam
-    sc.add_source(vol)
-    sc.render('test_perspective_%s.png' % field[1], sigma_clip=6.0)
 
-def test_stereoperspective_lens():
-    #ds = fake_random_ds(32, fields = field)
-    ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-    sc = Scene()
-    cam = Camera(ds, lens_type='stereo-perspective')
-    cam.resolution = [1024, 512]
-    cam.position = ds.arr(np.array([0.7, 0.7, 0.7]), 'code_length')
-    vol = VolumeSource(ds, field=field)
-    tf = vol.transfer_function
-    tf.grey_opacity = True
-    sc.camera = cam
-    sc.add_source(vol)
-    sc.render('test_stereoperspective_%s.png' % field[1], sigma_clip=6.0)
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
 
-def test_fisheye_lens():
-    ds = fake_random_ds(32, fields = field)
-    #ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-    dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 10)
-    sc = Scene()
-    cam = Camera(dd, lens_type='fisheye')
-    cam.lens.fov = 360.0
-    cam.set_width(ds.domain_width)
-    v, c = ds.find_max('density')
-    p = ds.domain_center.copy()
-    cam.set_position(c-0.0005*ds.domain_width)
-    vol = VolumeSource(dd, field=field)
-    tf = vol.transfer_function
-    tf.grey_opacity = True
-    sc.camera = cam
-    sc.add_source(vol)
-    sc.render('test_fisheye_%s.png' % field[1], sigma_clip=6.0)
 
-def test_plane_lens():
-    ds = fake_random_ds(32, fields = field)
-    #ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-    dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 10)
-    sc = Scene()
-    cam = Camera(dd, lens_type='plane-parallel')
-    cam.set_width(ds.domain_width*1e-2)
-    v, c = ds.find_max('density')
-    p = ds.domain_center.copy()
-    vol = VolumeSource(dd, field=field)
-    tf = vol.transfer_function
-    tf.grey_opacity = True
-    sc.camera = cam
-    sc.add_source(vol)
-    sc.render('test_plane_%s.png' % field[1], sigma_clip=6.0)
+class LensTest(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
 
-def test_spherical_lens():
-    #ds = fake_random_ds(32, fields = field)
-    ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-    sc = Scene()
-    cam = Camera(ds, lens_type='spherical')
-    cam.resolution = [512, 256]
-    cam.position = ds.arr(np.array([0.6, 0.5, 0.5]), 'code_length')
-    vol = VolumeSource(ds, field=field)
-    tf = vol.transfer_function
-    tf.grey_opacity = True
-    sc.camera = cam
-    sc.add_source(vol)
-    sc.render('test_spherical_%s.png' % field[1], sigma_clip=6.0)
+        self.field = ("gas", "density")
+        self.ds = fake_random_ds(32, fields=self.field)
 
-def test_stereospherical_lens():
-    #ds = fake_random_ds(32, fields = field)
-    ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
-    w = (ds.domain_width).in_units('code_length')
-    w = ds.arr(w, 'code_length')
-    sc = Scene()
-    cam = Camera(ds, lens_type='stereo-spherical')
-    cam.resolution = [1024, 256]
-    cam.position = ds.arr(np.array([0.6, 0.5, 0.5]), 'code_length')
-    vol = VolumeSource(ds, field=field)
-    tf = vol.transfer_function
-    tf.grey_opacity = True
-    sc.camera = cam
-    sc.add_source(vol)
-    sc.render('test_stereospherical_%s.png' % field[1], sigma_clip=6.0)
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
 
+    def test_perspective_lens(self):
+        sc = Scene()
+        cam = Camera(self.ds, lens_type='perspective')
+        cam.position = self.ds.arr(np.array([1.0, 1.0, 1.0]), 'code_length')
+        vol = VolumeSource(self.ds, field=self.field)
+        tf = vol.transfer_function
+        tf.grey_opacity = True
+        sc.camera = cam
+        sc.add_source(vol)
+        sc.render('test_perspective_%s.png' % self.field[1], sigma_clip=6.0)
+
+    def test_stereoperspective_lens(self):
+        sc = Scene()
+        cam = Camera(self.ds, lens_type='stereo-perspective')
+        cam.resolution = [1024, 512]
+        cam.position = self.ds.arr(np.array([0.7, 0.7, 0.7]), 'code_length')
+        vol = VolumeSource(self.ds, field=self.field)
+        tf = vol.transfer_function
+        tf.grey_opacity = True
+        sc.camera = cam
+        sc.add_source(vol)
+        sc.render('test_stereoperspective_%s.png' % self.field[1],
+                  sigma_clip=6.0)
+
+    def test_fisheye_lens(self):
+        dd = self.ds.sphere(self.ds.domain_center,
+                            self.ds.domain_width[0] / 10)
+        sc = Scene()
+        cam = Camera(dd, lens_type='fisheye')
+        cam.lens.fov = 360.0
+        cam.set_width(self.ds.domain_width)
+        v, c = self.ds.find_max('density')
+        p = self.ds.domain_center.copy()
+        cam.set_position(c-0.0005*self.ds.domain_width)
+        vol = VolumeSource(dd, field=self.field)
+        tf = vol.transfer_function
+        tf.grey_opacity = True
+        sc.camera = cam
+        sc.add_source(vol)
+        sc.render('test_fisheye_%s.png' % self.field[1],
+                  sigma_clip=6.0)
+
+    def test_plane_lens(self):
+        dd = self.ds.sphere(self.ds.domain_center,
+                            self.ds.domain_width[0] / 10)
+        sc = Scene()
+        cam = Camera(dd, lens_type='plane-parallel')
+        cam.set_width(self.ds.domain_width*1e-2)
+        v, c = self.ds.find_max('density')
+        p = self.ds.domain_center.copy()
+        vol = VolumeSource(dd, field=self.field)
+        tf = vol.transfer_function
+        tf.grey_opacity = True
+        sc.camera = cam
+        sc.add_source(vol)
+        sc.render('test_plane_%s.png' % self.field[1],
+                  sigma_clip=6.0)
+
+    def test_spherical_lens(self):
+        sc = Scene()
+        cam = Camera(self.ds, lens_type='spherical')
+        cam.resolution = [512, 256]
+        cam.position = self.ds.arr(np.array([0.6, 0.5, 0.5]), 'code_length')
+        vol = VolumeSource(self.ds, field=self.field)
+        tf = vol.transfer_function
+        tf.grey_opacity = True
+        sc.camera = cam
+        sc.add_source(vol)
+        sc.render('test_spherical_%s.png' % self.field[1],
+                  sigma_clip=6.0)
+
+    def test_stereospherical_lens(self):
+        w = (self.ds.domain_width).in_units('code_length')
+        w = self.ds.arr(w, 'code_length')
+        sc = Scene()
+        cam = Camera(self.ds, lens_type='stereo-spherical')
+        cam.resolution = [1024, 256]
+        cam.position = self.ds.arr(np.array([0.6, 0.5, 0.5]), 'code_length')
+        vol = VolumeSource(self.ds, field=self.field)
+        tf = vol.transfer_function
+        tf.grey_opacity = True
+        sc.camera = cam
+        sc.add_source(vol)
+        sc.render('test_stereospherical_%s.png' % self.field[1],
+                  sigma_clip=6.0)

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 yt/visualization/volume_rendering/tests/test_points.py
--- a/yt/visualization/volume_rendering/tests/test_points.py
+++ b/yt/visualization/volume_rendering/tests/test_points.py
@@ -10,44 +10,68 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
-import yt
+import os
+import tempfile
+import shutil
 from yt.testing import fake_random_ds
-from yt.visualization.volume_rendering.api import Scene, Camera, ZBuffer, \
-    VolumeSource, OpaqueSource, LineSource, BoxSource, PointSource
-from yt.utilities.lib.misc_utilities import lines
-from yt.data_objects.api import ImageArray
+from yt.visualization.volume_rendering.api import Scene, Camera, \
+    VolumeSource, PointSource
 import numpy as np
+from unittest import TestCase
+
 np.random.seed(0)
 
-def test_points_vr():
-    ds = fake_random_ds(64)
-    dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
-    ds.field_info[ds.field_list[0]].take_log=False
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True
 
-    sc = Scene()
-    cam = Camera(ds)
-    cam.resolution = (512,512)
-    sc.camera = cam
-    vr = VolumeSource(dd, field=ds.field_list[0])
-    vr.transfer_function.clear()
-    vr.transfer_function.grey_opacity=False
-    vr.transfer_function.map_to_colormap(0.0, 1.0, scale=10., colormap="Reds")
-    sc.add_source(vr)
 
-    cam.set_width( 1.8*ds.domain_width )
-    cam.lens.setup_box_properties(cam)
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
 
-    # DRAW SOME POINTS
-    npoints = 1000
-    vertices = np.random.random([npoints, 3])
-    colors = np.random.random([npoints, 4])
-    colors[:,3] = 0.10
 
-    points_source = PointSource(vertices, colors=colors)
-    sc.add_source(points_source)
-    im = sc.render()
-    im.write_png("points.png")
-    return im
+class PointsVRTest(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
 
-if __name__ == "__main__":
-    im = test_points_vr()
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
+
+    def test_points_vr(self):
+        ds = fake_random_ds(64)
+        dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
+        ds.field_info[ds.field_list[0]].take_log=False
+
+        sc = Scene()
+        cam = Camera(ds)
+        cam.resolution = (512,512)
+        sc.camera = cam
+        vr = VolumeSource(dd, field=ds.field_list[0])
+        vr.transfer_function.clear()
+        vr.transfer_function.grey_opacity=False
+        vr.transfer_function.map_to_colormap(0.0, 1.0, scale=10., colormap="Reds")
+        sc.add_source(vr)
+
+        cam.set_width( 1.8*ds.domain_width )
+        cam.lens.setup_box_properties(cam)
+
+        # DRAW SOME POINTS
+        npoints = 1000
+        vertices = np.random.random([npoints, 3])
+        colors = np.random.random([npoints, 4])
+        colors[:,3] = 0.10
+
+        points_source = PointSource(vertices, colors=colors)
+        sc.add_source(points_source)
+        im = sc.render()
+        im.write_png("points.png")
+        return im

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 yt/visualization/volume_rendering/tests/test_scene.py
--- a/yt/visualization/volume_rendering/tests/test_scene.py
+++ b/yt/visualization/volume_rendering/tests/test_scene.py
@@ -12,45 +12,73 @@
 #
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
-import yt
+
+import os
+import tempfile
+import shutil
 from yt.testing import fake_random_ds
-from yt.visualization.volume_rendering.api import Scene, \
-    volume_render, Camera, VolumeSource
+from yt.visualization.volume_rendering.api import volume_render, VolumeSource
 import numpy as np
+from unittest import TestCase
 
-def test_rotation():
-    ds = fake_random_ds(64)
-    ds2 = fake_random_ds(64)
-    dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 2)
-    dd2 = ds2.sphere(ds2.domain_center, ds2.domain_width[0] / 2)
-    
-    im, sc = volume_render(dd, field=('gas', 'density'))
-    im.write_png('test.png')
-    
-    vol = sc.get_source(0)
-    tf = vol.transfer_function
-    tf.clear()
-    mi, ma = dd.quantities.extrema('density')
-    mi = np.log10(mi)
-    ma = np.log10(ma)
-    mi_bound = ((ma-mi)*(0.10))+mi
-    ma_bound = ((ma-mi)*(0.90))+mi
-    tf.map_to_colormap(mi_bound, ma_bound, scale=0.01, colormap='Blues_r')
-    
-    vol2 = VolumeSource(dd2, field=('gas', 'density'))
-    sc.add_source(vol2)
-    
-    tf = vol2.transfer_function
-    tf.clear()
-    mi, ma = dd2.quantities.extrema('density')
-    mi = np.log10(mi)
-    ma = np.log10(ma)
-    mi_bound = ((ma-mi)*(0.10))+mi
-    ma_bound = ((ma-mi)*(0.90))+mi
-    tf.map_to_colormap(mi_bound, ma_bound,  scale=0.01, colormap='Reds_r')
-    sc.render('test_scene.png', sigma_clip=6.0)
-    
-    nrot = 2 
-    for i in range(nrot):
-        sc.camera.pitch(2*np.pi/nrot)
-        sc.render('test_rot_%04i.png' % i, sigma_clip=6.0)
+# 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"
+
+
+class RotationTest(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
+
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
+
+    def test_rotation(self):
+        ds = fake_random_ds(64)
+        ds2 = fake_random_ds(64)
+        dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 2)
+        dd2 = ds2.sphere(ds2.domain_center, ds2.domain_width[0] / 2)
+
+        im, sc = volume_render(dd, field=('gas', 'density'))
+        im.write_png('test.png')
+
+        vol = sc.get_source(0)
+        tf = vol.transfer_function
+        tf.clear()
+        mi, ma = dd.quantities.extrema('density')
+        mi = np.log10(mi)
+        ma = np.log10(ma)
+        mi_bound = ((ma-mi)*(0.10))+mi
+        ma_bound = ((ma-mi)*(0.90))+mi
+        tf.map_to_colormap(mi_bound, ma_bound, scale=0.01, colormap='Blues_r')
+
+        vol2 = VolumeSource(dd2, field=('gas', 'density'))
+        sc.add_source(vol2)
+
+        tf = vol2.transfer_function
+        tf.clear()
+        mi, ma = dd2.quantities.extrema('density')
+        mi = np.log10(mi)
+        ma = np.log10(ma)
+        mi_bound = ((ma-mi)*(0.10))+mi
+        ma_bound = ((ma-mi)*(0.90))+mi
+        tf.map_to_colormap(mi_bound, ma_bound,  scale=0.01, colormap='Reds_r')
+        sc.render('test_scene.png', sigma_clip=6.0)
+
+        nrot = 2 
+        for i in range(nrot):
+            sc.camera.pitch(2*np.pi/nrot)
+            sc.render('test_rot_%04i.png' % i, sigma_clip=6.0)

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 yt/visualization/volume_rendering/tests/test_simple_vr.py
--- a/yt/visualization/volume_rendering/tests/test_simple_vr.py
+++ b/yt/visualization/volume_rendering/tests/test_simple_vr.py
@@ -10,14 +10,41 @@
 #
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
+
+import os
+import tempfile
+import shutil
 import yt
 from yt.testing import fake_random_ds
+from unittest import TestCase
 
-def test_simple_vr():
-    ds = fake_random_ds(32)
-    im, sc = yt.volume_render(ds, fname='test.png', sigma_clip=4.0)
-    print(sc)
-    return im, sc
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True
 
-if __name__ == "__main__":
-    im, sc = test_simple_vr()
+
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
+
+
+class SimpleVRTest(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
+
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
+
+    def test_simple_vr(self):
+        ds = fake_random_ds(32)
+        im, sc = yt.volume_render(ds, fname='test.png', sigma_clip=4.0)
+        print(sc)
+        return im, sc

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 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
@@ -23,7 +23,8 @@
 from yt.visualization.volume_rendering.old_camera import \
     PerspectiveCamera, StereoPairCamera, InteractiveCamera, ProjectionCamera, \
     FisheyeCamera
-from yt.visualization.volume_rendering.api import ColorTransferFunction, ProjectionTransferFunction
+from yt.visualization.volume_rendering.api import ColorTransferFunction, \
+    ProjectionTransferFunction
 from yt.visualization.tests.test_plotwindow import assert_fname
 from unittest import TestCase
 

diff -r d22ec3d93d2ce6f954f7cd07d569f384039f02e6 -r ab8ab57886619190feb7c5ee2ac80e7bd08d59f8 yt/visualization/volume_rendering/tests/test_zbuff.py
--- a/yt/visualization/volume_rendering/tests/test_zbuff.py
+++ b/yt/visualization/volume_rendering/tests/test_zbuff.py
@@ -10,98 +10,121 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
+import os
+import tempfile
+import shutil
 from yt.testing import fake_random_ds
 from yt.visualization.volume_rendering.api import \
     Scene, Camera, ZBuffer, \
     VolumeSource, OpaqueSource
 from yt.testing import assert_almost_equal
 import numpy as np
+from unittest import TestCase
+
 np.random.seed(0)
 
+# This toggles using a temporary directory. Turn off to examine images.
+use_tmpdir = True
 
-def test_composite_vr():
-    ds = fake_random_ds(64)
-    dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
-    ds.field_info[ds.field_list[0]].take_log=False
 
-    sc = Scene()
-    cam = Camera(ds)
-    cam.resolution = (512,512)
-    sc.camera = cam
-    vr = VolumeSource(dd, field=ds.field_list[0])
-    vr.transfer_function.clear()
-    vr.transfer_function.grey_opacity=True
-    vr.transfer_function.map_to_colormap(0.0, 1.0, scale=10.0, colormap="Reds")
-    sc.add_source(vr)
+def setup():
+    """Test specific setup."""
+    from yt.config import ytcfg
+    ytcfg["yt", "__withintesting"] = "True"
 
-    cam.set_width( 1.8*ds.domain_width )
-    cam.lens.setup_box_properties(cam)
 
-    # Create Arbitrary Z-buffer
-    empty = cam.lens.new_image(cam)
-    z = np.empty(empty.shape[:2], dtype='float64')
-    # Let's put a blue plane right through the center
-    z[:] = cam.width[2] / 2.
-    empty[:,:,2] = 1.0 # Set blue to 1's
-    empty[:,:,3] = 1.0 # Set alpha to 1's
-    zbuffer = ZBuffer(empty, z)
-    zsource = OpaqueSource()
-    zsource.set_zbuffer(zbuffer)
-    sc.add_source(zsource)
+class ZBufferTest(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
 
-    im = sc.render()
-    im.write_png("composite.png")
-    return im
+    def tearDown(self):
+        if use_tmpdir:
+            os.chdir(self.curdir)
+            shutil.rmtree(self.tmpdir)
 
 
-def test_nonrectangular_add():
-    rgba1 = np.ones((64, 1, 4))
-    z1 = np.expand_dims(np.arange(64.), 1)
+    def test_composite_vr(self):
+        ds = fake_random_ds(64)
+        dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
+        ds.field_info[ds.field_list[0]].take_log=False
 
-    rgba2 = np.zeros((64, 1, 4))
-    z2 = np.expand_dims(np.arange(63., -1., -1.), 1)
+        sc = Scene()
+        cam = Camera(ds)
+        cam.resolution = (512,512)
+        sc.camera = cam
+        vr = VolumeSource(dd, field=ds.field_list[0])
+        vr.transfer_function.clear()
+        vr.transfer_function.grey_opacity=True
+        vr.transfer_function.map_to_colormap(0.0, 1.0, scale=10.0, colormap="Reds")
+        sc.add_source(vr)
 
-    exact_rgba = np.concatenate((np.ones(32), np.zeros(32)))
-    exact_rgba = np.expand_dims(exact_rgba, 1)
-    exact_rgba = np.dstack((exact_rgba, exact_rgba, exact_rgba, exact_rgba))
+        cam.set_width( 1.8*ds.domain_width )
+        cam.lens.setup_box_properties(cam)
 
-    exact_z = np.concatenate((np.arange(32.), np.arange(31.,-1.,-1.)))
-    exact_z = np.expand_dims(exact_z, 1)
+        # Create Arbitrary Z-buffer
+        empty = cam.lens.new_image(cam)
+        z = np.empty(empty.shape[:2], dtype='float64')
+        # Let's put a blue plane right through the center
+        z[:] = cam.width[2] / 2.
+        empty[:,:,2] = 1.0 # Set blue to 1's
+        empty[:,:,3] = 1.0 # Set alpha to 1's
+        zbuffer = ZBuffer(empty, z)
+        zsource = OpaqueSource()
+        zsource.set_zbuffer(zbuffer)
+        sc.add_source(zsource)
 
-    buff1 = ZBuffer(rgba1, z1)
-    buff2 = ZBuffer(rgba2, z2)
+        im = sc.render()
+        im.write_png("composite.png")
+        return im
 
-    buff = buff1 + buff2
+    def test_nonrectangular_add(self):
+        rgba1 = np.ones((64, 1, 4))
+        z1 = np.expand_dims(np.arange(64.), 1)
 
-    assert_almost_equal(buff.rgba, exact_rgba)
-    assert_almost_equal(buff.z, exact_z)
+        rgba2 = np.zeros((64, 1, 4))
+        z2 = np.expand_dims(np.arange(63., -1., -1.), 1)
 
+        exact_rgba = np.concatenate((np.ones(32), np.zeros(32)))
+        exact_rgba = np.expand_dims(exact_rgba, 1)
+        exact_rgba = np.dstack((exact_rgba, exact_rgba, exact_rgba, exact_rgba))
+        
+        exact_z = np.concatenate((np.arange(32.), np.arange(31.,-1.,-1.)))
+        exact_z = np.expand_dims(exact_z, 1)
+        
+        buff1 = ZBuffer(rgba1, z1)
+        buff2 = ZBuffer(rgba2, z2)
+        
+        buff = buff1 + buff2
+        
+        assert_almost_equal(buff.rgba, exact_rgba)
+        assert_almost_equal(buff.z, exact_z)
 
-def test_rectangular_add():
-    rgba1 = np.ones((8, 8, 4))
-    z1 = np.arange(64.)
-    z1 = z1.reshape((8, 8))
-    buff1 = ZBuffer(rgba1, z1)
+    def test_rectangular_add(self):
+        rgba1 = np.ones((8, 8, 4))
+        z1 = np.arange(64.)
+        z1 = z1.reshape((8, 8))
+        buff1 = ZBuffer(rgba1, z1)
 
-    rgba2 = np.zeros((8, 8, 4))
-    z2 = np.arange(63., -1., -1.)
-    z2 = z2.reshape((8, 8))
-    buff2 = ZBuffer(rgba2, z2)
+        rgba2 = np.zeros((8, 8, 4))
+        z2 = np.arange(63., -1., -1.)
+        z2 = z2.reshape((8, 8))
+        buff2 = ZBuffer(rgba2, z2)
 
-    buff = buff1 + buff2
+        buff = buff1 + buff2
 
-    exact_rgba = np.empty((8, 8, 4), dtype=np.float64)
-    exact_rgba[0:4,0:8,:] = 1.0
-    exact_rgba[4:8,0:8,:] = 0.0
+        exact_rgba = np.empty((8, 8, 4), dtype=np.float64)
+        exact_rgba[0:4,0:8,:] = 1.0
+        exact_rgba[4:8,0:8,:] = 0.0
+        
+        exact_z = np.concatenate((np.arange(32.), np.arange(31., -1., -1.)))
+        exact_z = np.expand_dims(exact_z, 1)
+        exact_z = exact_z.reshape(8, 8)
 
-    exact_z = np.concatenate((np.arange(32.), np.arange(31., -1., -1.)))
-    exact_z = np.expand_dims(exact_z, 1)
-    exact_z = exact_z.reshape(8, 8)
-
-    assert_almost_equal(buff.rgba, exact_rgba)
-    assert_almost_equal(buff.z, exact_z)
-
-if __name__ == "__main__":
-    im = test_composite_vr()
-    test_nonrectangular_add()
-    test_rectangular_add()
+        assert_almost_equal(buff.rgba, exact_rgba)
+        assert_almost_equal(buff.z, exact_z)

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