[yt-svn] commit/yt: chummels: Merged in ngoldbaum/yt (pull request #1810)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Oct 15 23:04:00 PDT 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/00fd411044ba/
Changeset: 00fd411044ba
Branch: yt
User: chummels
Date: 2015-10-16 06:03:49+00:00
Summary: Merged in ngoldbaum/yt (pull request #1810)
Adding VR image comparison tests as well as a new answer test for this. Fixes #1120
Affected #: 2 files
diff -r 6912d9a2ce191dea530405370cb3ca47879d420a -r 00fd411044ba420d06186ebaba2e040e77836f93 yt/utilities/answer_testing/framework.py
--- a/yt/utilities/answer_testing/framework.py
+++ b/yt/utilities/answer_testing/framework.py
@@ -305,7 +305,9 @@
result_storage = None
prefix = ""
def __init__(self, ds_fn):
- if isinstance(ds_fn, Dataset):
+ if ds_fn is None:
+ self.ds = None
+ elif isinstance(ds_fn, Dataset):
self.ds = ds_fn
else:
self.ds = data_dir_load(ds_fn)
@@ -315,7 +317,8 @@
if self.reference_storage.reference_name is not None:
dd = self.reference_storage.get(self.storage_name)
if dd is None or self.description not in dd:
- raise YTNoOldAnswer("%s : %s" % (self.storage_name , self.description))
+ raise YTNoOldAnswer(
+ "%s : %s" % (self.storage_name, self.description))
ov = dd[self.description]
self.compare(nv, ov)
else:
@@ -660,6 +663,29 @@
assert compare_images(fns[0], fns[1], 10**(-decimals)) == None
for fn in fns: os.remove(fn)
+class VRImageComparisonTest(AnswerTestingTest):
+ _type_name = "VRImageComparison"
+ _attrs = ('desc',)
+
+ def __init__(self, scene, ds, desc, decimals):
+ super(VRImageComparisonTest, self).__init__(None)
+ self.obj_type = ('vr',)
+ self.ds = ds
+ self.scene = scene
+ self.desc = desc
+ self.decimals = decimals
+
+ def run(self):
+ tmpfd, tmpname = tempfile.mkstemp(suffix='.png')
+ os.close(tmpfd)
+ self.scene.render(tmpname, sigma_clip=1.0)
+ image = mpimg.imread(tmpname)
+ os.remove(tmpname)
+ return [zlib.compress(image.dumps())]
+
+ def compare(self, new_result, old_result):
+ compare_image_lists(new_result, old_result, self.decimals)
+
class PlotWindowAttributeTest(AnswerTestingTest):
_type_name = "PlotWindowAttribute"
_attrs = ('plot_type', 'plot_field', 'plot_axis', 'attr_name', 'attr_args',
@@ -774,6 +800,16 @@
else:
return ftrue
+def requires_answer_testing():
+ def ffalse(func):
+ return lambda: None
+ def ftrue(func):
+ return func
+ if AnswerTestingTest.result_storage is not None:
+ return ftrue
+ else:
+ return ffalse
+
def requires_ds(ds_fn, big_data = False, file_check = False):
def ffalse(func):
return lambda: None
diff -r 6912d9a2ce191dea530405370cb3ca47879d420a -r 00fd411044ba420d06186ebaba2e040e77836f93 yt/visualization/volume_rendering/tests/test_vr_orientation.py
--- /dev/null
+++ b/yt/visualization/volume_rendering/tests/test_vr_orientation.py
@@ -0,0 +1,151 @@
+"""
+Answer test to verify VR orientation and rotation is correct
+"""
+
+# -----------------------------------------------------------------------------
+# Copyright (c) 2015, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+# -----------------------------------------------------------------------------
+
+
+import numpy as np
+
+from yt import load_uniform_grid
+from yt.utilities.answer_testing.framework import \
+ requires_answer_testing, \
+ VRImageComparisonTest
+from yt.visualization.volume_rendering.api import \
+ Scene, \
+ Camera, \
+ VolumeSource, \
+ ColorTransferFunction
+
+
+def setup_ds():
+
+ N = 96
+
+ xmin = ymin = zmin = -1.0
+ xmax = ymax = zmax = 1.0
+
+ dcoord = (xmax - xmin)/N
+
+ arr = np.zeros((N, N, N), dtype=np.float64)
+ arr[:, :, :] = 1.e-4
+
+ bbox = np.array([[xmin, xmax], [ymin, ymax], [zmin, zmax]])
+
+ # coordinates -- in the notation data[i, j, k]
+ x = (np.arange(N) + 0.5)*(xmax - xmin)/N + xmin
+ y = (np.arange(N) + 0.5)*(ymax - ymin)/N + ymin
+ z = (np.arange(N) + 0.5)*(zmax - zmin)/N + zmin
+
+ x3d, y3d, z3d = np.meshgrid(x, y, z, indexing="ij")
+
+ # sphere at the origin
+ c = np.array([0.5*(xmin + xmax), 0.5*(ymin + ymax), 0.5*(zmin + zmax)])
+
+ r = np.sqrt((x3d - c[0])**2 + (y3d - c[1])**2 + (z3d - c[2])**2)
+ arr[r < 0.05] = 1.0
+
+ arr[abs(x3d - xmin) < 2*dcoord] = 0.3
+ arr[abs(y3d - ymin) < 2*dcoord] = 0.3
+ arr[abs(z3d - zmin) < 2*dcoord] = 0.3
+
+ # single cube on +x
+ xc = 0.75
+ dx = 0.05
+ idx = np.logical_and(np.logical_and(x3d > xc-dx, x3d < xc+dx),
+ np.logical_and(np.logical_and(y3d > -dx, y3d < dx),
+ np.logical_and(z3d > -dx, z3d < dx)))
+
+ arr[idx] = 1.0
+
+ # two cubes on +y
+ dy = 0.05
+ for yc in [0.65, 0.85]:
+
+ idx = np.logical_and(np.logical_and(y3d > yc-dy, y3d < yc+dy),
+ np.logical_and(np.logical_and(x3d > -dy, x3d < dy),
+ np.logical_and(z3d > -dy, z3d < dy)))
+
+ arr[idx] = 0.8
+
+ # three cubes on +z
+ dz = 0.05
+ for zc in [0.5, 0.7, 0.9]:
+
+ idx = np.logical_and(np.logical_and(z3d > zc-dz, z3d < zc+dz),
+ np.logical_and(np.logical_and(x3d > -dz, x3d < dz),
+ np.logical_and(y3d > -dz, y3d < dz)))
+
+ arr[idx] = 0.6
+
+ data = dict(Density=arr)
+ ds = load_uniform_grid(data, arr.shape, bbox=bbox)
+
+ return ds
+
+
+ at requires_answer_testing()
+def test_orientation():
+ ds = setup_ds()
+
+ sc = Scene()
+
+ vol = VolumeSource(ds, field=('gas', 'Density'))
+
+ tf = vol.transfer_function
+ tf = ColorTransferFunction((0.1, 1.0))
+ tf.sample_colormap(1.0, 0.01, colormap="coolwarm")
+ tf.sample_colormap(0.8, 0.01, colormap="coolwarm")
+ tf.sample_colormap(0.6, 0.01, colormap="coolwarm")
+ tf.sample_colormap(0.3, 0.01, colormap="coolwarm")
+
+ n_frames = 5
+ theta = np.pi / n_frames
+ decimals = 3
+
+ for lens_type in ['plane-parallel', 'perspective']:
+ frame = 0
+
+ cam = Camera(ds, lens_type='plane-parallel')
+ cam.resolution = (1000, 1000)
+ cam.position = ds.arr(np.array([-4., 0., 0.]), 'code_length')
+ cam.switch_orientation(normal_vector=[1., 0., 0.],
+ north_vector=[0., 0., 1.])
+ cam.set_width(ds.domain_width*2.)
+
+ sc.camera = cam
+ sc.add_source(vol)
+ yield VRImageComparisonTest(
+ sc, ds, '%s_%04d' % (lens_type, frame), decimals)
+
+ for i in range(n_frames):
+ frame += 1
+ center = ds.arr([0, 0, 0], 'code_length')
+ cam.yaw(theta, rot_center=center)
+ sc.camera = cam
+ yield VRImageComparisonTest(
+ sc, ds, 'yaw_%s_%04d' % (lens_type, frame), decimals)
+
+ for i in range(n_frames):
+ frame += 1
+ theta = np.pi / n_frames
+ center = ds.arr([0, 0, 0], 'code_length')
+ cam.pitch(theta, rot_center=center)
+ sc.camera = cam
+ yield VRImageComparisonTest(
+ sc, ds, 'pitch_%s_%04d' % (lens_type, frame), decimals)
+
+ for i in range(n_frames):
+ frame += 1
+ theta = np.pi / n_frames
+ center = ds.arr([0, 0, 0], 'code_length')
+ cam.roll(theta, rot_center=center)
+ sc.camera = cam
+ yield VRImageComparisonTest(
+ sc, ds, 'roll_%s_%04d' % (lens_type, frame), decimals)
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