[Yt-svn] yt-commit r1115 - trunk/yt/extensions/lightcone

britton at wrangler.dreamhost.com britton at wrangler.dreamhost.com
Thu Jan 15 14:12:18 PST 2009


Author: britton
Date: Thu Jan 15 14:12:18 2009
New Revision: 1115
URL: http://yt.spacepope.org/changeset/1115

Log:
Added explicit deletions of plot collections and fixed resolution buffers made 
in LightConeProjection instead of just letting them go out of scope, which it 
seems they weren't doing.  Both the plot collection and frb are deleted in the 
outer ProjectLightCone routine, so that everything is deleted in order and all 
in the same scope.  This seems to cut down on memory usage significantly.

Also, LightConeProjection now explicitly deletes the cells outside the 
light cone slice width instead of keeping them and just using set_xlim and 
set_ylim to frame the image correctly.


Modified:
   trunk/yt/extensions/lightcone/LightCone.py
   trunk/yt/extensions/lightcone/LightConeProjection.py

Modified: trunk/yt/extensions/lightcone/LightCone.py
==============================================================================
--- trunk/yt/extensions/lightcone/LightCone.py	(original)
+++ trunk/yt/extensions/lightcone/LightCone.py	Thu Jan 15 14:12:18 2009
@@ -81,10 +81,10 @@
         # Combine all data dumps.
         self._CombineDataOutputs()
 
-        if self.lightConeParameters['UseMinimumNumberOfProjections']:
-            # Calculate maximum delta z for each data dump.
-            self._CalculateDeltaZMax()
-        else:
+        # Calculate maximum delta z for each data dump.
+        self._CalculateDeltaZMax()
+
+        if not self.lightConeParameters['UseMinimumNumberOfProjections']:
             # Calculate minimum delta z for each data dump.
             self._CalculateDeltaZMin()
 
@@ -239,12 +239,19 @@
                 else:
                     self.projectionStack.append(frb[field])
 
+                # Delete the frb.  This saves a decent amount of ram.
+                if (q < len(self.lightConeSolution) - 1):
+                    del frb
+
                 # Flatten stack to save memory.
                 if flatten_stack and (len(self.projectionStack) > 1):
                     self.projectionStack = [sum(self.projectionStack)]
                     if weight_field is not None:
                         self.projectionWeightFieldStack = [sum(self.projectionWeightFieldStack)]
 
+            # Delete the plot collection now that the frb is deleted.
+            del output['pc']
+
             # Unless this is the last slice, delete the dataset object.
             # The last one will be saved to make the plot collection.
             if (q < len(self.lightConeSolution) - 1):

Modified: trunk/yt/extensions/lightcone/LightConeProjection.py
==============================================================================
--- trunk/yt/extensions/lightcone/LightConeProjection.py	(original)
+++ trunk/yt/extensions/lightcone/LightConeProjection.py	Thu Jan 15 14:12:18 2009
@@ -59,14 +59,21 @@
     # Make an Enzo data object.
     dataset_object = lightConeSlice['object']
 
-    # Make plot collection.
     region_center = [0.5 * (dataset_object.parameters['DomainRightEdge'][q] +
                             dataset_object.parameters['DomainLeftEdge'][q]) \
                          for q in range(dataset_object.parameters['TopGridRank'])]
-    pc = raven.PlotCollection(dataset_object,center=region_center)
+
+    # Make the plot collection and put it in the slice so we can delete it cleanly in the same scope 
+    # as where the frb will be deleted.
+    lightConeSlice['pc'] = raven.PlotCollection(dataset_object,center=region_center)
 
     # 1. The Depth Problem
     # Use coordinate field cut in line of sight to cut projection to proper depth.
+    if field_cuts is None:
+        these_field_cuts = []
+    else:
+        these_field_cuts = copy.deepcopy(field_cuts)
+
     if (lightConeSlice['DepthBoxFraction'] < 1):
         axis = ('x','y','z')[lightConeSlice['ProjectionAxis']]
         depthLeft = lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']] - 0.5 * lightConeSlice['DepthBoxFraction']
@@ -80,40 +87,36 @@
         else:
             cut_mask = "(grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"%s\"] <= %f)" % (axis,axis,depthLeft,axis,axis,depthRight)
 
-        if field_cuts is None:
-            these_field_cuts = []
-        else:
-            these_field_cuts = copy.deepcopy(field_cuts)
         these_field_cuts.append(cut_mask)
 
     # Make projection.
-    pc.add_projection(field,lightConeSlice['ProjectionAxis'],weight_field=weight_field,field_cuts=these_field_cuts,use_colorbar=True,
+    lightConeSlice['pc'].add_projection(field,lightConeSlice['ProjectionAxis'],weight_field=weight_field,field_cuts=these_field_cuts,use_colorbar=True,
                       node_name=node_name,**kwargs)
 
     # If parallel: all the processes have the whole projection object, but we only need to do the tiling, shifting, and cutting once.
-
-    # 2. The Tile Problem
-    # Tile projection to specified width.
     if ytcfg.getint("yt","__parallel_rank") == 0:
 
+        # 2. The Tile Problem
+        # Tile projection to specified width.
+
         # Original projection data.
-        original_px = copy.deepcopy(pc.plots[0].data['px'])
-        original_py = copy.deepcopy(pc.plots[0].data['py'])
-        original_pdx = copy.deepcopy(pc.plots[0].data['pdx'])
-        original_pdy = copy.deepcopy(pc.plots[0].data['pdy'])
-        original_field = copy.deepcopy(pc.plots[0].data[field])
-        original_weight_field = copy.deepcopy(pc.plots[0].data['weight_field'])
+        original_px = copy.deepcopy(lightConeSlice['pc'].plots[0].data['px'])
+        original_py = copy.deepcopy(lightConeSlice['pc'].plots[0].data['py'])
+        original_pdx = copy.deepcopy(lightConeSlice['pc'].plots[0].data['pdx'])
+        original_pdy = copy.deepcopy(lightConeSlice['pc'].plots[0].data['pdy'])
+        original_field = copy.deepcopy(lightConeSlice['pc'].plots[0].data[field])
+        original_weight_field = copy.deepcopy(lightConeSlice['pc'].plots[0].data['weight_field'])
 
         # Copy original into offset positions to make tiles.
         for x in range(int(na.ceil(lightConeSlice['WidthBoxFraction']))):
             for y in range(int(na.ceil(lightConeSlice['WidthBoxFraction']))):
                 if ((x + y) > 0):
-                    pc.plots[0].data['px'] = na.concatenate([pc.plots[0].data['px'],original_px+x])
-                    pc.plots[0].data['py'] = na.concatenate([pc.plots[0].data['py'],original_py+y])
-                    pc.plots[0].data['pdx'] = na.concatenate([pc.plots[0].data['pdx'],original_pdx])
-                    pc.plots[0].data['pdy'] = na.concatenate([pc.plots[0].data['pdy'],original_pdy])
-                    pc.plots[0].data[field] = na.concatenate([pc.plots[0].data[field],original_field])
-                    pc.plots[0].data['weight_field'] = na.concatenate([pc.plots[0].data['weight_field'],original_weight_field])
+                    lightConeSlice['pc'].plots[0].data['px'] = na.concatenate([lightConeSlice['pc'].plots[0].data['px'],original_px+x])
+                    lightConeSlice['pc'].plots[0].data['py'] = na.concatenate([lightConeSlice['pc'].plots[0].data['py'],original_py+y])
+                    lightConeSlice['pc'].plots[0].data['pdx'] = na.concatenate([lightConeSlice['pc'].plots[0].data['pdx'],original_pdx])
+                    lightConeSlice['pc'].plots[0].data['pdy'] = na.concatenate([lightConeSlice['pc'].plots[0].data['pdy'],original_pdy])
+                    lightConeSlice['pc'].plots[0].data[field] = na.concatenate([lightConeSlice['pc'].plots[0].data[field],original_field])
+                    lightConeSlice['pc'].plots[0].data['weight_field'] = na.concatenate([lightConeSlice['pc'].plots[0].data['weight_field'],original_weight_field])
 
         # Delete originals.
         del original_px
@@ -131,67 +134,67 @@
         del offset[lightConeSlice['ProjectionAxis']]
 
         # Shift x and y positions.
-        pc.plots[0]['px'] -= offset[0]
-        pc.plots[0]['py'] -= offset[1]
+        lightConeSlice['pc'].plots[0]['px'] -= offset[0]
+        lightConeSlice['pc'].plots[0]['py'] -= offset[1]
 
         # Wrap off-edge cells back around to other side (periodic boundary conditions).
-        pc.plots[0]['px'][pc.plots[0]['px'] < 0] += na.ceil(lightConeSlice['WidthBoxFraction'])
-        pc.plots[0]['py'][pc.plots[0]['py'] < 0] += na.ceil(lightConeSlice['WidthBoxFraction'])
+        lightConeSlice['pc'].plots[0]['px'][lightConeSlice['pc'].plots[0]['px'] < 0] += na.ceil(lightConeSlice['WidthBoxFraction'])
+        lightConeSlice['pc'].plots[0]['py'][lightConeSlice['pc'].plots[0]['py'] < 0] += na.ceil(lightConeSlice['WidthBoxFraction'])
 
         # After shifting, some cells have fractional coverage on both sides of the box.
         # Find those cells and make copies to be placed on the other side.
 
         # Cells hanging off the right edge.
-        add_x_right = pc.plots[0]['px'] + 0.5 * pc.plots[0]['pdx'] > na.ceil(lightConeSlice['WidthBoxFraction'])
-        add_x_px = pc.plots[0]['px'][add_x_right]
+        add_x_right = lightConeSlice['pc'].plots[0]['px'] + 0.5 * lightConeSlice['pc'].plots[0]['pdx'] > na.ceil(lightConeSlice['WidthBoxFraction'])
+        add_x_px = lightConeSlice['pc'].plots[0]['px'][add_x_right]
         add_x_px -= na.ceil(lightConeSlice['WidthBoxFraction'])
-        add_x_py = pc.plots[0]['py'][add_x_right]
-        add_x_pdx = pc.plots[0]['pdx'][add_x_right]
-        add_x_pdy = pc.plots[0]['pdy'][add_x_right]
-        add_x_field = pc.plots[0][field][add_x_right]
-        add_x_weight_field = pc.plots[0]['weight_field'][add_x_right]
+        add_x_py = lightConeSlice['pc'].plots[0]['py'][add_x_right]
+        add_x_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_x_right]
+        add_x_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_x_right]
+        add_x_field = lightConeSlice['pc'].plots[0][field][add_x_right]
+        add_x_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_x_right]
         del add_x_right
 
         # Cells hanging off the left edge.
-        add_x_left = pc.plots[0]['px'] - 0.5 * pc.plots[0]['pdx'] < 0
-        add2_x_px = pc.plots[0]['px'][add_x_left]
+        add_x_left = lightConeSlice['pc'].plots[0]['px'] - 0.5 * lightConeSlice['pc'].plots[0]['pdx'] < 0
+        add2_x_px = lightConeSlice['pc'].plots[0]['px'][add_x_left]
         add2_x_px += na.ceil(lightConeSlice['WidthBoxFraction'])
-        add2_x_py = pc.plots[0]['py'][add_x_left]
-        add2_x_pdx = pc.plots[0]['pdx'][add_x_left]
-        add2_x_pdy = pc.plots[0]['pdy'][add_x_left]
-        add2_x_field = pc.plots[0][field][add_x_left]
-        add2_x_weight_field = pc.plots[0]['weight_field'][add_x_left]
+        add2_x_py = lightConeSlice['pc'].plots[0]['py'][add_x_left]
+        add2_x_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_x_left]
+        add2_x_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_x_left]
+        add2_x_field = lightConeSlice['pc'].plots[0][field][add_x_left]
+        add2_x_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_x_left]
         del add_x_left
 
         # Cells hanging off the top edge.
-        add_y_right = pc.plots[0]['py'] + 0.5 * pc.plots[0]['pdy'] > na.ceil(lightConeSlice['WidthBoxFraction'])
-        add_y_px = pc.plots[0]['px'][add_y_right]
-        add_y_py = pc.plots[0]['py'][add_y_right]
+        add_y_right = lightConeSlice['pc'].plots[0]['py'] + 0.5 * lightConeSlice['pc'].plots[0]['pdy'] > na.ceil(lightConeSlice['WidthBoxFraction'])
+        add_y_px = lightConeSlice['pc'].plots[0]['px'][add_y_right]
+        add_y_py = lightConeSlice['pc'].plots[0]['py'][add_y_right]
         add_y_py -= na.ceil(lightConeSlice['WidthBoxFraction'])
-        add_y_pdx = pc.plots[0]['pdx'][add_y_right]
-        add_y_pdy = pc.plots[0]['pdy'][add_y_right]
-        add_y_field = pc.plots[0][field][add_y_right]
-        add_y_weight_field = pc.plots[0]['weight_field'][add_y_right]
+        add_y_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_y_right]
+        add_y_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_y_right]
+        add_y_field = lightConeSlice['pc'].plots[0][field][add_y_right]
+        add_y_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_y_right]
         del add_y_right
 
         # Cells hanging off the bottom edge.
-        add_y_left = pc.plots[0]['py'] - 0.5 * pc.plots[0]['pdy'] < 0
-        add2_y_px = pc.plots[0]['px'][add_y_left]
-        add2_y_py = pc.plots[0]['py'][add_y_left]
+        add_y_left = lightConeSlice['pc'].plots[0]['py'] - 0.5 * lightConeSlice['pc'].plots[0]['pdy'] < 0
+        add2_y_px = lightConeSlice['pc'].plots[0]['px'][add_y_left]
+        add2_y_py = lightConeSlice['pc'].plots[0]['py'][add_y_left]
         add2_y_py += na.ceil(lightConeSlice['WidthBoxFraction'])
-        add2_y_pdx = pc.plots[0]['pdx'][add_y_left]
-        add2_y_pdy = pc.plots[0]['pdy'][add_y_left]
-        add2_y_field = pc.plots[0][field][add_y_left]
-        add2_y_weight_field = pc.plots[0]['weight_field'][add_y_left]
+        add2_y_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_y_left]
+        add2_y_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_y_left]
+        add2_y_field = lightConeSlice['pc'].plots[0][field][add_y_left]
+        add2_y_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_y_left]
         del add_y_left
 
         # Add the hanging cells back to the projection data.
-        pc.plots[0].data['px'] = na.concatenate([pc.plots[0]['px'],add_x_px,add_y_px,add2_x_px,add2_y_px])
-        pc.plots[0].data['py'] = na.concatenate([pc.plots[0]['py'],add_x_py,add_y_py,add2_x_py,add2_y_py])
-        pc.plots[0].data['pdx'] = na.concatenate([pc.plots[0]['pdx'],add_x_pdx,add_y_pdx,add2_x_pdx,add2_y_pdx])
-        pc.plots[0].data['pdy'] = na.concatenate([pc.plots[0]['pdy'],add_x_pdy,add_y_pdy,add2_x_pdy,add2_y_pdy])
-        pc.plots[0].data[field] = na.concatenate([pc.plots[0][field],add_x_field,add_y_field,add2_x_field,add2_y_field])
-        pc.plots[0].data['weight_field'] = na.concatenate([pc.plots[0]['weight_field'],add_x_weight_field,add_y_weight_field,
+        lightConeSlice['pc'].plots[0].data['px'] = na.concatenate([lightConeSlice['pc'].plots[0]['px'],add_x_px,add_y_px,add2_x_px,add2_y_px])
+        lightConeSlice['pc'].plots[0].data['py'] = na.concatenate([lightConeSlice['pc'].plots[0]['py'],add_x_py,add_y_py,add2_x_py,add2_y_py])
+        lightConeSlice['pc'].plots[0].data['pdx'] = na.concatenate([lightConeSlice['pc'].plots[0]['pdx'],add_x_pdx,add_y_pdx,add2_x_pdx,add2_y_pdx])
+        lightConeSlice['pc'].plots[0].data['pdy'] = na.concatenate([lightConeSlice['pc'].plots[0]['pdy'],add_x_pdy,add_y_pdy,add2_x_pdy,add2_y_pdy])
+        lightConeSlice['pc'].plots[0].data[field] = na.concatenate([lightConeSlice['pc'].plots[0][field],add_x_field,add_y_field,add2_x_field,add2_y_field])
+        lightConeSlice['pc'].plots[0].data['weight_field'] = na.concatenate([lightConeSlice['pc'].plots[0]['weight_field'],add_x_weight_field,add_y_weight_field,
                                                            add2_x_weight_field,add2_y_weight_field])
 
         # Delete original copies of hanging cells.
@@ -204,16 +207,35 @@
 
         # Tiles were made rounding up the width to the nearest integer.
         # Cut off the edges to get the specified width.
-        pc.set_xlim(0,lightConeSlice['WidthBoxFraction'])
-        pc.set_ylim(0,lightConeSlice['WidthBoxFraction'])
+        # Cut in the x direction.
+        cut_x = lightConeSlice['pc'].plots[0].data['px'] - 0.5 * lightConeSlice['pc'].plots[0].data['pdx'] < lightConeSlice['WidthBoxFraction']
+        lightConeSlice['pc'].plots[0].data['px'] = lightConeSlice['pc'].plots[0].data['px'][cut_x]
+        lightConeSlice['pc'].plots[0].data['py'] = lightConeSlice['pc'].plots[0].data['py'][cut_x]
+        lightConeSlice['pc'].plots[0].data['pdx'] = lightConeSlice['pc'].plots[0].data['pdx'][cut_x]
+        lightConeSlice['pc'].plots[0].data['pdy'] = lightConeSlice['pc'].plots[0].data['pdy'][cut_x]
+        lightConeSlice['pc'].plots[0].data[field] = lightConeSlice['pc'].plots[0].data[field][cut_x]
+        lightConeSlice['pc'].plots[0].data['weight_field'] = lightConeSlice['pc'].plots[0].data['weight_field'][cut_x]
+        del cut_x
+
+        # Cut in the y direction.
+        cut_y = lightConeSlice['pc'].plots[0].data['py'] - 0.5 * lightConeSlice['pc'].plots[0].data['pdy'] < lightConeSlice['WidthBoxFraction']
+        lightConeSlice['pc'].plots[0].data['px'] = lightConeSlice['pc'].plots[0].data['px'][cut_y]
+        lightConeSlice['pc'].plots[0].data['py'] = lightConeSlice['pc'].plots[0].data['py'][cut_y]
+        lightConeSlice['pc'].plots[0].data['pdx'] = lightConeSlice['pc'].plots[0].data['pdx'][cut_y]
+        lightConeSlice['pc'].plots[0].data['pdy'] = lightConeSlice['pc'].plots[0].data['pdy'][cut_y]
+        lightConeSlice['pc'].plots[0].data[field] = lightConeSlice['pc'].plots[0].data[field][cut_y]
+        lightConeSlice['pc'].plots[0].data['weight_field'] = lightConeSlice['pc'].plots[0].data['weight_field'][cut_y]
+        del cut_y
 
         # Save an image if requested.
         if save_image:
-            pc.save(name)
+            lightConeSlice['pc'].set_xlim(0,lightConeSlice['WidthBoxFraction'])
+            lightConeSlice['pc'].set_ylim(0,lightConeSlice['WidthBoxFraction'])
+            lightConeSlice['pc'].save(name)
 
         # Create fixed resolution buffer to return back to the light cone object.
         # These buffers will be stacked together to make the light cone.
-        frb = raven.FixedResolutionBuffer(pc.plots[0].data,(0,lightConeSlice['WidthBoxFraction'],0,lightConeSlice['WidthBoxFraction']),
+        frb = raven.FixedResolutionBuffer(lightConeSlice['pc'].plots[0].data,(0,lightConeSlice['WidthBoxFraction'],0,lightConeSlice['WidthBoxFraction']),
                                           (pixels,pixels),antialias=False)
 
         return frb



More information about the yt-svn mailing list