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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Jun 4 08:42:29 PDT 2014


4 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/b847df8cb7f6/
Changeset:   b847df8cb7f6
Branch:      yt-3.0
User:        mzingale
Date:        2014-05-24 02:41:42
Summary:     allow for optional arguments giving text to annotate the annotated
fig
Affected #:  1 file

diff -r 91a14a8d910d993e32d51b06849453a3d3306174 -r b847df8cb7f6e1fe567c58e0b679966fa87251cc yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -642,10 +642,15 @@
     def draw(self):
         self._pylab.draw()
     
-    def save_annotated(self, fn, image, enhance=True, dpi=100):
+    def save_annotated(self, fn, image, enhance=True, dpi=100, 
+                       text_x=0.1, text_y=0.9, text=None):
         image = image.swapaxes(0,1) 
         ax = self.show_mpl(image, enhance=enhance)
         self.annotate(ax.axes, enhance)
+        if not text == None:
+            f = self._pylab.gcf()
+            self._pylab.text(text_x, text_y, text, 
+                             transform=f.transFigure, color="white")
         self._pylab.savefig(fn, bbox_inches='tight', facecolor='black', dpi=dpi)
         
     def save_image(self, image, fn=None, clip_ratio=None, transparent=False):


https://bitbucket.org/yt_analysis/yt/commits/c7287cd22426/
Changeset:   c7287cd22426
Branch:      yt-3.0
User:        mzingale
Date:        2014-05-24 16:02:18
Summary:     remove my previous hack to get text onto an annotated vol render
and instead allow us to specify whether we want an existing figure
cleared.  Default is to clear (existing behavior), but now we can
create the figure after the camera object, set the camera object's
_render_figure, and then annotate as needed before calling
save_annotated().  Anything we add to the figure will be preserved
if clear_fig=False is used.
Affected #:  1 file

diff -r b847df8cb7f6e1fe567c58e0b679966fa87251cc -r c7287cd22426c974d11b07fe14ac85e176f905f2 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -620,13 +620,13 @@
             label = '$\\rm{log}\\/ $' + label
         self.transfer_function.vert_cbar(ax=cb.ax, label=label)
 
-    def show_mpl(self, im, enhance=True):
+    def show_mpl(self, im, enhance=True, clear_fig=True):
         if self._pylab is None:
             import pylab
             self._pylab = pylab
         if self._render_figure is None:
             self._render_figure = self._pylab.figure(1)
-        self._render_figure.clf()
+        if clear_fig: self._render_figure.clf()
 
         if enhance:
             nz = im[im > 0.0]
@@ -642,15 +642,10 @@
     def draw(self):
         self._pylab.draw()
     
-    def save_annotated(self, fn, image, enhance=True, dpi=100, 
-                       text_x=0.1, text_y=0.9, text=None):
+    def save_annotated(self, fn, image, enhance=True, dpi=100, clear_fig=True):
         image = image.swapaxes(0,1) 
-        ax = self.show_mpl(image, enhance=enhance)
+        ax = self.show_mpl(image, enhance=enhance, clear_fig=clear_fig)
         self.annotate(ax.axes, enhance)
-        if not text == None:
-            f = self._pylab.gcf()
-            self._pylab.text(text_x, text_y, text, 
-                             transform=f.transFigure, color="white")
         self._pylab.savefig(fn, bbox_inches='tight', facecolor='black', dpi=dpi)
         
     def save_image(self, image, fn=None, clip_ratio=None, transparent=False):


https://bitbucket.org/yt_analysis/yt/commits/07a3b293bd1d/
Changeset:   07a3b293bd1d
Branch:      yt-3.0
User:        mzingale
Date:        2014-05-25 01:00:46
Summary:     merge to sync with ytanalysis
Affected #:  3 files

diff -r c7287cd22426c974d11b07fe14ac85e176f905f2 -r 07a3b293bd1d2eacba098070e8377c35f375649d yt/data_objects/profiles.py
--- a/yt/data_objects/profiles.py
+++ b/yt/data_objects/profiles.py
@@ -1154,7 +1154,10 @@
         for bin_field in bin_fields:
             bf_units = data_source.pf._get_field_info(bin_field[0],
                                                       bin_field[1]).units
-            field_ex = list(extrema[bin_field[-1]])
+            try:
+                field_ex = list(extrema[bin_field[-1]])
+            except KeyError:
+                field_ex = list(extrema[bin_field])
             if iterable(field_ex[0]):
                 field_ex[0] = data_source.pf.quan(field_ex[0][0], field_ex[0][1])
                 field_ex[0] = field_ex[0].in_units(bf_units)

diff -r c7287cd22426c974d11b07fe14ac85e176f905f2 -r 07a3b293bd1d2eacba098070e8377c35f375649d yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -30,10 +30,10 @@
 
 from yt.funcs import \
     defaultdict, get_image_suffix, \
-    get_ipython_api_version, iterable
+    get_ipython_api_version, iterable, \
+    ensure_list
 from yt.utilities.exceptions import \
     YTNotInsideNotebook
-from ._mpl_imports import FigureCanvasAgg
 
 def invalidate_data(f):
     @wraps(f)
@@ -241,7 +241,7 @@
         if field is 'all':
             fields = self.plots.keys()
         else:
-            fields = [field]
+            fields = ensure_list(field)
         for field in self.data_source._determine_fields(fields):
             myzmin = zmin
             myzmax = zmax

diff -r c7287cd22426c974d11b07fe14ac85e176f905f2 -r 07a3b293bd1d2eacba098070e8377c35f375649d yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -24,7 +24,6 @@
 import matplotlib
 import numpy as np
 import cStringIO
-import __builtin__
 
 
 from .base_plot_types import ImagePlotMPL
@@ -69,7 +68,7 @@
 
 class FigureContainer(dict):
     def __init__(self):
-        super(dict, self).__init__()
+        super(FigureContainer, self).__init__()
 
     def __missing__(self, key):
         figure = mpl.matplotlib.figure.Figure((10, 8))
@@ -79,13 +78,18 @@
 class AxesContainer(dict):
     def __init__(self, fig_container):
         self.fig_container = fig_container
-        super(dict, self).__init__()
+        self.ylim = {}
+        super(AxesContainer, self).__init__()
 
     def __missing__(self, key):
         figure = self.fig_container[key]
         self[key] = figure.add_subplot(111)
         return self[key]
 
+    def __setitem__(self, key, value):
+        super(AxesContainer, self).__setitem__(key, value)
+        self.ylim[key] = (None, None)
+
 def sanitize_label(label, nprofiles):
     label = ensure_list(label)
     
@@ -156,16 +160,17 @@
 
     This creates profiles of a single dataset.
 
-    >>> pf = load("enzo_tiny_cosmology/DD0046/DD0046")
-    >>> ad = pf.h.all_data()
+    >>> import yt
+    >>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
+    >>> ad = ds.all_data()
     >>> plot = ProfilePlot(ad, "density", ["temperature", "velocity_x"],
-                           weight_field="cell_mass",
-                           plot_spec=dict(color='red', linestyle="--"))
+    ...                    weight_field="cell_mass",
+    ...                    plot_spec=dict(color='red', linestyle="--"))
     >>> plot.save()
 
     This creates profiles from a time series object.
-    
-    >>> es = simulation("AMRCosmology.enzo", "Enzo")
+
+    >>> es = yt.simulation("AMRCosmology.enzo", "Enzo")
     >>> es.get_time_series()
 
     >>> profiles = []
@@ -218,7 +223,9 @@
             self.plot_spec = [dict() for p in self.profiles]
         if not isinstance(self.plot_spec, list):
             self.plot_spec = [self.plot_spec.copy() for p in self.profiles]
-        
+
+        self.figures = FigureContainer()
+        self.axes = AxesContainer(self.figures)
         self._setup_plots()
         
     def save(self, name=None):
@@ -235,7 +242,7 @@
             self._setup_plots()
         unique = set(self.figures.values())
         if len(unique) < len(self.figures):
-            figiter = izip(xrange(len(unique)), sorted(unique))
+            iters = izip(xrange(len(unique)), sorted(unique))
         else:
             iters = self.figures.iteritems()
         if name is None:
@@ -256,8 +263,7 @@
             if isinstance(uid, types.TupleType):
                 uid = uid[1]
             canvas = canvas_cls(fig)
-            fn = "%s_1d-Profile_%s_%s%s" % \
-              (prefix, xfn, uid, suffix)
+            fn = "%s_1d-Profile_%s_%s%s" % (prefix, xfn, uid, suffix)
             mylog.info("Saving %s", fn)
             canvas.print_figure(fn)
         return self
@@ -276,8 +282,10 @@
         Examples
         --------
 
-        >>> slc = SlicePlot(pf, "x", ["Density", "VelocityMagnitude"])
-        >>> slc.show()
+        >>> import yt
+        >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+        >>> pp = ProfilePlot(ds.all_data(), 'density', 'temperature')
+        >>> pp.show()
 
         """
         if "__IPYTHON__" in dir(__builtin__):
@@ -290,14 +298,13 @@
         else:
             raise YTNotInsideNotebook
 
-
     def _repr_html_(self):
         """Return an html representation of the plot object. Will display as a
         png for each WindowPlotMPL instance in self.plots"""
         ret = ''
         unique = set(self.figures.values())
         if len(unique) < len(self.figures):
-            figiter = izip(xrange(len(unique)), sorted(unique))
+            iters = izip(xrange(len(unique)), sorted(unique))
         else:
             iters = self.figures.iteritems()
         for uid, fig in iters:
@@ -310,14 +317,12 @@
         return ret
 
     def _setup_plots(self):
-        self.figures = FigureContainer()
-        self.axes = AxesContainer(self.figures)
         for i, profile in enumerate(self.profiles):
             for field, field_data in profile.items():
-                self.axes[field].plot(np.array(profile.x),
-                                      np.array(field_data),
-                                      label=self.label[i],
-                                      **self.plot_spec[i])
+                if field in self.axes:
+                    self.axes[field].cla()
+                self.axes[field].plot(np.array(profile.x), np.array(field_data),
+                                      label=self.label[i], **self.plot_spec[i])
         
         # This relies on 'profile' leaking
         for fname, axes in self.axes.items():
@@ -327,6 +332,7 @@
             axes.set_yscale(yscale)
             axes.set_xlabel(xtitle)
             axes.set_ylabel(ytitle)
+            axes.set_ylim(*self.axes.ylim[fname])
             if any(self.label):
                 axes.legend(loc="best")
         self._plot_valid = True
@@ -443,7 +449,7 @@
     def set_unit(self, field, unit):
         """Sets a new unit for the requested field
 
-        parameters
+        Parameters
         ----------
         field : string
            The name of the field that is to be changed.
@@ -460,6 +466,97 @@
                 raise KeyError("Field %s not in profile plot!" % (field))
         return self
 
+    @invalidate_plot
+    def set_xlim(self, xmin=None, xmax=None):
+        """Sets the limits of the bin field
+
+        Parameters
+        ----------
+        
+        xmin : float or None
+          The new x minimum.  Defaults to None, which leaves the xmin
+          unchanged.
+
+        xmax : float or None
+          The new x maximum.  Defaults to None, which leaves the xmax
+          unchanged.
+
+        Examples
+        --------
+
+        >>> import yt
+        >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+        >>> pp = yt.ProfilePlot(ds.all_data(), 'density', 'temperature')
+        >>> pp.set_xlim(1e-29, 1e-24)
+        >>> pp.save()
+
+        """
+        for i, p in enumerate(self.profiles):
+            if xmin is None:
+                xmi = p.x_bins.min()
+            else:
+                xmi = xmin
+            if xmax is None:
+                xma = p.x_bins.max()
+            else:
+                xma = xmax
+            extrema = {p.x_field: ((xmi, str(p.x.units)), (xma, str(p.x.units)))}
+            units = {p.x_field: str(p.x.units)}
+            for field in p.field_map.values():
+                units[field] = str(p.field_data[field].units)
+            self.profiles[i] = \
+                create_profile(p.data_source, p.x_field,
+                               n_bins=len(p.x_bins)-2,
+                               fields=p.field_map.values(),
+                               weight_field=p.weight_field,
+                               accumulation=p.accumulation,
+                               fractional=p.fractional,
+                               extrema=extrema, units=units)
+        return self
+
+    @invalidate_plot
+    def set_ylim(self, field, ymin=None, ymax=None):
+        """Sets the plot limits for the specified field we are binning.
+
+        Parameters
+        ----------
+
+        field : string or field tuple
+
+        The field that we want to adjust the plot limits for.
+        
+        ymin : float or None
+          The new y minimum.  Defaults to None, which leaves the ymin
+          unchanged.
+
+        ymax : float or None
+          The new y maximum.  Defaults to None, which leaves the ymax
+          unchanged.
+
+        Examples
+        --------
+
+        >>> import yt
+        >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+        >>> pp = yt.ProfilePlot(ds.all_data(), 'density', ['temperature', 'x-velocity'])
+        >>> pp.set_ylim('temperature', 1e4, 1e6)
+        >>> pp.save()
+
+        """
+        for i, p in enumerate(self.profiles):
+            if field is 'all':
+                fields = self.axes.keys()
+            else:
+                fields = ensure_list(field)
+            for profile in self.profiles:
+                for field in profile.data_source._determine_fields(fields):
+                    if field in profile.field_map:
+                        field = profile.field_map[field]
+                    self.axes.ylim[field] = (ymin, ymax)
+                    # Continue on to the next profile.
+                    break
+        return self
+
     def _get_field_log(self, field_y, profile):
         pf = profile.data_source.pf
         yf, = profile.data_source._determine_fields([field_y])
@@ -508,7 +605,6 @@
                     self._get_field_label(field_y, yfi, y_unit, fractional)
 
         return (x_title, y_title)
-            
 
 class PhasePlot(ImagePlotContainer):
     r"""
@@ -570,10 +666,11 @@
     Examples
     --------
 
-    >>> pf = load("enzo_tiny_cosmology/DD0046/DD0046")
+    >>> import yt
+    >>> pf = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
     >>> ad = pf.h.all_data()
     >>> plot = PhasePlot(ad, "density", "temperature", ["cell_mass"],
-                         weight_field=None)
+    ...                  weight_field=None)
     >>> plot.save()
 
     >>> # Change plot properties.
@@ -706,7 +803,7 @@
 
             self.plots[f] = PhasePlotMPL(self.profile.x, self.profile.y, data,
                                          x_scale, y_scale, z_scale,
-                                         self._colormaps[f], np.array(zlim),
+                                         self._colormaps[f], zlim,
                                          self.figure_size, fp.get_size(),
                                          fig, axes, cax)
 
@@ -837,7 +934,7 @@
     def set_unit(self, field, unit):
         """Sets a new unit for the requested field
 
-        parameters
+        Parameters
         ----------
         field : string
            The name of the field that is to be changed.
@@ -857,6 +954,106 @@
             raise KeyError("Field %s not in phase plot!" % (field))
         return self
 
+    @invalidate_plot
+    def set_xlim(self, xmin=None, xmax=None):
+        """Sets the limits of the x bin field
+
+        Parameters
+        ----------
+        
+        xmin : float or None
+          The new x minimum.  Defaults to None, which leaves the xmin
+          unchanged.
+
+        xmax : float or None
+          The new x maximum.  Defaults to None, which leaves the xmax
+          unchanged.
+
+        Examples
+        --------
+
+        >>> import yt
+        >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+        >>> pp = yt.PhasePlot(ds.all_data(), 'density', 'temperature', 'cell_mass')
+        >>> pp.set_xlim(1e-29, 1e-24)
+        >>> pp.save()
+
+        """
+        p = self.profile
+        if xmin is None:
+            xmin = p.x_bins.min()
+        if xmax is None:
+            xmax = p.x_bins.max()
+        units = {p.x_field: str(p.x.units),
+                 p.y_field: str(p.y.units)}
+        zunits = dict((field, str(p.field_units[field])) for field in p.field_units)
+        extrema = {p.x_field: ((xmin, str(p.x.units)), (xmax, str(p.x.units))),
+                   p.y_field: ((p.y_bins.min(), str(p.y.units)),
+                               (p.y_bins.max(), str(p.y.units)))}
+        self.profile = create_profile(
+            p.data_source,
+            [p.x_field, p.y_field],
+            p.field_map.values(),
+            n_bins=[len(p.x_bins)-2, len(p.y_bins)-2],
+            weight_field=p.weight_field,
+            accumulation=p.accumulation,
+            fractional=p.fractional,
+            units=units,
+            extrema=extrema)
+        for field in zunits:
+            self.profile.set_field_unit(field, zunits[field])
+        return self
+
+    @invalidate_plot
+    def set_ylim(self, ymin=None, ymax=None):
+        """Sets the plot limits for the y bin field.
+
+        Parameters
+        ----------
+
+        ymin : float or None
+          The new y minimum.  Defaults to None, which leaves the ymin
+          unchanged.
+
+        ymax : float or None
+          The new y maximum.  Defaults to None, which leaves the ymax
+          unchanged.
+
+        Examples
+        --------
+
+        >>> import yt
+        >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+        >>> pp = yt.PhasePlot(ds.all_data(), 'density', 'temperature', 'cell_mass')
+        >>> pp.set_ylim(1e4, 1e6)
+        >>> pp.save()
+
+        """
+        p = self.profile
+        if ymin is None:
+            ymin = p.y_bins.min()
+        if ymax is None:
+            ymax = p.y_bins.max()
+        units = {p.x_field: str(p.x.units),
+                 p.y_field: str(p.y.units)}
+        zunits = dict((field, str(p.field_units[field])) for field in p.field_units)
+        extrema = {p.x_field: ((p.x_bins.min(), str(p.x.units)),
+                               (p.x_bins.max(), str(p.x.units))),
+                   p.y_field: ((ymin, str(p.y.units)), (ymax, str(p.y.units)))}
+        self.profile = create_profile(
+            p.data_source,
+            [p.x_field, p.y_field],
+            p.field_map.values(),
+            n_bins=[len(p.x_bins), len(p.y_bins)],
+            weight_field=p.weight_field,
+            accumulation=p.accumulation,
+            fractional=p.fractional,
+            units=units,
+            extrema=extrema)
+        for field in zunits:
+            self.profile.set_field_unit(field, zunits[field])
+        return self
+
     def run_callbacks(self, *args):
         raise NotImplementedError
     def setup_callbacks(self, *args):
@@ -901,10 +1098,10 @@
             norm = matplotlib.colors.Normalize(zlim[0], zlim[1])
         self.image = None
         self.cb = None
-        self.image = self.axes.pcolormesh(np.array(x_data), 
-                                          np.array(y_data), 
+        self.image = self.axes.pcolormesh(np.array(x_data),
+                                          np.array(y_data),
                                           np.array(image_data.T),
-                                          norm=norm, 
+                                          norm=norm,
                                           cmap=cmap)
         self.axes.set_xscale(x_scale)
         self.axes.set_yscale(y_scale)


https://bitbucket.org/yt_analysis/yt/commits/6238acba7afa/
Changeset:   6238acba7afa
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-06-04 17:42:21
Summary:     Merged in mzingale/yt/yt-3.0 (pull request #923)

Option for a figure to not be cleared by show_mpl() to allow for annotations
Affected #:  1 file

diff -r d891a87e20d3afc80819da0c038a657169b43d1c -r 6238acba7afaf2ce49353f3305fc6511f90fa9f0 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -620,13 +620,13 @@
             label = '$\\rm{log}\\/ $' + label
         self.transfer_function.vert_cbar(ax=cb.ax, label=label)
 
-    def show_mpl(self, im, enhance=True):
+    def show_mpl(self, im, enhance=True, clear_fig=True):
         if self._pylab is None:
             import pylab
             self._pylab = pylab
         if self._render_figure is None:
             self._render_figure = self._pylab.figure(1)
-        self._render_figure.clf()
+        if clear_fig: self._render_figure.clf()
 
         if enhance:
             nz = im[im > 0.0]
@@ -642,9 +642,9 @@
     def draw(self):
         self._pylab.draw()
     
-    def save_annotated(self, fn, image, enhance=True, dpi=100):
+    def save_annotated(self, fn, image, enhance=True, dpi=100, clear_fig=True):
         image = image.swapaxes(0,1) 
-        ax = self.show_mpl(image, enhance=enhance)
+        ax = self.show_mpl(image, enhance=enhance, clear_fig=clear_fig)
         self.annotate(ax.axes, enhance)
         self._pylab.savefig(fn, bbox_inches='tight', facecolor='black', dpi=dpi)

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