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

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Wed May 7 16:36:36 PDT 2008


Author: mturk
Date: Wed May  7 16:36:35 2008
New Revision: 442
URL: http://yt.spacepope.org/changeset/442

Log:
 * Added grid boundaries callback. (closes #92)
 * Sped things up a bit in the Hierarchy instantiation by using the reversed()
   call instead of manually doing a backwards xrange
 * Added GridPropertiesMixin, which gets grid properties from the ._grids
   property of objects.




Modified:
   trunk/yt/lagos/BaseDataTypes.py
   trunk/yt/lagos/HierarchyType.py
   trunk/yt/raven/PlotTypes.py

Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py	(original)
+++ trunk/yt/lagos/BaseDataTypes.py	Wed May  7 16:36:35 2008
@@ -169,7 +169,80 @@
     def _generate_field_in_grids(self, fieldName):
         pass
 
-class Enzo1DData(EnzoData):
+class GridPropertiesMixin(object):
+
+    def __get_levelIndices(self):
+        if self.__levelIndices: return self.__levelIndices
+        # Otherwise, generate
+        # We only have to do this once, so it's not terribly expensive:
+        ll = {}
+        for level in range(MAXLEVEL):
+            t = [i for i in range(len(self._grids)) if self._grids[i].Level == level]
+            ll[level] = na.array(t)
+        self.__levelIndices = ll
+        return self.__levelIndices
+
+    def __set_levelIndices(self, val):
+        self.__levelIndices = val
+
+    def __del_levelIndices(self):
+        del self.__levelIndices
+        self.__levelIndices = None
+
+    __levelIndices = None
+    levelIndices = property(__get_levelIndices, __set_levelIndices,
+                            __del_levelIndices)
+
+    def __get_gridLeftEdge(self):
+        if self.__gridLeftEdge == None:
+            self.__gridLeftEdge = na.array([g.LeftEdge for g in self._grids])
+        return self.__gridLeftEdge
+
+    def __del_gridLeftEdge(self):
+        del self.__gridLeftEdge
+        self.__gridLeftEdge = None
+
+    def __set_gridLeftEdge(self, val):
+        self.__gridLeftEdge = val
+
+    __gridLeftEdge = None
+    gridLeftEdge = property(__get_gridLeftEdge, __set_gridLeftEdge,
+                              __del_gridLeftEdge)
+
+    def __get_gridRightEdge(self):
+        if self.__gridRightEdge == None:
+            self.__gridRightEdge = na.array([g.RightEdge for g in self._grids])
+        return self.__gridRightEdge
+
+    def __del_gridRightEdge(self):
+        del self.__gridRightEdge
+        self.__gridRightEdge = None
+
+    def __set_gridRightEdge(self, val):
+        self.__gridRightEdge = val
+
+    __gridRightEdge = None
+    gridRightEdge = property(__get_gridRightEdge, __set_gridRightEdge,
+                             __del_gridRightEdge)
+
+    def __get_gridLevels(self):
+        if self.__gridLevels == None:
+            self.__gridLevels = na.array([g.Level for g in self._grids])
+        return self.__gridLevels
+
+    def __del_gridLevels(self):
+        del self.__gridLevels
+        self.__gridLevels = None
+
+    def __set_gridLevels(self, val):
+        self.__gridLevels = val
+
+    __gridLevels = None
+    gridLevels = property(__get_gridLevels, __set_gridLevels,
+                             __del_gridLevels)
+
+
+class Enzo1DData(EnzoData, GridPropertiesMixin):
     _spatial = False
     def __init__(self, pf, fields, **kwargs):
         EnzoData.__init__(self, pf, fields, **kwargs)
@@ -252,7 +325,7 @@
             gf = grid[field][sl]
         return gf[na.where(grid.child_mask[sl])]
 
-class Enzo2DData(EnzoData):
+class Enzo2DData(EnzoData, GridPropertiesMixin):
     """
     Class to represent a set of EnzoData that's 2-D in nature, and thus
     does not have as many actions as the 3-D data types.
@@ -878,7 +951,7 @@
         if grid.id == 1: self._temp[grid.id] = d
         return d
 
-class Enzo3DData(EnzoData):
+class Enzo3DData(EnzoData, GridPropertiesMixin):
     """
     Class describing a cluster of data points, not necessarily sharing any
     particular attribute.
@@ -1046,76 +1119,6 @@
         grids = [g for g in self._grids if g.Level == level]
         return grids
 
-    def __get_levelIndices(self):
-        if self.__levelIndices: return self.__levelIndices
-        # Otherwise, generate
-        # We only have to do this once, so it's not terribly expensive:
-        ll = {}
-        for level in range(MAXLEVEL):
-            t = [i for i in range(len(self._grids)) if self._grids[i].Level == level]
-            ll[level] = na.array(t)
-        self.__levelIndices = ll
-        return self.__levelIndices
-
-    def __set_levelIndices(self, val):
-        self.__levelIndices = val
-
-    def __del_levelIndices(self):
-        del self.__levelIndices
-        self.__levelIndices = None
-
-    __levelIndices = None
-    levelIndices = property(__get_levelIndices, __set_levelIndices,
-                            __del_levelIndices)
-
-    def __get_gridLeftEdge(self):
-        if self.__gridLeftEdge == None:
-            self.__gridLeftEdge = na.array([g.LeftEdge for g in self._grids])
-        return self.__gridLeftEdge
-
-    def __del_gridLeftEdge(self):
-        del self.__gridLeftEdge
-        self.__gridLeftEdge = None
-
-    def __set_gridLeftEdge(self, val):
-        self.__gridLeftEdge = val
-
-    __gridLeftEdge = None
-    gridLeftEdge = property(__get_gridLeftEdge, __set_gridLeftEdge,
-                              __del_gridLeftEdge)
-
-    def __get_gridRightEdge(self):
-        if self.__gridRightEdge == None:
-            self.__gridRightEdge = na.array([g.RightEdge for g in self._grids])
-        return self.__gridRightEdge
-
-    def __del_gridRightEdge(self):
-        del self.__gridRightEdge
-        self.__gridRightEdge = None
-
-    def __set_gridRightEdge(self, val):
-        self.__gridRightEdge = val
-
-    __gridRightEdge = None
-    gridRightEdge = property(__get_gridRightEdge, __set_gridRightEdge,
-                             __del_gridRightEdge)
-
-    def __get_gridLevels(self):
-        if self.__gridLevels == None:
-            self.__gridLevels = na.array([g.Level for g in self._grids])
-        return self.__gridLevels
-
-    def __del_gridLevels(self):
-        del self.__gridLevels
-        self.__gridLevels = None
-
-    def __set_gridLevels(self, val):
-        self.__gridLevels = val
-
-    __gridLevels = None
-    gridLevels = property(__get_gridLevels, __set_gridLevels,
-                             __del_gridLevels)
-
     def __get_quantities(self):
         if self.__quantities is None:
             self.__quantities = DerivedQuantityCollection(self)

Modified: trunk/yt/lagos/HierarchyType.py
==============================================================================
--- trunk/yt/lagos/HierarchyType.py	(original)
+++ trunk/yt/lagos/HierarchyType.py	Wed May  7 16:36:35 2008
@@ -64,8 +64,7 @@
         if len(self.__hierarchy_lines) == 0:
             raise IOError(-1,"File empty", self.hierarchy_filename)
         self.__hierarchy_string = open(self.hierarchy_filename).read()
-        for i in xrange(len(self.__hierarchy_lines)-1,0,-1):
-            line = self.__hierarchy_lines[i]
+        for line in reversed(self.__hierarchy_lines):
             if line.startswith("Grid ="):
                 self.num_grids = int(line.split("=")[-1])
                 break
@@ -336,7 +335,7 @@
             elif param == "Time":
                 __split_convert(vals, float, self.gridTimes, curGrid)
             elif param == "NumberOfParticles":
-                __split_convert(vals, float, self.gridNumberOfParticles, curGrid)
+                __split_convert(vals, int, self.gridNumberOfParticles, curGrid)
             elif param == "FileName":
                 self.grids[curGrid-1].set_filename(vals[1:-1])
             elif param == "BaryonFileName":
@@ -344,7 +343,7 @@
         mylog.info("Caching hierarchy information")
         allArrays = na.zeros((self.num_grids,18),'float64')
         allArrays[:,0:3] = self.gridDimensions[:]
-        allArrays[:,3:6] = self.gridStartIndices[:]
+        allArrays[:,3:6] = self.gridStartIndices[:]  
         allArrays[:,6:9] = self.gridEndIndices[:]
         allArrays[:,9:12] = self.gridLeftEdge[:]
         allArrays[:,12:15] = self.gridRightEdge[:]

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Wed May  7 16:36:35 2008
@@ -40,6 +40,7 @@
 import matplotlib.colors
 import matplotlib.colorbar
 import matplotlib.cm
+import matplotlib.collections
 
 def ClusterFilePlot(cls, x, y, xlog=None, ylog=None, fig=None, filename=None,
                     format="png", xbounds = None, ybounds = None):
@@ -789,3 +790,30 @@
         plot._axes.set_ylim(yy0,yy1)
         plot._axes.hold(False)
     return runCallback
+
+def gridBoundaryCallback(alpha=1.0):
+    def runCallback(plot):
+        x0, x1 = plot.xlim
+        y0, y1 = plot.ylim
+        dx = plot.image._A.shape[0] / (x1-x0)
+        dy = plot.image._A.shape[1] / (y1-y0)
+        GLE = plot.data.gridLeftEdge
+        GRE = plot.data.gridRightEdge
+        px_index = lagos.x_dict[plot.data.axis]
+        py_index = lagos.y_dict[plot.data.axis]
+        left_edge_px = (GLE[:,px_index]-x0)*dx
+        left_edge_py = (GLE[:,py_index]-y0)*dy
+        right_edge_px = (GRE[:,px_index]-x0)*dx
+        right_edge_py = (GRE[:,py_index]-y0)*dy
+        verts = na.array( 
+                [(left_edge_px, left_edge_px, right_edge_px, right_edge_px),
+                 (left_edge_py, right_edge_py, right_edge_py, left_edge_py)])
+        verts=verts.transpose()
+        edgecolors = (0.0,0.0,0.0,alpha)
+        grid_collection = matplotlib.collections.PolyCollection(
+                verts, facecolors=(0.0,0.0,0.0,0.0),
+                       edgecolors=edgecolors)
+        plot._axes.hold(True)
+        plot._axes.add_collection(grid_collection)
+        plot._axes.hold(False)
+    return runCallback



More information about the yt-svn mailing list