[yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Dec 21 14:29:50 PST 2012
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/96e0d5ebb3fa/
changeset: 96e0d5ebb3fa
branch: yt
user: samskillman
date: 2012-12-21 23:28:04
summary: This was changed at some point, breaking rotations.
affected #: 1 file
diff -r fa22322ff1494d97e851748f8e78523e5a2b77ad -r 96e0d5ebb3fac3e6b6028c32c0b38af89d6b27ac yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -193,10 +193,12 @@
resolution = (resolution, resolution)
self.resolution = resolution
self.sub_samples = sub_samples
+ self.rotation_vector = north_vector
if not iterable(width):
width = (width, width, width) # left/right, top/bottom, front/back
self.orienter = Orientation(normal_vector, north_vector=north_vector, steady_north=steady_north)
- self.rotation_vector = self.orienter.unit_vectors[1]
+ if not steady_north:
+ self.rotation_vector = self.orienter.unit_vectors[1]
self._setup_box_properties(width, center, self.orienter.unit_vectors)
if fields is None: fields = ["Density"]
self.fields = fields
https://bitbucket.org/yt_analysis/yt/changeset/5fa636d7db1d/
changeset: 5fa636d7db1d
branch: yt
user: samskillman
date: 2012-12-21 23:29:00
summary: Merging
affected #: 4 files
diff -r 96e0d5ebb3fac3e6b6028c32c0b38af89d6b27ac -r 5fa636d7db1d29773dceb55ffff30ef104ced496 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -185,7 +185,7 @@
.. code-block:: python
- @rootonly
+ @deprecate
def some_really_old_function(...):
"""
@@ -205,7 +205,7 @@
.. code-block:: python
- @rootonly
+ @pdb_run
def some_function_to_debug(...):
"""
diff -r 96e0d5ebb3fac3e6b6028c32c0b38af89d6b27ac -r 5fa636d7db1d29773dceb55ffff30ef104ced496 yt/visualization/base_plot_types.py
--- /dev/null
+++ b/yt/visualization/base_plot_types.py
@@ -0,0 +1,84 @@
+"""
+This is a place for base classes of the various plot types.
+
+Author: Nathan Goldbaum <goldbaum at ucolick.org>
+Affiliation: UCSC Astronomy
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2010-2012 Nathan Goldbaum. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+import matplotlib
+from ._mpl_imports import \
+ FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
+from yt.funcs import \
+ get_image_suffix, mylog
+
+
+class PlotMPL(object):
+ """A base class for all yt plots made using matplotlib.
+
+ """
+ def __init__(self, fsize, axrect):
+ """Initialize PlotMPL class"""
+ self._plot_valid = True
+ self.figure = matplotlib.figure.Figure(figsize=fsize,
+ frameon=True)
+ self.axes = self.figure.add_axes(axrect)
+
+ def save(self, name, mpl_kwargs, canvas=None):
+ """Choose backend and save image to disk"""
+ suffix = get_image_suffix(name)
+ if suffix == '':
+ suffix = '.png'
+ name = "%s%s" % (name, suffix)
+
+ mylog.info("Saving plot %s", name)
+
+ if suffix == ".png":
+ canvas = FigureCanvasAgg(self.figure)
+ elif suffix == ".pdf":
+ canvas = FigureCanvasPdf(self.figure)
+ elif suffix in (".eps", ".ps"):
+ canvas = FigureCanvasPS(self.figure)
+ else:
+ mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
+ canvas = FigureCanvasAgg(self.figure)
+
+ canvas.print_figure(name, **mpl_kwargs)
+ return name
+
+
+class ImagePlotMPL(PlotMPL):
+ """A base class for yt plots made using imshow
+
+ """
+ def __init__(self, fsize, axrect, caxrect, zlim):
+ """Initialize ImagePlotMPL class object"""
+ PlotMPL.__init__(self, fsize, axrect)
+ self.zmin, self.zmax = zlim
+ self.cax = self.figure.add_axes(caxrect)
+
+ def _init_image(self, data, cbnorm, cmap, extent, aspect=None):
+ """Store output of imshow in image variable"""
+ if (cbnorm == 'log10'):
+ norm = matplotlib.colors.LogNorm()
+ elif (cbnorm == 'linear'):
+ norm = matplotlib.colors.Normalize()
+ self.image = self.axes.imshow(data, origin='lower', extent=extent,
+ norm=norm, vmin=self.zmin, aspect=aspect,
+ vmax=self.zmax, cmap=cmap)
diff -r 96e0d5ebb3fac3e6b6028c32c0b38af89d6b27ac -r 5fa636d7db1d29773dceb55ffff30ef104ced496 yt/visualization/fixed_resolution.py
--- a/yt/visualization/fixed_resolution.py
+++ b/yt/visualization/fixed_resolution.py
@@ -159,14 +159,27 @@
info['projected_units'] = \
self.data_source.pf.field_info[item].get_projected_units()
info['center'] = self.data_source.center
+
try:
info['coord'] = self.data_source.coord
except AttributeError:
pass
+
try:
info['weight_field'] = self.data_source.weight_field
except AttributeError:
pass
+
+ info['label'] = self.data_source.pf.field_info[item].display_name
+ if info['label'] is None:
+ info['label'] = r'$\rm{'+item+r'}$'
+ elif info['label'].find('$') == -1:
+ info['label'] = r'$\rm{'+info['label']+r'}$'
+ if info['units'] is None or info['units'] == '':
+ pass
+ else:
+ info['label'] += r'$\/\/('+info['units']+r')$'
+
return info
def convert_to_pixel(self, coords):
diff -r 96e0d5ebb3fac3e6b6028c32c0b38af89d6b27ac -r 5fa636d7db1d29773dceb55ffff30ef104ced496 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -25,29 +25,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import base64
-import matplotlib.figure
-from matplotlib.mathtext import MathTextParser
-from distutils import version
+import numpy as np
import matplotlib
-
-# Some magic for dealing with pyparsing being included or not
-# included in matplotlib (not in gentoo, yes in everything else)
-# Also accounting for the fact that in 1.2.0, pyparsing got renamed.
-try:
- if version.LooseVersion(matplotlib.__version__) < version.LooseVersion("1.2.0"):
- from matplotlib.pyparsing import ParseFatalException
- else:
- from matplotlib.pyparsing_py2 import ParseFatalException
-except ImportError:
- from pyparsing import ParseFatalException
-
import cStringIO
import types
import __builtin__
+
+from matplotlib.mathtext import MathTextParser
+from distutils import version
from functools import wraps
-import numpy as np
-from ._mpl_imports import *
+from ._mpl_imports import \
+ FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
from .color_maps import yt_colormaps, is_colormap
from .image_writer import \
write_image, apply_colormap
@@ -58,10 +47,13 @@
from .plot_modifications import get_smallest_appropriate_unit, \
callback_registry
from .tick_locators import LogLocator, LinearLocator
+from .base_plot_types import ImagePlotMPL
+
from yt.utilities.delaunay.triangulate import Triangulation as triang
from yt.config import ytcfg
-
-from yt.funcs import *
+from yt.funcs import \
+ mylog, defaultdict, iterable, ensure_list, \
+ fix_axis, get_image_suffix
from yt.utilities.lib import write_png_to_string
from yt.utilities.definitions import \
x_dict, x_names, \
@@ -75,6 +67,17 @@
from yt.data_objects.time_series import \
TimeSeriesData
+# Some magic for dealing with pyparsing being included or not
+# included in matplotlib (not in gentoo, yes in everything else)
+# Also accounting for the fact that in 1.2.0, pyparsing got renamed.
+try:
+ if version.LooseVersion(matplotlib.__version__) < version.LooseVersion("1.2.0"):
+ from matplotlib.pyparsing import ParseFatalException
+ else:
+ from matplotlib.pyparsing_py2 import ParseFatalException
+except ImportError:
+ from pyparsing import ParseFatalException
+
def invalidate_data(f):
@wraps(f)
def newfunc(*args, **kwargs):
@@ -763,7 +766,6 @@
fields = self._frb.keys()
self._colorbar_valid = True
for f in self.fields:
- md = self.get_metadata(f, strip_mathml = False, return_string = False)
axis_index = self.data_source.axis
if self.origin == 'center-window':
@@ -781,7 +783,11 @@
raise RuntimeError(
'origin keyword: \"%(k)s\" not recognized' % {'k': self.origin})
- (unit_x, unit_y) = md['axes_unit_names']
+ if self._axes_unit_names is None:
+ unit = get_smallest_appropriate_unit(self.xlim[1] - self.xlim[0], self.pf)
+ (unit_x, unit_y) = (unit, unit)
+ else:
+ (unit_x, unit_y) = self._axes_unit_names
extentx = [(self.xlim[i] - xc) * self.pf[unit_x] for i in (0,1)]
extenty = [(self.ylim[i] - yc) * self.pf[unit_y] for i in (0,1)]
@@ -807,8 +813,11 @@
# Correct the aspect ratio in case unit_x and unit_y are different
aspect = self.pf[unit_x]/self.pf[unit_y]
- self.plots[f] = WindowPlotMPL(self._frb[f], extent, aspect, self._field_transform[f],
- self._colormaps[f], size, zlim)
+ image = self._frb[f]
+
+ self.plots[f] = WindowPlotMPL(image, self._field_transform[f].name,
+ self._colormaps[f], extent, aspect,
+ zlim, size)
self.plots[f].cb = self.plots[f].figure.colorbar(
self.plots[f].image, cax = self.plots[f].cax)
@@ -830,29 +839,15 @@
self.plots[f].axes.tick_params(labelsize=self.fontsize)
- field_name = self.data_source.pf.field_info[f].display_name
+ colorbar_label = image.info['label']
- if field_name is None:
- field_name = r'$\rm{'+f+r'}$'
- elif field_name.find('$') == -1:
- field_name = r'$\rm{'+field_name+r'}$'
-
parser = MathTextParser('Agg')
try:
- parser.parse(field_name)
+ parser.parse(colorbar_label)
except ParseFatalException, err:
- raise YTCannotParseFieldDisplayName(f,field_name,str(err))
-
- if md['colorbar_unit'] is None or md['colorbar_unit'] == '':
- label = field_name
- else:
- try:
- parser.parse(r'$'+md['colorbar_unit']+r'$')
- except ParseFatalException, err:
- raise YTCannotParseUnitDisplayName(f, md['colorbar_unit'],str(err))
- label = field_name+r'$\/\/('+md['colorbar_unit']+r')$'
-
- self.plots[f].cb.set_label(label,fontsize=self.fontsize)
+ raise YTCannotParseUnitDisplayName(f, colorbar_label, str(err))
+
+ self.plots[f].cb.set_label(colorbar_label, fontsize=self.fontsize)
self.plots[f].cb.ax.tick_params(labelsize=self.fontsize)
@@ -1468,51 +1463,19 @@
else:
self._field_transform[field] = linear_transform
-class PlotMPL(object):
- """A base class for all yt plots made using matplotlib.
-
- """
- datalabel = None
- figure = None
- def __init__(self, field, size):
- self._plot_valid = True
+class WindowPlotMPL(ImagePlotMPL):
+ def __init__(self, data, cbname, cmap, extent, aspect, zlim, size):
fsize, axrect, caxrect = self._get_best_layout(size)
-
if np.any(np.array(axrect) < 0):
- self.figure = matplotlib.figure.Figure(figsize = size,
- frameon = True)
- self.axes = self.figure.add_axes((.07,.10,.8,.8))
- self.cax = self.figure.add_axes((.87,.10,.04,.8))
mylog.warning('The axis ratio of the requested plot is very narrow. '
'There is a good chance the plot will not look very good, '
'consider making the plot manually using FixedResolutionBuffer '
'and matplotlib.')
- else:
- self.figure = matplotlib.figure.Figure(figsize = fsize,
- frameon = True)
- self.axes = self.figure.add_axes(axrect)
- self.cax = self.figure.add_axes(caxrect)
-
- def save(self, name, mpl_kwargs, canvas = None):
- suffix = get_image_suffix(name)
-
- if suffix == '':
- suffix = '.png'
- name = "%s%s" % (name, suffix)
- mylog.info("Saving plot %s", name)
- if suffix == ".png":
- canvas = FigureCanvasAgg(self.figure)
- elif suffix == ".pdf":
- canvas = FigureCanvasPdf(self.figure)
- elif suffix in (".eps", ".ps"):
- canvas = FigureCanvasPS(self.figure)
- else:
- mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
- canvas = FigureCanvasAgg(self.figure)
-
-
- canvas.print_figure(name,**mpl_kwargs)
- return name
+ axrect = (0.07, 0.10, 0.80, 0.80)
+ caxrect = (0.87, 0.10, 0.04, 0.80)
+ ImagePlotMPL.__init__(self, fsize, axrect, caxrect, zlim)
+ self._init_image(data, cbname, cmap, extent, aspect)
+ self.image.axes.ticklabel_format(scilimits=(-2,3))
def _get_best_layout(self, size):
aspect = 1.0*size[0]/size[1]
@@ -1551,26 +1514,3 @@
axrect = (text_buffx, text_bottomy, xfrac, yfrac )
caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
return newsize, axrect, caxrect
-
- def _repr_png_(self):
- canvas = FigureCanvasAgg(self.figure)
- f = cStringIO.StringIO()
- canvas.print_figure(f)
- f.seek(0)
- return f.read()
-
-class WindowPlotMPL(PlotMPL):
- def __init__(self, data, extent, aspect, field_transform, cmap, size, zlim):
- self.zmin, self.zmax = zlim
- PlotMPL.__init__(self, data, size)
- self.__init_image(data, extent, aspect, field_transform, cmap)
-
- def __init_image(self, data, extent, aspect, field_transform, cmap):
- if (field_transform.name == 'log10'):
- norm = matplotlib.colors.LogNorm()
- elif (field_transform.name == 'linear'):
- norm = matplotlib.colors.Normalize()
- self.image = self.axes.imshow(data, origin='lower', extent=extent,
- norm=norm, vmin=self.zmin, aspect=aspect,
- vmax=self.zmax, cmap=cmap)
- self.image.axes.ticklabel_format(scilimits=(-2,3))
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