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

Bitbucket commits-noreply at bitbucket.org
Sat Jul 7 13:50:42 PDT 2012


6 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/45651e758327/
changeset:   45651e758327
branch:      yt
user:        ngoldbaum
date:        2012-07-07 01:14:43
summary:     Updating the command line tool to use yt plot.  Temporarily disabling
callbacks from the command line until we can port them over to
PlotWindow
affected #:  2 files

diff -r bbdf747507950d710e067f930a46fbbd967e53b2 -r 45651e7583275b5e6d3f68b9330504f0c9dec0f1 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1134,25 +1134,30 @@
         elif args.center is None:
             center = 0.5*(pf.domain_left_edge + pf.domain_right_edge)
         center = na.array(center)
-        pc=PlotCollection(pf, center=center)
         if args.axis == 4:
             axes = range(3)
         else:
             axes = [args.axis]
         for ax in axes:
             mylog.info("Adding plot for axis %i", ax)
-            if args.projection: pc.add_projection(args.field, ax,
-                                    weight_field=args.weight, center=center)
-            else: pc.add_slice(args.field, ax, center=center)
-            if args.grids: pc.plots[-1].modify["grids"]()
+            if args.projection:
+                plt = ProjectionPlot(pf, ax, args.field, center=center,
+                                     width=args.width,
+                                     weight_field=args.weight)
+            else:
+                plt = SlicePlot(pf, ax, args.field, center=center,
+                                width=args.width)
+            if args.grids:
+                warnings.warn("Grids are temporarily disabled from the command line")
             if args.time: 
-                time = pf.current_time*pf['Time']*pf['years']
-                pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2e yr'%time)
-        pc.set_width(args.width, args.unit)
-        pc.set_cmap(args.cmap)
-        if args.zlim: pc.set_zlim(*args.zlim)
-        if not os.path.isdir(args.output): os.makedirs(args.output)
-        pc.save(os.path.join(args.output,"%s" % (pf)))
+                warnings.warn("Time annotation is temporarily disabled from the command line")
+                #time = pf.current_time*pf['Time']*pf['years']
+                #pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2e yr'%time)
+            plt.set_cmap(args.field,args.cmap)
+            if args.zlim:
+                plt.set_zlim(args.field,*args.zlim)
+            if not os.path.isdir(args.output): os.makedirs(args.output)
+            plt.save(os.path.join(args.output,"%s" % (pf)))
 
 class YTRenderCmd(YTCommand):
         


diff -r bbdf747507950d710e067f930a46fbbd967e53b2 -r 45651e7583275b5e6d3f68b9330504f0c9dec0f1 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -224,7 +224,7 @@
 
 def OffAxisSlicePlot(pf, normal, fields, center=None, width=None, north_vector=None):
     r"""
-    SlicePlot(pf, normal, fields, center=None, width=None, north_vector=None)
+    OffAxisSlicePlot(pf, normal, fields, center=None, width=None, north_vector=None)
 
     Given a pf object, a normal vector defining a slicing plonae, and
     a field name string, this will return a PWViewrMPL object
@@ -674,8 +674,13 @@
         self.plots[field].image.set_cmap(cmap)
 
     def save(self,name):
+        axis = axis_names[self.data_source.axis]
+        if 'Slice' in self.data_source.__class__.__name__:
+            type = 'Slice'
+        if 'Proj' in self.data_source.__class__.__name__:
+            type = 'Projection'
         for k,v in self.plots.iteritems():
-            n = "%s_%s" % (name, k)
+            n = "%s_%s_%s_%s" % (name, type, axis, k)
             v.save(n)
 
 class PWViewerRaw(PWViewer):
@@ -877,7 +882,7 @@
         self.cax = self.figure.add_axes((.86,.10,.04,.8))
 
     def save(self,name):
-        print "saving plot %s" % name
+        print "saving plot %s.png" % name
         self.figure.savefig('%s.png' % name)
 
 class WindowPlotMPL(PlotMPL):



https://bitbucket.org/yt_analysis/yt/changeset/7cfa057309e7/
changeset:   7cfa057309e7
branch:      yt
user:        MatthewTurk
date:        2012-07-07 04:20:40
summary:     Modifying the plot window docstrings slightly to fit with the standard.
affected #:  1 file

diff -r 45651e7583275b5e6d3f68b9330504f0c9dec0f1 -r 7cfa057309e72fd218cfb1da31aea042e90ca04c yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -94,8 +94,6 @@
 
 def SlicePlot(pf, axis, fields, center=None, width=None, origin='center-window'):
     r"""
-    SlicePlot(pf, axis, fields, center=None, width=None, origin='center-window')
-
     Given a pf object, an axis to slice along, and a field name
     string, this will return a PWViewrMPL object containing
     the plot.
@@ -105,48 +103,38 @@
 
     Parameters
     ----------
-    pf : :class:`yt.data_objects.apy.StaticOutput`
-
+    pf : :class:`yt.data_objects.api.StaticOutput`
         This is the parameter file object corresponding to the
         simulation output to be plotted.
-
     axis : int
-
-         An int corresponding to the axis to slice along.  
-	 (0 : x, 1 : y, 2 : z)
-
+        An int corresponding to the axis to slice along.  (0=x, 1=y, 2=z)
     fields : string
-    
-          The name of the field(s) to be plotted.
-
+        The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or
              'center'
+        The coordinate of the center of the image.  If left blanck,
+        the image centers on the location of the maximum density
+        cell.  If set to 'c' or 'center', the plot is centered on
+        the middle of the domain.
+    width : A tuple or a float
+        A tuple containing the width of image and the string key of
+        the unit: (width, 'unit').  If set to a float, code units
+        are assumed
+    origin : A string
+        The location of the origin of the plot coordinate system.
+        Currently, can be set to three options: 'left-domain', corresponding
+        to the bottom-left hand corner of the simulation domain, 'left-window',
+        corresponding to the bottom-left hand cordiner of the plot window, or
+        'center-window' for the center of the plot window.
 
-           The coordinate of the center of the image.  If left blanck,
-           the image centers on the location of the maximum density
-           cell.  If set to 'c' or 'center', the plot is centered on
-           the middle of the domain.
+    Examples
+    --------
 
-    width : A tuple or a float
-    
-           A tuple containing the width of image and the string key of
-           the unit: (width, 'unit').  If set to a float, code units
-           are assumed
+    This is a very simple way of creating a slice plot.
 
-    origin : A string
-
-            The location of the origin of the plot coordinate system.
-            Currently, can be set to three options:
-
-	    'left-domain':
-	         The bottom-left hand corner of the simulation domain.
-
-            'left-window':
-	         The bottom-left hand cordiner of the plot window.
-
-	    'center-window'
-	         The center of the plot window.
-
+    >>> pf = load('galaxy0030/galaxy0030')
+    >>> p = SlicePlot(pf,2,'Density','c',(20,'kpc'))
+    >>> p.save('sliceplot')
     """
     (bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
     slice = pf.h.slice(axis,center[axis],fields=fields)
@@ -155,9 +143,6 @@
 def ProjectionPlot(pf, axis, fields, center=None, width=None,
                    weight_field=None, max_level=None, origin='center-window'):
     r"""
-    ProjectionPlot(pf, axis, fields, center=None, width=None, 
-                   weight_field=None, max_level=None, origin='center-window')
-
     Given a pf object, an axis to project along, and a field name
     string, this will return a PWViewrMPL object containing
     the plot.
@@ -167,55 +152,48 @@
 
     Parameters
     ----------
-    pf : :class:`yt.data_objects.apy.StaticOutput`
-
+    pf : :class:`yt.data_objects.api.StaticOutput`
         This is the parameter file object corresponding to the
         simulation output to be plotted.
-
     axis : int
-
-         An int corresponding to the axis to project along.  
-	 (0 : x, 1 : y, 2 : z)
-
+        An int corresponding to the axis to slice along.  (0=x, 1=y, 2=z)
     fields : string
-    
-          The name of the field(s) to be plotted.
-
+        The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or
              'center'
+        The coordinate of the center of the image.  If left blanck,
+        the image centers on the location of the maximum density
+        cell.  If set to 'c' or 'center', the plot is centered on
+        the middle of the domain.
+    width : A tuple or a float
+        A tuple containing the width of image and the string key of
+        the unit: (width, 'unit').  If set to a float, code units
+        are assumed
+    origin : A string
+        The location of the origin of the plot coordinate system.
+        Currently, can be set to three options: 'left-domain', corresponding
+        to the bottom-left hand corner of the simulation domain, 'left-window',
+        corresponding to the bottom-left hand cordiner of the plot window, or
+        'center-window' for the center of the plot window.
+    weight_field : string
+        The name of the weighting field.  Set to None for no weight.
+    max_level: int
+        The maximum level to project to.
+    origin : A string
+        The location of the origin of the plot coordinate system.
+        Currently, can be set to three options: 'left-domain', corresponding
+        to the bottom-left hand corner of the simulation domain, 'left-window',
+        corresponding to the bottom-left hand cordiner of the plot window, or
+        'center-window' for the center of the plot window.
 
-           The coordinate of the center of the image.  If left blanck,
-           the image centers on the location of the maximum density
-           cell.  If set to 'c' or 'center', the plot is centered on
-           the middle of the domain.
+    Examples
+    --------
 
-    width : A tuple or a float
-    
-           A tuple containing the width of image and the string key of
-           the unit: (width, 'unit').  If set to a float, code units
-           are assumed
+    This is a very simple way of creating a projection plot.
 
-    weight_field : string
-
-            The name of the weighting field.  Set to None for no weight.
-
-    max_level: int
-
-            The maximum level to project to.
-            
-    origin : string
-
-            The location of the origin of the plot coordinate system.
-            Currently, can be set to three options:
-
-	    'left-domain':
-	         The bottom-left hand corner of the simulation domain.
-
-            'left-window':
-	         The bottom-left hand cordiner of the plot window.
-
-	    'center-window'
-	         The center of the plot window.
+    >>> pf = load('galaxy0030/galaxy0030')
+    >>> p = ProjectionPlot(pf,2,'Density','c',(20,'kpc'))
+    >>> p.save('sliceplot')
 
     """
     (bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
@@ -224,9 +202,7 @@
 
 def OffAxisSlicePlot(pf, normal, fields, center=None, width=None, north_vector=None):
     r"""
-    OffAxisSlicePlot(pf, normal, fields, center=None, width=None, north_vector=None)
-
-    Given a pf object, a normal vector defining a slicing plonae, and
+    Given a pf object, a normal vector defining a slicing plane, and
     a field name string, this will return a PWViewrMPL object
     containing the plot.
 
@@ -235,39 +211,27 @@
 
     Parameters
     ----------
-    pf : :class:`yt.data_objects.apy.StaticOutput`
-
+    pf : :class:`yt.data_objects.api.StaticOutput`
         This is the parameter file object corresponding to the
         simulation output to be plotted.
-
     normal : a sequence of floats
-
          The vector normal to the slicing plane.
-
     fields : string
-    
-          The name of the field(s) to be plotted.
-
+        The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or
              'center'
-
-           The coordinate of the center of the image.  If left blanck,
-           the image centers on the location of the maximum density
-           cell.  If set to 'c' or 'center', the plot is centered on
-           the middle of the domain.
-
+        The coordinate of the center of the image.  If left blanck,
+        the image centers on the location of the maximum density
+        cell.  If set to 'c' or 'center', the plot is centered on
+        the middle of the domain.
     width : A tuple or a float
-    
-           A tuple containing the width of image and the string key of
-           the unit: (width, 'unit').  If set to a float, code units
-           are assumed
-
+        A tuple containing the width of image and the string key of
+        the unit: (width, 'unit').  If set to a float, code units
+        are assumed
     north-vector : a sequence of floats
-    
-           A vector defining the 'up' direction in the plot.  This
-           option sets the orientation of the slicing plane.  If not
-           set, an arbitrary grid-aligned north-vector is chosen.
-
+        A vector defining the 'up' direction in the plot.  This
+        option sets the orientation of the slicing plane.  If not
+        set, an arbitrary grid-aligned north-vector is chosen.
     """
     (bounds,center_rot) = GetOffAxisBoundsAndCenter(normal,center,width,pf)
     cutting = pf.h.cutting(normal,center,fields=fields,north_vector=north_vector)



https://bitbucket.org/yt_analysis/yt/changeset/4f6f912d7c36/
changeset:   4f6f912d7c36
branch:      yt
user:        MatthewTurk
date:        2012-07-07 05:07:02
summary:     First pass at getting grid callbacks to work.  This in principle should work
for all of the callbacks, but we will need to investigate each individually.
Grids now work.  The syntactic sugar for adding them should be added as well.

Example script for this iteration:

http://paste.yt-project.org/show/2527/
affected #:  2 files

diff -r 7cfa057309e72fd218cfb1da31aea042e90ca04c -r 4f6f912d7c3668cdcbc85d6bc77829ad8722b0f4 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -275,10 +275,10 @@
         for px_off, py_off in zip(pxs.ravel(), pys.ravel()):
             pxo = px_off * dom[px_index]
             pyo = py_off * dom[py_index]
-            left_edge_px = (GLE[:,px_index]+pxo-x0)*dx
-            left_edge_py = (GLE[:,py_index]+pyo-y0)*dy
-            right_edge_px = (GRE[:,px_index]+pxo-x0)*dx
-            right_edge_py = (GRE[:,py_index]+pyo-y0)*dy
+            left_edge_px = (GLE[:,px_index]+pxo-x0)*dx + xx0
+            left_edge_py = (GLE[:,py_index]+pyo-y0)*dy + yy0
+            right_edge_px = (GRE[:,px_index]+pxo-x0)*dx + xx0
+            right_edge_py = (GRE[:,py_index]+pyo-y0)*dy + yy0
             verts = na.array(
                     [(left_edge_px, left_edge_px, right_edge_px, right_edge_px),
                      (left_edge_py, right_edge_py, right_edge_py, left_edge_py)])


diff -r 7cfa057309e72fd218cfb1da31aea042e90ca04c -r 4f6f912d7c3668cdcbc85d6bc77829ad8722b0f4 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -72,6 +72,21 @@
 
 field_transforms = {}
 
+class IMPlot(object): pass
+
+class CallbackWrapper(object):
+    def __init__(self, window_plot, frb, field):
+        self.data = frb.data_source
+        self._axes = window_plot.axes
+        self._figure = window_plot.figure
+        if len(self._axes.images) > 0:
+            self.image = self._axes.images[0]
+        self._period = frb.pf.domain_width
+        self.pf = frb.pf
+        self.xlim = (frb.bounds[0], frb.bounds[1])
+        self.ylim = (frb.bounds[2], frb.bounds[3])
+        self._type_name = ''
+
 class FieldTransform(object):
     def __init__(self, name, func, locator):
         self.name = name
@@ -327,6 +342,7 @@
         if self.data_source.center is not None and oblique == False:
             center = [self.data_source.center[i] for i in range(len(self.data_source.center)) if i != self.data_source.axis]
             self.set_center(center)
+        self._callbacks = []
         self._initfinished = True
 
     def __getitem__(self, item):
@@ -632,6 +648,10 @@
 
             cb.set_label(r'$\rm{'+f.encode('string-escape')+r'}\/\/('+md['units']+r')$')
 
+            for callback in self._callbacks:
+                cbr = CallbackWrapper(self.plots[f], self._frb, f)
+                callback(cbr)
+
         self._plot_valid = True
 
     def set_cmap(self, field, cmap):



https://bitbucket.org/yt_analysis/yt/changeset/97a845b8b280/
changeset:   97a845b8b280
branch:      yt
user:        ngoldbaum
date:        2012-07-07 09:03:38
summary:     Numerous fixes for plotwindow plus working callbacks from the command line.
The yt colormaps should now show up for PlotWindowMPL.
affected #:  2 files

diff -r 4f6f912d7c3668cdcbc85d6bc77829ad8722b0f4 -r 97a845b8b280c92188b3aae09f359965615edcf8 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1148,11 +1148,11 @@
                 plt = SlicePlot(pf, ax, args.field, center=center,
                                 width=args.width)
             if args.grids:
-                warnings.warn("Grids are temporarily disabled from the command line")
+                plt.draw_grids()
             if args.time: 
-                warnings.warn("Time annotation is temporarily disabled from the command line")
-                #time = pf.current_time*pf['Time']*pf['years']
-                #pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2e yr'%time)
+                time = pf.current_time*pf['Time']*pf['years']
+                plt.annotate_text((0.2,0.8), 't = %5.2e yr'%time)
+
             plt.set_cmap(args.field,args.cmap)
             if args.zlim:
                 plt.set_zlim(args.field,*args.zlim)


diff -r 4f6f912d7c3668cdcbc85d6bc77829ad8722b0f4 -r 97a845b8b280c92188b3aae09f359965615edcf8 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -30,12 +30,14 @@
 from functools import wraps
 
 import numpy as na
+from .color_maps import yt_colormaps, is_colormap
 from .image_writer import \
     write_image, apply_colormap
 from .fixed_resolution import \
     FixedResolutionBuffer, \
     ObliqueFixedResolutionBuffer
-from .plot_modifications import get_smallest_appropriate_unit
+from .plot_modifications import get_smallest_appropriate_unit, \
+    GridBoundaryCallback, TextLabelCallback
 from .tick_locators import LogLocator, LinearLocator
 from yt.utilities.delaunay.triangulate import Triangulation as triang
 
@@ -256,7 +258,7 @@
 
 def GetBoundsAndCenter(axis, center, width, pf):
     if width == None:
-        width = (pf.domain_right_edge - pf.domain_left_edge)
+        width = 1.0
     elif iterable(width):
         w,u = width
         width = w/pf[u]
@@ -342,7 +344,6 @@
         if self.data_source.center is not None and oblique == False:
             center = [self.data_source.center[i] for i in range(len(self.data_source.center)) if i != self.data_source.axis]
             self.set_center(center)
-        self._callbacks = []
         self._initfinished = True
 
     def __getitem__(self, item):
@@ -475,10 +476,6 @@
         Wy = self.ylim[1] - self.ylim[0]
         return (Wx, Wy)
 
-    # @property
-    # def window(self):
-    #     return self.xlim + self.ylim
-
     @invalidate_data
     def set_antialias(self,aa):
         self.antialias = aa
@@ -510,6 +507,9 @@
         self._colormaps = defaultdict(lambda: 'algae')
         self.zmin = None
         self.zmax = None
+        self._draw_grids = False
+        self._annotate_text = False
+        self._callbacks = []
         self._field_transform = {}
         for field in self._frb.data.keys():
             if self.pf.field_info[field].take_log:
@@ -552,6 +552,16 @@
         self.zmin = zmin
         self.zmax = zmax
 
+    @invalidate_plot
+    def draw_grids(self, alpha=1.0, min_pix=1, annotate = False, periodic = True):
+        self._draw_grids = True
+        self.grid_params = (alpha, min_pix, annotate, periodic)
+
+    @invalidate_plot
+    def annotate_text(self, position, message, data_coords = False, text_args = None):
+        self._annotate_text = True
+        self.text_params = (position, message, data_coords, text_args)
+
     def get_metadata(self, field, strip_mathml = True, return_string = True):
         fval = self._frb[field]
         mi = fval.min()
@@ -632,7 +642,8 @@
             extent.extend([self.xlim[i] - yc for i in (0,1)])
             extent = [el*self.pf[md['unit']] for el in extent]
 
-            self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], zlim = (self.zmin,self.zmax))
+            self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], 
+                                          self._colormaps[f], zlim = (self.zmin,self.zmax))
             
             cb = matplotlib.pyplot.colorbar(self.plots[f].image,cax = self.plots[f].cax)
 
@@ -648,13 +659,29 @@
 
             cb.set_label(r'$\rm{'+f.encode('string-escape')+r'}\/\/('+md['units']+r')$')
 
+            if self._draw_grids:
+                self._callbacks.append(GridBoundaryCallback(*self.grid_params))
+
+            if self._annotate_text:
+                self._callbacks.append(TextLabelCallback(*self.text_params))
+                
             for callback in self._callbacks:
                 cbr = CallbackWrapper(self.plots[f], self._frb, f)
                 callback(cbr)
 
         self._plot_valid = True
 
+    @invalidate_plot
     def set_cmap(self, 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))
+        else:
+            self.cmap = cmap
         self.plots[field].image.set_cmap(cmap)
 
     def save(self,name):
@@ -870,14 +897,15 @@
         self.figure.savefig('%s.png' % name)
 
 class WindowPlotMPL(PlotMPL):
-    def __init__(self, data, extent, field_transform, size=(9,8), zlim = (None, None)):
+    def __init__(self, data, extent, field_transform, cmap, size=(9,8), zlim = (None, None)):
         PlotMPL.__init__(self, data, size)
-        self.__init_image(data, extent, field_transform, zlim)
+        self.__init_image(data, extent, field_transform, zlim, cmap)
 
-    def __init_image(self, data, extent, field_transform, zlim):
+    def __init_image(self, data, extent, field_transform, zlim, 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 = zlim[0], vmax = zlim[1])
+        self.image = self.axes.imshow(data, origin='lower', extent = extent,
+                                      norm = norm, vmin = zlim[0], vmax = zlim[1],
+                                      cmap = cmap)



https://bitbucket.org/yt_analysis/yt/changeset/624a9a5d599c/
changeset:   624a9a5d599c
branch:      yt
user:        ngoldbaum
date:        2012-07-07 20:30:16
summary:     Removing this enzo-ism.
affected #:  1 file

diff -r 97a845b8b280c92188b3aae09f359965615edcf8 -r 624a9a5d599c59cf4b99f79ede3fdece184c3bb7 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -258,7 +258,7 @@
 
 def GetBoundsAndCenter(axis, center, width, pf):
     if width == None:
-        width = 1.0
+        width = pf.domain_width.min()
     elif iterable(width):
         w,u = width
         width = w/pf[u]



https://bitbucket.org/yt_analysis/yt/changeset/2cdcd4e65129/
changeset:   2cdcd4e65129
branch:      yt
user:        MatthewTurk
date:        2012-07-07 22:50:40
summary:     Merged in ngoldbaum/yt-ngoldbaum (pull request #187)
affected #:  3 files

diff -r a5b46d54d7f768b64c6d75ec6c504940438aaca0 -r 2cdcd4e6512919d48d3d1292864f26be791601c0 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1133,25 +1133,30 @@
         elif args.center is None:
             center = 0.5*(pf.domain_left_edge + pf.domain_right_edge)
         center = na.array(center)
-        pc=PlotCollection(pf, center=center)
         if args.axis == 4:
             axes = range(3)
         else:
             axes = [args.axis]
         for ax in axes:
             mylog.info("Adding plot for axis %i", ax)
-            if args.projection: pc.add_projection(args.field, ax,
-                                    weight_field=args.weight, center=center)
-            else: pc.add_slice(args.field, ax, center=center)
-            if args.grids: pc.plots[-1].modify["grids"]()
+            if args.projection:
+                plt = ProjectionPlot(pf, ax, args.field, center=center,
+                                     width=args.width,
+                                     weight_field=args.weight)
+            else:
+                plt = SlicePlot(pf, ax, args.field, center=center,
+                                width=args.width)
+            if args.grids:
+                plt.draw_grids()
             if args.time: 
                 time = pf.current_time*pf['Time']*pf['years']
-                pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2e yr'%time)
-        pc.set_width(args.width, args.unit)
-        pc.set_cmap(args.cmap)
-        if args.zlim: pc.set_zlim(*args.zlim)
-        if not os.path.isdir(args.output): os.makedirs(args.output)
-        pc.save(os.path.join(args.output,"%s" % (pf)))
+                plt.annotate_text((0.2,0.8), 't = %5.2e yr'%time)
+
+            plt.set_cmap(args.field,args.cmap)
+            if args.zlim:
+                plt.set_zlim(args.field,*args.zlim)
+            if not os.path.isdir(args.output): os.makedirs(args.output)
+            plt.save(os.path.join(args.output,"%s" % (pf)))
 
 class YTRenderCmd(YTCommand):
         


diff -r a5b46d54d7f768b64c6d75ec6c504940438aaca0 -r 2cdcd4e6512919d48d3d1292864f26be791601c0 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -275,10 +275,10 @@
         for px_off, py_off in zip(pxs.ravel(), pys.ravel()):
             pxo = px_off * dom[px_index]
             pyo = py_off * dom[py_index]
-            left_edge_px = (GLE[:,px_index]+pxo-x0)*dx
-            left_edge_py = (GLE[:,py_index]+pyo-y0)*dy
-            right_edge_px = (GRE[:,px_index]+pxo-x0)*dx
-            right_edge_py = (GRE[:,py_index]+pyo-y0)*dy
+            left_edge_px = (GLE[:,px_index]+pxo-x0)*dx + xx0
+            left_edge_py = (GLE[:,py_index]+pyo-y0)*dy + yy0
+            right_edge_px = (GRE[:,px_index]+pxo-x0)*dx + xx0
+            right_edge_py = (GRE[:,py_index]+pyo-y0)*dy + yy0
             verts = na.array(
                     [(left_edge_px, left_edge_px, right_edge_px, right_edge_px),
                      (left_edge_py, right_edge_py, right_edge_py, left_edge_py)])


diff -r a5b46d54d7f768b64c6d75ec6c504940438aaca0 -r 2cdcd4e6512919d48d3d1292864f26be791601c0 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -30,12 +30,14 @@
 from functools import wraps
 
 import numpy as na
+from .color_maps import yt_colormaps, is_colormap
 from .image_writer import \
     write_image, apply_colormap
 from .fixed_resolution import \
     FixedResolutionBuffer, \
     ObliqueFixedResolutionBuffer
-from .plot_modifications import get_smallest_appropriate_unit
+from .plot_modifications import get_smallest_appropriate_unit, \
+    GridBoundaryCallback, TextLabelCallback
 from .tick_locators import LogLocator, LinearLocator
 from yt.utilities.delaunay.triangulate import Triangulation as triang
 
@@ -72,6 +74,21 @@
 
 field_transforms = {}
 
+class IMPlot(object): pass
+
+class CallbackWrapper(object):
+    def __init__(self, window_plot, frb, field):
+        self.data = frb.data_source
+        self._axes = window_plot.axes
+        self._figure = window_plot.figure
+        if len(self._axes.images) > 0:
+            self.image = self._axes.images[0]
+        self._period = frb.pf.domain_width
+        self.pf = frb.pf
+        self.xlim = (frb.bounds[0], frb.bounds[1])
+        self.ylim = (frb.bounds[2], frb.bounds[3])
+        self._type_name = ''
+
 class FieldTransform(object):
     def __init__(self, name, func, locator):
         self.name = name
@@ -94,8 +111,6 @@
 
 def SlicePlot(pf, axis, fields, center=None, width=None, origin='center-window'):
     r"""
-    SlicePlot(pf, axis, fields, center=None, width=None, origin='center-window')
-
     Given a pf object, an axis to slice along, and a field name
     string, this will return a PWViewrMPL object containing
     the plot.
@@ -105,48 +120,38 @@
 
     Parameters
     ----------
-    pf : :class:`yt.data_objects.apy.StaticOutput`
-
+    pf : :class:`yt.data_objects.api.StaticOutput`
         This is the parameter file object corresponding to the
         simulation output to be plotted.
-
     axis : int
-
-         An int corresponding to the axis to slice along.  
-	 (0 : x, 1 : y, 2 : z)
-
+        An int corresponding to the axis to slice along.  (0=x, 1=y, 2=z)
     fields : string
-    
-          The name of the field(s) to be plotted.
-
+        The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or
              'center'
+        The coordinate of the center of the image.  If left blanck,
+        the image centers on the location of the maximum density
+        cell.  If set to 'c' or 'center', the plot is centered on
+        the middle of the domain.
+    width : A tuple or a float
+        A tuple containing the width of image and the string key of
+        the unit: (width, 'unit').  If set to a float, code units
+        are assumed
+    origin : A string
+        The location of the origin of the plot coordinate system.
+        Currently, can be set to three options: 'left-domain', corresponding
+        to the bottom-left hand corner of the simulation domain, 'left-window',
+        corresponding to the bottom-left hand cordiner of the plot window, or
+        'center-window' for the center of the plot window.
 
-           The coordinate of the center of the image.  If left blanck,
-           the image centers on the location of the maximum density
-           cell.  If set to 'c' or 'center', the plot is centered on
-           the middle of the domain.
+    Examples
+    --------
 
-    width : A tuple or a float
-    
-           A tuple containing the width of image and the string key of
-           the unit: (width, 'unit').  If set to a float, code units
-           are assumed
+    This is a very simple way of creating a slice plot.
 
-    origin : A string
-
-            The location of the origin of the plot coordinate system.
-            Currently, can be set to three options:
-
-	    'left-domain':
-	         The bottom-left hand corner of the simulation domain.
-
-            'left-window':
-	         The bottom-left hand cordiner of the plot window.
-
-	    'center-window'
-	         The center of the plot window.
-
+    >>> pf = load('galaxy0030/galaxy0030')
+    >>> p = SlicePlot(pf,2,'Density','c',(20,'kpc'))
+    >>> p.save('sliceplot')
     """
     (bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
     slice = pf.h.slice(axis,center[axis],fields=fields)
@@ -155,9 +160,6 @@
 def ProjectionPlot(pf, axis, fields, center=None, width=None,
                    weight_field=None, max_level=None, origin='center-window'):
     r"""
-    ProjectionPlot(pf, axis, fields, center=None, width=None, 
-                   weight_field=None, max_level=None, origin='center-window')
-
     Given a pf object, an axis to project along, and a field name
     string, this will return a PWViewrMPL object containing
     the plot.
@@ -167,55 +169,48 @@
 
     Parameters
     ----------
-    pf : :class:`yt.data_objects.apy.StaticOutput`
-
+    pf : :class:`yt.data_objects.api.StaticOutput`
         This is the parameter file object corresponding to the
         simulation output to be plotted.
-
     axis : int
-
-         An int corresponding to the axis to project along.  
-	 (0 : x, 1 : y, 2 : z)
-
+        An int corresponding to the axis to slice along.  (0=x, 1=y, 2=z)
     fields : string
-    
-          The name of the field(s) to be plotted.
-
+        The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or
              'center'
+        The coordinate of the center of the image.  If left blanck,
+        the image centers on the location of the maximum density
+        cell.  If set to 'c' or 'center', the plot is centered on
+        the middle of the domain.
+    width : A tuple or a float
+        A tuple containing the width of image and the string key of
+        the unit: (width, 'unit').  If set to a float, code units
+        are assumed
+    origin : A string
+        The location of the origin of the plot coordinate system.
+        Currently, can be set to three options: 'left-domain', corresponding
+        to the bottom-left hand corner of the simulation domain, 'left-window',
+        corresponding to the bottom-left hand cordiner of the plot window, or
+        'center-window' for the center of the plot window.
+    weight_field : string
+        The name of the weighting field.  Set to None for no weight.
+    max_level: int
+        The maximum level to project to.
+    origin : A string
+        The location of the origin of the plot coordinate system.
+        Currently, can be set to three options: 'left-domain', corresponding
+        to the bottom-left hand corner of the simulation domain, 'left-window',
+        corresponding to the bottom-left hand cordiner of the plot window, or
+        'center-window' for the center of the plot window.
 
-           The coordinate of the center of the image.  If left blanck,
-           the image centers on the location of the maximum density
-           cell.  If set to 'c' or 'center', the plot is centered on
-           the middle of the domain.
+    Examples
+    --------
 
-    width : A tuple or a float
-    
-           A tuple containing the width of image and the string key of
-           the unit: (width, 'unit').  If set to a float, code units
-           are assumed
+    This is a very simple way of creating a projection plot.
 
-    weight_field : string
-
-            The name of the weighting field.  Set to None for no weight.
-
-    max_level: int
-
-            The maximum level to project to.
-            
-    origin : string
-
-            The location of the origin of the plot coordinate system.
-            Currently, can be set to three options:
-
-	    'left-domain':
-	         The bottom-left hand corner of the simulation domain.
-
-            'left-window':
-	         The bottom-left hand cordiner of the plot window.
-
-	    'center-window'
-	         The center of the plot window.
+    >>> pf = load('galaxy0030/galaxy0030')
+    >>> p = ProjectionPlot(pf,2,'Density','c',(20,'kpc'))
+    >>> p.save('sliceplot')
 
     """
     (bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
@@ -224,9 +219,7 @@
 
 def OffAxisSlicePlot(pf, normal, fields, center=None, width=None, north_vector=None):
     r"""
-    SlicePlot(pf, normal, fields, center=None, width=None, north_vector=None)
-
-    Given a pf object, a normal vector defining a slicing plonae, and
+    Given a pf object, a normal vector defining a slicing plane, and
     a field name string, this will return a PWViewrMPL object
     containing the plot.
 
@@ -235,39 +228,27 @@
 
     Parameters
     ----------
-    pf : :class:`yt.data_objects.apy.StaticOutput`
-
+    pf : :class:`yt.data_objects.api.StaticOutput`
         This is the parameter file object corresponding to the
         simulation output to be plotted.
-
     normal : a sequence of floats
-
          The vector normal to the slicing plane.
-
     fields : string
-    
-          The name of the field(s) to be plotted.
-
+        The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or
              'center'
-
-           The coordinate of the center of the image.  If left blanck,
-           the image centers on the location of the maximum density
-           cell.  If set to 'c' or 'center', the plot is centered on
-           the middle of the domain.
-
+        The coordinate of the center of the image.  If left blanck,
+        the image centers on the location of the maximum density
+        cell.  If set to 'c' or 'center', the plot is centered on
+        the middle of the domain.
     width : A tuple or a float
-    
-           A tuple containing the width of image and the string key of
-           the unit: (width, 'unit').  If set to a float, code units
-           are assumed
-
+        A tuple containing the width of image and the string key of
+        the unit: (width, 'unit').  If set to a float, code units
+        are assumed
     north-vector : a sequence of floats
-    
-           A vector defining the 'up' direction in the plot.  This
-           option sets the orientation of the slicing plane.  If not
-           set, an arbitrary grid-aligned north-vector is chosen.
-
+        A vector defining the 'up' direction in the plot.  This
+        option sets the orientation of the slicing plane.  If not
+        set, an arbitrary grid-aligned north-vector is chosen.
     """
     (bounds,center_rot) = GetOffAxisBoundsAndCenter(normal,center,width,pf)
     cutting = pf.h.cutting(normal,center,fields=fields,north_vector=north_vector)
@@ -277,7 +258,7 @@
 
 def GetBoundsAndCenter(axis, center, width, pf):
     if width == None:
-        width = (pf.domain_right_edge - pf.domain_left_edge)
+        width = pf.domain_width.min()
     elif iterable(width):
         w,u = width
         width = w/pf[u]
@@ -495,10 +476,6 @@
         Wy = self.ylim[1] - self.ylim[0]
         return (Wx, Wy)
 
-    # @property
-    # def window(self):
-    #     return self.xlim + self.ylim
-
     @invalidate_data
     def set_antialias(self,aa):
         self.antialias = aa
@@ -530,6 +507,9 @@
         self._colormaps = defaultdict(lambda: 'algae')
         self.zmin = None
         self.zmax = None
+        self._draw_grids = False
+        self._annotate_text = False
+        self._callbacks = []
         self._field_transform = {}
         for field in self._frb.data.keys():
             if self.pf.field_info[field].take_log:
@@ -572,6 +552,16 @@
         self.zmin = zmin
         self.zmax = zmax
 
+    @invalidate_plot
+    def draw_grids(self, alpha=1.0, min_pix=1, annotate = False, periodic = True):
+        self._draw_grids = True
+        self.grid_params = (alpha, min_pix, annotate, periodic)
+
+    @invalidate_plot
+    def annotate_text(self, position, message, data_coords = False, text_args = None):
+        self._annotate_text = True
+        self.text_params = (position, message, data_coords, text_args)
+
     def get_metadata(self, field, strip_mathml = True, return_string = True):
         fval = self._frb[field]
         mi = fval.min()
@@ -652,7 +642,8 @@
             extent.extend([self.xlim[i] - yc for i in (0,1)])
             extent = [el*self.pf[md['unit']] for el in extent]
 
-            self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], zlim = (self.zmin,self.zmax))
+            self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], 
+                                          self._colormaps[f], zlim = (self.zmin,self.zmax))
             
             cb = matplotlib.pyplot.colorbar(self.plots[f].image,cax = self.plots[f].cax)
 
@@ -668,14 +659,39 @@
 
             cb.set_label(r'$\rm{'+f.encode('string-escape')+r'}\/\/('+md['units']+r')$')
 
+            if self._draw_grids:
+                self._callbacks.append(GridBoundaryCallback(*self.grid_params))
+
+            if self._annotate_text:
+                self._callbacks.append(TextLabelCallback(*self.text_params))
+                
+            for callback in self._callbacks:
+                cbr = CallbackWrapper(self.plots[f], self._frb, f)
+                callback(cbr)
+
         self._plot_valid = True
 
+    @invalidate_plot
     def set_cmap(self, 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))
+        else:
+            self.cmap = cmap
         self.plots[field].image.set_cmap(cmap)
 
     def save(self,name):
+        axis = axis_names[self.data_source.axis]
+        if 'Slice' in self.data_source.__class__.__name__:
+            type = 'Slice'
+        if 'Proj' in self.data_source.__class__.__name__:
+            type = 'Projection'
         for k,v in self.plots.iteritems():
-            n = "%s_%s" % (name, k)
+            n = "%s_%s_%s_%s" % (name, type, axis, k)
             v.save(n)
 
 class PWViewerRaw(PWViewer):
@@ -877,18 +893,19 @@
         self.cax = self.figure.add_axes((.86,.10,.04,.8))
 
     def save(self,name):
-        print "saving plot %s" % name
+        print "saving plot %s.png" % name
         self.figure.savefig('%s.png' % name)
 
 class WindowPlotMPL(PlotMPL):
-    def __init__(self, data, extent, field_transform, size=(9,8), zlim = (None, None)):
+    def __init__(self, data, extent, field_transform, cmap, size=(9,8), zlim = (None, None)):
         PlotMPL.__init__(self, data, size)
-        self.__init_image(data, extent, field_transform, zlim)
+        self.__init_image(data, extent, field_transform, zlim, cmap)
 
-    def __init_image(self, data, extent, field_transform, zlim):
+    def __init_image(self, data, extent, field_transform, zlim, 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 = zlim[0], vmax = zlim[1])
+        self.image = self.axes.imshow(data, origin='lower', extent = extent,
+                                      norm = norm, vmin = zlim[0], vmax = zlim[1],
+                                      cmap = cmap)

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