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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Sep 8 19:18:49 PDT 2014


6 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/f921bb49288f/
Changeset:   f921bb49288f
Branch:      yt
User:        samskillman
Date:        2014-09-06 20:40:51
Summary:     Adding hooks to colorbrewer via brewer2mpl into the plot window
Affected #:  2 files

diff -r 0abeb6afd3bc2b563c023b4a72be222447d843af -r f921bb49288f8239c63596780a80d7f3338c2c6f yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -19,6 +19,12 @@
 from yt.funcs import \
     get_image_suffix, mylog, iterable
 import numpy as np
+try:
+    import brewer2mpl
+    has_brewer = True
+except:
+    has_brewer = False
+
 
 class CallbackWrapper(object):
     def __init__(self, viewer, window_plot, frb, field):
@@ -110,6 +116,10 @@
         elif (cbnorm == 'linear'):
             norm = matplotlib.colors.Normalize()
         extent = [float(e) for e in extent]
+        if isinstance(cmap, tuple) and has_brewer:
+            bmap = brewer2mpl.get_map(*cmap)
+            cmap = bmap.get_mpl_colormap(N=cmap[2])
+
         self.image = self.axes.imshow(data.to_ndarray(), origin='lower',
                                       extent=extent, norm=norm, vmin=self.zmin,
                                       aspect=aspect, vmax=self.zmax, cmap=cmap)

diff -r 0abeb6afd3bc2b563c023b4a72be222447d843af -r f921bb49288f8239c63596780a80d7f3338c2c6f yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -35,6 +35,7 @@
 from yt.utilities.exceptions import \
     YTNotInsideNotebook
 
+
 def invalidate_data(f):
     @wraps(f)
     def newfunc(*args, **kwargs):
@@ -384,37 +385,6 @@
         return self.set_font({'size': size})
 
     @invalidate_plot
-    def set_cmap(self, field, cmap):
-        """set the colormap for one of the fields
-
-        Parameters
-        ----------
-        field : string
-            the field to set a transform
-            if field == 'all', applies to all plots.
-        cmap : string
-            name of the colormap
-
-        """
-        if field == 'all':
-            fields = self.plots.keys()
-        else:
-            fields = [field]
-
-        for field in self.data_source._determine_fields(fields):
-            self._colorbar_valid = False
-            self._colormaps[field] = cmap
-            if isinstance(cmap, types.StringTypes):
-                if str(cmap) in yt_colormaps:
-                    cmap = yt_colormaps[str(cmap)]
-                elif hasattr(matplotlib.cm, cmap):
-                    cmap = getattr(matplotlib.cm, cmap)
-            if not is_colormap(cmap) and cmap is not None:
-                raise RuntimeError("Colormap '%s' does not exist!" % str(cmap))
-            self.plots[field].image.set_cmap(cmap)
-        return self
-
-    @invalidate_plot
     @invalidate_figure
     def set_figure_size(self, size):
         """Sets a new figure size for the plot


https://bitbucket.org/yt_analysis/yt/commits/799a2466bf86/
Changeset:   799a2466bf86
Branch:      yt
User:        samskillman
Date:        2014-09-06 21:20:46
Summary:     Adding colorbrewer maps via brewer2mpl to image_writer tools. Also move cast to uint8 earlier to save a bit of memory.
Affected #:  1 file

diff -r f921bb49288f8239c63596780a80d7f3338c2c6f -r 799a2466bf8638eeca17fbb84b4fed2da7656f12 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -23,6 +23,12 @@
 import yt.utilities.lib.image_utilities as au
 import yt.utilities.png_writer as pw
 from yt.extern.six.moves import builtins
+try:
+    import brewer2mpl
+    has_brewer = True
+except:
+    has_brewer = False
+
 
 def scale_image(image, mi=None, ma=None):
     r"""Scale an image ([NxNxM] where M = 1-4) to be uint8 and values scaled 
@@ -248,7 +254,11 @@
         lut = cmd.color_map_luts[cmap_name]
     except KeyError:
         try:
-            cmap = mcm.get_cmap(cmap_name)
+            if isinstance(cmap_name, tuple) and has_brewer:
+                bmap = brewer2mpl.get_map(*cmap_name)
+                cmap = bmap.get_mpl_colormap(N=cmap_name[2])
+            else:
+                cmap = mcm.get_cmap(cmap_name)
             dummy = cmap(0.0)
             lut = cmap._lut.T
         except ValueError:
@@ -256,10 +266,19 @@
                 " colormap file or matplotlib colormaps"
             raise KeyError(cmap_name)
 
-    x = np.mgrid[0.0:1.0:lut[0].shape[0]*1j]
-    shape = buff.shape
-    mapped = np.dstack(
-            [(np.interp(buff, x, v)*255) for v in lut ]).astype("uint8")
+    if isinstance(cmap_name, tuple) and has_brewer:
+        # If we are using the colorbrewer maps, don't interpolate
+        shape = buff.shape
+        # We add float_eps so that digitize doesn't go out of bounds
+        x = np.mgrid[0.0:1.0+np.finfo(np.float32).eps:lut[0].shape[0]*1j]
+        inds = np.digitize(buff.ravel(), x)
+        inds.shape = (shape[0], shape[1])
+        mapped = np.dstack([(v[inds]*255).astype('uint8') for v in lut])
+        del inds
+    else:
+        x = np.mgrid[0.0:1.0:lut[0].shape[0]*1j]
+        mapped = np.dstack(
+                [(np.interp(buff, x, v)*255).astype('uint8') for v in lut ])
     return mapped.copy("C")
 
 def strip_colormap_data(fn = "color_map_data.py",


https://bitbucket.org/yt_analysis/yt/commits/7a65edbdf2f4/
Changeset:   7a65edbdf2f4
Branch:      yt
User:        samskillman
Date:        2014-09-06 21:43:59
Summary:     Adding docs for brewer2mpl functionality in set_cmap.
Affected #:  2 files

diff -r 799a2466bf8638eeca17fbb84b4fed2da7656f12 -r 7a65edbdf2f4e36ea42033c7cf092a4b4d7090c4 doc/source/visualizing/colormaps/index.rst
--- a/doc/source/visualizing/colormaps/index.rst
+++ b/doc/source/visualizing/colormaps/index.rst
@@ -6,12 +6,17 @@
 There are several colormaps available for yt.  yt includes all of the 
 matplotlib colormaps as well for nearly all functions.  Individual visualization
 functions usually allow you to specify a colormap with the ``cmap`` flag.
-There are a small number of functions (mostly contained in the image_writer 
-module; e.g. write_bitmap, write_image, write_projection, etc.), which do 
-not load the matplotlib infrastructure and can only access the colormaps 
-native to yt.  
 
-Here is a chart of all of the colormaps available.  In addition to each 
+If you have installed `brewer2mpl`
+(`pip install brewer2mpl` or see `https://github.com/jiffyclub/brewer2mpl`_),
+you can also access the discrete colormaps available on
+`http://colorbrewer2.org`_. Instead of supplying the colormap name, specify
+a tuple formed of (name, type, number), for example `('RdBu', 'Diverging', 9)`.
+These discrete colormaps will not be interpolated, and can be useful for
+creating colorblind/printer/grayscale-friendly plots. For more information,
+visit `http://colorbrewer2.org`_.
+
+Here is a chart of all of the yt and matplotlib colormaps available.  In addition to each 
 colormap displayed here, you can access its "reverse" by simply appending a 
 ``"_r"`` to the end of the colormap name.
 

diff -r 799a2466bf8638eeca17fbb84b4fed2da7656f12 -r 7a65edbdf2f4e36ea42033c7cf092a4b4d7090c4 yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -207,8 +207,11 @@
         field : string
             the field to set the colormap
             if field == 'all', applies to all plots.
-        cmap_name : string
-            name of the colormap
+        cmap_name : string or tuple
+            If a string, will be interpreted as name of the colormap.
+            If a tuple, it is assumed to be of the form (name, type, number)
+            to be used for brewer2mpl functionality. (name, type, number, bool)
+            can be used to specify if a reverse colormap is to be used.
 
         """
 


https://bitbucket.org/yt_analysis/yt/commits/5d15a9f9591f/
Changeset:   5d15a9f9591f
Branch:      yt
User:        samskillman
Date:        2014-09-06 21:50:06
Summary:     Adding error catching if brewer2mpl is not installed.
Affected #:  2 files

diff -r 7a65edbdf2f4e36ea42033c7cf092a4b4d7090c4 -r 5d15a9f9591f9e1c9010b2640ee5e5deb24ea6ee yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -116,9 +116,12 @@
         elif (cbnorm == 'linear'):
             norm = matplotlib.colors.Normalize()
         extent = [float(e) for e in extent]
-        if isinstance(cmap, tuple) and has_brewer:
-            bmap = brewer2mpl.get_map(*cmap)
-            cmap = bmap.get_mpl_colormap(N=cmap[2])
+        if isinstance(cmap, tuple):
+            if has_brewer:
+                bmap = brewer2mpl.get_map(*cmap)
+                cmap = bmap.get_mpl_colormap(N=cmap[2])
+            else:
+                raise RuntimeError("Please install brewer2mpl to use colorbrewer colormaps")
 
         self.image = self.axes.imshow(data.to_ndarray(), origin='lower',
                                       extent=extent, norm=norm, vmin=self.zmin,

diff -r 7a65edbdf2f4e36ea42033c7cf092a4b4d7090c4 -r 5d15a9f9591f9e1c9010b2640ee5e5deb24ea6ee yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -254,9 +254,12 @@
         lut = cmd.color_map_luts[cmap_name]
     except KeyError:
         try:
-            if isinstance(cmap_name, tuple) and has_brewer:
-                bmap = brewer2mpl.get_map(*cmap_name)
-                cmap = bmap.get_mpl_colormap(N=cmap_name[2])
+            if isinstance(cmap_name, tuple):
+                if has_brewer:
+                    bmap = brewer2mpl.get_map(*cmap_name)
+                    cmap = bmap.get_mpl_colormap(N=cmap_name[2])
+                else:
+                    raise RuntimeError("Please install brewer2mpl to use colorbrewer colormaps")
             else:
                 cmap = mcm.get_cmap(cmap_name)
             dummy = cmap(0.0)


https://bitbucket.org/yt_analysis/yt/commits/358d320375c8/
Changeset:   358d320375c8
Branch:      yt
User:        samskillman
Date:        2014-09-06 22:13:15
Summary:     of the form
Affected #:  1 file

diff -r 5d15a9f9591f9e1c9010b2640ee5e5deb24ea6ee -r 358d320375c8f06b7caf02d67f01e0a91542f81f doc/source/visualizing/colormaps/index.rst
--- a/doc/source/visualizing/colormaps/index.rst
+++ b/doc/source/visualizing/colormaps/index.rst
@@ -11,7 +11,7 @@
 (`pip install brewer2mpl` or see `https://github.com/jiffyclub/brewer2mpl`_),
 you can also access the discrete colormaps available on
 `http://colorbrewer2.org`_. Instead of supplying the colormap name, specify
-a tuple formed of (name, type, number), for example `('RdBu', 'Diverging', 9)`.
+a tuple of the form (name, type, number), for example `('RdBu', 'Diverging', 9)`.
 These discrete colormaps will not be interpolated, and can be useful for
 creating colorblind/printer/grayscale-friendly plots. For more information,
 visit `http://colorbrewer2.org`_.


https://bitbucket.org/yt_analysis/yt/commits/4444ee578e99/
Changeset:   4444ee578e99
Branch:      yt
User:        xarthisius
Date:        2014-09-09 04:18:42
Summary:     Merged in samskillman/yt (pull request #1189)

Add colorbrewer2 colormaps via (optional) brewer2mpl
Affected #:  4 files

diff -r 793de33241a8059c099cbaade4ec7ed0f1e1741f -r 4444ee578e9968f136123f87125e02d41c84737e doc/source/visualizing/colormaps/index.rst
--- a/doc/source/visualizing/colormaps/index.rst
+++ b/doc/source/visualizing/colormaps/index.rst
@@ -6,12 +6,17 @@
 There are several colormaps available for yt.  yt includes all of the 
 matplotlib colormaps as well for nearly all functions.  Individual visualization
 functions usually allow you to specify a colormap with the ``cmap`` flag.
-There are a small number of functions (mostly contained in the image_writer 
-module; e.g. write_bitmap, write_image, write_projection, etc.), which do 
-not load the matplotlib infrastructure and can only access the colormaps 
-native to yt.  
 
-Here is a chart of all of the colormaps available.  In addition to each 
+If you have installed `brewer2mpl`
+(`pip install brewer2mpl` or see `https://github.com/jiffyclub/brewer2mpl`_),
+you can also access the discrete colormaps available on
+`http://colorbrewer2.org`_. Instead of supplying the colormap name, specify
+a tuple of the form (name, type, number), for example `('RdBu', 'Diverging', 9)`.
+These discrete colormaps will not be interpolated, and can be useful for
+creating colorblind/printer/grayscale-friendly plots. For more information,
+visit `http://colorbrewer2.org`_.
+
+Here is a chart of all of the yt and matplotlib colormaps available.  In addition to each 
 colormap displayed here, you can access its "reverse" by simply appending a 
 ``"_r"`` to the end of the colormap name.
 

diff -r 793de33241a8059c099cbaade4ec7ed0f1e1741f -r 4444ee578e9968f136123f87125e02d41c84737e yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -19,6 +19,12 @@
 from yt.funcs import \
     get_image_suffix, mylog, iterable
 import numpy as np
+try:
+    import brewer2mpl
+    has_brewer = True
+except:
+    has_brewer = False
+
 
 class CallbackWrapper(object):
     def __init__(self, viewer, window_plot, frb, field):
@@ -110,6 +116,13 @@
         elif (cbnorm == 'linear'):
             norm = matplotlib.colors.Normalize()
         extent = [float(e) for e in extent]
+        if isinstance(cmap, tuple):
+            if has_brewer:
+                bmap = brewer2mpl.get_map(*cmap)
+                cmap = bmap.get_mpl_colormap(N=cmap[2])
+            else:
+                raise RuntimeError("Please install brewer2mpl to use colorbrewer colormaps")
+
         self.image = self.axes.imshow(data.to_ndarray(), origin='lower',
                                       extent=extent, norm=norm, vmin=self.zmin,
                                       aspect=aspect, vmax=self.zmax, cmap=cmap)

diff -r 793de33241a8059c099cbaade4ec7ed0f1e1741f -r 4444ee578e9968f136123f87125e02d41c84737e yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -23,6 +23,12 @@
 import yt.utilities.lib.image_utilities as au
 import yt.utilities.png_writer as pw
 from yt.extern.six.moves import builtins
+try:
+    import brewer2mpl
+    has_brewer = True
+except:
+    has_brewer = False
+
 
 def scale_image(image, mi=None, ma=None):
     r"""Scale an image ([NxNxM] where M = 1-4) to be uint8 and values scaled 
@@ -248,7 +254,14 @@
         lut = cmd.color_map_luts[cmap_name]
     except KeyError:
         try:
-            cmap = mcm.get_cmap(cmap_name)
+            if isinstance(cmap_name, tuple):
+                if has_brewer:
+                    bmap = brewer2mpl.get_map(*cmap_name)
+                    cmap = bmap.get_mpl_colormap(N=cmap_name[2])
+                else:
+                    raise RuntimeError("Please install brewer2mpl to use colorbrewer colormaps")
+            else:
+                cmap = mcm.get_cmap(cmap_name)
             dummy = cmap(0.0)
             lut = cmap._lut.T
         except ValueError:
@@ -256,10 +269,19 @@
                 " colormap file or matplotlib colormaps"
             raise KeyError(cmap_name)
 
-    x = np.mgrid[0.0:1.0:lut[0].shape[0]*1j]
-    shape = buff.shape
-    mapped = np.dstack(
-            [(np.interp(buff, x, v)*255) for v in lut ]).astype("uint8")
+    if isinstance(cmap_name, tuple) and has_brewer:
+        # If we are using the colorbrewer maps, don't interpolate
+        shape = buff.shape
+        # We add float_eps so that digitize doesn't go out of bounds
+        x = np.mgrid[0.0:1.0+np.finfo(np.float32).eps:lut[0].shape[0]*1j]
+        inds = np.digitize(buff.ravel(), x)
+        inds.shape = (shape[0], shape[1])
+        mapped = np.dstack([(v[inds]*255).astype('uint8') for v in lut])
+        del inds
+    else:
+        x = np.mgrid[0.0:1.0:lut[0].shape[0]*1j]
+        mapped = np.dstack(
+                [(np.interp(buff, x, v)*255).astype('uint8') for v in lut ])
     return mapped.copy("C")
 
 def strip_colormap_data(fn = "color_map_data.py",

diff -r 793de33241a8059c099cbaade4ec7ed0f1e1741f -r 4444ee578e9968f136123f87125e02d41c84737e yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -35,6 +35,7 @@
 from yt.utilities.exceptions import \
     YTNotInsideNotebook
 
+
 def invalidate_data(f):
     @wraps(f)
     def newfunc(*args, **kwargs):
@@ -206,8 +207,11 @@
         field : string
             the field to set the colormap
             if field == 'all', applies to all plots.
-        cmap_name : string
-            name of the colormap
+        cmap_name : string or tuple
+            If a string, will be interpreted as name of the colormap.
+            If a tuple, it is assumed to be of the form (name, type, number)
+            to be used for brewer2mpl functionality. (name, type, number, bool)
+            can be used to specify if a reverse colormap is to be used.
 
         """
 
@@ -384,37 +388,6 @@
         return self.set_font({'size': size})
 
     @invalidate_plot
-    def set_cmap(self, field, cmap):
-        """set the colormap for one of the fields
-
-        Parameters
-        ----------
-        field : string
-            the field to set a transform
-            if field == 'all', applies to all plots.
-        cmap : string
-            name of the colormap
-
-        """
-        if field == 'all':
-            fields = self.plots.keys()
-        else:
-            fields = [field]
-
-        for field in self.data_source._determine_fields(fields):
-            self._colorbar_valid = False
-            self._colormaps[field] = cmap
-            if isinstance(cmap, types.StringTypes):
-                if str(cmap) in yt_colormaps:
-                    cmap = yt_colormaps[str(cmap)]
-                elif hasattr(matplotlib.cm, cmap):
-                    cmap = getattr(matplotlib.cm, cmap)
-            if not is_colormap(cmap) and cmap is not None:
-                raise RuntimeError("Colormap '%s' does not exist!" % str(cmap))
-            self.plots[field].image.set_cmap(cmap)
-        return self
-
-    @invalidate_plot
     @invalidate_figure
     def set_figure_size(self, size):
         """Sets a new figure size for the plot

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