[Yt-svn] yt: 4 new changesets

hg at spacepope.org hg at spacepope.org
Fri Jan 28 20:31:02 PST 2011


hg Repository: yt
details:   yt/rev/6c13341d63d9
changeset: 3697:6c13341d63d9
user:      Matthew Turk <matthewturk at gmail.com>
date:
Fri Jan 28 22:25:20 2011 -0500
description:
Minor change to install script to print the afterword to the log file.

hg Repository: yt
details:   yt/rev/79cf5a4f7103
changeset: 3698:79cf5a4f7103
user:      Matthew Turk <matthewturk at gmail.com>
date:
Fri Jan 28 23:01:52 2011 -0500
description:
Some more fiddling with time-series calculations.  Setting up time-series
analysis tasks was a bit complex and heavy; this is now easier with a
decorator.  For instance, now you can do:

   from yt.mods import *
   from yt.data_objects.api import *
   import yt.data_objects.analyzer_objects as ao

   ts = EnzoTimeSeries("PopulationIII", output_log = "OutputLog")

   @ao.analysis_task(("unit",))
   def CurrentTimeUnit(params, pf):
       return pf["InitialTime"] * pf[params.unit]

   t1 = CurrentTimeUnit(unit = "years")
   rr = ts.eval(t1)

I'll expand on this a bit more in the documentation and on the blog; however,
it's becoming easier to create an operator that will act on every dataset in a
series.  In this case, we've added a simple one that accepts a single parameter
(the unit to convert with).

hg Repository: yt
details:   yt/rev/7bb43511696e
changeset: 3699:7bb43511696e
user:      Matthew Turk <matthewturk at gmail.com>
date:
Fri Jan 28 23:19:36 2011 -0500
description:
Adding a .tasks object, into which AnalysisTask objects are auto-registered,
that behaves like the .quantities object on AMRData.  Now individual analyzers
do not have to be instantiated and called with eval.  They can now be called
directly using tasks.  For instance:

   from yt.mods import *
   from yt.data_objects.api import *
   ts = EnzoTimeSeries("PopulationIII", output_log = "OutputLog")
   max_rhos = ts.tasks["MaximumValue"]("Density")

Newly created (even with the decorator) AnalyzerObject classes will also go
into this registry:

   import yt.data_objects.analyzer_objects as ao
   @ao.analysis_task(("unit",))
   def CurrentTimeUnit(params, pf):
       return pf["InitialTime"] * pf[params.unit]
   time_days = ts.tasks["CurrentTimeUnit"]("Days")

I think this is approaching a pleasant API.

hg Repository: yt
details:   yt/rev/2e2e92e629eb
changeset: 3700:2e2e92e629eb
user:      Matthew Turk <matthewturk at gmail.com>
date:
Fri Jan 28 23:30:16 2011 -0500
description:
Adding time_series stuff to yt.mods and to the data_objects import.

diffstat:

 doc/install_script.sh               |  124 ++++++++++++++++++-----------------
 yt/data_objects/analyzer_objects.py |   64 ++++++++++--------
 yt/data_objects/api.py              |    2 +-
 yt/data_objects/time_series.py      |   24 ++++++-
 yt/mods.py                          |    3 +-
 5 files changed, 125 insertions(+), 92 deletions(-)

diffs (294 lines):

diff -r 3bb373d4f5cd -r 2e2e92e629eb doc/install_script.sh
--- a/doc/install_script.sh	Fri Jan 28 22:10:02 2011 -0500
+++ b/doc/install_script.sh	Fri Jan 28 23:30:16 2011 -0500
@@ -489,62 +489,68 @@
     cd $MY_PWD
 fi
 
-echo
-echo
-echo "========================================================================"
-echo
-echo "yt is now installed in $DEST_DIR ."
-echo "To run from this new installation, the a few variables need to be"
-echo "prepended with the following information:"
-echo
-echo "YT_DEST         => $DEST_DIR"
-echo "PATH            => $DEST_DIR/bin/"
-echo "PYTHONPATH      => $DEST_DIR/lib/python2.6/site-packages/"
-echo "LD_LIBRARY_PATH => $DEST_DIR/lib/"
-echo
-echo "For interactive data analysis and visualization, we recommend running"
-echo "the IPython interface, which will become more fully featured with time:"
-echo
-echo "$DEST_DIR/bin/iyt"
-echo
-echo "For command line analysis run:"
-echo
-echo "$DEST_DIR/bin/yt"
-echo
-echo "Note of interest: this installation will use the directory:"
-echo "    $YT_DIR"
-echo "as the source for all the YT code.  This means you probably shouldn't"
-echo "delete it, but on the plus side, any changes you make there are"
-echo "automatically propagated."
-if [ $INST_HG -eq 1 ]
-then
-  echo
-  echo "Mercurial has also been installed:"
-  echo
-  echo "$DEST_DIR/bin/hg"
-  echo
-fi
-if [ $INST_ENZO -eq 1 ]
-then
-  echo "Enzo has also been checked out, but not built."
-  echo
-  echo "$DEST_DIR/src/enzo-hg-stable"
-  echo
-  echo "The value of YT_DEST can be used as an HDF5 installation location."
-  echo "Questions about Enzo should be directed to the Enzo User List."
-  echo
-fi
-echo
-echo "For support, see one of the following websites:"
-echo
-echo "    http://yt.enzotools.org/wiki/"
-echo "    http://yt.enzotools.org/doc/"
-echo
-echo "Please also join the mailing list:"
-echo 
-echo "    http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org"
-echo
-echo "========================================================================"
-echo
-echo "Oh, look at me, still talking when there's science to do!"
-echo "Good luck, and email the user list if you run into any problems."
+function print_afterword
+{
+    echo
+    echo
+    echo "========================================================================"
+    echo
+    echo "yt is now installed in $DEST_DIR ."
+    echo "To run from this new installation, the a few variables need to be"
+    echo "prepended with the following information:"
+    echo
+    echo "YT_DEST         => $DEST_DIR"
+    echo "PATH            => $DEST_DIR/bin/"
+    echo "PYTHONPATH      => $DEST_DIR/lib/python2.6/site-packages/"
+    echo "LD_LIBRARY_PATH => $DEST_DIR/lib/"
+    echo
+    echo "For interactive data analysis and visualization, we recommend running"
+    echo "the IPython interface, which will become more fully featured with time:"
+    echo
+    echo "$DEST_DIR/bin/iyt"
+    echo
+    echo "For command line analysis run:"
+    echo
+    echo "$DEST_DIR/bin/yt"
+    echo
+    echo "Note of interest: this installation will use the directory:"
+    echo "    $YT_DIR"
+    echo "as the source for all the YT code.  This means you probably shouldn't"
+    echo "delete it, but on the plus side, any changes you make there are"
+    echo "automatically propagated."
+    if [ $INST_HG -eq 1 ]
+    then
+      echo
+      echo "Mercurial has also been installed:"
+      echo
+      echo "$DEST_DIR/bin/hg"
+      echo
+    fi
+    if [ $INST_ENZO -eq 1 ]
+    then
+      echo "Enzo has also been checked out, but not built."
+      echo
+      echo "$DEST_DIR/src/enzo-hg-stable"
+      echo
+      echo "The value of YT_DEST can be used as an HDF5 installation location."
+      echo "Questions about Enzo should be directed to the Enzo User List."
+      echo
+    fi
+    echo
+    echo "For support, see one of the following websites:"
+    echo
+    echo "    http://yt.enzotools.org/wiki/"
+    echo "    http://yt.enzotools.org/doc/"
+    echo
+    echo "Please also join the mailing list:"
+    echo 
+    echo "    http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org"
+    echo
+    echo "========================================================================"
+    echo
+    echo "Oh, look at me, still talking when there's science to do!"
+    echo "Good luck, and email the user list if you run into any problems."
+}
+
+print_afterword
+print_afterword >> ${LOG_FILE}
diff -r 3bb373d4f5cd -r 2e2e92e629eb yt/data_objects/analyzer_objects.py
--- a/yt/data_objects/analyzer_objects.py	Fri Jan 28 22:10:02 2011 -0500
+++ b/yt/data_objects/analyzer_objects.py	Fri Jan 28 23:30:16 2011 -0500
@@ -27,7 +27,15 @@
 
 from yt.funcs import *
 
+analysis_task_registry = {}
+
 class AnalysisTask(object):
+    class __metaclass__(type):
+        def __init__(cls, name, b, d):
+            type.__init__(cls, name, b, d)
+            if hasattr(cls, "skip") and cls.skip == False:
+                return
+            analysis_task_registry[cls.__name__] = cls
 
     def __init__(self, *args, **kwargs):
         # This should only get called if the subclassed object
@@ -44,37 +52,23 @@
                        for i in self._params])
         return s
 
-class MaximumValue(AnalysisTask):
-    _params = ['field']
+def analysis_task(params = None):
+    if params is None: params = tuple()
+    def create_new_class(func):
+        cls = type(func.func_name, (AnalysisTask,),
+                   dict(eval = func, _params = params))
+        return cls
+    return create_new_class
 
-    def eval(self, data_object):
-        v = data_object.quantities["MaxLocation"](
-                self.field, lazy_reader=True)[0]
-        return v
+ at analysis_task(('field',))
+def MaximumValue(params, data_object):
+    v = data_object.quantities["MaxLocation"](
+            params.field, lazy_reader=True)[0]
+    return v
 
-class ParameterValue(AnalysisTask):
-    _params = ['parameter']
-
-    def __init__(self, parameter, cast=None):
-        self.parameter = parameter
-        if cast is None:
-            cast = lambda a: a
-        self.cast = cast
-
-    def eval(self, pf):
-        return self.cast(pf.get_parameter(self.parameter))
-
-class CurrentTimeYears(AnalysisTask):
-    _params = []
-
-    def eval(self, pf):
-        return pf.current_time * pf["years"]
-
-class SliceDataset(AnalysisTask):
-    _params = ['field', 'axis']
-
-    def eval(self, pf):
-        pass
+ at analysis_task()
+def CurrentTimeYears(params, pf):
+    return pf.current_time * pf["years"]
 
 class SlicePlotDataset(AnalysisTask):
     _params = ['field', 'axis', 'center']
@@ -109,6 +103,18 @@
             *self.args, **self.kwargs)
         return rv
 
+class ParameterValue(AnalysisTask):
+    _params = ['parameter']
+
+    def __init__(self, parameter, cast=None):
+        self.parameter = parameter
+        if cast is None:
+            cast = lambda a: a
+        self.cast = cast
+
+    def eval(self, pf):
+        return self.cast(pf.get_parameter(self.parameter))
+
 def create_quantity_proxy(quantity_object):
     args, varargs, kwargs, defaults = inspect.getargspec(quantity_object[1])
     # Strip off 'data' which is on every quantity function
diff -r 3bb373d4f5cd -r 2e2e92e629eb yt/data_objects/api.py
--- a/yt/data_objects/api.py	Fri Jan 28 22:10:02 2011 -0500
+++ b/yt/data_objects/api.py	Fri Jan 28 23:30:16 2011 -0500
@@ -58,7 +58,7 @@
     TimeSeriesDataObject
 
 from analyzer_objects import \
-      AnalysisTask
+    AnalysisTask, analysis_task
 
 from data_containers import \
     data_object_registry
diff -r 3bb373d4f5cd -r 2e2e92e629eb yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py	Fri Jan 28 22:10:02 2011 -0500
+++ b/yt/data_objects/time_series.py	Fri Jan 28 23:30:16 2011 -0500
@@ -28,13 +28,33 @@
 from yt.funcs import *
 from yt.convenience import load
 from .data_containers import data_object_registry
-from .analyzer_objects import create_quantity_proxy
+from .analyzer_objects import create_quantity_proxy, \
+    analysis_task_registry
 from .derived_quantities import quantity_info
 from yt.utilities.exceptions import YTException
 
+class AnalysisTaskProxy(object):
+    def __init__(self, time_series):
+        self.time_series = time_series
+
+    def __getitem__(self, key):
+        task_cls = analysis_task_registry[key]
+        @wraps(task_cls.__init__)
+        def func(*args, **kwargs):
+            task = task_cls(*args, **kwargs)
+            return self.time_series.eval(task)
+        return func
+
+    def keys(self):
+        return analysis_task_registry.keys()
+
+    def __contains__(self, key):
+        return key in analysis_task_registry
+
 class TimeSeriesData(object):
     def __init__(self, name):
         self.outputs = []
+        self.tasks = AnalysisTaskProxy(self)
 
     def __iter__(self):
         # We can make this fancier, but this works
@@ -65,7 +85,7 @@
                         arg = pf
                     elif style == 'data_object':
                         arg = obj.get(pf)
-                        rv = task.eval(arg)
+                    rv = task.eval(arg)
                 # We catch and store YT-originating exceptions
                 # This fixes the standard problem of having a sphere that's too
                 # small.
diff -r 3bb373d4f5cd -r 2e2e92e629eb yt/mods.py
--- a/yt/mods.py	Fri Jan 28 22:10:02 2011 -0500
+++ b/yt/mods.py	Fri Jan 28 23:30:16 2011 -0500
@@ -46,7 +46,8 @@
     data_object_registry, \
     derived_field, add_field, FieldInfo, \
     ValidateParameter, ValidateDataField, ValidateProperty, \
-    ValidateSpatial, ValidateGridType
+    ValidateSpatial, ValidateGridType, \
+    EnzoTimeSeries, TimeSeriesData, AnalysisTask, analysis_task
 
 from yt.data_objects.derived_quantities import \
     add_quantity, quantity_info



More information about the yt-svn mailing list