[yt-svn] commit/yt: xarthisius: Die gracefully if colormap passed to set_cmap does not exist

Bitbucket commits-noreply at bitbucket.org
Tue Jan 24 11:09:41 PST 2012


1 new commit in yt:


https://bitbucket.org/yt_analysis/yt/changeset/20c994f42b5e/
changeset:   20c994f42b5e
branch:      yt
user:        xarthisius
date:        2012-01-24 20:04:23
summary:     Die gracefully if colormap passed to set_cmap does not exist
affected #:  2 files

diff -r 2a62fb4acbf0694c42970070f2b3ede048718424 -r 20c994f42b5ebf39dfbb7441f559fad91a53c20b yt/visualization/color_maps.py
--- a/yt/visualization/color_maps.py
+++ b/yt/visualization/color_maps.py
@@ -27,6 +27,9 @@
 import matplotlib.colors as cc
 import matplotlib.cm as mcm
 
+def is_colormap(cmap):
+    return isinstance(cmap,cc.Colormap)
+
 def check_color(name):
     try:
         ss = cc.colorConverter.to_rgb(name)


diff -r 2a62fb4acbf0694c42970070f2b3ede048718424 -r 20c994f42b5ebf39dfbb7441f559fad91a53c20b yt/visualization/plot_types.py
--- a/yt/visualization/plot_types.py
+++ b/yt/visualization/plot_types.py
@@ -35,7 +35,7 @@
     x_dict, \
     y_dict, \
     axis_names
-from .color_maps import yt_colormaps
+from .color_maps import yt_colormaps, is_colormap
 
 class CallbackRegistryHandler(object):
     def __init__(self, plot):
@@ -231,7 +231,10 @@
                 cmap = yt_colormaps[str(cmap)]
             elif hasattr(matplotlib.cm, cmap):
                 cmap = getattr(matplotlib.cm, cmap)
-        self.cmap = cmap
+        if not is_colormap(cmap):
+            raise RuntimeError("Colormap '%s' does not exist!" % str(cmap))
+        else:
+            self.cmap = cmap
         
     def __setitem__(self, item, val):
         self.im[item] = val

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