[yt-svn] commit/yt: 3 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Sep 3 08:01:23 PDT 2014
3 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/e42d637aacb3/
Changeset: e42d637aacb3
Branch: yt-3.0
User: samskillman
Date: 2014-07-28 23:56:15
Summary: Adding filter_sphere, and iter_sphere functionality to sdf io
Affected #: 1 file
diff -r 00c05e1eead49798a15fedcee014d89f00695a19 -r e42d637aacb32aae7c48e9c9facc05f598969def yt/utilities/sdf.py
--- a/yt/utilities/sdf.py
+++ b/yt/utilities/sdf.py
@@ -887,6 +887,49 @@
yield filtered
+ def filter_sphere(self, center, radius, myiter):
+ """
+ Filter data by masking out data outside of a sphere defined
+ by a center and radius. Account for periodicity of data, allowing
+ left/right to be outside of the domain.
+ """
+
+ # Get left/right for periodicity considerations
+ left = center - radius
+ right = center + radius
+ for data in myiter:
+ pos = np.array([data['x'].copy(), data['y'].copy(), data['z'].copy()]).T
+
+ DW = self.true_domain_width
+ # This hurts, but is useful for periodicity. Probably should check first
+ # if it is even needed for a given left/right
+ for i in range(3):
+ #pos[:,i] = np.mod(pos[:,i] - left[i],
+ # self.true_domain_width[i]) + left[i]
+ mask = pos[:,i] >= left[i] + DW[i]
+ pos[mask, i] -= DW[i]
+ mask = pos[:,i] < right[i] - DW[i]
+ pos[mask, i] += DW[i]
+ #del mask
+
+ # Now get all particles that are within the bbox
+ mask = ((pos-center)**2).sum(axis=1)**0.5 < radius
+ #print 'Mask shape, sum:', mask.shape, mask.sum()
+
+ mylog.debug("Filtering particles, returning %i out of %i" % (mask.sum(), mask.shape[0]))
+
+ if not np.any(mask):
+ continue
+
+ filtered = {ax: pos[:, i][mask] for i, ax in enumerate('xyz')}
+ for f in data.keys():
+ if f in 'xyz':
+ continue
+ filtered[f] = data[f][mask]
+
+ yield filtered
+
+
def iter_filtered_bbox_fields(self, left, right, data,
pos_fields, fields):
"""
@@ -929,6 +972,10 @@
yield f, data[f][mask]
def iter_bbox_data(self, left, right, fields):
+ """
+ Iterate over all data within a bounding box defined by a left
+ and a right.
+ """
_ensure_xyz_fields(fields)
mylog.debug('MIDX Loading region from %s to %s' %(left, right))
inds = self.get_bbox(left, right)
@@ -949,15 +996,17 @@
# yield dd
def iter_sphere_data(self, center, radius, fields):
+ """
+ Iterate over all data within some sphere defined by a center and
+ a radius.
+ """
_ensure_xyz_fields(fields)
mylog.debug('MIDX Loading spherical region %s to %s' %(center, radius))
inds = self.get_bbox(center-radius, center+radius)
- my_filter = sphere_filter(center, radius, self.true_domain_width)
-
- for dd in self.filter_particles(
- self.iter_data(inds, fields),
- my_filter):
+ for dd in self.filter_sphere(
+ center, radius,
+ self.iter_data(inds, fields)):
yield dd
def iter_ibbox_data(self, left, right, fields):
https://bitbucket.org/yt_analysis/yt/commits/2d06ee475e48/
Changeset: 2d06ee475e48
Branch: yt-3.0
User: samskillman
Date: 2014-09-03 01:20:26
Summary: Use a single function in multiple places rather than the same code copied 3 times.
Affected #: 1 file
diff -r e42d637aacb32aae7c48e9c9facc05f598969def -r 2d06ee475e4837e7b224d38cee35bb0c93d3b5bb yt/utilities/sdf.py
--- a/yt/utilities/sdf.py
+++ b/yt/utilities/sdf.py
@@ -458,6 +458,19 @@
return sdf
+def _shift_periodic(pos, left, right, domain_width):
+ """
+ Periodically shift positions that are right of left+domain_width to
+ the left, and those left of right-domain_width to the right.
+ """
+ for i in range(3):
+ mask = pos[:,i] >= left[i] + domain_width[i]
+ pos[mask, i] -= domain_width[i]
+ mask = pos[:,i] < right[i] - domain_width[i]
+ pos[mask, i] += domain_width[i]
+ return
+
+
class SDFIndex(object):
"""docstring for SDFIndex
@@ -856,14 +869,7 @@
DW = self.true_domain_width
# This hurts, but is useful for periodicity. Probably should check first
# if it is even needed for a given left/right
- for i in range(3):
- #pos[:,i] = np.mod(pos[:,i] - left[i],
- # self.true_domain_width[i]) + left[i]
- mask = pos[:,i] >= left[i] + DW[i]
- pos[mask, i] -= DW[i]
- mask = pos[:,i] < right[i] - DW[i]
- pos[mask, i] += DW[i]
- #del mask
+ _shift_periodic(pos, left, right, DW)
# Now get all particles that are within the bbox
mask = np.all(pos >= left, axis=1) * np.all(pos < right, axis=1)
@@ -901,20 +907,10 @@
pos = np.array([data['x'].copy(), data['y'].copy(), data['z'].copy()]).T
DW = self.true_domain_width
- # This hurts, but is useful for periodicity. Probably should check first
- # if it is even needed for a given left/right
- for i in range(3):
- #pos[:,i] = np.mod(pos[:,i] - left[i],
- # self.true_domain_width[i]) + left[i]
- mask = pos[:,i] >= left[i] + DW[i]
- pos[mask, i] -= DW[i]
- mask = pos[:,i] < right[i] - DW[i]
- pos[mask, i] += DW[i]
- #del mask
+ _shift_periodic(pos, left, right, DW)
- # Now get all particles that are within the bbox
+ # Now get all particles that are within the sphere
mask = ((pos-center)**2).sum(axis=1)**0.5 < radius
- #print 'Mask shape, sum:', mask.shape, mask.sum()
mylog.debug("Filtering particles, returning %i out of %i" % (mask.sum(), mask.shape[0]))
@@ -949,11 +945,7 @@
# This hurts, but is useful for periodicity. Probably should check first
# if it is even needed for a given left/right
- for i in range(3):
- mask = pos[:,i] >= DW[i] + left[i]
- pos[mask, i] -= DW[i]
- mask = pos[:,i] < right[i] - DW[i]
- pos[mask, i] += DW[i]
+ _shift_periodic(pos, left, right, DW)
mylog.debug("Periodic filtering, %s %s %s %s" % (left, right, pos.min(axis=0), pos.max(axis=0)))
# Now get all particles that are within the bbox
https://bitbucket.org/yt_analysis/yt/commits/a5f1bc376dd3/
Changeset: a5f1bc376dd3
Branch: yt-3.0
User: MatthewTurk
Date: 2014-09-03 17:01:14
Summary: Merged in samskillman/yt/yt-3.0 (pull request #1089)
Adding filter_sphere, and iter_sphere functionality to sdf io
Affected #: 1 file
diff -r 49d4aca8c7e3f8a83057956b39a5840785a0daa5 -r a5f1bc376dd3fe5266e5dfc9463817872c48810d yt/utilities/sdf.py
--- a/yt/utilities/sdf.py
+++ b/yt/utilities/sdf.py
@@ -458,6 +458,19 @@
return sdf
+def _shift_periodic(pos, left, right, domain_width):
+ """
+ Periodically shift positions that are right of left+domain_width to
+ the left, and those left of right-domain_width to the right.
+ """
+ for i in range(3):
+ mask = pos[:,i] >= left[i] + domain_width[i]
+ pos[mask, i] -= domain_width[i]
+ mask = pos[:,i] < right[i] - domain_width[i]
+ pos[mask, i] += domain_width[i]
+ return
+
+
class SDFIndex(object):
"""docstring for SDFIndex
@@ -856,14 +869,7 @@
DW = self.true_domain_width
# This hurts, but is useful for periodicity. Probably should check first
# if it is even needed for a given left/right
- for i in range(3):
- #pos[:,i] = np.mod(pos[:,i] - left[i],
- # self.true_domain_width[i]) + left[i]
- mask = pos[:,i] >= left[i] + DW[i]
- pos[mask, i] -= DW[i]
- mask = pos[:,i] < right[i] - DW[i]
- pos[mask, i] += DW[i]
- #del mask
+ _shift_periodic(pos, left, right, DW)
# Now get all particles that are within the bbox
mask = np.all(pos >= left, axis=1) * np.all(pos < right, axis=1)
@@ -887,6 +893,39 @@
yield filtered
+ def filter_sphere(self, center, radius, myiter):
+ """
+ Filter data by masking out data outside of a sphere defined
+ by a center and radius. Account for periodicity of data, allowing
+ left/right to be outside of the domain.
+ """
+
+ # Get left/right for periodicity considerations
+ left = center - radius
+ right = center + radius
+ for data in myiter:
+ pos = np.array([data['x'].copy(), data['y'].copy(), data['z'].copy()]).T
+
+ DW = self.true_domain_width
+ _shift_periodic(pos, left, right, DW)
+
+ # Now get all particles that are within the sphere
+ mask = ((pos-center)**2).sum(axis=1)**0.5 < radius
+
+ mylog.debug("Filtering particles, returning %i out of %i" % (mask.sum(), mask.shape[0]))
+
+ if not np.any(mask):
+ continue
+
+ filtered = {ax: pos[:, i][mask] for i, ax in enumerate('xyz')}
+ for f in data.keys():
+ if f in 'xyz':
+ continue
+ filtered[f] = data[f][mask]
+
+ yield filtered
+
+
def iter_filtered_bbox_fields(self, left, right, data,
pos_fields, fields):
"""
@@ -906,11 +945,7 @@
# This hurts, but is useful for periodicity. Probably should check first
# if it is even needed for a given left/right
- for i in range(3):
- mask = pos[:,i] >= DW[i] + left[i]
- pos[mask, i] -= DW[i]
- mask = pos[:,i] < right[i] - DW[i]
- pos[mask, i] += DW[i]
+ _shift_periodic(pos, left, right, DW)
mylog.debug("Periodic filtering, %s %s %s %s" % (left, right, pos.min(axis=0), pos.max(axis=0)))
# Now get all particles that are within the bbox
@@ -929,6 +964,10 @@
yield f, data[f][mask]
def iter_bbox_data(self, left, right, fields):
+ """
+ Iterate over all data within a bounding box defined by a left
+ and a right.
+ """
_ensure_xyz_fields(fields)
mylog.debug('MIDX Loading region from %s to %s' %(left, right))
inds = self.get_bbox(left, right)
@@ -949,15 +988,17 @@
# yield dd
def iter_sphere_data(self, center, radius, fields):
+ """
+ Iterate over all data within some sphere defined by a center and
+ a radius.
+ """
_ensure_xyz_fields(fields)
mylog.debug('MIDX Loading spherical region %s to %s' %(center, radius))
inds = self.get_bbox(center-radius, center+radius)
- my_filter = sphere_filter(center, radius, self.true_domain_width)
-
- for dd in self.filter_particles(
- self.iter_data(inds, fields),
- my_filter):
+ for dd in self.filter_sphere(
+ center, radius,
+ self.iter_data(inds, fields)):
yield dd
def iter_ibbox_data(self, left, right, fields):
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