[Yt-svn] yt-commit r1786 - in branches/yt-1.7/yt: extensions lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Wed Jun 30 08:45:51 PDT 2010


Author: mturk
Date: Wed Jun 30 08:45:50 2010
New Revision: 1786
URL: http://yt.enzotools.org/changeset/1786

Log:
Backporting fixes for merger tree, two point functions, and parallel data file
access from trunk



Modified:
   branches/yt-1.7/yt/extensions/merger_tree.py
   branches/yt-1.7/yt/lagos/HierarchyType.py
   branches/yt-1.7/yt/lagos/TwoPointFunctions.py

Modified: branches/yt-1.7/yt/extensions/merger_tree.py
==============================================================================
--- branches/yt-1.7/yt/extensions/merger_tree.py	(original)
+++ branches/yt-1.7/yt/extensions/merger_tree.py	Wed Jun 30 08:45:50 2010
@@ -752,6 +752,118 @@
             results = self.cursor.fetchone()
         return items
 
+    def get_GlobalHaloID(self, SnapHaloID, z):
+        r"""Returns the GlobalHaloID for the given halo.
+        
+        Parameters
+        ---------
+        SnapHaloID : Integer
+            The index label for the halo of interest, equivalent to
+            the first column of the halo finder text output file.
+        z : Float
+            The redshift for the halo of interest. The value returned will be
+            for the halo with SnapHaloID equal to ID (above) with redshift
+            closest to this value.
+        
+        Examples
+        --------
+        >>> this_halo = mtc.get_GlobalHaloID(0, 0.)
+        """
+        string = "SELECT GlobalHaloID,SnapZ FROM Halos WHERE SnapHaloID = %d;" \
+            % SnapHaloID
+        minz = 99999.
+        # If -1 is returned, something went wrong.
+        this_halo = -1
+        self.cursor.execute(string)
+        results = self.cursor.fetchone()
+        while results:
+            if results[1] < minz:
+                minz = results[1]
+                this_halo = results[0]
+            results = self.cursor.fetchone()
+        return this_halo
+
+    def get_halo_parents(self, GlobalHaloID):
+        r"""Returns a list of the parent halos to the given halo, along with
+        the contribution fractions from parent to child.
+        
+        This function returns a list of lists, where each entry in the top list
+        is [GlobalHaloID, ChildHaloFrac] of the parent halo in relationship
+        to the given child halo.
+        
+        Parameters
+        ----------
+        GlobalHaloID : Integer
+            The GlobalHaloID of the halo of interest.
+        
+        Examples
+        --------
+        >>> parents = mtc.get_halo_parents(1688)
+        >>> print parents
+        [[1544, 0.9642857141249418],
+         [1613, 0.0],
+         [1614, 0.0],
+         [1489, 0.0],
+         [1512, 0.0],
+         [1519, 0.0],
+         [1609, 0.0]]
+        """
+        parents = []
+        for i in range(5):
+            string = "SELECT GlobalHaloID, ChildHaloFrac%d FROM Halos\
+            WHERE ChildHaloID%d=%d;" % (i, i, GlobalHaloID)
+            self.cursor.execute(string)
+            results = self.cursor.fetchone()
+            while results:
+                parents.append([results[0], results[1]])
+                results = self.cursor.fetchone()
+        return parents
+
+    def get_halo_info(self, GlobalHaloID):
+        r"""Returns all available information for the given GlobalHaloID
+        in the form of a dict.
+        
+        Parameters
+        ----------
+        GlobalHaloID : Integer
+            The unique index for the halo of interest.
+        
+        Examples
+        --------
+        >>> info = mtc.get_halo_info(1544)
+        >>> print info
+        {'BulkVelX': -32759799.359999999,
+         'BulkVelY': -28740239.109999999,
+         'BulkVelZ': -20066000.690000001,
+         'CenMassX': 0.23059111360000001,
+         'CenMassY': 0.4061139809,
+         'CenMassZ': 0.80882763749999997,
+         'ChildHaloFrac0': 0.9642857141249418,
+         'ChildHaloFrac1': 0.0,
+         'ChildHaloFrac2': 0.0,
+         'ChildHaloFrac3': 0.0,
+         'ChildHaloFrac4': 0.0,
+         'ChildHaloID0': 1688,
+         'ChildHaloID1': 1712,
+         'ChildHaloID2': 1664,
+         'ChildHaloID3': 1657,
+         'ChildHaloID4': 1634,
+         'GlobalHaloID': 1544,
+         'HaloMass': 20934692770000.0,
+         'MaxRad': 0.01531299899,
+         'NumPart': 196,
+         'SnapCurrentTimeIdentifier': 1275946788,
+         'SnapHaloID': 56,
+         'SnapZ': 0.024169713061444002}
+        """
+        string = "SELECT * FROM Halos WHERE GlobalHaloID=%d;" % GlobalHaloID
+        d = {}
+        self.cursor.execute(string)
+        results = self.cursor.fetchone()
+        for pair in zip(columns, results):
+            d[pair[0]] = pair[1]
+        return d
+
 class Node(object):
     def __init__(self, CoM, mass, parentIDs, z, color):
         self.CoM = CoM

Modified: branches/yt-1.7/yt/lagos/HierarchyType.py
==============================================================================
--- branches/yt-1.7/yt/lagos/HierarchyType.py	(original)
+++ branches/yt-1.7/yt/lagos/HierarchyType.py	Wed Jun 30 08:45:50 2010
@@ -144,21 +144,30 @@
                 fn = os.path.join(self.directory,
                         "%s.yt" % self.parameter_file.basename)
         dir_to_check = os.path.dirname(fn)
-        if os.path.isfile(fn):
-            writable = os.access(fn, os.W_OK)
+        # We have four options:
+        #    Writeable, does not exist      : create, open as append
+        #    Writeable, does exist          : open as append
+        #    Not writeable, does not exist  : do not attempt to open
+        #    Not writeable, does exist      : open as read-only
+        exists = os.path.isfile(fn)
+        if not exists:
+            writeable = os.access(dir_to_check, os.W_OK)
         else:
-            writable = os.access(dir_to_check, os.W_OK)
-        if ytcfg.getboolean('lagos','onlydeserialize') or not writable:
-            self._data_mode = mode = 'r'
+            writeable = os.access(fn, os.W_OK)
+        writeable = writeable and not ytcfg.getboolean('lagos','onlydeserialize')
+        # We now have our conditional stuff
+        if not writeable and not exists: return
+        if writeable:
+            self._data_mode = 'a'
+            if not exists: self.__create_data_file(fn)
         else:
-            self._data_mode = mode = 'a'
-
-        self.__create_data_file(fn)
+            self._data_mode = 'r'
         self.__data_filename = fn
         self._data_file = h5py.File(fn, self._data_mode)
 
-    @parallel_root_only
     def __create_data_file(self, fn):
+        # Note that this used to be parallel_root_only; it no longer is,
+        # because we have better logic to decide who owns the file.
         f = h5py.File(fn, 'a')
         f.close()
 

Modified: branches/yt-1.7/yt/lagos/TwoPointFunctions.py
==============================================================================
--- branches/yt-1.7/yt/lagos/TwoPointFunctions.py	(original)
+++ branches/yt-1.7/yt/lagos/TwoPointFunctions.py	Wed Jun 30 08:45:50 2010
@@ -796,7 +796,14 @@
             for d1 in range(dim):
                 multi *= self.bin_edges[d1].size
             if dim == 0 and len(self.out_labels)==1:
-                digi = na.digitize(results, self.bin_edges[dim])
+                try:
+                    digi = na.digitize(results, self.bin_edges[dim])
+                except ValueError:
+                    # The user probably did something like 
+                    # return a * b rather than
+                    # return a[0] * b[0], which will only happen
+                    # for single field functions.
+                    digi = na.digitize(results[0], self.bin_edges[dim])
             else:
                 digi = na.digitize(results[:,dim], self.bin_edges[dim])
             too_low = (digi == 0)



More information about the yt-svn mailing list