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

britton at wrangler.dreamhost.com britton at wrangler.dreamhost.com
Tue Nov 11 15:32:37 PST 2008


Author: britton
Date: Tue Nov 11 15:32:36 2008
New Revision: 918
URL: http://yt.spacepope.org/changeset/918

Log:
The function RecycleLightConeSolution has been renamed 
RerandomizeLightConeSolution and is now a general solution rescrambler.  If 
the keyword, recycle=True, is thrown, the solution will be recycled based on 
the original solution.  If recycle=False is thrown, an entirely new 
randomization will be made.  In each case, the code will calculate the 
fractional volume in common with the last solution made.

Additionally, if a random seed is not given in the parameter file, one can 
be supplied to CalculateLightConeSolution with the keyword, seed.


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

Modified: trunk/yt/extensions/lightcone/LightCone.py
==============================================================================
--- trunk/yt/extensions/lightcone/LightCone.py	(original)
+++ trunk/yt/extensions/lightcone/LightCone.py	Tue Nov 11 15:32:36 2008
@@ -64,12 +64,15 @@
         # Calculate maximum delta z for each data dump.
         self._CalculateDeltaZMax()
 
-    def CalculateLightConeSolution(self):
+    def CalculateLightConeSolution(self,seed=None):
         "Create list of projections to be added together to make the light cone."
 
         # Make sure recycling flag is off.
         self.recycleSolution = False
 
+        if seed is not None:
+            self.lightConeParameters['RandomSeed'] = seed
+
         # Make light cone using minimum number of projections.
         if (self.lightConeParameters['UseMinimumNumberOfProjections']):
 
@@ -216,7 +219,7 @@
         # Return the plot collection so the user can remake the plot if they want.
         return pc
 
-    def RecycleLightConeSolution(self,newSeed):
+    def RerandomizeLightConeSolution(self,newSeed,recycle=True):
         """
         When making a projection for a light cone, only randomizations along the line of sight make any 
         given projection unique, since the lateral shifting and tiling is done after the projection is made.
@@ -225,28 +228,38 @@
         This routine will take in a new random seed and rerandomize the parts of the light cone that do not contribute 
         to creating a unique projection object.  Additionally, this routine is built such that if the same random 
         seed is given for the rerandomizing, the solution will be identical to the original.
+
+        This routine has now been updated to be a general solution rescrambler.  If the keyword recycle is set to 
+        True, then it will recycle.  Otherwise, it will create a completely new solution.
         """
 
-        mylog.info("Recycling solution made with %s with new seed %s." % (str(self.lightConeParameters['RandomSeed']),
-                                                                          str(newSeed)))
+        if recycle:
+            mylog.info("Recycling solution made with %s with new seed %s." % (self.lightConeParameters['RandomSeed'],
+                                                                              newSeed))
+            self.recycleRandomSeed = newSeed
+        else:
+            mylog.info("Creating new solution with random seed %s." % newSeed)
+            self.lightConeParameters['RandomSeed'] = newSeed
+            self.recycleRandomSeed = 0
 
-        self.recycleSolution = True
-        self.recycleRandomSeed = newSeed
+        self.recycleSolution = recycle
 
         # Keep track of fraction of volume in common between the original and recycled solution.
         commonVolume = 0.0
         totalVolume = 0.0
 
         # Seed random number generator with new seed.
-        rand.seed(self.recycleRandomSeed)
+        rand.seed(newSeed)
 
         for q,output in enumerate(self.lightConeSolution):
             # It is necessary to make the same number of calls to the random number generator
             # so the original solution willbe produced if the same seed is given.
 
             # Get random projection axis and center.
-            # Axis will get thrown away since it is used in creating a unique projection object.
+            # If recyclsing, axis will get thrown away since it is used in creating a unique projection object.
             newAxis = rand.randint(0,2)
+            if not recycle:
+                output['ProjectionAxis'] = newAxis
 
             newCenter = [rand.random(),rand.random(),rand.random()]
 
@@ -255,24 +268,29 @@
             oldCube = na.zeros(shape=(len(newCenter),2))
             for w in range(len(newCenter)):
                 if (w == output['ProjectionAxis']):
-                    newCube[w] = [output['ProjectionCenter'][w] - 0.5 * output['DepthBoxFraction'],
+                    oldCube[w] = [output['ProjectionCenter'][w] - 0.5 * output['DepthBoxFraction'],
                                   output['ProjectionCenter'][w] + 0.5 * output['DepthBoxFraction']]
-                    oldCube[w] = newCube[w]
+                    # If recycling old solution, then keep center for axis in line of sight.
+                    if recycle:
+                        newCube[w] = oldCube[w]
+                    else:
+                        newCube[w] = [newCenter[w] - 0.5 * output['DepthBoxFraction'],
+                                      newCenter[w] + 0.5 * output['DepthBoxFraction']]
                 else:
-                    newCube[w] = [newCenter[w] - 0.5 * output['WidthBoxFraction'],
-                                  newCenter[w] + 0.5 * output['WidthBoxFraction']]
                     oldCube[w] = [output['ProjectionCenter'][w] - 0.5 * output['WidthBoxFraction'],
                                   output['ProjectionCenter'][w] + 0.5 * output['WidthBoxFraction']]
+                    newCube[w] = [newCenter[w] - 0.5 * output['WidthBoxFraction'],
+                                  newCenter[w] + 0.5 * output['WidthBoxFraction']]
 
             commonVolume += commonNVolume(oldCube,newCube,periodic=na.array([[0,1],[0,1],[0,1]]))
             totalVolume += output['DepthBoxFraction'] * output['WidthBoxFraction']**2
 
             # Replaces centers for every axis except the line of sight axis.
             for w in range(len(newCenter)):
-                if (w != self.lightConeSolution[q]['ProjectionAxis']):
+                if not(recycle and (w == self.lightConeSolution[q]['ProjectionAxis'])):
                     self.lightConeSolution[q]['ProjectionCenter'][w] = newCenter[w]
 
-        mylog.info("Recycled solution has %.2e of total volume in common with the original." % (commonVolume/totalVolume))
+        mylog.info("Fraction of total volume in common with old solution is %.2e." % (commonVolume/totalVolume))
 
     def SaveLightConeSolution(self,file="light_cone.dat"):
         "Write out a text file with information on light cone solution."



More information about the yt-svn mailing list