[Yt-svn] yt-commit r400 - trunk/yt/lagos

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Sat Apr 12 12:51:19 PDT 2008


Author: mturk
Date: Sat Apr 12 12:51:19 2008
New Revision: 400
URL: http://yt.spacepope.org/changeset/400

Log:
Some quick fixes to make sure that we don't get errors in the case where no
datapoints match the criteria for a profile, and additionally we force a cast
to float64 for all of the data fields in profiles.



Modified:
   trunk/yt/lagos/Profiles.py

Modified: trunk/yt/lagos/Profiles.py
==============================================================================
--- trunk/yt/lagos/Profiles.py	(original)
+++ trunk/yt/lagos/Profiles.py	Sat Apr 12 12:51:19 2008
@@ -121,11 +121,11 @@
         inv_bin_indices = args
         if check_cut:
             cm = self._data_source._get_point_indices(source)
-            source_data = source[field][cm]
-            if weight: weight_data = source[weight][cm]
+            source_data = source[field][cm].astype('float64')
+            if weight: weight_data = source[weight][cm].astype('float64')
         else:
-            source_data = source[field]
-            if weight: weight_data = source[weight]
+            source_data = source[field].astype('float64')
+            if weight: weight_data = source[weight].astype('float64')
         binned_field = self._get_empty_field()
         weight_field = self._get_empty_field()
         used_field = na.ones(weight_field.shape, dtype='bool')
@@ -146,6 +146,27 @@
             source_data = source[self.bin_field][cm]
         else:
             source_data = source[self.bin_field]
+        if source_data.size == 0:
+            return
+        mi = na.where( (source_data > self[self.bin_field].min())
+                     & (source_data < self[self.bin_field].max()))
+        sd = source_data[mi]
+        if sd.size == 0:
+            return
+        bin_indices = na.digitize(sd, self[self.bin_field])
+        # Now we set up our inverse bin indices
+        inv_bin_indices = {}
+        for bin in range(self[self.bin_field].size):
+            inv_bin_indices[bin] = na.where(bin_indices == bin)
+        return inv_bin_indices
+
+    @preserve_source_parameters
+    def old_get_bins(self, source, check_cut=False):
+        if check_cut:
+            cm = self._data_source._get_point_indices(source)
+            source_data = source[self.bin_field][cm]
+        else:
+            source_data = source[self.bin_field]
         bin_order = na.argsort(source_data)
         bin_indices = na.searchsorted(self[self.bin_field],
                                       source_data)
@@ -191,13 +212,13 @@
                    args, check_cut=False):
         if check_cut:
             pointI = self._data_source._get_point_indices(source)
-            source_data = source[field][pointI].ravel()
-            weight_data = na.ones(source_data.shape)
-            if weight: weight_data = source[weight][pointI].ravel()
-        else:
-            source_data = source[field].ravel()
-            weight_data = na.ones(source_data.shape)
-            if weight: weight_data = source[weight].ravel()
+            source_data = source[field][pointI].ravel().astype('float64')
+            weight_data = na.ones(source_data.shape).astype('float64')
+            if weight: weight_data = source[weight][pointI].ravel().astype('float64')
+        else:
+            source_data = source[field].ravel().astype('float64')
+            weight_data = na.ones(source_data.shape).astype('float64')
+            if weight: weight_data = source[weight].ravel().astype('float64')
         self.total_stuff = source_data.sum()
         binned_field = self._get_empty_field()
         weight_field = self._get_empty_field()



More information about the yt-svn mailing list