[Yt-svn] yt-commit r1434 - in trunk/yt: . lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Tue Sep 8 09:54:43 PDT 2009


Author: mturk
Date: Tue Sep  8 09:54:42 2009
New Revision: 1434
URL: http://yt.spacepope.org/changeset/1434

Log:
Added a new derived_field decorator.

For instance:

{{{
#!python

from yt.mods import *

@derived_field(units="Density times two")
def SomeField(field, data):
    return data['Density'] * 2.0

plots.get_slice("RedshiftOutput0005", "SomeField", 0).save_image("d1")
plots.get_slice("RedshiftOutput0005", "Density", 0).save_image("d2")

}}}



Modified:
   trunk/yt/lagos/FieldInfoContainer.py
   trunk/yt/mods.py

Modified: trunk/yt/lagos/FieldInfoContainer.py
==============================================================================
--- trunk/yt/lagos/FieldInfoContainer.py	(original)
+++ trunk/yt/lagos/FieldInfoContainer.py	Tue Sep  8 09:54:42 2009
@@ -64,6 +64,15 @@
 FieldInfo = FieldInfoContainer()
 add_field = FieldInfo.add_field
 
+def derived_field(**kwargs):
+    def inner_decorator(function):
+        if 'name' not in kwargs:
+            kwargs['name'] = function.func_name
+        kwargs['function'] = function
+        add_field(**kwargs)
+        return function
+    return inner_decorator
+
 class CodeFieldInfoContainer(FieldInfoContainer):
     def __setitem__(self, key, val):
         self._field_list[key] = val

Modified: trunk/yt/mods.py
==============================================================================
--- trunk/yt/mods.py	(original)
+++ trunk/yt/mods.py	Tue Sep  8 09:54:42 2009
@@ -40,6 +40,7 @@
 # Now individual component imports from lagos
 from yt.lagos import EnzoStaticOutput, \
     BinnedProfile1D, BinnedProfile2D, BinnedProfile3D, \
+    derived_field, \
     add_field, FieldInfo, EnzoFieldInfo, Enzo2DFieldInfo, OrionFieldInfo, \
     Clump, write_clump_hierarchy, find_clumps, write_clumps, \
     OrionStaticOutput, HaloFinder, HOPHaloFinder, FOFHaloFinder



More information about the yt-svn mailing list