[Yt-svn] yt: Whitespace changes, changed a package name, and updated time...

hg at spacepope.org hg at spacepope.org
Wed Sep 22 17:10:05 PDT 2010


hg Repository: yt
details:   yt/rev/25370ee2cc16
changeset: 3406:25370ee2cc16
user:      Matthew Turk <matthewturk at gmail.com>
date:
Wed Sep 22 17:10:00 2010 -0700
description:
Whitespace changes, changed a package name, and updated time series to work
now.

The following script actually works!


from yt.mods import *

from yt.data_objects.time_series import EnzoTimeSeries

ts = EnzoTimeSeries("collapse_test", output_log = "OutputLog")
sphere = ts.sphere('max', 0.1)
total_mass = sphere.quantities["TotalQuantity"]("CellMassMsun")
print total_mass

diffstat:

 yt/config.py                        |   4 ++--
 yt/data_objects/analyzer_objects.py |  35 ++++++++++++++++++++++++++++++++++-
 yt/data_objects/data_containers.py  |   9 ++++-----
 yt/data_objects/time_series.py      |  32 ++++++++++++++++++++++++++++----
 yt/frontends/gdf/setup.py           |   2 +-
 yt/mods.py                          |   1 +
 6 files changed, 70 insertions(+), 13 deletions(-)

diffs (186 lines):

diff -r 7a02c229811f -r 25370ee2cc16 yt/config.py
--- a/yt/config.py	Wed Sep 22 15:11:24 2010 -0700
+++ b/yt/config.py	Wed Sep 22 17:10:00 2010 -0700
@@ -45,8 +45,8 @@
         },
     "lagos":{
         'ReconstructHierarchy': 'True',
-        'serialize' : 'True',
-        'onlydeserialize' : 'False',
+        'serialize': 'True',
+        'onlydeserialize': 'False',
         'loadfieldplugins':'True',
         'pluginfilename':'my_plugins.py',
         },
diff -r 7a02c229811f -r 25370ee2cc16 yt/data_objects/analyzer_objects.py
--- a/yt/data_objects/analyzer_objects.py	Wed Sep 22 15:11:24 2010 -0700
+++ b/yt/data_objects/analyzer_objects.py	Wed Sep 22 17:10:00 2010 -0700
@@ -1,3 +1,7 @@
+import inspect
+
+from yt.funcs import *
+
 class AnalysisTask(object):
 
     def __init__(self, *args, **kwargs):
@@ -10,7 +14,7 @@
 
     def __repr__(self):
         # Stolen from AMRData.__repr__
-        s = "%s: " % (self.__class__.__name__, self._analysis_type)
+        s = "%s: " % (self.__class__.__name__)
         s += ", ".join(["%s=%s" % (i, getattr(self,i))
                        for i in self._params])
         return s
@@ -59,3 +63,32 @@
         pc = self.PlotCollection(pf, center = self.center)
         pc.add_slice(self.field, self.axis)
         return pc.save()[0]
+
+class QuantityProxy(AnalysisTask):
+    _params = None
+    quantity_name = None
+
+    def __repr__(self):
+        # Stolen from AMRData.__repr__
+        s = "%s: " % (self.__class__.__name__)
+        s += ", ".join(["%s" % [arg for arg in self.args]])
+        s += ", ".join(["%s=%s" % (k,v) for k, v in self.kwargs.items()])
+        return s
+
+    def __init__(self, *args, **kwargs):
+        self.args = args
+        self.kwargs = kwargs
+
+    def eval(self, data_object):
+        rv = data_object.quantities[self.quantity_name](
+            *self.args, **self.kwargs)
+        return rv
+
+def create_quantity_proxy(quantity_object):
+    args, varargs, kwargs, defaults = inspect.getargspec(quantity_object[1])
+    # Strip off 'data' which is on every quantity function
+    params = args[1:] 
+    if kwargs is not None: params += kwargs
+    dd = dict(_params = params, quantity_name = quantity_object[0])
+    cls = type(quantity_object[0], (QuantityProxy,), dd)
+    return cls
diff -r 7a02c229811f -r 25370ee2cc16 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py	Wed Sep 22 15:11:24 2010 -0700
+++ b/yt/data_objects/data_containers.py	Wed Sep 22 17:10:00 2010 -0700
@@ -195,9 +195,9 @@
         elif isinstance(center, (types.ListType, types.TupleType, na.ndarray)):
             center = na.array(center)
         elif center == ("max"): # is this dangerous for race conditions?
-            center = pf.h.find_max("Density")
+            center = self.pf.h.find_max("Density")[1]
         elif center.startswith("max_"):
-            center = pf.h.find_max(center[4:])
+            center = self.pf.h.find_max(center[4:])[1]
         else:
             center = na.array(center, dtype='float64')
         self.center = center
@@ -1009,7 +1009,7 @@
         # Taken from Cutting Plane
         #
         AMR2DData.__init__(self, 4, fields, **kwargs)
-        self.center = center
+        self._set_center(center)
         self.width = width
         self.dims = dims
         self.dds = self.width / self.dims
@@ -2069,8 +2069,7 @@
         """
         AMRData.__init__(self, pf, fields, **kwargs)
         self._set_center(center)
-        self.set_field_parameter("center",center)
-        self.coords = None
+        self.coords = Noe
         self._grids = None
 
     def _generate_coords(self):
diff -r 7a02c229811f -r 25370ee2cc16 yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py	Wed Sep 22 15:11:24 2010 -0700
+++ b/yt/data_objects/time_series.py	Wed Sep 22 17:10:00 2010 -0700
@@ -23,7 +23,13 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-import inspect, functools
+import inspect, functools, weakref
+
+from yt.funcs import *
+from yt.convenience import load
+from .data_containers import data_object_registry
+from .analyzer_objects import create_quantity_proxy
+from .derived_quantities import quantity_info
 
 class TimeSeriesData(object):
     def __init__(self, name):
@@ -51,9 +57,9 @@
 
     def _populate_output_log(self, output_log):
         for line in open(output_log):
-            if not line.startswith(_enzo_header): continue
-            fn = line[len(_enzo_header):].strip()
-            self._insert(EnzoStaticOutput(fn))
+            if not line.startswith(self._enzo_header): continue
+            fn = line[len(self._enzo_header):].strip()
+            self._insert(load(fn))
 
     def __getitem__(self, key):
         if isinstance(key, types.SliceType):
@@ -80,12 +86,30 @@
                 return_values[-1].append(task.eval(arg))
         return return_values
 
+class TimeSeriesQuantitiesContainer(object):
+    def __init__(self, data_object, quantities):
+        self.data_object = data_object
+        self.quantities = quantities
+
+    def __getitem__(self, key):
+        if key not in self.quantities: raise KeyError(key)
+        q = self.quantities[key]
+        def run_quantity_wrapper(quantity, quantity_name):
+            @wraps(quantity_info[quantity_name][1])
+            def run_quantity(*args, **kwargs):
+                to_run = quantity(*args, **kwargs)
+                return self.data_object.eval(to_run)
+            return run_quantity
+        return run_quantity_wrapper(q, key)
+
 class TimeSeriesDataObject(object):
     def __init__(self, time_series, data_object_name, *args, **kwargs):
         self.time_series = weakref.proxy(time_series)
         self.data_object_name = data_object_name
         self._args = args
         self._kwargs = kwargs
+        qs = dict([(qn, create_quantity_proxy(qv)) for qn, qv in quantity_info.items()])
+        self.quantities = TimeSeriesQuantitiesContainer(self, qs)
 
     def eval(self, tasks):
         return self.time_series.eval(tasks, self)
diff -r 7a02c229811f -r 25370ee2cc16 yt/frontends/gdf/setup.py
--- a/yt/frontends/gdf/setup.py	Wed Sep 22 15:11:24 2010 -0700
+++ b/yt/frontends/gdf/setup.py	Wed Sep 22 17:10:00 2010 -0700
@@ -6,7 +6,7 @@
 
 def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration
-    config = Configuration('chombo',parent_package,top_path)
+    config = Configuration('gdf',parent_package,top_path)
     config.make_config_py() # installs __config__.py
     config.make_svn_version_py()
     return config
diff -r 7a02c229811f -r 25370ee2cc16 yt/mods.py
--- a/yt/mods.py	Wed Sep 22 15:11:24 2010 -0700
+++ b/yt/mods.py	Wed Sep 22 17:10:00 2010 -0700
@@ -81,6 +81,7 @@
     PlotCollection, PlotCollectionInteractive, \
     get_multi_plot, FixedResolutionBuffer, ObliqueFixedResolutionBuffer, \
     callback_registry
+
 for name, cls in callback_registry.items():
     exec("%s = cls" % name)
 



More information about the yt-svn mailing list