[yt-svn] commit/yt: brittonsmith: Merged in qobilidop/yt (pull request #1769)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Oct 26 12:00:42 PDT 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/9a49e5d6da9f/
Changeset: 9a49e5d6da9f
Branch: yt
User: brittonsmith
Date: 2015-10-26 19:00:24+00:00
Summary: Merged in qobilidop/yt (pull request #1769)
Add add_smoothed_particle_field
Affected #: 2 files
diff -r 0de661aae1faf32e535097b8f4557ac5e7f2a5a9 -r 9a49e5d6da9fc23bc7a2858bb5a304b9c4f5537b yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -37,6 +37,8 @@
FieldInfoContainer, NullFunc
from yt.fields.fluid_fields import \
setup_gradient_fields
+from yt.fields.particle_fields import \
+ add_volume_weighted_smoothed_field
from yt.data_objects.particle_filters import \
filter_registry
from yt.data_objects.particle_unions import \
@@ -968,6 +970,56 @@
validators=[ValidateSpatial()])
return ("deposit", field_name)
+ def add_smoothed_particle_field(self, smooth_field, method="volume_weighted",
+ nneighbors=64, kernel_name="cubic"):
+ """Add a new smoothed particle field
+
+ Creates a new smoothed field based on the particle *smooth_field*.
+
+ Parameters
+ ----------
+
+ smooth_field : tuple
+ The field name tuple of the particle field the smoothed field will
+ be created from. This must be a field name tuple so yt can
+ appropriately infer the correct particle type.
+ method : string, default 'volume_weighted'
+ The particle smoothing method to use. Can only be 'volume_weighted'
+ for now.
+ nneighbors : int, default 64
+ The number of neighbors to examine during the process.
+ kernel_name : string, default 'cubic'
+ This is the name of the smoothing kernel to use. Current supported
+ kernel names include `cubic`, `quartic`, `quintic`, `wendland2`,
+ `wendland4`, and `wendland6`.
+
+ Returns
+ -------
+
+ The field name tuple for the newly created field.
+ """
+ self.index
+ if isinstance(smooth_field, tuple):
+ ptype, smooth_field = smooth_field[0], smooth_field[1]
+ else:
+ raise RuntimeError("smooth_field must be a tuple, received %s" %
+ smooth_field)
+ if method != "volume_weighted":
+ raise NotImplementedError("method must be 'volume_weighted'")
+
+ coord_name = "particle_position"
+ mass_name = "particle_mass"
+ smoothing_length_name = "smoothing_length"
+ if (ptype, smoothing_length_name) not in self.derived_field_list:
+ raise ValueError("%s not in derived_field_list" %
+ ((ptype, smoothing_length_name),))
+ density_name = "density"
+ registry = self.field_info
+
+ return add_volume_weighted_smoothed_field(ptype, coord_name, mass_name,
+ smoothing_length_name, density_name, smooth_field, registry,
+ nneighbors=nneighbors, kernel_name=kernel_name)[0]
+
def add_gradient_fields(self, input_field):
"""Add gradient fields.
diff -r 0de661aae1faf32e535097b8f4557ac5e7f2a5a9 -r 9a49e5d6da9fc23bc7a2858bb5a304b9c4f5537b yt/fields/tests/test_fields.py
--- a/yt/fields/tests/test_fields.py
+++ b/yt/fields/tests/test_fields.py
@@ -1,11 +1,15 @@
import numpy as np
+from yt import \
+ load
from yt.testing import \
fake_random_ds, \
+ assert_almost_equal, \
assert_equal, \
assert_array_almost_equal_nulp, \
assert_array_equal, \
- assert_raises
+ assert_raises, \
+ requires_file
from yt.utilities.cosmology import \
Cosmology
from yt.frontends.stream.fields import \
@@ -188,6 +192,15 @@
ret = ad[fn]
assert_equal(ret.sum(), ad['particle_ones'].sum())
+ at requires_file('GadgetDiskGalaxy/snapshot_200.hdf5')
+def test_add_smoothed_particle_field():
+ ds = load('GadgetDiskGalaxy/snapshot_200.hdf5')
+ fn = ds.add_smoothed_particle_field(('PartType0', 'particle_ones'))
+ assert_equal(fn, ('deposit', 'PartType0_smoothed_particle_ones'))
+ ad = ds.all_data()
+ ret = ad[fn]
+ assert_almost_equal(ret.sum(), 3824750.912653606)
+
def test_add_gradient_fields():
gfields = base_ds.add_gradient_fields(("gas","density"))
gfields += base_ds.add_gradient_fields(("index", "ones"))
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