[Yt-svn] yt: 2 new changesets

hg at spacepope.org hg at spacepope.org
Thu Oct 21 09:31:27 PDT 2010


hg Repository: yt
details:   yt/rev/cf384d5c4cf1
changeset: 3454:cf384d5c4cf1
user:      Matthew Turk <matthewturk at gmail.com>
date:
Wed Oct 20 21:54:15 2010 -0600
description:
* Adding an easy_plots module, wherein very simple recipes for common plot
   types are added.  First one is a simple probability density function.  Much
   like the plot window, these are designed to process some data, make a plot,
   and then return control to the user for more advanced manipulation.
 * Changed default number of bins in profiles to be 128 instead of 64.

hg Repository: yt
details:   yt/rev/74ae175dd525
changeset: 3455:74ae175dd525
user:      Matthew Turk <matthewturk at gmail.com>
date:
Thu Oct 21 09:31:23 2010 -0700
description:
Merging

diffstat:

 yt/convenience.py                   |   5 +-
 yt/visualization/api.py             |   3 +
 yt/visualization/easy_plots.py      |  72 +++++++++++++++++++++++++++++++++++++
 yt/visualization/plot_collection.py |  12 +++---
 4 files changed, 84 insertions(+), 8 deletions(-)

diffs (153 lines):

diff -r 33bc244f64c0 -r 74ae175dd525 yt/convenience.py
--- a/yt/convenience.py	Mon Oct 18 09:27:17 2010 -0500
+++ b/yt/convenience.py	Thu Oct 21 09:31:23 2010 -0700
@@ -33,7 +33,7 @@
 from yt.utilities.parameter_file_storage import \
     output_type_registry
 
-def all_pfs(max_depth=1, name_spec="*.hierarchy", **kwargs):
+def all_pfs(basedir='.',max_depth=1, name_spec="*.hierarchy", **kwargs):
     """
     This function searchs a directory and its sub-directories, up to a depth of
     *max_depth*, for parameter files.  It looks for the *name_spec* and then
@@ -41,9 +41,10 @@
     passed on to the EnzoStaticOutput constructor.
     """
     list_of_names = []
+    basedir = os.path.expanduser(basedir)
     for i in range(max_depth):
         bb = list('*' * i) + [name_spec]
-        list_of_names += glob.glob(os.path.join(*bb))
+        list_of_names += glob.glob(os.path.join(basedir,*bb))
     list_of_names.sort(key=lambda b: os.path.basename(b))
     for fn in list_of_names:
         yield load(fn[:-10], **kwargs)
diff -r 33bc244f64c0 -r 74ae175dd525 yt/visualization/api.py
--- a/yt/visualization/api.py	Mon Oct 18 09:27:17 2010 -0500
+++ b/yt/visualization/api.py	Thu Oct 21 09:31:23 2010 -0700
@@ -51,3 +51,6 @@
 from plot_modifications import \
     PlotCallback, \
     callback_registry
+
+from easy_plots import \
+    plot_type_registry
diff -r 33bc244f64c0 -r 74ae175dd525 yt/visualization/easy_plots.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/visualization/easy_plots.py	Thu Oct 21 09:31:23 2010 -0700
@@ -0,0 +1,72 @@
+"""
+Easy plotting.
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2010 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 _mpl_imports import *
+from yt.data_objects.profiles import BinnedProfile1D
+
+plot_type_registry = {}
+
+class EasyPlot(object):
+    class __metaclass__(type):
+        def __init__(cls, name, b, d):
+            type.__init__(cls, name, b, d)
+            if hasattr(cls, "_type_name"):
+                plot_type_registry[cls._type_name] = cls
+
+    def __init__(self):
+        pass
+
+    def save(self, fn):
+        canvas = FigureCanvasAgg(self.figure)
+        canvas.print_figure(fn)
+
+class EasyPDFPlot(EasyPlot):
+    _type_name = "PDF"
+
+    def __init__(self, data_source, x_field, x_log = True,
+                 n_bins = 128, y_log = True,
+                 plot_args = None,
+                 figure_args = None):
+        if plot_args is None: plot_args = {}
+        if figure_args is None: figure_args = {}
+        self.x_field = x_field
+        self.data_source = data_source
+        # Now we just make the plot
+        x_min, x_max = self.data_source.quantities["Extrema"](
+                x_field, non_zero = x_log, lazy_reader = True)[0]
+        self.profile = BinnedProfile1D(self.data_source,
+            n_bins, self.x_field, x_min, x_max, x_log,
+            lazy_reader = True)
+        self.profile.add_fields(["CellMassMsun"], weight=None)
+        self.profile["CellMassMsun"] /= self.profile["CellMassMsun"].sum()
+        self.figure = matplotlib.figure.Figure(**figure_args)
+        self.axes = self.figure.add_subplot(1,1,1)
+        if y_log and x_log: f = self.axes.loglog
+        elif y_log: f = self.axes.semilogy
+        elif x_log: f = self.axes.semilogx
+        else: f = self.axes.plot
+        self.plot = f(self.profile[x_field], self.profile["CellMassMsun"],
+                      **plot_args)
+        self.axes.set_xlabel(data_source.pf.field_info[x_field].get_label())
diff -r 33bc244f64c0 -r 74ae175dd525 yt/visualization/plot_collection.py
--- a/yt/visualization/plot_collection.py	Mon Oct 18 09:27:17 2010 -0500
+++ b/yt/visualization/plot_collection.py	Thu Oct 21 09:31:23 2010 -0700
@@ -838,7 +838,7 @@
 
     def add_profile_object(self, data_source, fields,
                            weight="CellMassMsun", accumulation=False,
-                           x_bins=64, x_log=True, x_bounds=None,
+                           x_bins=128, x_log=True, x_bounds=None,
                            lazy_reader=True, id=None,
                            figure=None, axes=None):
         r"""From an existing object, create a 1D, binned profile.
@@ -928,7 +928,7 @@
 
     def add_profile_sphere(self, radius, unit, fields, center = None,
                            weight="CellMassMsun", accumulation=False,
-                           x_bins=64, x_log=True, x_bounds=None,
+                           x_bins=128, x_log=True, x_bounds=None,
                            lazy_reader=True, id=None,
                            figure=None, axes=None):
         r"""From a description of a sphere, create a 1D, binned profile.
@@ -1018,8 +1018,8 @@
 
     def add_phase_object(self, data_source, fields, cmap=None,
                                weight="CellMassMsun", accumulation=False,
-                               x_bins=64, x_log=True, x_bounds=None,
-                               y_bins=64, y_log=True, y_bounds=None,
+                               x_bins=128, x_log=True, x_bounds=None,
+                               y_bins=128, y_log=True, y_bounds=None,
                                lazy_reader=True, id=None,
                                axes = None, figure = None,
                                fractional=False):
@@ -1139,8 +1139,8 @@
 
     def add_phase_sphere(self, radius, unit, fields, center = None, cmap=None,
                          weight="CellMassMsun", accumulation=False,
-                         x_bins=64, x_log=True, x_bounds=None,
-                         y_bins=64, y_log=True, y_bounds=None,
+                         x_bins=128, x_log=True, x_bounds=None,
+                         y_bins=128, y_log=True, y_bounds=None,
                          lazy_reader=True, id=None,
                          axes = None, figure = None,
                          fractional=False):



More information about the yt-svn mailing list