[yt-svn] commit/yt: 2 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Nov 29 07:45:00 PST 2017
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/3994620bd9eb/
Changeset: 3994620bd9eb
User: ngoldbaum
Date: 2017-11-01 16:32:39+00:00
Summary: screen particles outside the domain for load_uniform_grid and load_amr_grids
Fixes #1600
Affected #: 2 files
diff -r 21be624bbb559f9f6ff0c47251e53397d8804f1b -r 3994620bd9ebf1f4a0e79e4aa1d07c4a35f3bbc4 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -385,7 +385,7 @@
particle_types[key] = False
return particle_types
-def assign_particle_data(ds, pdata):
+def assign_particle_data(ds, pdata, bbox):
"""
Assign particle data to the grids using MatchPointsToGrids. This
@@ -446,6 +446,26 @@
"Cannot decompose particle data without position fields!")
pts = MatchPointsToGrids(grid_tree, len(x), x, y, z)
particle_grid_inds = pts.find_points_in_tree()
+ assigned_particles, = (particle_grid_inds >= 0).nonzero()
+ num_particles = particle_grid_inds.size
+ num_unassigned = num_particles - assigned_particles.size
+ if num_unassigned > 0:
+ m = ("Discarding %s particles (out of %s) that are outside "
+ "bounding box. ")
+ eps = np.finfo(x.dtype).eps
+ s = np.array([[x.min() - eps, x.max() + eps],
+ [y.min() - eps, y.max() + eps],
+ [z.min() - eps, z.max() + eps]])
+ sug_bbox = [
+ [min(bbox[0, 0], s[0, 0]), max(bbox[0, 1], s[0, 1])],
+ [min(bbox[1, 0], s[1, 0]), max(bbox[1, 1], s[1, 1])],
+ [min(bbox[2, 0], s[2, 0]), max(bbox[2, 1], s[2, 1])]]
+ m += ("Set bbox=%s to avoid this in the future.")
+ mylog.warn(m % (num_unassigned, num_particles, sug_bbox))
+ particle_grid_inds = particle_grid_inds[assigned_particles]
+ x = x[assigned_particles]
+ y = y[assigned_particles]
+ z = z[assigned_particles]
idxs = np.argsort(particle_grid_inds)
particle_grid_count = np.bincount(particle_grid_inds.astype("intp"),
minlength=num_grids)
@@ -751,7 +771,7 @@
# Now figure out where the particles go
if number_of_particles > 0:
# This will update the stream handler too
- assign_particle_data(sds, pdata)
+ assign_particle_data(sds, pdata, bbox)
return sds
@@ -1043,7 +1063,7 @@
# Now figure out where the particles go
if number_of_particles > 0:
# This will update the stream handler too
- assign_particle_data(ds, pdata)
+ assign_particle_data(ds, pdata, bbox)
cur_gc = ds.index.num_grids
diff -r 21be624bbb559f9f6ff0c47251e53397d8804f1b -r 3994620bd9ebf1f4a0e79e4aa1d07c4a35f3bbc4 yt/frontends/stream/tests/test_stream_particles.py
--- a/yt/frontends/stream/tests/test_stream_particles.py
+++ b/yt/frontends/stream/tests/test_stream_particles.py
@@ -304,3 +304,21 @@
npart += dd[ptype, "particle_position_%s" % ax].size
assert npart == num_tot_particles
assert dd["all", "particle_position_%s" % ax].size == num_tot_particles
+
+def test_particles_outside_domain():
+ np.random.seed(0x4d3d3d3)
+ posx_arr = np.random.uniform(low=-1.6, high=1.5, size=1000)
+ posy_arr = np.random.uniform(low=-1.5, high=1.5, size=1000)
+ posz_arr = np.random.uniform(low=-1.5, high=1.5, size=1000)
+ dens_arr = np.random.random((16, 16, 16))
+ data = dict(
+ density=dens_arr,
+ particle_position_x=posx_arr,
+ particle_position_y=posy_arr,
+ particle_position_z=posz_arr)
+ bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])
+ ds = load_uniform_grid(data, (16, 16, 16), bbox=bbox, nprocs=4)
+ wh = (posx_arr < bbox[0, 0]).nonzero()[0]
+ assert wh.size == 1000 - ds.particle_type_counts['io']
+ ad = ds.all_data()
+ assert ds.particle_type_counts['io'] == ad['particle_position_x'].size
https://bitbucket.org/yt_analysis/yt/commits/ed6f78140485/
Changeset: ed6f78140485
User: xarthisius
Date: 2017-11-29 15:44:46+00:00
Summary: Merge pull request #1602 from ngoldbaum/stream-outside-domain
screen particles outside the domain for load_uniform_grid and load_amr_grids
Affected #: 2 files
diff -r 33b9af9222cfd060e54070839a20d731bdb12bb0 -r ed6f781404856bf839b22a1539c6a7abce5b3859 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -385,7 +385,7 @@
particle_types[key] = False
return particle_types
-def assign_particle_data(ds, pdata):
+def assign_particle_data(ds, pdata, bbox):
"""
Assign particle data to the grids using MatchPointsToGrids. This
@@ -446,6 +446,26 @@
"Cannot decompose particle data without position fields!")
pts = MatchPointsToGrids(grid_tree, len(x), x, y, z)
particle_grid_inds = pts.find_points_in_tree()
+ assigned_particles, = (particle_grid_inds >= 0).nonzero()
+ num_particles = particle_grid_inds.size
+ num_unassigned = num_particles - assigned_particles.size
+ if num_unassigned > 0:
+ m = ("Discarding %s particles (out of %s) that are outside "
+ "bounding box. ")
+ eps = np.finfo(x.dtype).eps
+ s = np.array([[x.min() - eps, x.max() + eps],
+ [y.min() - eps, y.max() + eps],
+ [z.min() - eps, z.max() + eps]])
+ sug_bbox = [
+ [min(bbox[0, 0], s[0, 0]), max(bbox[0, 1], s[0, 1])],
+ [min(bbox[1, 0], s[1, 0]), max(bbox[1, 1], s[1, 1])],
+ [min(bbox[2, 0], s[2, 0]), max(bbox[2, 1], s[2, 1])]]
+ m += ("Set bbox=%s to avoid this in the future.")
+ mylog.warn(m % (num_unassigned, num_particles, sug_bbox))
+ particle_grid_inds = particle_grid_inds[assigned_particles]
+ x = x[assigned_particles]
+ y = y[assigned_particles]
+ z = z[assigned_particles]
idxs = np.argsort(particle_grid_inds)
particle_grid_count = np.bincount(particle_grid_inds.astype("intp"),
minlength=num_grids)
@@ -751,7 +771,7 @@
# Now figure out where the particles go
if number_of_particles > 0:
# This will update the stream handler too
- assign_particle_data(sds, pdata)
+ assign_particle_data(sds, pdata, bbox)
return sds
@@ -1043,7 +1063,7 @@
# Now figure out where the particles go
if number_of_particles > 0:
# This will update the stream handler too
- assign_particle_data(ds, pdata)
+ assign_particle_data(ds, pdata, bbox)
cur_gc = ds.index.num_grids
diff -r 33b9af9222cfd060e54070839a20d731bdb12bb0 -r ed6f781404856bf839b22a1539c6a7abce5b3859 yt/frontends/stream/tests/test_stream_particles.py
--- a/yt/frontends/stream/tests/test_stream_particles.py
+++ b/yt/frontends/stream/tests/test_stream_particles.py
@@ -304,3 +304,21 @@
npart += dd[ptype, "particle_position_%s" % ax].size
assert npart == num_tot_particles
assert dd["all", "particle_position_%s" % ax].size == num_tot_particles
+
+def test_particles_outside_domain():
+ np.random.seed(0x4d3d3d3)
+ posx_arr = np.random.uniform(low=-1.6, high=1.5, size=1000)
+ posy_arr = np.random.uniform(low=-1.5, high=1.5, size=1000)
+ posz_arr = np.random.uniform(low=-1.5, high=1.5, size=1000)
+ dens_arr = np.random.random((16, 16, 16))
+ data = dict(
+ density=dens_arr,
+ particle_position_x=posx_arr,
+ particle_position_y=posy_arr,
+ particle_position_z=posz_arr)
+ bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]])
+ ds = load_uniform_grid(data, (16, 16, 16), bbox=bbox, nprocs=4)
+ wh = (posx_arr < bbox[0, 0]).nonzero()[0]
+ assert wh.size == 1000 - ds.particle_type_counts['io']
+ ad = ds.all_data()
+ assert ds.particle_type_counts['io'] == ad['particle_position_x'].size
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