[Yt-svn] yt-commit r1257 - in trunk/yt: . raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Fri Apr 17 22:56:26 PDT 2009


Author: mturk
Date: Fri Apr 17 22:56:25 2009
New Revision: 1257
URL: http://yt.spacepope.org/changeset/1257

Log:
Added a new PlotInterface module that handles getting single plots of slices
and projections.  In the yt.mods namespace it is called "plots".  The override
argument in save_image is now by default off.

The following commands now work:

from yt.mods import *
plots.get_slice("galaxy1200.dir/galaxy1200", "Density", 0) 

and alternatively, the string literal can be replaced with a StaticOutput
object.  Right now it's called 'plots' but maybe it should just be imported
into the local namespace.  Center is guessed if not provided.

Phase spheres and profile sphers and whatnot need to be added.

Once Jae-Joon Lee's multi-axis stuff is included in a released MPL, we'll
support that nicely through this interface.  For now though, this is pretty
effective.

I'm closing #158 now, but phase things need to be included.  I have not yet
because I am not yet sure of the appropriate relationship between these
functions and the PlotCollection.  There is some code dupliation that I might
get rid of.



Added:
   trunk/yt/raven/PlotInterface.py
Modified:
   trunk/yt/mods.py
   trunk/yt/raven/PlotTypes.py

Modified: trunk/yt/mods.py
==============================================================================
--- trunk/yt/mods.py	(original)
+++ trunk/yt/mods.py	Fri Apr 17 22:56:25 2009
@@ -62,6 +62,8 @@
 except ImportError:
     pass
 
+import yt.raven.PlotInterface as plots
+
 # Individual imports from Fido
 from yt.fido import GrabCollections, OutputCollection
 

Added: trunk/yt/raven/PlotInterface.py
==============================================================================
--- (empty file)
+++ trunk/yt/raven/PlotInterface.py	Fri Apr 17 22:56:25 2009
@@ -0,0 +1,72 @@
+"""
+A high-level interface that obtains plots outside of a PlotCollection.
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2007-2009 Matthew Turk.  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/>.
+"""
+
+from yt.raven import *
+from yt.funcs import *
+from yt.recipes import _fix_pf
+
+def check_plot_args(func):
+    @wraps(func)
+    def run_func(pf, *args, **kwargs):
+        PlotTypes.Initialize()
+        pf1 = _fix_pf(pf)
+        if "center" not in kwargs:
+            kwargs['center'] = pf1.h.find_max("Density")[1]
+        p = func(pf1, *args, **kwargs)
+        # This next bit is to ensure we have a strong reference
+        # until the plot object is deleted
+        if pf1 is not pf: p["pf"] = pf1
+        return p
+    return run_func
+
+ at check_plot_args
+def get_slice(pf, field, axis, center=None, axes=None, figure=None,
+              use_colorbar=True, **kwargs):
+    """
+    Get a single slice plot, with standard *field*, *axis* and *center*
+    arguments.
+    """
+    coord = center[axis]
+    data_source = pf.hierarchy.slice(axis, coord, field, center, **kwargs)
+    plot = PlotTypes.SlicePlot(data_source, field,
+            use_colorbar=use_colorbar, axes=axes, figure=figure)
+    plot["Axis"] = lagos.axis_names[axis]
+    return plot
+
+ at check_plot_args
+def get_projection(pf, field, axis, weight_field=None, center=None,
+                   axes=None, figure=None,
+              use_colorbar=True, **kwargs):
+    """
+    Get a single projection plot, with standard *field*, *axis* and *center*
+    arguments.
+    """
+    data_source = pf.hierarchy.proj(axis, field, weight_field, center=center, **kwargs)
+    plot = PlotTypes.ProjectionPlot(data_source, field,
+            use_colorbar=use_colorbar, axes=axes, figure=figure)
+    plot["Axis"] = lagos.axis_names[axis]
+    return plot
+
+

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Fri Apr 17 22:56:25 2009
@@ -101,7 +101,7 @@
     def __getitem__(self, item):
         return self.data[item] # Should be returned in CGS
 
-    def save_image(self, prefix, format, submit=None, override=False):
+    def save_image(self, prefix, format="png", submit=None, override=True):
         """
         Save this plot image.  Will generate a filename based on the *prefix*,
         *format*.  *submit* will govern the submission to the Deliverator and



More information about the yt-svn mailing list