[yt-svn] commit/yt: 5 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Oct 15 10:38:15 PDT 2015
5 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/dc2b603a990e/
Changeset: dc2b603a990e
Branch: yt
User: atmyers
Date: 2015-09-30 21:02:11+00:00
Summary: perform the VR tests in temporary directories if they do file IO
Affected #: 7 files
diff -r 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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], clip_ratio=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], clip_ratio=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], clip_ratio=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], clip_ratio=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], clip_ratio=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], clip_ratio=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], clip_ratio=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],
+ clip_ratio=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],
+ clip_ratio=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],
+ clip_ratio=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],
+ clip_ratio=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],
+ clip_ratio=6.0)
diff -r 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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', clip_ratio=6.0)
-
- nrot = 2
- for i in range(nrot):
- sc.camera.pitch(2*np.pi/nrot)
- sc.render('test_rot_%04i.png' % i, clip_ratio=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', clip_ratio=6.0)
+
+ nrot = 2
+ for i in range(nrot):
+ sc.camera.pitch(2*np.pi/nrot)
+ sc.render('test_rot_%04i.png' % i, clip_ratio=6.0)
diff -r 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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', clip_ratio=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', clip_ratio=4.0)
+ print(sc)
+ return im, sc
diff -r 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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 52b57ac913dd7e334914c7e8985f35ebb1618346 -r dc2b603a990e19c060684c2801c67fde6e13acf8 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,48 +10,121 @@
# 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.data_objects.api import ImageArray
+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)
-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
+# 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=True
- vr.transfer_function.map_to_colormap(0.0, 1.0, scale=10.0, 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"
- # 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)
- im = sc.render()
- im.write_png("composite.png")
- return im
+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
-if __name__ == "__main__":
- im = test_composite_vr()
+ def tearDown(self):
+ if use_tmpdir:
+ os.chdir(self.curdir)
+ shutil.rmtree(self.tmpdir)
+
+
+ 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
+
+ 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)
+
+ 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)
+
+ im = sc.render()
+ im.write_png("composite.png")
+ return im
+
+ def test_nonrectangular_add(self):
+ rgba1 = np.ones((64, 1, 4))
+ z1 = np.expand_dims(np.arange(64.), 1)
+
+ 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(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)
+
+ 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_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)
https://bitbucket.org/yt_analysis/yt/commits/3494a37cefbc/
Changeset: 3494a37cefbc
Branch: yt
User: atmyers
Date: 2015-10-14 21:04:28+00:00
Summary: merging
Affected #: 2 files
diff -r dc2b603a990e19c060684c2801c67fde6e13acf8 -r 3494a37cefbc1ed14f5cd17778f066fcb08e64ea yt/visualization/volume_rendering/zbuffer_array.py
--- a/yt/visualization/volume_rendering/zbuffer_array.py
+++ b/yt/visualization/volume_rendering/zbuffer_array.py
@@ -28,13 +28,16 @@
def __add__(self, other):
assert(self.shape == other.shape)
- f_or_b = self.z < other.z
+ f = self.z < other.z
if self.z.shape[1] == 1:
# Non-rectangular
- rgba = (self.rgba * f_or_b[:,None,:])
- rgba += (other.rgba * (1.0 - f_or_b)[:,None,:])
+ rgba = (self.rgba * f[:,None,:])
+ rgba += (other.rgba * (1.0 - f)[:,None,:])
else:
- rgba = (self.rgba.T * f_or_b).T + (other.rgba.T * (1 - f_or_b)).T
+ b = self.z > other.z
+ rgba = np.empty(self.rgba.shape)
+ rgba[f] = self.rgba[f]
+ rgba[b] = other.rgba[b]
z = np.min([self.z, other.z], axis=0)
return ZBuffer(rgba, z)
https://bitbucket.org/yt_analysis/yt/commits/b775a31efc1e/
Changeset: b775a31efc1e
Branch: yt
User: atmyers
Date: 2015-10-14 21:05:09+00:00
Summary: merging
Affected #: 2 files
diff -r 3494a37cefbc1ed14f5cd17778f066fcb08e64ea -r b775a31efc1e9725fadc3c2f6552b75044438df5 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -70,7 +70,7 @@
self.normal_vector = None
self.light = None
self._resolution = (512, 512)
- self._width = 1.0
+ 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)
diff -r 3494a37cefbc1ed14f5cd17778f066fcb08e64ea -r b775a31efc1e9725fadc3c2f6552b75044438df5 yt/visualization/volume_rendering/render_source.py
--- a/yt/visualization/volume_rendering/render_source.py
+++ b/yt/visualization/volume_rendering/render_source.py
@@ -513,7 +513,7 @@
class GridSource(LineSource):
- def __init__(self, data_source, alpha=0.3, cmap='alage',
+ def __init__(self, data_source, alpha=0.3, cmap='algae',
min_level=None, max_level=None):
r"""A render source for drawing grids in a scene.
https://bitbucket.org/yt_analysis/yt/commits/cd35619d3944/
Changeset: cd35619d3944
Branch: yt
User: atmyers
Date: 2015-10-14 21:12:34+00:00
Summary: merging
Affected #: 16 files
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 .hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -31,6 +31,7 @@
yt/utilities/lib/CICDeposit.c
yt/utilities/lib/ContourFinding.c
yt/utilities/lib/DepthFirstOctree.c
+yt/utilities/lib/element_mappings.c
yt/utilities/lib/FixedInterpolator.c
yt/utilities/lib/fortran_reader.c
yt/utilities/lib/freetype_writer.c
@@ -38,6 +39,7 @@
yt/utilities/lib/image_utilities.c
yt/utilities/lib/Interpolators.c
yt/utilities/lib/kdtree.c
+yt/utilities/lib/line_integral_convolution.c
yt/utilities/lib/mesh_utilities.c
yt/utilities/lib/misc_utilities.c
yt/utilities/lib/Octree.c
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/cookbook/amrkdtree_downsampling.py
--- a/doc/source/cookbook/amrkdtree_downsampling.py
+++ b/doc/source/cookbook/amrkdtree_downsampling.py
@@ -48,12 +48,12 @@
tf.clear()
tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5],
alpha=np.ones(4, dtype='float64'), colormap='RdBu_r')
-sc.render("v2.png", clip_ratio=6.0)
+sc.render("v2.png", sigma_clip=6.0)
# This looks better. Now let's try turning on opacity.
tf.grey_opacity = True
-sc.render("v3.png", clip_ratio=6.0)
+sc.render("v3.png", sigma_clip=6.0)
#
## That seemed to pick out som interesting structures. Now let's bump up the
## opacity.
@@ -61,11 +61,11 @@
tf.clear()
tf.add_layers(4, 0.01, col_bounds=[-27.5, -25.5],
alpha=10.0 * np.ones(4, dtype='float64'), colormap='RdBu_r')
-sc.render("v4.png", clip_ratio=6.0)
+sc.render("v4.png", sigma_clip=6.0)
#
## This looks pretty good, now lets go back to the full resolution AMRKDTree
#
render_source.set_volume(kd)
-sc.render("v5.png", clip_ratio=6.0)
+sc.render("v5.png", sigma_clip=6.0)
# This looks great!
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/cookbook/camera_movement.py
--- a/doc/source/cookbook/camera_movement.py
+++ b/doc/source/cookbook/camera_movement.py
@@ -14,15 +14,15 @@
frame = 0
# Move to the maximum density location over 5 frames
for _ in cam.iter_move(max_c, 5):
- sc.render('camera_movement_%04i.png' % frame, clip_ratio=8.0)
+ sc.render('camera_movement_%04i.png' % frame, sigma_clip=8.0)
frame += 1
# Zoom in by a factor of 10 over 5 frames
for _ in cam.iter_zoom(10.0, 5):
- sc.render('camera_movement_%04i.png' % frame, clip_ratio=8.0)
+ sc.render('camera_movement_%04i.png' % frame, sigma_clip=8.0)
frame += 1
# Do a rotation over 5 frames
for _ in cam.iter_rotate(np.pi, 5):
- sc.render('camera_movement_%04i.png' % frame, clip_ratio=8.0)
+ sc.render('camera_movement_%04i.png' % frame, sigma_clip=8.0)
frame += 1
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/cookbook/image_background_colors.py
--- a/doc/source/cookbook/image_background_colors.py
+++ b/doc/source/cookbook/image_background_colors.py
@@ -9,7 +9,7 @@
ds = yt.load("Enzo_64/DD0043/data0043")
im, sc = yt.volume_render(ds, 'density')
-im.write_png("original.png", clip_ratio=8.0)
+im.write_png("original.png", sigma_clip=8.0)
# Our image array can now be transformed to include different background
# colors. By default, the background color is black. The following
@@ -22,10 +22,10 @@
# None (0.,0.,0.,0.) <-- Transparent!
# any rgba list/array: [r,g,b,a], bounded by 0..1
-# We include the clip_ratio=8 keyword here to bring out more contrast between
+# We include the sigma_clip=8 keyword here to bring out more contrast between
# the background and foreground, but it is entirely optional.
-im.write_png('black_bg.png', background='black', clip_ratio=8.0)
-im.write_png('white_bg.png', background='white', clip_ratio=8.0)
-im.write_png('green_bg.png', background=[0.,1.,0.,1.], clip_ratio=8.0)
-im.write_png('transparent_bg.png', background=None, clip_ratio=8.0)
+im.write_png('black_bg.png', background='black', sigma_clip=8.0)
+im.write_png('white_bg.png', background='white', sigma_clip=8.0)
+im.write_png('green_bg.png', background=[0.,1.,0.,1.], sigma_clip=8.0)
+im.write_png('transparent_bg.png', background=None, sigma_clip=8.0)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/cookbook/opaque_rendering.py
--- a/doc/source/cookbook/opaque_rendering.py
+++ b/doc/source/cookbook/opaque_rendering.py
@@ -5,14 +5,14 @@
# We start by building a default volume rendering scene
-im, sc = yt.volume_render(ds, field=("gas","density"), fname="v0.png", clip_ratio=6.0)
+im, sc = yt.volume_render(ds, field=("gas","density"), fname="v0.png", sigma_clip=6.0)
sc.camera.set_width(ds.arr(0.1,'code_length'))
tf = sc.get_source(0).transfer_function
tf.clear()
tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
alpha=np.logspace(-3,0,4), colormap = 'RdBu_r')
-im = sc.render("v1.png", clip_ratio=6.0)
+im = sc.render("v1.png", sigma_clip=6.0)
# In this case, the default alphas used (np.logspace(-3,0,Nbins)) does not
# accentuate the outer regions of the galaxy. Let's start by bringing up the
@@ -22,27 +22,27 @@
tf.clear()
tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
alpha=np.logspace(0,0,4), colormap = 'RdBu_r')
-im = sc.render("v2.png", clip_ratio=6.0)
+im = sc.render("v2.png", sigma_clip=6.0)
# Now let's set the grey_opacity to True. This should make the inner portions
# start to be obcured
tf.grey_opacity = True
-im = sc.render("v3.png", clip_ratio=6.0)
+im = sc.render("v3.png", sigma_clip=6.0)
# That looks pretty good, but let's start bumping up the opacity.
tf.clear()
tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
alpha=10.0*np.ones(4,dtype='float64'), colormap = 'RdBu_r')
-im = sc.render("v4.png", clip_ratio=6.0)
+im = sc.render("v4.png", sigma_clip=6.0)
# Let's bump up again to see if we can obscure the inner contour.
tf.clear()
tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
alpha=30.0*np.ones(4,dtype='float64'), colormap = 'RdBu_r')
-im = sc.render("v5.png", clip_ratio=6.0)
+im = sc.render("v5.png", sigma_clip=6.0)
# Now we are losing sight of everything. Let's see if we can obscure the next
# layer
@@ -50,13 +50,13 @@
tf.clear()
tf.add_layers(4, 0.01, col_bounds = [-27.5,-25.5],
alpha=100.0*np.ones(4,dtype='float64'), colormap = 'RdBu_r')
-im = sc.render("v6.png", clip_ratio=6.0)
+im = sc.render("v6.png", sigma_clip=6.0)
# That is very opaque! Now lets go back and see what it would look like with
# grey_opacity = False
tf.grey_opacity=False
-im = sc.render("v7.png", clip_ratio=6.0)
+im = sc.render("v7.png", sigma_clip=6.0)
# That looks pretty different, but the main thing is that you can see that the
# inner contours are somewhat visible again.
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/cookbook/simple_volume_rendering.py
--- a/doc/source/cookbook/simple_volume_rendering.py
+++ b/doc/source/cookbook/simple_volume_rendering.py
@@ -6,14 +6,14 @@
# Create a volume rendering, which will determine data bounds, use the first
# acceptable field in the field_list, and set up a default transfer function.
-#im, sc = yt.volume_render(ds, fname="%s_volume_rendered.png" % ds, clip_ratio=8.0)
+#im, sc = yt.volume_render(ds, fname="%s_volume_rendered.png" % ds, sigma_clip=8.0)
# You can easily specify a different field
-im, sc = yt.volume_render(ds, field=('gas','density'), fname="%s_density_volume_rendered.png" % ds, clip_ratio=8.0)
+im, sc = yt.volume_render(ds, field=('gas','density'), fname="%s_density_volume_rendered.png" % ds, sigma_clip=8.0)
# Now increase the resolution
sc.camera.resolution = (512, 512)
-im = sc.render(fname='big.png', clip_ratio=8.0)
+im = sc.render(fname='big.png', sigma_clip=8.0)
# Now modify the transfer function
# First get the render source, in this case the entire domain, with field ('gas','density')
@@ -25,4 +25,4 @@
np.log10(ds.quan(5.0e-31, 'g/cm**3')),
np.log10(ds.quan(1.0e-29, 'g/cm**3')),
scale=30.0, colormap='RdBu_r')
-im = sc.render(fname='new_tf.png', clip_ratio=None)
+im = sc.render(fname='new_tf.png', sigma_clip=None)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/cookbook/various_lens.py
--- a/doc/source/cookbook/various_lens.py
+++ b/doc/source/cookbook/various_lens.py
@@ -34,7 +34,7 @@
cam.set_width(ds.domain_width * 0.5)
sc.camera = cam
sc.add_source(vol)
-sc.render('lens_plane-parallel.png', clip_ratio=6.0)
+sc.render('lens_plane-parallel.png', sigma_clip=6.0)
# Perspective lens
cam = Camera(ds, lens_type='perspective')
@@ -50,7 +50,7 @@
cam.set_width(ds.domain_width * 0.5)
sc.camera = cam
sc.add_source(vol)
-sc.render('lens_perspective.png', clip_ratio=6.0)
+sc.render('lens_perspective.png', sigma_clip=6.0)
# Stereo-perspective lens
cam = Camera(ds, lens_type='stereo-perspective')
@@ -65,7 +65,7 @@
cam.lens.disparity = ds.domain_width[0] * 1.e-3
sc.camera = cam
sc.add_source(vol)
-sc.render('lens_stereo-perspective.png', clip_ratio=6.0)
+sc.render('lens_stereo-perspective.png', sigma_clip=6.0)
# Fisheye lens
dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 10)
@@ -79,7 +79,7 @@
cam.lens.fov = 360.0
sc.camera = cam
sc.add_source(vol)
-sc.render('lens_fisheye.png', clip_ratio=6.0)
+sc.render('lens_fisheye.png', sigma_clip=6.0)
# Spherical lens
cam = Camera(ds, lens_type='spherical')
@@ -96,7 +96,7 @@
cam.set_width(ds.domain_width * 0.5)
sc.camera = cam
sc.add_source(vol)
-sc.render('lens_spherical.png', clip_ratio=6.0)
+sc.render('lens_spherical.png', sigma_clip=6.0)
# Stereo-spherical lens
cam = Camera(ds, lens_type='stereo-spherical')
@@ -111,4 +111,4 @@
cam.lens.disparity = ds.domain_width[0] * 1.e-3
sc.camera = cam
sc.add_source(vol)
-sc.render('lens_stereo-spherical.png', clip_ratio=6.0)
\ No newline at end of file
+sc.render('lens_stereo-spherical.png', sigma_clip=6.0)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 doc/source/quickstart/6)_Volume_Rendering.ipynb
--- a/doc/source/quickstart/6)_Volume_Rendering.ipynb
+++ b/doc/source/quickstart/6)_Volume_Rendering.ipynb
@@ -56,14 +56,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "If we want to apply a clipping, we can specify the `clip_ratio`. This will clip the upper bounds to this value times the standard deviation of the values in the image array."
+ "If we want to apply a clipping, we can specify the `sigma_clip`. This will clip the upper bounds to this value times the standard deviation of the values in the image array."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
- "cam.show(clip_ratio=4)"
+ "cam.show(sigma_clip=4)"
],
"language": "python",
"metadata": {},
@@ -83,7 +83,7 @@
"tf = yt.ColorTransferFunction((-28, -25))\n",
"tf.add_layers(4, w=0.03)\n",
"cam = ds.camera([0.5, 0.5, 0.5], [1.0, 1.0, 1.0], (20.0, 'kpc'), 512, tf, no_ghost=False)\n",
- "cam.show(clip_ratio=4.0)"
+ "cam.show(sigma_clip=4.0)"
],
"language": "python",
"metadata": {},
@@ -93,4 +93,4 @@
"metadata": {}
}
]
-}
\ No newline at end of file
+}
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 yt/data_objects/image_array.py
--- a/yt/data_objects/image_array.py
+++ b/yt/data_objects/image_array.py
@@ -11,10 +11,12 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
+import warnings
import numpy as np
from yt.visualization.image_writer import write_bitmap, write_image
from yt.units.yt_array import YTArray
+
class ImageArray(YTArray):
r"""A custom Numpy ndarray used for images.
@@ -237,15 +239,15 @@
np.clip(out, 0.0, 1.0, out)
return out
- def write_png(self, filename, clip_ratio=None, background='black',
- rescale=True):
+ def write_png(self, filename, sigma_clip=None, background='black',
+ rescale=True, clip_ratio=None):
r"""Writes ImageArray to png file.
Parameters
----------
filename: string
Note filename not be modified.
- clip_ratio: float, optional
+ sigma_clip: float, optional
Image will be clipped before saving to the standard deviation
of the image multiplied by this value. Useful for enhancing
images. Default: None
@@ -293,9 +295,13 @@
filename += '.png'
if clip_ratio is not None:
+ warnings.warn("'clip_ratio' keyword is deprecated. Use 'sigma_clip' instead")
+ sigma_clip = clip_ratio
+
+ if sigma_clip is not None:
nz = out[:, :, :3][out[:, :, :3].nonzero()]
return write_bitmap(out.swapaxes(0, 1), filename,
- nz.mean() + clip_ratio*nz.std())
+ nz.mean() + sigma_clip * nz.std())
else:
return write_bitmap(out.swapaxes(0, 1), filename)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 yt/visualization/volume_rendering/scene.py
--- a/yt/visualization/volume_rendering/scene.py
+++ b/yt/visualization/volume_rendering/scene.py
@@ -90,7 +90,7 @@
return self
- def render(self, fname=None, clip_ratio=None, camera=None):
+ def render(self, fname=None, sigma_clip=None, camera=None):
r"""Render all sources in the Scene.
Use the current state of the Scene object to render all sources
@@ -101,9 +101,10 @@
fname: string, optional
If specified, save the rendering as a bitmap to the file "fname".
Default: None
- clip_ratio: float, optional
- If supplied, the 'max_val' argument to write_bitmap will be handed
- clip_ratio * image.std()
+ sigma_clip: float, optional
+ Image will be clipped before saving to the standard deviation
+ of the image multiplied by this value. Useful for enhancing
+ images. Default: None
camera: :class:`Camera`, optional
If specified, use a different :class:`Camera` to render the scene.
@@ -125,7 +126,7 @@
self._validate()
bmp = self.composite(camera=camera)
if fname is not None:
- bmp.write_png(fname, clip_ratio=clip_ratio)
+ bmp.write_png(fname, sigma_clip=sigma_clip)
return bmp
def _validate(self):
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 yt/visualization/volume_rendering/tests/rotation_volume_rendering.py
--- a/yt/visualization/volume_rendering/tests/rotation_volume_rendering.py
+++ b/yt/visualization/volume_rendering/tests/rotation_volume_rendering.py
@@ -21,4 +21,4 @@
frames = 10
for i in range(frames):
sc.camera.yaw(angle/frames)
- sc.render('test_rot_%04i.png' % i, clip_ratio=6.0)
+ sc.render('test_rot_%04i.png' % i, sigma_clip=6.0)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 yt/visualization/volume_rendering/tests/simple_volume_rendering.py
--- a/yt/visualization/volume_rendering/tests/simple_volume_rendering.py
+++ b/yt/visualization/volume_rendering/tests/simple_volume_rendering.py
@@ -14,4 +14,4 @@
fake_random_ds
ds = fake_random_ds(32)
-im, sc = yt.volume_render(ds, fname='test.png', clip_ratio=4.0)
+im, sc = yt.volume_render(ds, fname='test.png', sigma_clip=4.0)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 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
@@ -55,7 +55,7 @@
tf.grey_opacity = True
sc.camera = cam
sc.add_source(vol)
- sc.render('test_perspective_%s.png' % self.field[1], clip_ratio=6.0)
+ sc.render('test_perspective_%s.png' % self.field[1], sigma_clip=6.0)
def test_stereoperspective_lens(self):
sc = Scene()
@@ -68,7 +68,7 @@
sc.camera = cam
sc.add_source(vol)
sc.render('test_stereoperspective_%s.png' % self.field[1],
- clip_ratio=6.0)
+ sigma_clip=6.0)
def test_fisheye_lens(self):
dd = self.ds.sphere(self.ds.domain_center,
@@ -86,7 +86,7 @@
sc.camera = cam
sc.add_source(vol)
sc.render('test_fisheye_%s.png' % self.field[1],
- clip_ratio=6.0)
+ sigma_clip=6.0)
def test_plane_lens(self):
dd = self.ds.sphere(self.ds.domain_center,
@@ -102,7 +102,7 @@
sc.camera = cam
sc.add_source(vol)
sc.render('test_plane_%s.png' % self.field[1],
- clip_ratio=6.0)
+ sigma_clip=6.0)
def test_spherical_lens(self):
sc = Scene()
@@ -115,7 +115,7 @@
sc.camera = cam
sc.add_source(vol)
sc.render('test_spherical_%s.png' % self.field[1],
- clip_ratio=6.0)
+ sigma_clip=6.0)
def test_stereospherical_lens(self):
w = (self.ds.domain_width).in_units('code_length')
@@ -130,4 +130,4 @@
sc.camera = cam
sc.add_source(vol)
sc.render('test_stereospherical_%s.png' % self.field[1],
- clip_ratio=6.0)
+ sigma_clip=6.0)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 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
@@ -76,9 +76,9 @@
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', clip_ratio=6.0)
+ 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, clip_ratio=6.0)
+ sc.render('test_rot_%04i.png' % i, sigma_clip=6.0)
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 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
@@ -45,6 +45,6 @@
def test_simple_vr(self):
ds = fake_random_ds(32)
- im, sc = yt.volume_render(ds, fname='test.png', clip_ratio=4.0)
+ im, sc = yt.volume_render(ds, fname='test.png', sigma_clip=4.0)
print(sc)
return im, sc
diff -r b775a31efc1e9725fadc3c2f6552b75044438df5 -r cd35619d3944db6d496f07b3abb63962b9ae5cf7 yt/visualization/volume_rendering/volume_rendering.py
--- a/yt/visualization/volume_rendering/volume_rendering.py
+++ b/yt/visualization/volume_rendering/volume_rendering.py
@@ -19,7 +19,7 @@
from yt.funcs import mylog
-def volume_render(data_source, field=None, fname=None, clip_ratio=None):
+def volume_render(data_source, field=None, fname=None, sigma_clip=4.0):
r""" Create a simple volume rendering of a data source.
A helper function that creates a default camera view, transfer
@@ -41,10 +41,10 @@
fname: string, optional
If specified, the resulting rendering will be saved to this filename
in png format.
- clip_ratio: float, optional
- If specified, the resulting image will be clipped before saving,
- using a threshold based on clip_ratio multiplied by the standard
- deviation of the pixel values. Recommended values are between 2 and 6.
+ sigma_clip: float
+ The resulting image will be clipped before saving, using a threshold
+ based on `sigma_clip` multiplied by the standard deviation of the pixel
+ values. Recommended values are between 2 and 6. Default: 4.0
Returns
-------
@@ -58,7 +58,7 @@
Example:
>>> import yt
>>> ds = yt.load("Enzo_64/DD0046/DD0046")
- >>> im, sc = yt.volume_render(ds, fname='test.png', clip_ratio=4.0)
+ >>> im, sc = yt.volume_render(ds, fname='test.png')
"""
data_source = data_source_or_all(data_source)
sc = Scene()
@@ -82,5 +82,5 @@
vol = VolumeSource(data_source, field=field)
sc.add_source(vol)
sc.camera = Camera(data_source)
- im = sc.render(fname=fname, clip_ratio=clip_ratio)
+ im = sc.render(fname=fname, sigma_clip=sigma_clip)
return im, sc
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