[yt-svn] commit/yt: 3 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Apr 12 14:47:39 PDT 2013
3 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/64fabb67c5eb/
Changeset: 64fabb67c5eb
Branch: yt
User: samskillman
Date: 2013-04-02 05:31:44
Summary: Adding particle io for ellipsoids, speeding up the ellipsoid data object by ~2x, and some PEP8 style fixes.
Affected #: 2 files
diff -r ae7a263311d3d0cfd7809e7841501dc724384106 -r 64fabb67c5eb9eadb2e51ee891217f3d1e98708a yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -3587,12 +3587,12 @@
given the tilt about the x axis when e0 was aligned
to x after t1, t2 rotations about z, y
"""
- RX = get_rotation_matrix(-tilt, (1,0,0)).transpose()
- RY = get_rotation_matrix(-t2, (0,1,0)).transpose()
- RZ = get_rotation_matrix(-t1, (0,0,1)).transpose()
- e1 = ((0, 1, 0) * RX).sum(axis = 1)
- e1 = (e1 * RY).sum(axis = 1)
- e1 = (e1 * RZ).sum(axis = 1)
+ RX = get_rotation_matrix(-tilt, (1, 0, 0)).transpose()
+ RY = get_rotation_matrix(-t2, (0, 1, 0)).transpose()
+ RZ = get_rotation_matrix(-t1, (0, 0, 1)).transpose()
+ e1 = ((0, 1, 0) * RX).sum(axis=1)
+ e1 = (e1 * RY).sum(axis=1)
+ e1 = (e1 * RZ).sum(axis=1)
e2 = np.cross(e0, e1)
self._e1 = e1
@@ -3612,87 +3612,64 @@
can just use the sphere one and forget about checking orientation
but feed in the A parameter for radius
"""
- def _get_list_of_grids(self, field = None):
+ def _get_list_of_grids(self, field=None):
"""
This returns the grids that are possibly within the ellipse
"""
- grids,ind = self.hierarchy.find_sphere_grids(self.center, self._A)
+ grids, ind = self.hierarchy.find_sphere_grids(self.center, self._A)
# Now we sort by level
grids = grids.tolist()
- grids.sort(key=lambda x: (x.Level, \
- x.LeftEdge[0], \
- x.LeftEdge[1], \
+ grids.sort(key=lambda x: (x.Level,
+ x.LeftEdge[0],
+ x.LeftEdge[1],
x.LeftEdge[2]))
- self._grids = np.array(grids, dtype = 'object')
+ self._grids = np.array(grids, dtype='object')
def _is_fully_enclosed(self, grid):
"""
check if all grid corners are inside the ellipsoid
"""
- # vector from corner to center
- vr = (grid._corners - self.center)
- # 3 possible cases of locations taking periodic BC into account
- # just listing the components, find smallest later
- dotarr=np.array([vr, vr + self.DW, vr - self.DW])
- # these vrdote# finds the product of vr components with e#
- # square the results
- # find the smallest
- # sums it
- vrdote0_2 = (np.multiply(dotarr, self._e0)**2).min(axis \
- = 0).sum(axis = 1)
- vrdote1_2 = (np.multiply(dotarr, self._e1)**2).min(axis \
- = 0).sum(axis = 1)
- vrdote2_2 = (np.multiply(dotarr, self._e2)**2).min(axis \
- = 0).sum(axis = 1)
- return np.all(vrdote0_2 / self._A**2 + \
- vrdote1_2 / self._B**2 + \
- vrdote2_2 / self._C**2 <=1.0)
-
- @restore_grid_state # Pains me not to decorate with cache_mask here
- def _get_cut_mask(self, grid, field = None):
+ return False
+
+ @restore_grid_state # Pains me not to decorate with cache_mask here
+ def _get_cut_mask(self, grid, field=None):
"""
This checks if each cell is inside the ellipsoid
"""
# We have the *property* center, which is not necessarily
# the same as the field_parameter
if self._is_fully_enclosed(grid):
- return True # We do not want child masking here
+ return True # We do not want child masking here
if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)) \
and grid.id in self._cut_masks:
return self._cut_masks[grid.id]
- Inside = np.zeros(grid["x"].shape, dtype = 'float64')
- dim = grid["x"].shape
- # need this to take into account non-cube root grid tiles
- if (len(dim) == 1):
- dot_evec = np.zeros([3, dim[0]])
- elif (len(dim) == 2):
- dot_evec = np.zeros([3, dim[0], dim[1]])
- elif (len(dim) == 3):
- dot_evec = np.zeros([3, dim[0], dim[1], dim[2]])
+
+ dot_evecx = np.zeros(grid.ActiveDimensions)
+ dot_evecy = np.zeros(grid.ActiveDimensions)
+ dot_evecz = np.zeros(grid.ActiveDimensions)
for i, ax in enumerate('xyz'):
# distance to center
- ar = grid[ax]-self.center[i]
- # cases to take into account periodic BC
- case = np.array([ar, ar + self.DW[i], ar - self.DW[i]])
- # find which of the 3 cases is smallest in magnitude
- index = np.abs(case).argmin(axis = 0)
- # restrict distance to only the smallest cases
- vec = np.choose(index, case)
+ ar = grid[ax]-self.center[i]
+ # correct for periodicity
+ vec = np.array([ar, ar + self.DW[i], ar - self.DW[i]])
+ ind = np.argmin(np.abs(vec), axis=0)
+ vec = np.choose(ind, vec)
# sum up to get the dot product with e_vectors
- dot_evec += np.array([vec * self._e0[i], \
- vec * self._e1[i], \
- vec * self._e2[i]])
+ dot_evecx += vec * self._e0[i] / self._A
+ dot_evecy += vec * self._e1[i] / self._B
+ dot_evecz += vec * self._e2[i] / self._C
+
# Calculate the eqn of ellipsoid, if it is inside
# then result should be <= 1.0
- Inside = dot_evec[0]**2 / self._A**2 + \
- dot_evec[1]**2 / self._B**2 + \
- dot_evec[2]**2 / self._C**2
- cm = ((Inside <= 1.0) & grid.child_mask)
+ cm = ((dot_evecx**2 +
+ dot_evecy**2 +
+ dot_evecz**2 <= 1.0) & grid.child_mask)
if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)):
self._cut_masks[grid.id] = cm
return cm
+
class AMRCoveringGridBase(AMR3DData):
"""A 3D region with all data extracted to a single, specified
resolution.
diff -r ae7a263311d3d0cfd7809e7841501dc724384106 -r 64fabb67c5eb9eadb2e51ee891217f3d1e98708a yt/data_objects/particle_io.py
--- a/yt/data_objects/particle_io.py
+++ b/yt/data_objects/particle_io.py
@@ -145,6 +145,23 @@
return (1, (np.array(self.center, dtype='float64'), self.radius,
1, DLE, DRE))
+class ParticleIOHandlerEllipsoid(ParticleIOHandlerImplemented):
+ _source_type = "ellipsoid"
+
+ def __init__(self, pf, source):
+ self.center = source.center
+ self._A = source._A
+ self._B = source._B
+ self._C = source._C
+ self._e0 = source._e0
+ self._tilt = source._tilt
+ ParticleIOHandler.__init__(self, pf, source)
+
+ def _get_args(self):
+ return (1, (np.array(self.center, dtype='float64'), self._A, self._B,
+ self._C, self._e0, self._tilt))
+
+
class ParticleIOHandlerDisk(ParticleIOHandlerImplemented):
_source_type = "disk"
https://bitbucket.org/yt_analysis/yt/commits/8dd9d9819b06/
Changeset: 8dd9d9819b06
Branch: yt
User: samskillman
Date: 2013-04-02 06:11:44
Summary: Getting rid of bad attempt at particle io for ellipsoids.
Affected #: 1 file
diff -r 64fabb67c5eb9eadb2e51ee891217f3d1e98708a -r 8dd9d9819b061bcfa68d2ef962e44f44810228f3 yt/data_objects/particle_io.py
--- a/yt/data_objects/particle_io.py
+++ b/yt/data_objects/particle_io.py
@@ -145,23 +145,6 @@
return (1, (np.array(self.center, dtype='float64'), self.radius,
1, DLE, DRE))
-class ParticleIOHandlerEllipsoid(ParticleIOHandlerImplemented):
- _source_type = "ellipsoid"
-
- def __init__(self, pf, source):
- self.center = source.center
- self._A = source._A
- self._B = source._B
- self._C = source._C
- self._e0 = source._e0
- self._tilt = source._tilt
- ParticleIOHandler.__init__(self, pf, source)
-
- def _get_args(self):
- return (1, (np.array(self.center, dtype='float64'), self._A, self._B,
- self._C, self._e0, self._tilt))
-
-
class ParticleIOHandlerDisk(ParticleIOHandlerImplemented):
_source_type = "disk"
https://bitbucket.org/yt_analysis/yt/commits/af7c2b1e3697/
Changeset: af7c2b1e3697
Branch: yt
User: MatthewTurk
Date: 2013-04-12 23:47:35
Summary: Merged in samskillman/yt (pull request #472)
Ellipsoid Data Object Speedup
Affected #: 2 files
diff -r 7f171073bb43bebf2c1af25596cb9e7fb0bc2b0a -r af7c2b1e3697906d0a4faa0f244903d079490c2e yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -3587,12 +3587,12 @@
given the tilt about the x axis when e0 was aligned
to x after t1, t2 rotations about z, y
"""
- RX = get_rotation_matrix(-tilt, (1,0,0)).transpose()
- RY = get_rotation_matrix(-t2, (0,1,0)).transpose()
- RZ = get_rotation_matrix(-t1, (0,0,1)).transpose()
- e1 = ((0, 1, 0) * RX).sum(axis = 1)
- e1 = (e1 * RY).sum(axis = 1)
- e1 = (e1 * RZ).sum(axis = 1)
+ RX = get_rotation_matrix(-tilt, (1, 0, 0)).transpose()
+ RY = get_rotation_matrix(-t2, (0, 1, 0)).transpose()
+ RZ = get_rotation_matrix(-t1, (0, 0, 1)).transpose()
+ e1 = ((0, 1, 0) * RX).sum(axis=1)
+ e1 = (e1 * RY).sum(axis=1)
+ e1 = (e1 * RZ).sum(axis=1)
e2 = np.cross(e0, e1)
self._e1 = e1
@@ -3612,87 +3612,64 @@
can just use the sphere one and forget about checking orientation
but feed in the A parameter for radius
"""
- def _get_list_of_grids(self, field = None):
+ def _get_list_of_grids(self, field=None):
"""
This returns the grids that are possibly within the ellipse
"""
- grids,ind = self.hierarchy.find_sphere_grids(self.center, self._A)
+ grids, ind = self.hierarchy.find_sphere_grids(self.center, self._A)
# Now we sort by level
grids = grids.tolist()
- grids.sort(key=lambda x: (x.Level, \
- x.LeftEdge[0], \
- x.LeftEdge[1], \
+ grids.sort(key=lambda x: (x.Level,
+ x.LeftEdge[0],
+ x.LeftEdge[1],
x.LeftEdge[2]))
- self._grids = np.array(grids, dtype = 'object')
+ self._grids = np.array(grids, dtype='object')
def _is_fully_enclosed(self, grid):
"""
check if all grid corners are inside the ellipsoid
"""
- # vector from corner to center
- vr = (grid._corners - self.center)
- # 3 possible cases of locations taking periodic BC into account
- # just listing the components, find smallest later
- dotarr=np.array([vr, vr + self.DW, vr - self.DW])
- # these vrdote# finds the product of vr components with e#
- # square the results
- # find the smallest
- # sums it
- vrdote0_2 = (np.multiply(dotarr, self._e0)**2).min(axis \
- = 0).sum(axis = 1)
- vrdote1_2 = (np.multiply(dotarr, self._e1)**2).min(axis \
- = 0).sum(axis = 1)
- vrdote2_2 = (np.multiply(dotarr, self._e2)**2).min(axis \
- = 0).sum(axis = 1)
- return np.all(vrdote0_2 / self._A**2 + \
- vrdote1_2 / self._B**2 + \
- vrdote2_2 / self._C**2 <=1.0)
-
- @restore_grid_state # Pains me not to decorate with cache_mask here
- def _get_cut_mask(self, grid, field = None):
+ return False
+
+ @restore_grid_state # Pains me not to decorate with cache_mask here
+ def _get_cut_mask(self, grid, field=None):
"""
This checks if each cell is inside the ellipsoid
"""
# We have the *property* center, which is not necessarily
# the same as the field_parameter
if self._is_fully_enclosed(grid):
- return True # We do not want child masking here
+ return True # We do not want child masking here
if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)) \
and grid.id in self._cut_masks:
return self._cut_masks[grid.id]
- Inside = np.zeros(grid["x"].shape, dtype = 'float64')
- dim = grid["x"].shape
- # need this to take into account non-cube root grid tiles
- if (len(dim) == 1):
- dot_evec = np.zeros([3, dim[0]])
- elif (len(dim) == 2):
- dot_evec = np.zeros([3, dim[0], dim[1]])
- elif (len(dim) == 3):
- dot_evec = np.zeros([3, dim[0], dim[1], dim[2]])
+
+ dot_evecx = np.zeros(grid.ActiveDimensions)
+ dot_evecy = np.zeros(grid.ActiveDimensions)
+ dot_evecz = np.zeros(grid.ActiveDimensions)
for i, ax in enumerate('xyz'):
# distance to center
- ar = grid[ax]-self.center[i]
- # cases to take into account periodic BC
- case = np.array([ar, ar + self.DW[i], ar - self.DW[i]])
- # find which of the 3 cases is smallest in magnitude
- index = np.abs(case).argmin(axis = 0)
- # restrict distance to only the smallest cases
- vec = np.choose(index, case)
+ ar = grid[ax]-self.center[i]
+ # correct for periodicity
+ vec = np.array([ar, ar + self.DW[i], ar - self.DW[i]])
+ ind = np.argmin(np.abs(vec), axis=0)
+ vec = np.choose(ind, vec)
# sum up to get the dot product with e_vectors
- dot_evec += np.array([vec * self._e0[i], \
- vec * self._e1[i], \
- vec * self._e2[i]])
+ dot_evecx += vec * self._e0[i] / self._A
+ dot_evecy += vec * self._e1[i] / self._B
+ dot_evecz += vec * self._e2[i] / self._C
+
# Calculate the eqn of ellipsoid, if it is inside
# then result should be <= 1.0
- Inside = dot_evec[0]**2 / self._A**2 + \
- dot_evec[1]**2 / self._B**2 + \
- dot_evec[2]**2 / self._C**2
- cm = ((Inside <= 1.0) & grid.child_mask)
+ cm = ((dot_evecx**2 +
+ dot_evecy**2 +
+ dot_evecz**2 <= 1.0) & grid.child_mask)
if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)):
self._cut_masks[grid.id] = cm
return cm
+
class AMRCoveringGridBase(AMR3DData):
"""A 3D region with all data extracted to a single, specified
resolution.
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