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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Jul 26 07:21:20 PDT 2017


10 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/94fd40b730f1/
Changeset:   94fd40b730f1
User:        ngoldbaum
Date:        2017-07-24 16:50:58+00:00
Summary:     Move assert_fname to yt.testing
Affected #:  5 files

diff -r 292512de33aa61e0c24350fce522ab4c1649cd41 -r 94fd40b730f173913ea6748be9f4133587cf1aad yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -23,9 +23,9 @@
 from yt.testing import \
     fake_amr_ds, \
     fake_tetrahedral_ds, \
-    fake_hexahedral_ds
+    fake_hexahedral_ds, \
+    assert_fname
 import yt.units as u
-from .test_plotwindow import assert_fname
 from yt.utilities.exceptions import \
     YTPlotCallbackError, \
     YTDataTypeUnsupported

diff -r 292512de33aa61e0c24350fce522ab4c1649cd41 -r 94fd40b730f173913ea6748be9f4133587cf1aad yt/visualization/tests/test_particle_plot.py
--- a/yt/visualization/tests/test_particle_plot.py
+++ b/yt/visualization/tests/test_particle_plot.py
@@ -18,10 +18,12 @@
 import unittest
 from yt.data_objects.profiles import create_profile
 from yt.visualization.tests.test_plotwindow import \
-    assert_fname, WIDTH_SPECS, ATTR_ARGS
+    WIDTH_SPECS, ATTR_ARGS
 from yt.data_objects.particle_filters import add_particle_filter
 from yt.testing import \
-    fake_particle_ds, assert_array_almost_equal
+    fake_particle_ds, \
+    assert_array_almost_equal, \
+    assert_fname
 from yt.utilities.answer_testing.framework import \
     requires_ds, \
     data_dir_load, \

diff -r 292512de33aa61e0c24350fce522ab4c1649cd41 -r 94fd40b730f173913ea6748be9f4133587cf1aad yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -24,7 +24,7 @@
 
 from yt.testing import \
     fake_random_ds, assert_equal, assert_rel_equal, assert_array_equal, \
-    assert_array_almost_equal, assert_raises
+    assert_array_almost_equal, assert_raises, assert_fname
 from yt.utilities.answer_testing.framework import \
     requires_ds, data_dir_load, PlotWindowAttributeTest
 from yt.utilities.exceptions import \
@@ -43,33 +43,6 @@
     ytcfg["yt", "__withintesting"] = "True"
 
 
-def assert_fname(fname):
-    """Function that checks file type using libmagic"""
-    if fname is None:
-        return
-
-    with open(fname, 'rb') as fimg:
-        data = fimg.read()
-    image_type = ''
-
-    # see http://www.w3.org/TR/PNG/#5PNG-file-signature
-    if data.startswith(b'\211PNG\r\n\032\n'):
-        image_type = '.png'
-    # see http://www.mathguide.de/info/tools/media-types/image/jpeg
-    elif data.startswith(b'\377\330'):
-        image_type = '.jpeg'
-    elif data.startswith(b'%!PS-Adobe'):
-        data_str = data.decode("utf-8", "ignore")
-        if 'EPSF' in data_str[:data_str.index('\n')]:
-            image_type = '.eps'
-        else:
-            image_type = '.ps'
-    elif data.startswith(b'%PDF'):
-        image_type = '.pdf'
-
-    return image_type == os.path.splitext(fname)[1]
-
-
 TEST_FLNMS = [None, 'test', 'test.png', 'test.eps',
               'test.ps', 'test.pdf']
 M7 = "DD0010/moving7_0010"

diff -r 292512de33aa61e0c24350fce522ab4c1649cd41 -r 94fd40b730f173913ea6748be9f4133587cf1aad yt/visualization/tests/test_profile_plots.py
--- a/yt/visualization/tests/test_profile_plots.py
+++ b/yt/visualization/tests/test_profile_plots.py
@@ -21,11 +21,12 @@
 from yt.testing import \
     fake_random_ds, \
     assert_array_almost_equal, \
-    requires_file
+    requires_file, \
+    assert_fname
 from yt.visualization.profile_plotter import \
     ProfilePlot, PhasePlot
 from yt.visualization.tests.test_plotwindow import \
-    assert_fname, TEST_FLNMS
+    TEST_FLNMS
 from yt.utilities.answer_testing.framework import \
     PhasePlotAttributeTest, \
     requires_ds, \

diff -r 292512de33aa61e0c24350fce522ab4c1649cd41 -r 94fd40b730f173913ea6748be9f4133587cf1aad 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
@@ -18,14 +18,14 @@
 import tempfile
 import shutil
 from yt.testing import \
-    fake_random_ds
+    fake_random_ds, \
+    assert_fname
 import numpy as np
 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.tests.test_plotwindow import assert_fname
 from unittest import TestCase
 
 


https://bitbucket.org/yt_analysis/yt/commits/23ada1dae4f7/
Changeset:   23ada1dae4f7
User:        ngoldbaum
Date:        2017-07-24 16:51:29+00:00
Summary:     Make scene.save() support saving pdf, ps, and eps files. Closes #1503
Affected #:  2 files

diff -r 94fd40b730f173913ea6748be9f4133587cf1aad -r 23ada1dae4f796daa29615f33a8e01133956f3ae yt/visualization/volume_rendering/scene.py
--- a/yt/visualization/volume_rendering/scene.py
+++ b/yt/visualization/volume_rendering/scene.py
@@ -241,8 +241,10 @@
         Parameters
         ----------
         fname: string, optional
-            If specified, save the rendering as a bitmap to the file "fname".
+            If specified, save the rendering as to the file "fname".
             If unspecified, it creates a default based on the dataset filename.
+            The file format is inferred from the filename's suffix. Supported
+            fomats are png, pdf, eps, and ps.
             Default: None
         sigma_clip: float, optional
             Image values greater than this number times the standard deviation
@@ -302,7 +304,28 @@
         self.render()
 
         mylog.info("Saving render %s", fname)
-        self._last_render.write_png(fname, sigma_clip=sigma_clip)
+        # We can render pngs natively but for other formats we defer to
+        # matplotlib.
+        if suffix == '.png':
+            self._last_render.write_png(fname, sigma_clip=sigma_clip)
+        else:
+            from matplotlib import pyplot as plt
+            fig, ax = plt.subplots()
+            shape = self._last_render.shape
+            fig.set_size_inches(shape[0]/100., shape[1]/100.)
+            fig.subplots_adjust(left=0, bottom=0, right=1, top=1)
+            ax.set_axis_off()
+            out = self._last_render
+            nz = out[:, :, :3][out[:, :, :3].nonzero()]
+            max_val = nz.mean() + sigma_clip * nz.std()
+            alpha = 255 * out[:, :, 3].astype('uint8')
+            out = np.clip(out[:, :, :3] / max_val, 0.0, 1.0) * 255
+            out = np.concatenate(
+                [out.astype('uint8'), alpha[..., None]], axis=-1)
+            # not sure why we need rot90, but this makes the orentation
+            # match the png writer
+            ax.imshow(np.rot90(out), origin='lower')
+            plt.savefig(fname, dpi=100)
 
 
     def save_annotated(self, fname=None, label_fmt=None,

diff -r 94fd40b730f173913ea6748be9f4133587cf1aad -r 23ada1dae4f796daa29615f33a8e01133956f3ae 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
@@ -16,7 +16,9 @@
 import os
 import tempfile
 import shutil
-from yt.testing import fake_random_ds
+from yt.testing import \
+    fake_random_ds, \
+    assert_fname
 from yt.visualization.volume_rendering.api import volume_render, VolumeSource
 import numpy as np
 from unittest import TestCase
@@ -78,7 +80,10 @@
         ma_bound = ((ma-mi)*(0.90))+mi
         tf.map_to_colormap(mi_bound, ma_bound,  scale=0.01, colormap='Reds_r')
         sc.render()
-        sc.save('test_scene.png', sigma_clip=6.0)
+        for suffix in ['png', 'eps', 'ps', 'pdf']:
+            fname = 'test_scene.{}'.format(suffix)
+            sc.save(fname, sigma_clip=6.0)
+            assert_fname(fname)
 
         nrot = 2 
         for i in range(nrot):


https://bitbucket.org/yt_analysis/yt/commits/1bf79ba655df/
Changeset:   1bf79ba655df
User:        ngoldbaum
Date:        2017-07-24 16:56:53+00:00
Summary:     re-add assert_fname
Affected #:  1 file

diff -r 23ada1dae4f796daa29615f33a8e01133956f3ae -r 1bf79ba655df2d7f96eb1fa9beca0cf5eafc55c0 yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -1019,3 +1019,30 @@
     at = at.value
 
     return assert_allclose(act, des, rt, at, **kwargs)
+
+def assert_fname(fname):
+    """Function that checks file type using libmagic"""
+    if fname is None:
+        return
+
+    with open(fname, 'rb') as fimg:
+        data = fimg.read()
+    image_type = ''
+
+    # see http://www.w3.org/TR/PNG/#5PNG-file-signature
+    if data.startswith(b'\211PNG\r\n\032\n'):
+        image_type = '.png'
+    # see http://www.mathguide.de/info/tools/media-types/image/jpeg
+    elif data.startswith(b'\377\330'):
+        image_type = '.jpeg'
+    elif data.startswith(b'%!PS-Adobe'):
+        data_str = data.decode("utf-8", "ignore")
+        if 'EPSF' in data_str[:data_str.index('\n')]:
+            image_type = '.eps'
+        else:
+            image_type = '.ps'
+    elif data.startswith(b'%PDF'):
+        image_type = '.pdf'
+
+    return image_type == os.path.splitext(fname)[1]
+


https://bitbucket.org/yt_analysis/yt/commits/dd9e1f067aad/
Changeset:   dd9e1f067aad
User:        ngoldbaum
Date:        2017-07-24 19:40:32+00:00
Summary:     fix travis failures by dropping pyplot usage
Affected #:  1 file

diff -r 1bf79ba655df2d7f96eb1fa9beca0cf5eafc55c0 -r dd9e1f067aade9faa0c2ee8cfa086914172518d5 yt/visualization/volume_rendering/scene.py
--- a/yt/visualization/volume_rendering/scene.py
+++ b/yt/visualization/volume_rendering/scene.py
@@ -309,11 +309,21 @@
         if suffix == '.png':
             self._last_render.write_png(fname, sigma_clip=sigma_clip)
         else:
-            from matplotlib import pyplot as plt
-            fig, ax = plt.subplots()
+            from matplotlib.figure import Figure
+            from matplotlib.backends.backend_pdf import \
+                FigureCanvasPdf
+            from matplotlib.backends.backend_ps import \
+                FigureCanvasPS
             shape = self._last_render.shape
-            fig.set_size_inches(shape[0]/100., shape[1]/100.)
-            fig.subplots_adjust(left=0, bottom=0, right=1, top=1)
+            fig = Figure((shape[0]/100., shape[1]/100.))
+            if suffix == '.pdf':
+                canvas = FigureCanvasPdf(fig)
+            elif suffix in ('.eps', '.ps'):
+                canvas = FigureCanvasPS(fig)
+            else:
+                raise NotImplementedError(
+                    "Unknown file suffix '{}'".format(suffix))
+            ax = fig.add_axes([0, 0, 1, 1])
             ax.set_axis_off()
             out = self._last_render
             nz = out[:, :, :3][out[:, :, :3].nonzero()]
@@ -325,8 +335,7 @@
             # not sure why we need rot90, but this makes the orentation
             # match the png writer
             ax.imshow(np.rot90(out), origin='lower')
-            plt.savefig(fname, dpi=100)
-
+            canvas.print_figure(fname, dpi=100)
 
     def save_annotated(self, fname=None, label_fmt=None,
                        text_annotate=None, dpi=100, sigma_clip=None):


https://bitbucket.org/yt_analysis/yt/commits/f6656af29431/
Changeset:   f6656af29431
User:        ngoldbaum
Date:        2017-07-25 15:57:39+00:00
Summary:     get verbose output from appveyor build to understand what's going wrong
Affected #:  1 file

diff -r dd9e1f067aade9faa0c2ee8cfa086914172518d5 -r f6656af2943118cc28f30bfef206331426b94784 appveyor.yml
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -28,7 +28,7 @@
     - "python --version"
 
     # Install specified version of numpy and dependencies
-    - "conda install -q --yes -c conda-forge numpy scipy nose setuptools ipython Cython sympy fastcache h5py matplotlib flake8 mock"
+    - "conda install --yes -c conda-forge numpy scipy nose setuptools ipython Cython sympy fastcache h5py matplotlib flake8 mock"
     - "pip install -e ."
 
 # Not a .NET project


https://bitbucket.org/yt_analysis/yt/commits/ec0f97020204/
Changeset:   ec0f97020204
User:        ngoldbaum
Date:        2017-07-25 16:46:42+00:00
Summary:     enable login to appveyor build host
Affected #:  1 file

diff -r f6656af2943118cc28f30bfef206331426b94784 -r ec0f970202041e802cb8c0c8e6cf8294e29a2e65 appveyor.yml
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -36,3 +36,9 @@
 
 test_script:
   - "nosetests --nologcapture -sv yt"
+
+# Enable this to be able to login to the build worker. You can use the
+# `remmina` program in Ubuntu, use the login information that the line below
+# prints into the log.
+on_finish:
+- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))


https://bitbucket.org/yt_analysis/yt/commits/a7680b3864f1/
Changeset:   a7680b3864f1
User:        ngoldbaum
Date:        2017-07-25 16:50:50+00:00
Summary:     temporarily turn off py3.6 build
Affected #:  1 file

diff -r ec0f970202041e802cb8c0c8e6cf8294e29a2e65 -r a7680b3864f1ad2c93ed3f09f77d6e62e0b812c3 appveyor.yml
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -7,7 +7,7 @@
       PYTHON: "C:\\Miniconda3-x64"
 
   matrix:
-      - PYTHON_VERSION: "3.6"
+#      - PYTHON_VERSION: "3.6"
       - PYTHON_VERSION: "2.7"
 
 platform:


https://bitbucket.org/yt_analysis/yt/commits/f07d084783e3/
Changeset:   f07d084783e3
User:        ngoldbaum
Date:        2017-07-25 16:52:59+00:00
Summary:     do python2.7 build first
Affected #:  1 file

diff -r a7680b3864f1ad2c93ed3f09f77d6e62e0b812c3 -r f07d084783e3992c7d30c90d18833c1e4b41e1b5 appveyor.yml
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -7,8 +7,8 @@
       PYTHON: "C:\\Miniconda3-x64"
 
   matrix:
+      - PYTHON_VERSION: "2.7"
 #      - PYTHON_VERSION: "3.6"
-      - PYTHON_VERSION: "2.7"
 
 platform:
     -x64


https://bitbucket.org/yt_analysis/yt/commits/d4d15c64db06/
Changeset:   d4d15c64db06
User:        ngoldbaum
Date:        2017-07-25 17:14:32+00:00
Summary:     update conda first before trying to install packages
Affected #:  1 file

diff -r f07d084783e3992c7d30c90d18833c1e4b41e1b5 -r d4d15c64db06f944b583dffa1f0f735e2dab50d8 appveyor.yml
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -8,7 +8,7 @@
 
   matrix:
       - PYTHON_VERSION: "2.7"
-#      - PYTHON_VERSION: "3.6"
+      - PYTHON_VERSION: "3.6"
 
 platform:
     -x64
@@ -21,6 +21,7 @@
 
     # Install the build and runtime dependencies of the project.
     # Create a conda environment
+    - "conda update -q --yes conda"
     - "conda create -q --yes -n test python=%PYTHON_VERSION%"
     - "activate test"
 
@@ -40,5 +41,5 @@
 # Enable this to be able to login to the build worker. You can use the
 # `remmina` program in Ubuntu, use the login information that the line below
 # prints into the log.
-on_finish:
-- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
+#on_finish:
+#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))


https://bitbucket.org/yt_analysis/yt/commits/44d22df96ff0/
Changeset:   44d22df96ff0
User:        xarthisius
Date:        2017-07-26 14:20:47+00:00
Summary:     Merge pull request #1504 from ngoldbaum/save-pdf

Make scene.save() support saving pdf, ps, and eps files.
Affected #:  9 files

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 appveyor.yml
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -7,8 +7,8 @@
       PYTHON: "C:\\Miniconda3-x64"
 
   matrix:
+      - PYTHON_VERSION: "2.7"
       - PYTHON_VERSION: "3.6"
-      - PYTHON_VERSION: "2.7"
 
 platform:
     -x64
@@ -21,6 +21,7 @@
 
     # Install the build and runtime dependencies of the project.
     # Create a conda environment
+    - "conda update -q --yes conda"
     - "conda create -q --yes -n test python=%PYTHON_VERSION%"
     - "activate test"
 
@@ -28,7 +29,7 @@
     - "python --version"
 
     # Install specified version of numpy and dependencies
-    - "conda install -q --yes -c conda-forge numpy scipy nose setuptools ipython Cython sympy fastcache h5py matplotlib flake8 mock"
+    - "conda install --yes -c conda-forge numpy scipy nose setuptools ipython Cython sympy fastcache h5py matplotlib flake8 mock"
     - "pip install -e ."
 
 # Not a .NET project
@@ -36,3 +37,9 @@
 
 test_script:
   - "nosetests --nologcapture -sv yt"
+
+# Enable this to be able to login to the build worker. You can use the
+# `remmina` program in Ubuntu, use the login information that the line below
+# prints into the log.
+#on_finish:
+#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -1019,3 +1019,30 @@
     at = at.value
 
     return assert_allclose(act, des, rt, at, **kwargs)
+
+def assert_fname(fname):
+    """Function that checks file type using libmagic"""
+    if fname is None:
+        return
+
+    with open(fname, 'rb') as fimg:
+        data = fimg.read()
+    image_type = ''
+
+    # see http://www.w3.org/TR/PNG/#5PNG-file-signature
+    if data.startswith(b'\211PNG\r\n\032\n'):
+        image_type = '.png'
+    # see http://www.mathguide.de/info/tools/media-types/image/jpeg
+    elif data.startswith(b'\377\330'):
+        image_type = '.jpeg'
+    elif data.startswith(b'%!PS-Adobe'):
+        data_str = data.decode("utf-8", "ignore")
+        if 'EPSF' in data_str[:data_str.index('\n')]:
+            image_type = '.eps'
+        else:
+            image_type = '.ps'
+    elif data.startswith(b'%PDF'):
+        image_type = '.pdf'
+
+    return image_type == os.path.splitext(fname)[1]
+

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -23,9 +23,9 @@
 from yt.testing import \
     fake_amr_ds, \
     fake_tetrahedral_ds, \
-    fake_hexahedral_ds
+    fake_hexahedral_ds, \
+    assert_fname
 import yt.units as u
-from .test_plotwindow import assert_fname
 from yt.utilities.exceptions import \
     YTPlotCallbackError, \
     YTDataTypeUnsupported

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 yt/visualization/tests/test_particle_plot.py
--- a/yt/visualization/tests/test_particle_plot.py
+++ b/yt/visualization/tests/test_particle_plot.py
@@ -18,10 +18,12 @@
 import unittest
 from yt.data_objects.profiles import create_profile
 from yt.visualization.tests.test_plotwindow import \
-    assert_fname, WIDTH_SPECS, ATTR_ARGS
+    WIDTH_SPECS, ATTR_ARGS
 from yt.data_objects.particle_filters import add_particle_filter
 from yt.testing import \
-    fake_particle_ds, assert_array_almost_equal
+    fake_particle_ds, \
+    assert_array_almost_equal, \
+    assert_fname
 from yt.utilities.answer_testing.framework import \
     requires_ds, \
     data_dir_load, \

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -24,7 +24,7 @@
 
 from yt.testing import \
     fake_random_ds, assert_equal, assert_rel_equal, assert_array_equal, \
-    assert_array_almost_equal, assert_raises
+    assert_array_almost_equal, assert_raises, assert_fname
 from yt.utilities.answer_testing.framework import \
     requires_ds, data_dir_load, PlotWindowAttributeTest
 from yt.utilities.exceptions import \
@@ -43,33 +43,6 @@
     ytcfg["yt", "__withintesting"] = "True"
 
 
-def assert_fname(fname):
-    """Function that checks file type using libmagic"""
-    if fname is None:
-        return
-
-    with open(fname, 'rb') as fimg:
-        data = fimg.read()
-    image_type = ''
-
-    # see http://www.w3.org/TR/PNG/#5PNG-file-signature
-    if data.startswith(b'\211PNG\r\n\032\n'):
-        image_type = '.png'
-    # see http://www.mathguide.de/info/tools/media-types/image/jpeg
-    elif data.startswith(b'\377\330'):
-        image_type = '.jpeg'
-    elif data.startswith(b'%!PS-Adobe'):
-        data_str = data.decode("utf-8", "ignore")
-        if 'EPSF' in data_str[:data_str.index('\n')]:
-            image_type = '.eps'
-        else:
-            image_type = '.ps'
-    elif data.startswith(b'%PDF'):
-        image_type = '.pdf'
-
-    return image_type == os.path.splitext(fname)[1]
-
-
 TEST_FLNMS = [None, 'test', 'test.png', 'test.eps',
               'test.ps', 'test.pdf']
 M7 = "DD0010/moving7_0010"

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 yt/visualization/tests/test_profile_plots.py
--- a/yt/visualization/tests/test_profile_plots.py
+++ b/yt/visualization/tests/test_profile_plots.py
@@ -21,11 +21,12 @@
 from yt.testing import \
     fake_random_ds, \
     assert_array_almost_equal, \
-    requires_file
+    requires_file, \
+    assert_fname
 from yt.visualization.profile_plotter import \
     ProfilePlot, PhasePlot
 from yt.visualization.tests.test_plotwindow import \
-    assert_fname, TEST_FLNMS
+    TEST_FLNMS
 from yt.utilities.answer_testing.framework import \
     PhasePlotAttributeTest, \
     requires_ds, \

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 yt/visualization/volume_rendering/scene.py
--- a/yt/visualization/volume_rendering/scene.py
+++ b/yt/visualization/volume_rendering/scene.py
@@ -241,8 +241,10 @@
         Parameters
         ----------
         fname: string, optional
-            If specified, save the rendering as a bitmap to the file "fname".
+            If specified, save the rendering as to the file "fname".
             If unspecified, it creates a default based on the dataset filename.
+            The file format is inferred from the filename's suffix. Supported
+            fomats are png, pdf, eps, and ps.
             Default: None
         sigma_clip: float, optional
             Image values greater than this number times the standard deviation
@@ -302,8 +304,38 @@
         self.render()
 
         mylog.info("Saving render %s", fname)
-        self._last_render.write_png(fname, sigma_clip=sigma_clip)
-
+        # We can render pngs natively but for other formats we defer to
+        # matplotlib.
+        if suffix == '.png':
+            self._last_render.write_png(fname, sigma_clip=sigma_clip)
+        else:
+            from matplotlib.figure import Figure
+            from matplotlib.backends.backend_pdf import \
+                FigureCanvasPdf
+            from matplotlib.backends.backend_ps import \
+                FigureCanvasPS
+            shape = self._last_render.shape
+            fig = Figure((shape[0]/100., shape[1]/100.))
+            if suffix == '.pdf':
+                canvas = FigureCanvasPdf(fig)
+            elif suffix in ('.eps', '.ps'):
+                canvas = FigureCanvasPS(fig)
+            else:
+                raise NotImplementedError(
+                    "Unknown file suffix '{}'".format(suffix))
+            ax = fig.add_axes([0, 0, 1, 1])
+            ax.set_axis_off()
+            out = self._last_render
+            nz = out[:, :, :3][out[:, :, :3].nonzero()]
+            max_val = nz.mean() + sigma_clip * nz.std()
+            alpha = 255 * out[:, :, 3].astype('uint8')
+            out = np.clip(out[:, :, :3] / max_val, 0.0, 1.0) * 255
+            out = np.concatenate(
+                [out.astype('uint8'), alpha[..., None]], axis=-1)
+            # not sure why we need rot90, but this makes the orentation
+            # match the png writer
+            ax.imshow(np.rot90(out), origin='lower')
+            canvas.print_figure(fname, dpi=100)
 
     def save_annotated(self, fname=None, label_fmt=None,
                        text_annotate=None, dpi=100, sigma_clip=None):

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 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
@@ -16,7 +16,9 @@
 import os
 import tempfile
 import shutil
-from yt.testing import fake_random_ds
+from yt.testing import \
+    fake_random_ds, \
+    assert_fname
 from yt.visualization.volume_rendering.api import volume_render, VolumeSource
 import numpy as np
 from unittest import TestCase
@@ -78,7 +80,10 @@
         ma_bound = ((ma-mi)*(0.90))+mi
         tf.map_to_colormap(mi_bound, ma_bound,  scale=0.01, colormap='Reds_r')
         sc.render()
-        sc.save('test_scene.png', sigma_clip=6.0)
+        for suffix in ['png', 'eps', 'ps', 'pdf']:
+            fname = 'test_scene.{}'.format(suffix)
+            sc.save(fname, sigma_clip=6.0)
+            assert_fname(fname)
 
         nrot = 2 
         for i in range(nrot):

diff -r 85cb5b40cd70e9772c4f581e8133692d5f73ed9e -r 44d22df96ff0c461e1880a6da0ed5e23366fe666 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
@@ -18,14 +18,14 @@
 import tempfile
 import shutil
 from yt.testing import \
-    fake_random_ds
+    fake_random_ds, \
+    assert_fname
 import numpy as np
 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.tests.test_plotwindow import assert_fname
 from unittest import TestCase

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