[Yt-svn] yt: Modifying the add_filed function so that it can act as a dec...
hg at spacepope.org
hg at spacepope.org
Sat Jan 29 06:10:41 PST 2011
hg Repository: yt
details: yt/rev/8e2715e3dbd3
changeset: 3701:8e2715e3dbd3
user: Matthew Turk <matthewturk at gmail.com>
date:
Sat Jan 29 09:10:34 2011 -0500
description:
Modifying the add_filed function so that it can act as a decorator. Now you
can do:
@add_field("SimpleDensitySquared", display_name = r"\rho^2")
def DensitySquared(field, data):
return data["Density"]**2.0
for a very fast way of creating a new derived field. ("display_name" is
optional.)
diffstat:
yt/data_objects/field_info_container.py | 10 ++++------
yt/mods.py | 1 -
2 files changed, 4 insertions(+), 7 deletions(-)
diffs (31 lines):
diff -r 2e2e92e629eb -r 8e2715e3dbd3 yt/data_objects/field_info_container.py
--- a/yt/data_objects/field_info_container.py Fri Jan 28 23:30:16 2011 -0500
+++ b/yt/data_objects/field_info_container.py Sat Jan 29 09:10:34 2011 -0500
@@ -69,12 +69,10 @@
:class:`~yt.data_objects.api.DerivedField`.
"""
if function == None:
- if kwargs.has_key("function"):
- function = kwargs.pop("function")
- else:
- # This will fail if it does not exist,
- # which is our desired behavior
- function = eval("_%s" % name)
+ def create_function(function):
+ self[name] = DerivedField(name, function, **kwargs)
+ return function
+ return create_function
self[name] = DerivedField(name, function, **kwargs)
FieldInfo = FieldInfoContainer()
add_field = FieldInfo.add_field
diff -r 2e2e92e629eb -r 8e2715e3dbd3 yt/mods.py
--- a/yt/mods.py Fri Jan 28 23:30:16 2011 -0500
+++ b/yt/mods.py Sat Jan 29 09:10:34 2011 -0500
@@ -82,7 +82,6 @@
available_analysis_modules = get_available_modules()
# Import our analysis modules
-#import yt.analysis_modules.api as analysis
from yt.analysis_modules.halo_finding.api import \
HaloFinder
More information about the yt-svn
mailing list