[yt-svn] commit/yt: ngoldbaum: Merged in brittonsmith/yt (pull request #2148)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jun 15 11:09:50 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/b4f9e4c9baed/
Changeset: b4f9e4c9baed
Branch: yt
User: ngoldbaum
Date: 2016-06-15 18:09:43+00:00
Summary: Merged in brittonsmith/yt (pull request #2148)
Enabling particle fields for clump objects
Affected #: 5 files
diff -r e0b1c973fefe530286e6589ef119dce4e4fe09e4 -r b4f9e4c9baeda6a9c9dd92bd026ca8dc86fc8afe yt/analysis_modules/level_sets/clump_handling.py
--- a/yt/analysis_modules/level_sets/clump_handling.py
+++ b/yt/analysis_modules/level_sets/clump_handling.py
@@ -57,6 +57,9 @@
self.min_val = self.data[field].min()
self.max_val = self.data[field].max()
+ if parent is not None:
+ self.data.parent = self.parent.data
+
# List containing characteristics about clumps that are to be written
# out by the write routines.
if clump_info is None:
diff -r e0b1c973fefe530286e6589ef119dce4e4fe09e4 -r b4f9e4c9baeda6a9c9dd92bd026ca8dc86fc8afe yt/analysis_modules/level_sets/tests/test_clump_finding.py
--- /dev/null
+++ b/yt/analysis_modules/level_sets/tests/test_clump_finding.py
@@ -0,0 +1,74 @@
+"""
+Clump finder tests
+
+
+
+
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2016, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+import numpy as np
+
+from yt.analysis_modules.level_sets.api import \
+ Clump, \
+ find_clumps, \
+ get_lowest_clumps
+from yt.frontends.stream.api import \
+ load_uniform_grid
+from yt.testing import \
+ assert_array_equal, \
+ assert_equal
+
+def test_clump_finding():
+ n_c = 8
+ n_p = 1
+ dims = (n_c, n_c, n_c)
+
+ density = np.ones(dims)
+ high_rho = 10.
+ # add a couple disconnected density enhancements
+ density[2, 2, 2] = high_rho
+ density[6, 6, 6] = high_rho
+
+ # put a particle at the center of one of them
+ dx = 1. / n_c
+ px = 2.5 * dx * np.ones(n_p)
+
+ data = {"density": density,
+ "particle_mass": np.ones(n_p),
+ "particle_position_x": px,
+ "particle_position_y": px,
+ "particle_position_z": px,
+ "number_of_particles": n_p}
+
+ ds = load_uniform_grid(data, dims)
+
+ ad = ds.all_data()
+ master_clump = Clump(ad, ("gas", "density"))
+ master_clump.add_validator("min_cells", 1)
+
+ find_clumps(master_clump, 0.5, 2. * high_rho, 10.)
+
+ # there should be two children
+ assert_equal(len(master_clump.children), 2)
+
+ leaf_clumps = get_lowest_clumps(master_clump)
+ # two leaf clumps
+ assert_equal(len(leaf_clumps), 2)
+
+
+ # check some clump fields
+ assert_equal(master_clump.children[0]["density"][0].size, 1)
+ assert_equal(master_clump.children[0]["density"][0], ad["density"].max())
+ assert_equal(master_clump.children[0]["particle_mass"].size, 1)
+ assert_array_equal(master_clump.children[0]["particle_mass"], ad["particle_mass"])
+ assert_equal(master_clump.children[1]["density"][0].size, 1)
+ assert_equal(master_clump.children[1]["density"][0], ad["density"].max())
+ assert_equal(master_clump.children[1]["particle_mass"].size, 0)
diff -r e0b1c973fefe530286e6589ef119dce4e4fe09e4 -r b4f9e4c9baeda6a9c9dd92bd026ca8dc86fc8afe yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -24,12 +24,13 @@
iterable, \
validate_width_tuple, \
fix_length
+from yt.geometry.selection_routines import \
+ points_in_cells
from yt.units.yt_array import \
YTArray
from yt.utilities.exceptions import \
YTSphereTooSmall, \
YTIllDefinedCutRegion, \
- YTMixedCutRegion, \
YTEllipsoidOrdering
from yt.utilities.minimal_representation import \
MinimalSliceData
@@ -793,8 +794,10 @@
for field in fields:
f = self.base_object[field]
if f.shape != ind.shape:
- raise YTMixedCutRegion(self.conditionals, field)
- self.field_data[field] = self.base_object[field][ind]
+ parent = getattr(self, "parent", self.base_object)
+ self.field_data[field] = parent[field][self._part_ind]
+ else:
+ self.field_data[field] = self.base_object[field][ind]
@property
def blocks(self):
@@ -822,6 +825,22 @@
np.logical_and(res, ind, ind)
return ind
+ _particle_mask = None
+ @property
+ def _part_ind(self):
+ if self._particle_mask is None:
+ parent = getattr(self, "parent", self.base_object)
+ units = "code_length"
+ mask = points_in_cells(
+ self["x"].to(units), self["y"].to(units),
+ self["z"].to(units), self["dx"].to(units),
+ self["dy"].to(units), self["dz"].to(units),
+ parent["particle_position_x"].to(units),
+ parent["particle_position_y"].to(units),
+ parent["particle_position_z"].to(units))
+ self._particle_mask = mask
+ return self._particle_mask
+
@property
def icoords(self):
return self.base_object.icoords[self._cond_ind,:]
diff -r e0b1c973fefe530286e6589ef119dce4e4fe09e4 -r b4f9e4c9baeda6a9c9dd92bd026ca8dc86fc8afe yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -2046,3 +2046,42 @@
return ("halo_particles", self.halo_id)
halo_particles_selector = HaloParticlesSelector
+
+ at cython.cdivision(True)
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+def points_in_cells(
+ np.float64_t[:] cx,
+ np.float64_t[:] cy,
+ np.float64_t[:] cz,
+ np.float64_t[:] dx,
+ np.float64_t[:] dy,
+ np.float64_t[:] dz,
+ np.float64_t[:] px,
+ np.float64_t[:] py,
+ np.float64_t[:] pz):
+ # Take a list of cells and particles and calculate which particles
+ # are enclosed within one of the cells. This is used for querying
+ # particle fields on clump/contour objects.
+ # We use brute force since the cells are a relatively unordered collection.
+
+ cdef int p, c, n_p, n_c
+
+ n_p = px.size
+ n_c = cx.size
+ mask = np.ones(n_p, dtype="bool")
+
+ for p in range(n_p):
+ for c in range(n_c):
+ if fabs(px[p] - cx[c]) > 0.5 * dx[c]:
+ mask[p] = False
+ continue
+ if fabs(py[p] - cy[c]) > 0.5 * dy[c]:
+ mask[p] = False
+ continue
+ if fabs(pz[p] - cz[c]) > 0.5 * dz[c]:
+ mask[p] = False
+ continue
+ if mask[p]: break
+
+ return mask
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