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

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Feb 14 13:16:29 PST 2008


Author: mturk
Date: Thu Feb 14 13:16:25 2008
New Revision: 377
URL: http://yt.spacepope.org/changeset/377

Log:
* Removed defaultdict and replaced with something else.  (WIP?)
* Started implementation of Borg-style derived field container, which will ease
  a bit of the nastiness in getting field info.  Or it might get removed.
  Undecided...



Modified:
   trunk/yt/funcs.py
   trunk/yt/lagos/DerivedFields.py
   trunk/yt/lagos/HierarchyType.py
   trunk/yt/lagos/OutputTypes.py
   trunk/yt/raven/PlotTypes.py

Modified: trunk/yt/funcs.py
==============================================================================
--- trunk/yt/funcs.py	(original)
+++ trunk/yt/funcs.py	Thu Feb 14 13:16:25 2008
@@ -85,4 +85,25 @@
             ' ', pb.ETA(), ' ']
     pbar = pb.ProgressBar(widgets=widgets,
                           maxval=maxval).start()
-    return pbar
\ No newline at end of file
+    return pbar
+
+# Taken from
+# http://www.goldb.org/goldblog/2008/02/06/PythonConvertSecsIntoHumanReadableTimeStringHHMMSS.aspx
+def humanize_time(secs):
+    mins, secs = divmod(secs, 60)
+    hours, mins = divmod(mins, 60)
+    return '%02d:%02d:%02d' % (hours, mins, secs)
+
+class __defaultdict(dict):
+    def __init__(self, func):
+        self.__func = func
+        dict.__init__(self)
+    def __getitem__(self, key):
+        if not self.has_key(key):
+            self.__setitem__(key, self.__func())
+        return dict.__getitem__(key)
+
+try:
+    from collections import defaultdict
+except ImportError:
+    defaultdict = __defaultdict

Modified: trunk/yt/lagos/DerivedFields.py
==============================================================================
--- trunk/yt/lagos/DerivedFields.py	(original)
+++ trunk/yt/lagos/DerivedFields.py	Thu Feb 14 13:16:25 2008
@@ -1,7 +1,7 @@
 import types
-from collections import defaultdict
 import numpy as na
 import inspect
+import copy
 
 # All our math stuff here:
 try:
@@ -19,6 +19,31 @@
 clight = 3.0e10 # cm/s
 kboltz = 1.38e-16
 
+class FieldInfoContainer: # We are all Borg.
+    _shared_state = {}
+    def __new__(cls, *args, **kwargs):
+        self = object.__new__(cls, *args, **kwargs)
+        self.__dict__ = cls._shared_state
+        return self
+    def __init__(self):
+        self.__field_list = {}
+    def __getitem__(self, key):
+        if not self.__field_list.has_key(key): # Now we check it out, to see if we need to do anything to it
+            if key.endswith("Code"):
+                old_field = self.__field_list[key[:-4]]
+                new_field = copy.copy(old_field)
+                new_field.convert_function = \
+                            lambda a: 1.0/old_field._convert_function(a)
+            elif key.endswith("Abs"):
+                old_field = self.__field_list[key[:-4]]
+                new_field = copy.copy(old_field)
+                new_field._function = \
+                    lambda a,b: na.abs(old_field._function(a,b))
+            else:
+                raise KeyError
+            self.__field_list[key] = new_field
+        return self.__field_list[key]
+
 fieldInfo = {}
 
 class ValidationException(Exception):
@@ -340,8 +365,6 @@
     return data.convert("cm")
 add_field("Height", convert_function=_convertHeight,
           validators=[ValidateParameter("height_vector")])
-add_field("HeightCode", function=_Height,
-          validators=[ValidateParameter("height_vector")])
 
 def _DynamicalTime(field, data):
     """
@@ -422,7 +445,6 @@
           convert_function=_convertXRayEmissivity,
           projection_conversion="1")
 
-
 def _SZKinetic(field, data):
     vel_axis = data.get_field_parameter('axis')
     if vel_axis > 2:
@@ -442,8 +464,6 @@
     return conv
 add_field("SZY", convert_function=_convertSZY)
 
-
-
 def __gauss_kern(size):
     """ Returns a normalized 2D gauss kernel array for convolutions """
     size = int(size)
@@ -623,15 +643,9 @@
 _enzo_fields = ["Density","Temperature","Gas_Energy","Total_Energy",
                 "x-velocity","y-velocity","z-velocity"]
 _enzo_fields += [ "%s_Density" % sp for sp in _speciesList ]
-def _returnCodeField(real_field):
-    def _fieldFunction(field, data):
-        return data[real_field]
-    return _fieldFunction
 for field in _enzo_fields:
     add_field(field, function=lambda a, b: None, take_log=True,
               validators=[ValidateDataField(field)], units=r"\rm{g}/\rm{cm}^3")
-    add_field("_Code%s" % field, function=_returnCodeField(field),
-              take_log=True, validators=[ValidateDataField(field)])
 
 # Now we override
 

Modified: trunk/yt/lagos/HierarchyType.py
==============================================================================
--- trunk/yt/lagos/HierarchyType.py	(original)
+++ trunk/yt/lagos/HierarchyType.py	Thu Feb 14 13:16:25 2008
@@ -24,7 +24,6 @@
 
 from yt.lagos import *
 from yt.funcs import *
-from collections import defaultdict
 import string, re, gc, time
 import cPickle
 #import yt.enki

Modified: trunk/yt/lagos/OutputTypes.py
==============================================================================
--- trunk/yt/lagos/OutputTypes.py	(original)
+++ trunk/yt/lagos/OutputTypes.py	Thu Feb 14 13:16:25 2008
@@ -26,7 +26,6 @@
 
 from yt.lagos import *
 from yt.funcs import *
-from collections import defaultdict
 import string, re, gc, time, os, os.path
 
 # We want to support the movie format in the future.
@@ -58,7 +57,6 @@
         self.fullpath = os.path.abspath(self.directory)
         if len(self.directory) == 0:
             self.directory = "."
-        #self.conversion_factors = defaultdict(lambda: 1.0)
         self.conversion_factors = {}
         self.parameters = {}
         self.parameters["CurrentTimeIdentifier"] = \

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Thu Feb 14 13:16:25 2008
@@ -41,8 +41,6 @@
 import matplotlib.colorbar
 import matplotlib.cm
 
-from collections import defaultdict
-
 def ClusterFilePlot(cls, x, y, xlog=None, ylog=None, fig=None, filename=None,
                     format="png", xbounds = None, ybounds = None):
     """



More information about the yt-svn mailing list