[yt-svn] commit/yt: 10 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Mar 17 16:42:25 PDT 2014
10 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/e120579fe649/
Changeset: e120579fe649
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 15:01:47
Summary: Adding gravitational potential and fixing energy units.
Affected #: 1 file
diff -r c1fa5b0b65e9025d2f686e1f8464d6b343dff4ed -r e120579fe64917077ffaa5877f8292d47fc547f6 yt/frontends/enzo/fields.py
--- a/yt/frontends/enzo/fields.py
+++ b/yt/frontends/enzo/fields.py
@@ -68,6 +68,7 @@
("z-velocity", (vel_units, ["velocity_z"], None)),
("RaySegments", ("", ["ray_segments"], None)),
("PhotoGamma", (ra_units, ["photo_gamma"], None)),
+ ("PotentialField", ("code_velocity**2", ["gravitational_potential"], None)),
("Density", (rho_units, ["density"], None)),
("Metal_Density", (rho_units, ["metal_density"], None)),
("SN_Colour", (rho_units, [], None)),
@@ -178,13 +179,13 @@
if self.pf.parameters["HydroMethod"] == 2:
self.add_output_field(("enzo", te_name),
- units="code_length**2/code_time**2")
+ units="code_velocity**2")
self.alias(("gas", "thermal_energy"), ("enzo", te_name))
elif self.pf.parameters["DualEnergyFormalism"] == 1:
self.add_output_field(
("enzo", ge_name),
- units="code_length**2/code_time**2")
+ units="code_velocity**2")
self.alias(
("gas", "thermal_energy"),
("enzo", ge_name),
@@ -192,7 +193,7 @@
elif self.pf.parameters["HydroMethod"] in (4, 6):
self.add_output_field(
("enzo", te_name),
- units="code_length**2/code_time**2")
+ units="code_velocity**2")
# Subtract off B-field energy
def _sub_b(field, data):
return data[te_name] - 0.5*(
@@ -206,7 +207,7 @@
else: # Otherwise, we assume TotalEnergy is kinetic+thermal
self.add_output_field(
("enzo", te_name),
- units = "code_length**2/code_time**2")
+ units = "code_velocity**2")
def _tot_minus_kin(field, data):
return data[te_name] - 0.5*(
data["x-velocity"]**2.0
https://bitbucket.org/yt_analysis/yt/commits/df98e249cc0d/
Changeset: df98e249cc0d
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 17:42:15
Summary: Adding angular momentum magnitude fields.
Affected #: 1 file
diff -r e120579fe64917077ffaa5877f8292d47fc547f6 -r df98e249cc0d90576031b37d3d38f746f8de0331 yt/fields/angular_momentum.py
--- a/yt/fields/angular_momentum.py
+++ b/yt/fields/angular_momentum.py
@@ -28,6 +28,9 @@
from .field_plugin_registry import \
register_field_plugin
+from .vector_operations import \
+ create_magnitude_field
+
from yt.utilities.lib.geometry_utils import \
obtain_rvec, obtain_rv_vec
@@ -79,6 +82,9 @@
units="cm**2/s",
validators=[ValidateParameter("center")])
+ create_magnitude_field(registry, "specific_angular_momentum",
+ "cm**2 / s", ftype=ftype)
+
def _angular_momentum_x(field, data):
return data[ftype, "cell_mass"] \
* data[ftype, "specific_angular_momentum_x"]
@@ -103,3 +109,6 @@
units="g * cm**2 / s",
validators=[ValidateParameter('center')])
+ create_magnitude_field(registry, "angular_momentum",
+ "g * cm**2 / s", ftype=ftype)
+
https://bitbucket.org/yt_analysis/yt/commits/84875ada3320/
Changeset: 84875ada3320
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 17:42:49
Summary: Adding particle angular momentum magnitude fields.
Affected #: 2 files
diff -r df98e249cc0d90576031b37d3d38f746f8de0331 -r 84875ada332095e2d1ce2e3f125c89d277f6cfd6 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -39,7 +39,10 @@
get_cyl_z, get_sph_r, \
get_sph_theta, get_sph_phi, \
periodic_dist, euclidean_dist
-
+
+from .vector_operations import \
+ create_magnitude_field
+
def _field_concat(fname):
def _AllFields(field, data):
v = []
@@ -210,7 +213,7 @@
+ (data[ptype, svel % 'y'] - bulk_velocity[1])**2
+ (data[ptype, svel % 'z'] - bulk_velocity[2])**2 )
- registry.add_field((ptype, "particle_velocity_magnitude"),
+ registry.add_field((ptype, "particle_velocity_magnitude"),
function=_particle_velocity_magnitude,
particle_type=True,
take_log=False,
@@ -293,6 +296,9 @@
units="cm**2/s",
validators=[ValidateParameter("center")])
+ create_magnitude_field(registry, "particle_specific_angular_momentum",
+ "cm**2/s", ftype=ptype, particle_type=True)
+
def _particle_angular_momentum(field, data):
return data[ptype, "particle_mass"] \
* data[ptype, "particle_specific_angular_momentum"]
@@ -321,6 +327,9 @@
units="g*cm**2/s", particle_type=True,
validators=[ValidateParameter('center')])
+ create_magnitude_field(registry, "particle_angular_momentum",
+ "g*cm**2/s", ftype=ptype, particle_type=True)
+
from .field_functions import \
get_radius
diff -r df98e249cc0d90576031b37d3d38f746f8de0331 -r 84875ada332095e2d1ce2e3f125c89d277f6cfd6 yt/fields/vector_operations.py
--- a/yt/fields/vector_operations.py
+++ b/yt/fields/vector_operations.py
@@ -41,7 +41,7 @@
def create_magnitude_field(registry, basename, field_units,
ftype = "gas", slice_info = None,
- validators = None):
+ validators = None, particle_type=False):
xn, yn, zn = [(ftype, "%s_%s" % (basename, ax)) for ax in 'xyz']
@@ -59,7 +59,7 @@
registry.add_field((ftype, "%s_magnitude" % basename),
function = _magnitude, units = field_units,
- validators = validators)
+ validators = validators, particle_type = particle_type)
def create_vector_fields(registry, basename, field_units,
ftype = "gas", slice_info = None):
https://bitbucket.org/yt_analysis/yt/commits/88993e6371d9/
Changeset: 88993e6371d9
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 17:43:27
Summary: Adding spin parameter derived quantity.
Affected #: 1 file
diff -r 84875ada332095e2d1ce2e3f125c89d277f6cfd6 -r 88993e6371d9be6144e3a1a186adc55a29895b88 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -354,41 +354,32 @@
i = np.argmin(values[0]) # ma is values[0]
return [val[i] for val in values]
-def _BaryonSpinParameter(data):
- """
- This function returns the spin parameter for the baryons, but it uses
- the particles in calculating enclosed mass.
- """
- m_enc = _TotalMass(data)
- amx = data["specific_angular_momentum_x"]*data["cell_mass"]
- amy = data["specific_angular_momentum_y"]*data["cell_mass"]
- amz = data["specific_angular_momentum_z"]*data["cell_mass"]
- j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
- e_term_pre = np.sum(data["cell_mass"]*data["velocity_magnitude"]**2.0,dtype=np.float64)
- weight=data["cell_mass"].sum(dtype=np.float64)
- return j_mag, m_enc, e_term_pre, weight
-def _combBaryonSpinParameter(data, j_mag, m_enc, e_term_pre, weight):
- # Because it's a vector field, we have to ensure we have enough dimensions
- if len(j_mag.shape) < 2: j_mag = np.expand_dims(j_mag, 0)
- W = weight.sum()
- M = m_enc.sum()
- J = np.sqrt(((j_mag.sum(axis=0))**2.0).sum())/W
- E = np.sqrt(e_term_pre.sum()/W)
- spin = J * E / (M * mass_sun_cgs * gravitational_constant_cgs)
- return spin
+class SpinParameter(DerivedQuantity):
+ def count_values(self, **kwargs):
+ self.num_vals = 3
-def _ParticleSpinParameter(data):
- """
- This function returns the spin parameter for the baryons, but it uses
- the particles in calculating enclosed mass.
- """
- m_enc = _TotalMass(data)
- amx = data["particle_specific_angular_momentum_x"]*data["particle_mass"]
- if amx.size == 0: return (np.zeros((3,), dtype=np.float64), m_enc, 0, 0)
- amy = data["particle_specific_angular_momentum_y"]*data["particle_mass"]
- amz = data["particle_specific_angular_momentum_z"]*data["particle_mass"]
- j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
- e_term_pre = np.sum(data["particle_mass"]
- *data["particle_velocity_magnitude"]**2.0,dtype=np.float64)
- weight=data["particle_mass"].sum(dtype=np.float64)
- return j_mag, m_enc, e_term_pre, weight
+ def process_chunk(self, data, use_gas=True, use_particles=True):
+ include_gas = use_gas & \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ include_particles = use_particles & \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
+ e = data.pf.quan(0., "erg")
+ j = data.pf.quan(0., "g*cm**2/s")
+ m = data.pf.quan(0., "g")
+ if include_gas:
+ e += (data["gas", "kinetic_energy"] *
+ data["index", "cell_volume"]).sum(dtype=np.float64)
+ j += data["gas", "angular_momentum_magnitude"].sum(dtype=np.float64)
+ m += data["gas", "cell_mass"].sum(dtype=np.float64)
+ if include_particles:
+ e += (data["all", "particle_velocity_magnitude"]**2 *
+ data["all", "particle_mass"]).sum(dtype=np.float64)
+ j += data["all", "particle_angular_momentum_magnitude"].sum(dtype=np.float64)
+ m += data["all", "particle_mass"].sum(dtype=np.float64)
+ return (e, j, m)
+
+ def reduce_intermediate(self, values):
+ e = values.pop(0).sum(dtype=np.float64)
+ j = values.pop(0).sum(dtype=np.float64)
+ m = values.pop(0).sum(dtype=np.float64)
+ return j * np.sqrt(e) / m**2.5 / gravitational_constant_cgs
https://bitbucket.org/yt_analysis/yt/commits/99da293a4fd5/
Changeset: 99da293a4fd5
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 18:06:43
Summary: Replacing separate gas and particle angular momentum vector derived quantities with a single one that can do either or both.
Affected #: 1 file
diff -r 88993e6371d9be6144e3a1a186adc55a29895b88 -r 99da293a4fd58014783582a7f5bd8be1f43cbd48 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -259,20 +259,47 @@
all_weight))
rvals.append(all_mean)
return rvals
+
+class AngularMomentumVector(DerivedQuantity):
+ def count_values(self, use_gas=True, use_particles=True):
+ include_gas = use_gas & \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ include_particles = use_particles & \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
+ num_vals = 0
+ if include_gas: num_vals += 4
+ if include_particles: num_vals += 4
+ self.num_vals = num_vals
-class AngularMomentumVector(WeightedAverageQuantity):
- def __call__(self, ftype = "gas"):
- fields = [(ftype, "specific_angular_momentum_%s" % ax)
- for ax in 'xyz']
- weight = (ftype, "cell_mass")
- return super(AngularMomentumVector, self).__call__(fields, weight)
+ def process_chunk(self, data, use_gas=True, use_particles=True):
+ include_gas = use_gas & \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ include_particles = use_particles & \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
+ rvals = []
+ if include_gas:
+ rvals.extend([(data["gas", "specific_angular_momentum_%s" % axis] *
+ data["gas", "cell_mass"]).sum(dtype=np.float64) \
+ for axis in "xyz"])
+ rvals.append(data["gas", "cell_mass"].sum(dtype=np.float64))
+ if include_particles:
+ rvals.extend([(data["all", "particle_specific_angular_momentum_%s" % axis] *
+ data["all", "particle_mass"]).sum(dtype=np.float64) \
+ for axis in "xyz"])
+ rvals.append(data["all", "particle_mass"].sum(dtype=np.float64))
+ return rvals
-class ParticleAngularMomentumVector(WeightedAverageQuantity):
- def __call__(self, ptype = "all"):
- fields = [(ptype, "particle_specific_angular_momentum_%s" % ax)
- for ax in 'xyz']
- weight = (ptype, "particle_mass")
- return super(ParticleAngularMomentumVector, self).__call__(fields, weight)
+ def reduce_intermediate(self, values):
+ jx = values.pop(0).sum(dtype=np.float64)
+ jy = values.pop(0).sum(dtype=np.float64)
+ jz = values.pop(0).sum(dtype=np.float64)
+ m = values.pop(0).sum(dtype=np.float64)
+ if values:
+ jx += values.pop(0).sum(dtype=np.float64)
+ 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)
class Extrema(DerivedQuantity):
def count_values(self, fields, non_zero):
https://bitbucket.org/yt_analysis/yt/commits/4b26f4fcd897/
Changeset: 4b26f4fcd897
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 18:43:36
Summary: Adding docstrings to derived quantities and unifying the use_gas and use_particles keyword args.
Affected #: 1 file
diff -r 99da293a4fd58014783582a7f5bd8be1f43cbd48 -r 4b26f4fcd89773832cdfb27d7209bb6d53911367 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -94,7 +94,29 @@
return derived_quantity_registry.keys()
class WeightedAverageQuantity(DerivedQuantity):
+ r"""
+ Calculates the weight average of a field or 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).
+
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field or fields of which the average value is to be calculated.
+ weight : field
+ The weight field.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.weighted_average_quantity([("gas", "density"),
+ ... ("gas", "temperature")],
+ ("gas", "cell_mass"))
+
+ """
def count_values(self, fields, weight):
# This is a list now
self.num_vals = len(fields) + 1
@@ -116,7 +138,22 @@
return [v.sum(dtype=np.float64)/w for v in values]
class TotalQuantity(DerivedQuantity):
+ r"""
+ Calculates the sum of the field or fields.
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field to be summed.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.total_quantity([("gas", "cell_mass")])
+
+ """
def count_values(self, fields):
# This is a list now
self.num_vals = len(fields)
@@ -136,6 +173,17 @@
return [v.sum(dtype=np.float64) for v in values]
class TotalMass(TotalQuantity):
+ r"""
+ Calculates the total mass in gas and particles.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.total_mass()
+
+ """
def __call__(self):
fi = self.data_source.pf.field_info
fields = []
@@ -147,21 +195,52 @@
return rv
class CenterOfMass(DerivedQuantity):
- def count_values(self, use_cells = True, use_particles = False):
- # This is a list now
+ r"""
+ Calculates the center of mass, using gas and/or particles.
+
+ The center of mass is the mass-weighted mean position.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.center_of_mass()
+
+ """
+ def count_values(self, use_gas = True, use_particles = False):
+ include_gas = use_gas & \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ include_particles = use_particles & \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
self.num_vals = 0
- if use_cells:
+ if include_gas:
self.num_vals += 4
- if use_particles:
+ if include_particles:
self.num_vals += 4
- def process_chunk(self, data, use_cells = True, use_particles = False):
+ def process_chunk(self, data, use_gas = True, use_particles = False):
+ include_gas = use_gas & \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ include_particles = use_particles & \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
vals = []
- if use_cells:
+ if include_gas:
vals += [(data[ax] * data["cell_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
vals.append(data["cell_mass"].sum(dtype=np.float64))
- if use_particles:
+ if include_particles:
vals += [(data["particle_position_%s" % ax] *
data["particle_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
@@ -185,17 +264,41 @@
return [v/w for v in [x, y, z]]
class BulkVelocity(DerivedQuantity):
- def count_values(self, use_cells = True, use_particles = False):
+ r"""
+ Calculates the bulk velocity, using gas and/or particles.
+
+ The bulk velocity is the mass-weighted mean velocity.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.bulk_velocity()
+
+ """
+ def count_values(self, use_gas = True, use_particles = False):
# This is a list now
self.num_vals = 0
- if use_cells:
+ if use_gas:
self.num_vals += 4
if use_particles:
self.num_vals += 4
- def process_chunk(self, data, use_cells = True, use_particles = False):
+ def process_chunk(self, data, use_gas = True, use_particles = False):
vals = []
- if use_cells:
+ if use_gas:
vals += [(data["velocity_%s" % ax] * data["cell_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
vals.append(data["cell_mass"].sum(dtype=np.float64))
@@ -223,7 +326,32 @@
return [v/w for v in [x, y, z]]
class WeightedVariance(DerivedQuantity):
+ r"""
+ Calculates the weighted variance and weighted mean for a field
+ or list of fields.
+
+ Where f is the field, w is the weight, and <f_w> is the weighted mean,
+ the weighted variance is
+ Sum_i( (f_i - <f_w>)^2 * w_i ) / Sum_i(w_i).
+
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field or fields of which the variance and mean values are
+ to be calculated.
+ weight : field
+ The weight field.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.weighted_variance([("gas", "density"),
+ ... ("gas", "temperature")],
+ ("gas", "cell_mass"))
+ """
def count_values(self, fields, weight):
# This is a list now
self.num_vals = 2 * len(fields) + 1
@@ -261,6 +389,30 @@
return rvals
class AngularMomentumVector(DerivedQuantity):
+ r"""
+ Calculates the angular momentum vector, using gas and/or particles.
+
+ The angular momentum vector is the mass-weighted mean specific angular momentum.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.angular_momentum_vector()
+
+ """
def count_values(self, use_gas=True, use_particles=True):
include_gas = use_gas & \
(("gas", "cell_mass") in self.data_source.pf.field_info)
@@ -302,6 +454,26 @@
return (jx / m, jy / m, jz / m)
class Extrema(DerivedQuantity):
+ r"""
+ Calculates the min and max value of a field or list of fields.
+
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field over which the extrema are to be calculated.
+ non_zero : bool
+ If True, only positive values are considered in the calculation.
+ Default: False
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.extrema([("gas", "density"),
+ ("gas", "temperature")])
+
+ """
def count_values(self, fields, non_zero):
self.num_vals = len(fields) * 2
@@ -330,6 +502,23 @@
for mis, mas in zip(values[::2], values[1::2])]
class MaxLocation(DerivedQuantity):
+ r"""
+ Calculates the maximum value plus the index, x, y, and z position
+ of the maximum.
+
+ Parameters
+ ----------
+ field : field
+ The field over which the extrema are to be calculated.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.max_location(("gas", "density"))
+
+ """
def count_values(self, *args, **kwargs):
self.num_vals = 5
@@ -356,6 +545,23 @@
return [val[i] for val in values]
class MinLocation(DerivedQuantity):
+ r"""
+ Calculates the minimum value plus the index, x, y, and z position
+ of the minimum.
+
+ Parameters
+ ----------
+ field : field
+ The field over which the extrema are to be calculated.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.min_location(("gas", "density"))
+
+ """
def count_values(self, *args, **kwargs):
self.num_vals = 5
@@ -382,6 +588,35 @@
return [val[i] for val in values]
class SpinParameter(DerivedQuantity):
+ r"""
+ Calculates the dimensionless spin parameter.
+
+ Given by Equation 3 of Peebles (1971, A&A, 11, 377), the spin parameter
+ is defined as
+
+ lambda = (L * |E|^(1/2)) / (G * M^5/2),
+
+ where L is the total angular momentum, E is the total energy (kinetic and
+ potential), G is the gravitational constant, and M is the total mass.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.h.all_data()
+ >>> print ad.quantities.center_of_mass()
+ """
def count_values(self, **kwargs):
self.num_vals = 3
@@ -409,4 +644,4 @@
e = values.pop(0).sum(dtype=np.float64)
j = values.pop(0).sum(dtype=np.float64)
m = values.pop(0).sum(dtype=np.float64)
- return j * np.sqrt(e) / m**2.5 / gravitational_constant_cgs
+ return j * np.sqrt(np.abs(e)) / m**2.5 / gravitational_constant_cgs
https://bitbucket.org/yt_analysis/yt/commits/2c140836cdca/
Changeset: 2c140836cdca
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 22:46:57
Summary: Removing .h from stuff.
Affected #: 1 file
diff -r 4b26f4fcd89773832cdfb27d7209bb6d53911367 -r 2c140836cdcafd9c1ec0886185d07e63b4ef7cd7 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -111,7 +111,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.weighted_average_quantity([("gas", "density"),
... ("gas", "temperature")],
("gas", "cell_mass"))
@@ -150,7 +150,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.total_quantity([("gas", "cell_mass")])
"""
@@ -180,7 +180,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.total_mass()
"""
@@ -215,7 +215,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.center_of_mass()
"""
@@ -284,7 +284,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.bulk_velocity()
"""
@@ -346,7 +346,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.weighted_variance([("gas", "density"),
... ("gas", "temperature")],
("gas", "cell_mass"))
@@ -409,7 +409,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.angular_momentum_vector()
"""
@@ -469,7 +469,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.extrema([("gas", "density"),
("gas", "temperature")])
@@ -515,7 +515,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.max_location(("gas", "density"))
"""
@@ -558,7 +558,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.min_location(("gas", "density"))
"""
@@ -614,7 +614,7 @@
--------
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
- >>> ad = pf.h.all_data()
+ >>> ad = pf.all_data()
>>> print ad.quantities.center_of_mass()
"""
def count_values(self, **kwargs):
https://bitbucket.org/yt_analysis/yt/commits/a7e70548a656/
Changeset: a7e70548a656
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 23:01:37
Summary: Changing stuff.
Affected #: 1 file
diff -r 2c140836cdcafd9c1ec0886185d07e63b4ef7cd7 -r a7e70548a65679df2f03bd2eeb3cecc7754c86de yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -220,27 +220,27 @@
"""
def count_values(self, use_gas = True, use_particles = False):
- include_gas = use_gas & \
+ use_gas &= \
(("gas", "cell_mass") in self.data_source.pf.field_info)
- include_particles = use_particles & \
+ use_particles &= \
(("all", "particle_mass") in self.data_source.pf.field_info)
self.num_vals = 0
- if include_gas:
+ if use_gas:
self.num_vals += 4
- if include_particles:
+ if use_particles:
self.num_vals += 4
def process_chunk(self, data, use_gas = True, use_particles = False):
- include_gas = use_gas & \
+ use_gas &= \
(("gas", "cell_mass") in self.data_source.pf.field_info)
- include_particles = use_particles & \
+ use_particles &= \
(("all", "particle_mass") in self.data_source.pf.field_info)
vals = []
- if include_gas:
+ if use_gas:
vals += [(data[ax] * data["cell_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
vals.append(data["cell_mass"].sum(dtype=np.float64))
- if include_particles:
+ if use_particles:
vals += [(data["particle_position_%s" % ax] *
data["particle_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
@@ -414,27 +414,27 @@
"""
def count_values(self, use_gas=True, use_particles=True):
- include_gas = use_gas & \
+ use_gas &= \
(("gas", "cell_mass") in self.data_source.pf.field_info)
- include_particles = use_particles & \
+ use_particles &= \
(("all", "particle_mass") in self.data_source.pf.field_info)
num_vals = 0
- if include_gas: num_vals += 4
- if include_particles: num_vals += 4
+ if use_gas: num_vals += 4
+ if use_particles: num_vals += 4
self.num_vals = num_vals
def process_chunk(self, data, use_gas=True, use_particles=True):
- include_gas = use_gas & \
+ use_gas &= \
(("gas", "cell_mass") in self.data_source.pf.field_info)
- include_particles = use_particles & \
+ use_particles &= \
(("all", "particle_mass") in self.data_source.pf.field_info)
rvals = []
- if include_gas:
+ if use_gas:
rvals.extend([(data["gas", "specific_angular_momentum_%s" % axis] *
data["gas", "cell_mass"]).sum(dtype=np.float64) \
for axis in "xyz"])
rvals.append(data["gas", "cell_mass"].sum(dtype=np.float64))
- if include_particles:
+ if use_particles:
rvals.extend([(data["all", "particle_specific_angular_momentum_%s" % axis] *
data["all", "particle_mass"]).sum(dtype=np.float64) \
for axis in "xyz"])
@@ -621,19 +621,19 @@
self.num_vals = 3
def process_chunk(self, data, use_gas=True, use_particles=True):
- include_gas = use_gas & \
+ use_gas &= \
(("gas", "cell_mass") in self.data_source.pf.field_info)
- include_particles = use_particles & \
+ use_particles &= \
(("all", "particle_mass") in self.data_source.pf.field_info)
e = data.pf.quan(0., "erg")
j = data.pf.quan(0., "g*cm**2/s")
m = data.pf.quan(0., "g")
- if include_gas:
+ if use_gas:
e += (data["gas", "kinetic_energy"] *
data["index", "cell_volume"]).sum(dtype=np.float64)
j += data["gas", "angular_momentum_magnitude"].sum(dtype=np.float64)
m += data["gas", "cell_mass"].sum(dtype=np.float64)
- if include_particles:
+ if use_particles:
e += (data["all", "particle_velocity_magnitude"]**2 *
data["all", "particle_mass"]).sum(dtype=np.float64)
j += data["all", "particle_angular_momentum_magnitude"].sum(dtype=np.float64)
https://bitbucket.org/yt_analysis/yt/commits/018a92f8d4a6/
Changeset: 018a92f8d4a6
Branch: yt-3.0
User: brittonsmith
Date: 2014-03-17 23:09:07
Summary: Adding some dots.
Affected #: 1 file
diff -r a7e70548a65679df2f03bd2eeb3cecc7754c86de -r 018a92f8d4a637280f95c55811c4b65f72ccce8c yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -114,7 +114,7 @@
>>> ad = pf.all_data()
>>> print ad.quantities.weighted_average_quantity([("gas", "density"),
... ("gas", "temperature")],
- ("gas", "cell_mass"))
+ ... ("gas", "cell_mass"))
"""
def count_values(self, fields, weight):
@@ -349,7 +349,7 @@
>>> ad = pf.all_data()
>>> print ad.quantities.weighted_variance([("gas", "density"),
... ("gas", "temperature")],
- ("gas", "cell_mass"))
+ ... ("gas", "cell_mass"))
"""
def count_values(self, fields, weight):
@@ -471,7 +471,7 @@
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> ad = pf.all_data()
>>> print ad.quantities.extrema([("gas", "density"),
- ("gas", "temperature")])
+ ... ("gas", "temperature")])
"""
def count_values(self, fields, non_zero):
@@ -616,6 +616,7 @@
>>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> ad = pf.all_data()
>>> print ad.quantities.center_of_mass()
+
"""
def count_values(self, **kwargs):
self.num_vals = 3
https://bitbucket.org/yt_analysis/yt/commits/4bc951ee2db7/
Changeset: 4bc951ee2db7
Branch: yt-3.0
User: ngoldbaum
Date: 2014-03-18 00:42:17
Summary: Merged in brittonsmith/yt/yt-3.0 (pull request #725)
Adding Spin Parameter Derived Quantity and Docstrings for all DQs
Affected #: 5 files
diff -r 853ec46f9c5825bebe5bcdca0b548fb6bc173ab9 -r 4bc951ee2db7e00d453de6a3bdf95fdd03732836 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -94,7 +94,29 @@
return derived_quantity_registry.keys()
class WeightedAverageQuantity(DerivedQuantity):
+ r"""
+ Calculates the weight average of a field or 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).
+
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field or fields of which the average value is to be calculated.
+ weight : field
+ The weight field.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.weighted_average_quantity([("gas", "density"),
+ ... ("gas", "temperature")],
+ ... ("gas", "cell_mass"))
+
+ """
def count_values(self, fields, weight):
# This is a list now
self.num_vals = len(fields) + 1
@@ -116,7 +138,22 @@
return [v.sum(dtype=np.float64)/w for v in values]
class TotalQuantity(DerivedQuantity):
+ r"""
+ Calculates the sum of the field or fields.
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field to be summed.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.total_quantity([("gas", "cell_mass")])
+
+ """
def count_values(self, fields):
# This is a list now
self.num_vals = len(fields)
@@ -136,6 +173,17 @@
return [v.sum(dtype=np.float64) for v in values]
class TotalMass(TotalQuantity):
+ r"""
+ Calculates the total mass in gas and particles.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.total_mass()
+
+ """
def __call__(self):
fi = self.data_source.pf.field_info
fields = []
@@ -147,17 +195,48 @@
return rv
class CenterOfMass(DerivedQuantity):
- def count_values(self, use_cells = True, use_particles = False):
- # This is a list now
+ r"""
+ Calculates the center of mass, using gas and/or particles.
+
+ The center of mass is the mass-weighted mean position.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.center_of_mass()
+
+ """
+ def count_values(self, use_gas = True, use_particles = False):
+ use_gas &= \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ use_particles &= \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
self.num_vals = 0
- if use_cells:
+ if use_gas:
self.num_vals += 4
if use_particles:
self.num_vals += 4
- def process_chunk(self, data, use_cells = True, use_particles = False):
+ def process_chunk(self, data, use_gas = True, use_particles = False):
+ use_gas &= \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ use_particles &= \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
vals = []
- if use_cells:
+ if use_gas:
vals += [(data[ax] * data["cell_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
vals.append(data["cell_mass"].sum(dtype=np.float64))
@@ -185,17 +264,41 @@
return [v/w for v in [x, y, z]]
class BulkVelocity(DerivedQuantity):
- def count_values(self, use_cells = True, use_particles = False):
+ r"""
+ Calculates the bulk velocity, using gas and/or particles.
+
+ The bulk velocity is the mass-weighted mean velocity.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.bulk_velocity()
+
+ """
+ def count_values(self, use_gas = True, use_particles = False):
# This is a list now
self.num_vals = 0
- if use_cells:
+ if use_gas:
self.num_vals += 4
if use_particles:
self.num_vals += 4
- def process_chunk(self, data, use_cells = True, use_particles = False):
+ def process_chunk(self, data, use_gas = True, use_particles = False):
vals = []
- if use_cells:
+ if use_gas:
vals += [(data["velocity_%s" % ax] * data["cell_mass"]).sum(dtype=np.float64)
for ax in 'xyz']
vals.append(data["cell_mass"].sum(dtype=np.float64))
@@ -223,7 +326,32 @@
return [v/w for v in [x, y, z]]
class WeightedVariance(DerivedQuantity):
+ r"""
+ Calculates the weighted variance and weighted mean for a field
+ or list of fields.
+
+ Where f is the field, w is the weight, and <f_w> is the weighted mean,
+ the weighted variance is
+ Sum_i( (f_i - <f_w>)^2 * w_i ) / Sum_i(w_i).
+
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field or fields of which the variance and mean values are
+ to be calculated.
+ weight : field
+ The weight field.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.weighted_variance([("gas", "density"),
+ ... ("gas", "temperature")],
+ ... ("gas", "cell_mass"))
+ """
def count_values(self, fields, weight):
# This is a list now
self.num_vals = 2 * len(fields) + 1
@@ -259,22 +387,93 @@
all_weight))
rvals.append(all_mean)
return rvals
+
+class AngularMomentumVector(DerivedQuantity):
+ r"""
+ Calculates the angular momentum vector, using gas and/or particles.
-class AngularMomentumVector(WeightedAverageQuantity):
- def __call__(self, ftype = "gas"):
- fields = [(ftype, "specific_angular_momentum_%s" % ax)
- for ax in 'xyz']
- weight = (ftype, "cell_mass")
- return super(AngularMomentumVector, self).__call__(fields, weight)
+ The angular momentum vector is the mass-weighted mean specific angular momentum.
-class ParticleAngularMomentumVector(WeightedAverageQuantity):
- def __call__(self, ptype = "all"):
- fields = [(ptype, "particle_specific_angular_momentum_%s" % ax)
- for ax in 'xyz']
- weight = (ptype, "particle_mass")
- return super(ParticleAngularMomentumVector, self).__call__(fields, weight)
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.angular_momentum_vector()
+
+ """
+ def count_values(self, use_gas=True, use_particles=True):
+ use_gas &= \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ use_particles &= \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
+ num_vals = 0
+ if use_gas: num_vals += 4
+ if use_particles: num_vals += 4
+ self.num_vals = num_vals
+
+ def process_chunk(self, data, use_gas=True, use_particles=True):
+ use_gas &= \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ use_particles &= \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
+ rvals = []
+ if use_gas:
+ rvals.extend([(data["gas", "specific_angular_momentum_%s" % axis] *
+ data["gas", "cell_mass"]).sum(dtype=np.float64) \
+ for axis in "xyz"])
+ rvals.append(data["gas", "cell_mass"].sum(dtype=np.float64))
+ if use_particles:
+ rvals.extend([(data["all", "particle_specific_angular_momentum_%s" % axis] *
+ data["all", "particle_mass"]).sum(dtype=np.float64) \
+ for axis in "xyz"])
+ rvals.append(data["all", "particle_mass"].sum(dtype=np.float64))
+ return rvals
+
+ def reduce_intermediate(self, values):
+ jx = values.pop(0).sum(dtype=np.float64)
+ jy = values.pop(0).sum(dtype=np.float64)
+ jz = values.pop(0).sum(dtype=np.float64)
+ m = values.pop(0).sum(dtype=np.float64)
+ if values:
+ jx += values.pop(0).sum(dtype=np.float64)
+ 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)
class Extrema(DerivedQuantity):
+ r"""
+ Calculates the min and max value of a field or list of fields.
+
+ Parameters
+ ----------
+ fields : field or list of fields
+ The field over which the extrema are to be calculated.
+ non_zero : bool
+ If True, only positive values are considered in the calculation.
+ Default: False
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.extrema([("gas", "density"),
+ ... ("gas", "temperature")])
+
+ """
def count_values(self, fields, non_zero):
self.num_vals = len(fields) * 2
@@ -303,6 +502,23 @@
for mis, mas in zip(values[::2], values[1::2])]
class MaxLocation(DerivedQuantity):
+ r"""
+ Calculates the maximum value plus the index, x, y, and z position
+ of the maximum.
+
+ Parameters
+ ----------
+ field : field
+ The field over which the extrema are to be calculated.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.max_location(("gas", "density"))
+
+ """
def count_values(self, *args, **kwargs):
self.num_vals = 5
@@ -329,6 +545,23 @@
return [val[i] for val in values]
class MinLocation(DerivedQuantity):
+ r"""
+ Calculates the minimum value plus the index, x, y, and z position
+ of the minimum.
+
+ Parameters
+ ----------
+ field : field
+ The field over which the extrema are to be calculated.
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.min_location(("gas", "density"))
+
+ """
def count_values(self, *args, **kwargs):
self.num_vals = 5
@@ -354,41 +587,62 @@
i = np.argmin(values[0]) # ma is values[0]
return [val[i] for val in values]
-def _BaryonSpinParameter(data):
+class SpinParameter(DerivedQuantity):
+ r"""
+ Calculates the dimensionless spin parameter.
+
+ Given by Equation 3 of Peebles (1971, A&A, 11, 377), the spin parameter
+ is defined as
+
+ lambda = (L * |E|^(1/2)) / (G * M^5/2),
+
+ where L is the total angular momentum, E is the total energy (kinetic and
+ potential), G is the gravitational constant, and M is the total mass.
+
+ Parameters
+ ----------
+ use_gas : bool
+ Flag to include gas in the calculation. Gas is ignored if not
+ present.
+ Default: True
+ use_particles : bool
+ Flag to include particles in the calculation. Particles are ignored
+ if not present.
+ Default: True
+
+ Examples
+ --------
+
+ >>> pf = load("IsolatedGalaxy/galaxy0030/galaxy0030")
+ >>> ad = pf.all_data()
+ >>> print ad.quantities.center_of_mass()
+
"""
- This function returns the spin parameter for the baryons, but it uses
- the particles in calculating enclosed mass.
- """
- m_enc = _TotalMass(data)
- amx = data["specific_angular_momentum_x"]*data["cell_mass"]
- amy = data["specific_angular_momentum_y"]*data["cell_mass"]
- amz = data["specific_angular_momentum_z"]*data["cell_mass"]
- j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
- e_term_pre = np.sum(data["cell_mass"]*data["velocity_magnitude"]**2.0,dtype=np.float64)
- weight=data["cell_mass"].sum(dtype=np.float64)
- return j_mag, m_enc, e_term_pre, weight
-def _combBaryonSpinParameter(data, j_mag, m_enc, e_term_pre, weight):
- # Because it's a vector field, we have to ensure we have enough dimensions
- if len(j_mag.shape) < 2: j_mag = np.expand_dims(j_mag, 0)
- W = weight.sum()
- M = m_enc.sum()
- J = np.sqrt(((j_mag.sum(axis=0))**2.0).sum())/W
- E = np.sqrt(e_term_pre.sum()/W)
- spin = J * E / (M * mass_sun_cgs * gravitational_constant_cgs)
- return spin
+ def count_values(self, **kwargs):
+ self.num_vals = 3
-def _ParticleSpinParameter(data):
- """
- This function returns the spin parameter for the baryons, but it uses
- the particles in calculating enclosed mass.
- """
- m_enc = _TotalMass(data)
- amx = data["particle_specific_angular_momentum_x"]*data["particle_mass"]
- if amx.size == 0: return (np.zeros((3,), dtype=np.float64), m_enc, 0, 0)
- amy = data["particle_specific_angular_momentum_y"]*data["particle_mass"]
- amz = data["particle_specific_angular_momentum_z"]*data["particle_mass"]
- j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
- e_term_pre = np.sum(data["particle_mass"]
- *data["particle_velocity_magnitude"]**2.0,dtype=np.float64)
- weight=data["particle_mass"].sum(dtype=np.float64)
- return j_mag, m_enc, e_term_pre, weight
+ def process_chunk(self, data, use_gas=True, use_particles=True):
+ use_gas &= \
+ (("gas", "cell_mass") in self.data_source.pf.field_info)
+ use_particles &= \
+ (("all", "particle_mass") in self.data_source.pf.field_info)
+ e = data.pf.quan(0., "erg")
+ j = data.pf.quan(0., "g*cm**2/s")
+ m = data.pf.quan(0., "g")
+ if use_gas:
+ e += (data["gas", "kinetic_energy"] *
+ data["index", "cell_volume"]).sum(dtype=np.float64)
+ j += data["gas", "angular_momentum_magnitude"].sum(dtype=np.float64)
+ m += data["gas", "cell_mass"].sum(dtype=np.float64)
+ if use_particles:
+ e += (data["all", "particle_velocity_magnitude"]**2 *
+ data["all", "particle_mass"]).sum(dtype=np.float64)
+ j += data["all", "particle_angular_momentum_magnitude"].sum(dtype=np.float64)
+ m += data["all", "particle_mass"].sum(dtype=np.float64)
+ return (e, j, m)
+
+ def reduce_intermediate(self, values):
+ e = values.pop(0).sum(dtype=np.float64)
+ j = values.pop(0).sum(dtype=np.float64)
+ m = values.pop(0).sum(dtype=np.float64)
+ return j * np.sqrt(np.abs(e)) / m**2.5 / gravitational_constant_cgs
diff -r 853ec46f9c5825bebe5bcdca0b548fb6bc173ab9 -r 4bc951ee2db7e00d453de6a3bdf95fdd03732836 yt/fields/angular_momentum.py
--- a/yt/fields/angular_momentum.py
+++ b/yt/fields/angular_momentum.py
@@ -28,6 +28,9 @@
from .field_plugin_registry import \
register_field_plugin
+from .vector_operations import \
+ create_magnitude_field
+
from yt.utilities.lib.geometry_utils import \
obtain_rvec, obtain_rv_vec
@@ -79,6 +82,9 @@
units="cm**2/s",
validators=[ValidateParameter("center")])
+ create_magnitude_field(registry, "specific_angular_momentum",
+ "cm**2 / s", ftype=ftype)
+
def _angular_momentum_x(field, data):
return data[ftype, "cell_mass"] \
* data[ftype, "specific_angular_momentum_x"]
@@ -103,3 +109,6 @@
units="g * cm**2 / s",
validators=[ValidateParameter('center')])
+ create_magnitude_field(registry, "angular_momentum",
+ "g * cm**2 / s", ftype=ftype)
+
diff -r 853ec46f9c5825bebe5bcdca0b548fb6bc173ab9 -r 4bc951ee2db7e00d453de6a3bdf95fdd03732836 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -39,7 +39,10 @@
get_cyl_z, get_sph_r, \
get_sph_theta, get_sph_phi, \
periodic_dist, euclidean_dist
-
+
+from .vector_operations import \
+ create_magnitude_field
+
def _field_concat(fname):
def _AllFields(field, data):
v = []
@@ -210,7 +213,7 @@
+ (data[ptype, svel % 'y'] - bulk_velocity[1])**2
+ (data[ptype, svel % 'z'] - bulk_velocity[2])**2 )
- registry.add_field((ptype, "particle_velocity_magnitude"),
+ registry.add_field((ptype, "particle_velocity_magnitude"),
function=_particle_velocity_magnitude,
particle_type=True,
take_log=False,
@@ -293,6 +296,9 @@
units="cm**2/s",
validators=[ValidateParameter("center")])
+ create_magnitude_field(registry, "particle_specific_angular_momentum",
+ "cm**2/s", ftype=ptype, particle_type=True)
+
def _particle_angular_momentum(field, data):
return data[ptype, "particle_mass"] \
* data[ptype, "particle_specific_angular_momentum"]
@@ -321,6 +327,9 @@
units="g*cm**2/s", particle_type=True,
validators=[ValidateParameter('center')])
+ create_magnitude_field(registry, "particle_angular_momentum",
+ "g*cm**2/s", ftype=ptype, particle_type=True)
+
from .field_functions import \
get_radius
diff -r 853ec46f9c5825bebe5bcdca0b548fb6bc173ab9 -r 4bc951ee2db7e00d453de6a3bdf95fdd03732836 yt/fields/vector_operations.py
--- a/yt/fields/vector_operations.py
+++ b/yt/fields/vector_operations.py
@@ -41,7 +41,7 @@
def create_magnitude_field(registry, basename, field_units,
ftype = "gas", slice_info = None,
- validators = None):
+ validators = None, particle_type=False):
xn, yn, zn = [(ftype, "%s_%s" % (basename, ax)) for ax in 'xyz']
@@ -59,7 +59,7 @@
registry.add_field((ftype, "%s_magnitude" % basename),
function = _magnitude, units = field_units,
- validators = validators)
+ validators = validators, particle_type = particle_type)
def create_vector_fields(registry, basename, field_units,
ftype = "gas", slice_info = None):
diff -r 853ec46f9c5825bebe5bcdca0b548fb6bc173ab9 -r 4bc951ee2db7e00d453de6a3bdf95fdd03732836 yt/frontends/enzo/fields.py
--- a/yt/frontends/enzo/fields.py
+++ b/yt/frontends/enzo/fields.py
@@ -68,6 +68,7 @@
("z-velocity", (vel_units, ["velocity_z"], None)),
("RaySegments", ("", ["ray_segments"], None)),
("PhotoGamma", (ra_units, ["photo_gamma"], None)),
+ ("PotentialField", ("code_velocity**2", ["gravitational_potential"], None)),
("Density", (rho_units, ["density"], None)),
("Metal_Density", (rho_units, ["metal_density"], None)),
("SN_Colour", (rho_units, [], None)),
@@ -178,13 +179,13 @@
if self.pf.parameters["HydroMethod"] == 2:
self.add_output_field(("enzo", te_name),
- units="code_length**2/code_time**2")
+ units="code_velocity**2")
self.alias(("gas", "thermal_energy"), ("enzo", te_name))
elif self.pf.parameters["DualEnergyFormalism"] == 1:
self.add_output_field(
("enzo", ge_name),
- units="code_length**2/code_time**2")
+ units="code_velocity**2")
self.alias(
("gas", "thermal_energy"),
("enzo", ge_name),
@@ -192,7 +193,7 @@
elif self.pf.parameters["HydroMethod"] in (4, 6):
self.add_output_field(
("enzo", te_name),
- units="code_length**2/code_time**2")
+ units="code_velocity**2")
# Subtract off B-field energy
def _sub_b(field, data):
return data[te_name] - 0.5*(
@@ -206,7 +207,7 @@
else: # Otherwise, we assume TotalEnergy is kinetic+thermal
self.add_output_field(
("enzo", te_name),
- units = "code_length**2/code_time**2")
+ units = "code_velocity**2")
def _tot_minus_kin(field, data):
return data[te_name] - 0.5*(
data["x-velocity"]**2.0
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