[yt-svn] commit/yt: ngoldbaum: Merged in chummels/yt (pull request #1543)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Jul 9 09:45:41 PDT 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/832060c8ef25/
Changeset:   832060c8ef25
Branch:      yt
User:        ngoldbaum
Date:        2015-07-09 16:45:29+00:00
Summary:     Merged in chummels/yt (pull request #1543)

slight [API_CHANGE] Generalizing derived quantity outputs to all be YTArrays or lists of YTArrays as appropriate
Affected #:  1 file

diff -r 7ec5b0eb212762924b344dcb9a94e04f475d5606 -r 832060c8ef256adf8a22bac6f60f8de418d4541e yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -96,6 +96,10 @@
     r"""
     Calculates the weight average of a field or fields.
 
+    Returns a YTQuantity for each field requested; if one,
+    it returns a single YTQuantity, if many, it returns a list of YTQuantities
+    in order of the listed fields.  
+
     Where f is the field and w is the weight, the weighted average is
     Sum_i(f_i \* w_i) / Sum_i(w_i).
 
@@ -173,8 +177,9 @@
 
 class TotalMass(TotalQuantity):
     r"""
-    Calculates the total mass in gas and particles. Returns a tuple where the
-    first part is total gas mass and the second part is total particle mass.
+    Calculates the total mass of the object. Returns a YTArray where the
+    first element is total gas mass and the second element is total particle 
+    mass.
 
     Examples
     --------
@@ -189,11 +194,14 @@
         fi = self.data_source.ds.field_info
         fields = []
         if ("gas", "cell_mass") in fi:
-            fields.append(("gas", "cell_mass"))
+            gas = super(TotalMass, self).__call__([('gas', 'cell_mass')])
+        else:
+            gas = self.data_source.ds.arr([0], 'g')
         if ("all", "particle_mass") in fi:
-            fields.append(("all", "particle_mass"))
-        rv = super(TotalMass, self).__call__(fields)
-        return rv
+            part = super(TotalMass, self).__call__([('all', 'particle_mass')])
+        else:
+            part = self.data_source.ds.arr([0], 'g')
+        return self.data_source.ds.arr([gas, part])
 
 class CenterOfMass(DerivedQuantity):
     r"""
@@ -330,7 +338,10 @@
 class WeightedVariance(DerivedQuantity):
     r"""
     Calculates the weighted variance and weighted mean for a field
-    or list of fields.
+    or list of fields. Returns a YTArray for each field requested; if one,
+    it returns a single YTArray, if many, it returns a list of YTArrays
+    in order of the listed fields.  The first element of each YTArray is
+    the weighted variance, and the second element is the weighted mean.
 
     Where f is the field, w is the weight, and <f_w> is the weighted mean,
     the weighted variance is
@@ -384,10 +395,10 @@
             my_mean = values[i]
             my_var2 = values[i + int(len(values) / 2)]
             all_mean = (my_weight * my_mean).sum(dtype=np.float64) / all_weight
-            rvals.append(np.sqrt((my_weight * (my_var2 +
-                                               (my_mean - all_mean)**2)).sum(dtype=np.float64) /
-                                               all_weight))
-            rvals.append(all_mean)
+            rvals.append(self.data_source.ds.arr([(np.sqrt((my_weight * 
+                                                 (my_var2 + (my_mean - 
+                                                  all_mean)**2)).sum(dtype=np.float64) 
+                                                  / all_weight)), all_mean]))
         return rvals
 
 class AngularMomentumVector(DerivedQuantity):
@@ -395,6 +406,7 @@
     Calculates the angular momentum vector, using gas and/or particles.
 
     The angular momentum vector is the mass-weighted mean specific angular momentum.
+    Returns a YTArray of the vector.
 
     Parameters
     ----------
@@ -416,10 +428,6 @@
 
     """
     def count_values(self, use_gas=True, use_particles=True):
-        use_gas &= \
-          (("gas", "cell_mass") in self.data_source.ds.field_info)
-        use_particles &= \
-          (("all", "particle_mass") in self.data_source.ds.field_info)
         num_vals = 0
         if use_gas: num_vals += 4
         if use_particles: num_vals += 4
@@ -453,11 +461,15 @@
             jy += values.pop(0).sum(dtype=np.float64)
             jz += values.pop(0).sum(dtype=np.float64)
             m  += values.pop(0).sum(dtype=np.float64)
-        return (jx / m, jy / m, jz / m)
+        return self.data_source.ds.arr([jx / m, jy / m, jz / m])
 
 class Extrema(DerivedQuantity):
     r"""
     Calculates the min and max value of a field or list of fields.
+    Returns a YTArray for each field requested.  If one, a single YTArray
+    is returned, if many, a list of YTArrays in order of field list is 
+    returned.  The first element of each YTArray is the minimum of the
+    field and the second is the maximum of the field.
 
     Parameters
     ----------
@@ -500,7 +512,7 @@
 
     def reduce_intermediate(self, values):
         # The values get turned into arrays here.
-        return [(mis.min(), mas.max() )
+        return [self.data_source.ds.arr([mis.min(), mas.max()])
                 for mis, mas in zip(values[::2], values[1::2])]
 
 class MaxLocation(DerivedQuantity):

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list