[yt-svn] commit/yt: ngoldbaum: Merged in ngoldbaum/yt (pull request #2118)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Apr 20 11:14:43 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/8f91fd732959/
Changeset: 8f91fd732959
Branch: yt
User: ngoldbaum
Date: 2016-04-20 18:14:30+00:00
Summary: Merged in ngoldbaum/yt (pull request #2118)
Add get_brewer_cmap to get brewer colormaps without importing palettable at the top level
Affected #: 3 files
diff -r 454b81690191c4ee1c28f0120f39bf9ee99840ed -r 8f91fd7329595d87b927cec203b1246b1de963f9 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -930,3 +930,26 @@
pbar.finish()
return hasher.hexdigest()
+
+def get_brewer_cmap(cmap):
+ """Returns a colorbrewer colormap from palettable"""
+ try:
+ import brewer2mpl
+ except ImportError:
+ brewer2mpl = None
+ try:
+ import palettable
+ except ImportError:
+ palettable = None
+ if palettable is not None:
+ bmap = palettable.colorbrewer.get_map(*cmap)
+ elif brewer2mpl is not None:
+ warnings.warn("Using brewer2mpl colormaps is deprecated. "
+ "Please install the successor to brewer2mpl, "
+ "palettable, with `pip install palettable`. "
+ "Colormap tuple names remain unchanged.")
+ bmap = brewer2mpl.get_map(*cmap)
+ else:
+ raise RuntimeError(
+ "Please install palettable to use colorbrewer colormaps")
+ return bmap.get_mpl_colormap(N=cmap[2])
diff -r 454b81690191c4ee1c28f0120f39bf9ee99840ed -r 8f91fd7329595d87b927cec203b1246b1de963f9 yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -18,19 +18,11 @@
from ._mpl_imports import \
FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
from yt.funcs import \
- get_image_suffix, mylog, iterable
+ get_image_suffix, \
+ mylog, \
+ iterable, \
+ get_brewer_cmap
import numpy as np
-import warnings
-try:
- import brewer2mpl
- has_brewer = True
-except:
- has_brewer = False
-try:
- import palettable
- has_palettable = True
-except:
- has_palettable = False
class CallbackWrapper(object):
@@ -135,18 +127,7 @@
extent = [float(e) for e in extent]
# tuple colormaps are from palettable (or brewer2mpl)
if isinstance(cmap, tuple):
- if has_palettable:
- bmap = palettable.colorbrewer.get_map(*cmap)
- elif has_brewer:
- warnings.warn("Using brewer2mpl colormaps is deprecated. "
- "Please install the successor to brewer2mpl, "
- "palettable, with `pip install palettable`. "
- "Colormap tuple names remain unchanged.")
- bmap = brewer2mpl.get_map(*cmap)
- else:
- raise RuntimeError(
- "Please install palettable to use colorbrewer colormaps")
- cmap = bmap.get_mpl_colormap(N=cmap[2])
+ cmap = get_brewer_cmap(cmap)
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 454b81690191c4ee1c28f0120f39bf9ee99840ed -r 8f91fd7329595d87b927cec203b1246b1de963f9 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -17,7 +17,10 @@
from yt.config import \
ytcfg
-from yt.funcs import mylog, get_image_suffix
+from yt.funcs import \
+ mylog, \
+ get_image_suffix, \
+ get_brewer_cmap
from yt.units.yt_array import YTQuantity
from yt.utilities.exceptions import YTNotInsideNotebook
from .color_maps import mcm
@@ -25,17 +28,6 @@
import yt.utilities.lib.image_utilities as au
import yt.utilities.png_writer as pw
from yt.extern.six.moves import builtins
-import warnings
-try:
- import palettable
- has_palettable = True
-except:
- has_palettable = False
-try:
- import brewer2mpl
- has_brewer = True
-except:
- has_brewer = False
def scale_image(image, mi=None, ma=None):
@@ -268,27 +260,17 @@
try:
# if cmap is tuple, then we're using palettable or brewer2mpl cmaps
if isinstance(cmap_name, tuple):
- if has_palettable:
- bmap = palettable.colorbrewer.get_map(*cmap_name)
- elif has_brewer:
- warnings.warn("Using brewer2mpl colormaps is deprecated. "
- "Please install the successor to brewer2mpl, "
- "palettable, with `pip install palettable`. "
- "Colormap tuple names remain unchanged.")
- bmap = brewer2mpl.get_map(*cmap_name)
- else:
- raise RuntimeError("Please install palettable to use colorbrewer colormaps")
- cmap = bmap.get_mpl_colormap(N=cmap_name[2])
+ cmap = get_brewer_cmap(cmap_name)
else:
cmap = mcm.get_cmap(cmap_name)
cmap(0.0)
lut = cmap._lut.T
except ValueError:
- print("Your color map was not found in either the extracted" +\
- " colormap file or matplotlib colormaps")
- raise KeyError(cmap_name)
+ raise KeyError(
+ "Your color map (%s) was not found in either the extracted"
+ " colormap file or matplotlib colormaps" % cmap_name)
- if isinstance(cmap_name, tuple) and (has_palettable or has_brewer):
+ if isinstance(cmap_name, tuple):
# 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
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160420/9e0ca879/attachment.htm>
More information about the yt-svn
mailing list