[Yt-svn] yt-commit r1041 - branches/yt-object-serialization/yt/lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Dec 25 18:21:17 PST 2008


Author: mturk
Date: Thu Dec 25 18:21:17 2008
New Revision: 1041
URL: http://yt.spacepope.org/changeset/1041

Log:
Clumps now have a __reduce__ and _reconstruct pair, so they can be pickled.
Ran into a little bit of trouble wiht the parent/child relationship, and
additionally ensuring only the master clump returns the parameter file is kind
of sticky.



Modified:
   branches/yt-object-serialization/yt/lagos/Clump.py

Modified: branches/yt-object-serialization/yt/lagos/Clump.py
==============================================================================
--- branches/yt-object-serialization/yt/lagos/Clump.py	(original)
+++ branches/yt-object-serialization/yt/lagos/Clump.py	Thu Dec 25 18:21:17 2008
@@ -48,9 +48,27 @@
 
     def get_IsBound(self):
         if self.isBound is None:
-            self.isBound = self.data.quantities["IsBound"](truncate=True,include_thermal_energy=True)
+            self.isBound = self.data.quantities["IsBound"](
+                    truncate=True,include_thermal_energy=True)
         return self.isBound
 
+    def __reduce__(self):
+        return (_reconstruct_clump, 
+                (self.parent, self.field, self.min, self.max,
+                 self.isBound, self.children, self.data))
+
+def _reconstruct_clump(parent, field, mi, ma, isBound, children, data):
+    obj = object.__new__(Clump)
+    if iterable(parent): parent = parent[1]
+    obj.parent, obj.field, obj.min, obj.max, obj.isBound, \
+       obj.children = parent, field, mi, ma, isBound, children
+    # Now we override, because the parent/child relationship seems a bit
+    # unreliable in the unpickling
+    for child in children: child.parent = obj
+    obj.data = data[1] # Strip out the PF
+    if obj.parent is None: return (data[0], obj)
+    return obj
+
 def find_clumps(clump, min, max, d_clump):
     print "Finding clumps: min: %e, max: %e, step: %f" % (min, max, d_clump)
     if min >= max: return
@@ -124,15 +142,3 @@
     fmt_dict['min_density'] =  clump.data["NumberDensity"].min()
     fmt_dict['max_density'] =  clump.data["NumberDensity"].max()
     f_ptr.write(__clump_info_template % fmt_dict)
-
-class ClumpStorage(object):
-    def __init__(self, clump):
-        # This is to see if it's extracted
-        # We don't care about the base region,
-        # so we skip that.
-        if hasattr(clump.data, '_indices'):
-            self.indices = clump.data._indices
-            self.grids = [g.id-1 for g in clump.data._grids]
-        self.children = []
-        if clump.children is not None:
-            self.children = [ClumpStorage(child) for child in clump.children]



More information about the yt-svn mailing list