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

Bitbucket commits-noreply at bitbucket.org
Mon Jul 30 08:35:22 PDT 2012


2 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/569f260b332e/
changeset:   569f260b332e
branch:      yt
user:        MatthewTurk
date:        2012-07-27 04:56:12
summary:     Adding a show() function to Camera, which will call snapshot and then show that
snapshot inside IPython notebook.
affected #:  3 files

diff -r c3448a0dbf138ebc6fb19f7be8c5910e8c38ccff -r 569f260b332ee60201c939a402d6d775fed8286a yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -309,7 +309,8 @@
     """
     maxval = max(maxval, 1)
     from yt.config import ytcfg
-    if ytcfg.getboolean("yt","suppressStreamLogging"):
+    if ytcfg.getboolean("yt", "suppressStreamLogging") or \
+       ytcfg.getboolean("yt", "ipython_notebook"):
         return DummyProgressBar()
     elif ytcfg.getboolean("yt", "__withinreason"):
         from yt.gui.reason.extdirect_repl import ExtProgressBar


diff -r c3448a0dbf138ebc6fb19f7be8c5910e8c38ccff -r 569f260b332ee60201c939a402d6d775fed8286a yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -135,7 +135,8 @@
         Array of shape (N,M,3) or (N,M,4), to be written.  If it is not already
         a uint8 array, it will be scaled and converted to uint8.
     filename : string
-        Filename to save to
+        Filename to save to.  If None, PNG contents will be returned as a
+        string.
     max_val : float, optional
         The upper limit to clip values to in the output, if converting to uint8.
         If `bitmap_array` is already uint8, this will be ignore.
@@ -153,7 +154,10 @@
     if transpose:
         for channel in range(bitmap_array.shape[2]):
             bitmap_array[:,:,channel] = bitmap_array[:,:,channel].T
-    au.write_png(bitmap_array.copy(), filename)
+    if filename is not None:
+        au.write_png(bitmap_array.copy(), filename)
+    else:
+        return au.write_png_to_string(bitmap_array.copy())
     return bitmap_array
 
 def write_image(image, filename, color_bounds = None, cmap_name = "algae", func = lambda x: x):


diff -r c3448a0dbf138ebc6fb19f7be8c5910e8c38ccff -r 569f260b332ee60201c939a402d6d775fed8286a yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -23,6 +23,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
+import __builtin__
 import numpy as na
 
 from yt.funcs import *
@@ -382,18 +383,48 @@
         if num_threads is None:
             num_threads=get_num_threads()
         image = self.new_image()
+        args = self.get_sampler_args(image)
+        sampler = self.get_sampler(args)
+        self.initialize_source()
+        image = self._render(double_check, num_threads, image, sampler)
+        self.save_image(fn, clip_ratio, image)
+        return image
 
-        args = self.get_sampler_args(image)
+    def show(self, clip_ratio = None):
+        r"""This will take a snapshot and display the resultant image in the
+        IPython notebook.
 
-        sampler = self.get_sampler(args)
+        If yt is being run from within an IPython session, and it is able to
+        determine this, this function will snapshot and send the resultant
+        image to the IPython notebook for display.
 
-        self.initialize_source()
+        If yt can't determine if it's inside an IPython session, it will raise
+        YTNotInsideNotebook.
 
-        image = self._render(double_check, num_threads, image, sampler)
+        Parameters
+        ----------
+        clip_ratio : float, optional
+            If supplied, the 'max_val' argument to write_bitmap will be handed
+            clip_ratio * image.std()
 
-        self.save_image(fn, clip_ratio, image)
+        Examples
+        --------
 
-        return image
+        >>> cam.show()
+
+        """
+        if "__IPYTHON__" in dir(__builtin__):
+            from IPython.core.displaypub import publish_display_data
+            image = self.snapshot()
+            if clip_ratio is not None: clip_ratio *= image.std()
+            data = write_bitmap(image, None, clip_ratio)
+            publish_display_data(
+                'yt.visualization.volume_rendering.camera.Camera',
+                {'image/png' : data}
+            )
+        else:
+            raise YTNotInsideNotebook
+
 
     def set_default_light_dir(self):
         self.light_dir = [1.,1.,1.]
@@ -781,17 +812,11 @@
         if num_threads is None:
             num_threads=get_num_threads()
         image = self.new_image()
-
         args = self.get_sampler_args(image)
-
         sampler = self.get_sampler(args)
-
         self.volume.initialize_source()
-
         image = self._render(double_check, num_threads, image, sampler)
-
         self.save_image(fn, clim, image)
-
         return image
 
     def save_image(self, fn, clim, image):



https://bitbucket.org/yt_analysis/yt/changeset/eb215fb4f3d1/
changeset:   eb215fb4f3d1
branch:      yt
user:        samskillman
date:        2012-07-30 17:35:20
summary:     Merged in MatthewTurk/yt (pull request #222)
affected #:  3 files

diff -r 31d1c069f5a6e880f68415c2bd738ee9eed86787 -r eb215fb4f3d102ea5fdf69ac6f0a059f14c18997 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -309,7 +309,8 @@
     """
     maxval = max(maxval, 1)
     from yt.config import ytcfg
-    if ytcfg.getboolean("yt","suppressStreamLogging"):
+    if ytcfg.getboolean("yt", "suppressStreamLogging") or \
+       ytcfg.getboolean("yt", "ipython_notebook"):
         return DummyProgressBar()
     elif ytcfg.getboolean("yt", "__withinreason"):
         from yt.gui.reason.extdirect_repl import ExtProgressBar


diff -r 31d1c069f5a6e880f68415c2bd738ee9eed86787 -r eb215fb4f3d102ea5fdf69ac6f0a059f14c18997 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -135,7 +135,8 @@
         Array of shape (N,M,3) or (N,M,4), to be written.  If it is not already
         a uint8 array, it will be scaled and converted to uint8.
     filename : string
-        Filename to save to
+        Filename to save to.  If None, PNG contents will be returned as a
+        string.
     max_val : float, optional
         The upper limit to clip values to in the output, if converting to uint8.
         If `bitmap_array` is already uint8, this will be ignore.
@@ -153,7 +154,10 @@
     if transpose:
         for channel in range(bitmap_array.shape[2]):
             bitmap_array[:,:,channel] = bitmap_array[:,:,channel].T
-    au.write_png(bitmap_array.copy(), filename)
+    if filename is not None:
+        au.write_png(bitmap_array.copy(), filename)
+    else:
+        return au.write_png_to_string(bitmap_array.copy())
     return bitmap_array
 
 def write_image(image, filename, color_bounds = None, cmap_name = "algae", func = lambda x: x):


diff -r 31d1c069f5a6e880f68415c2bd738ee9eed86787 -r eb215fb4f3d102ea5fdf69ac6f0a059f14c18997 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -23,6 +23,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
+import __builtin__
 import numpy as na
 
 from yt.funcs import *
@@ -381,18 +382,48 @@
         if num_threads is None:
             num_threads=get_num_threads()
         image = self.new_image()
+        args = self.get_sampler_args(image)
+        sampler = self.get_sampler(args)
+        self.initialize_source()
+        image = self._render(double_check, num_threads, image, sampler)
+        self.save_image(fn, clip_ratio, image)
+        return image
 
-        args = self.get_sampler_args(image)
+    def show(self, clip_ratio = None):
+        r"""This will take a snapshot and display the resultant image in the
+        IPython notebook.
 
-        sampler = self.get_sampler(args)
+        If yt is being run from within an IPython session, and it is able to
+        determine this, this function will snapshot and send the resultant
+        image to the IPython notebook for display.
 
-        self.initialize_source()
+        If yt can't determine if it's inside an IPython session, it will raise
+        YTNotInsideNotebook.
 
-        image = self._render(double_check, num_threads, image, sampler)
+        Parameters
+        ----------
+        clip_ratio : float, optional
+            If supplied, the 'max_val' argument to write_bitmap will be handed
+            clip_ratio * image.std()
 
-        self.save_image(fn, clip_ratio, image)
+        Examples
+        --------
 
-        return image
+        >>> cam.show()
+
+        """
+        if "__IPYTHON__" in dir(__builtin__):
+            from IPython.core.displaypub import publish_display_data
+            image = self.snapshot()
+            if clip_ratio is not None: clip_ratio *= image.std()
+            data = write_bitmap(image, None, clip_ratio)
+            publish_display_data(
+                'yt.visualization.volume_rendering.camera.Camera',
+                {'image/png' : data}
+            )
+        else:
+            raise YTNotInsideNotebook
+
 
     def set_default_light_dir(self):
         self.light_dir = [1.,1.,1.]
@@ -780,17 +811,11 @@
         if num_threads is None:
             num_threads=get_num_threads()
         image = self.new_image()
-
         args = self.get_sampler_args(image)
-
         sampler = self.get_sampler(args)
-
         self.volume.initialize_source()
-
         image = self._render(double_check, num_threads, image, sampler)
-
         self.save_image(fn, clim, image)
-
         return image
 
     def save_image(self, fn, clim, image):

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