[yt-svn] commit/yt-3.0: 3 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Sep 25 14:39:01 PDT 2013
3 new commits in yt-3.0:
https://bitbucket.org/yt_analysis/yt-3.0/commits/374af9f92c7d/
Changeset: 374af9f92c7d
Branch: yt-3.0
User: MatthewTurk
Date: 2013-09-18 22:49:58
Summary: Removing unused functions and unsupported data objects.
Affected #: 2 files
diff -r 97b4dd0e60c14fc770dbcf4c6bfbaff3dac3bb8e -r 374af9f92c7dab96028195b697eab23529361926 yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -141,50 +141,6 @@
else:
raise KeyError(field)
- def _get_data_from_grid(self, grid, field):
- if self.pf.geometry == "cylindrical":
- if grid.id in self._masks:
- mask = self._masks[grid.id]
- else:
- mask = self._get_cut_mask(grid)
- ts, dts = self._ts[grid.id], self._dts[grid.id]
- else:
- mask = np.logical_and(self._get_cut_mask(grid), grid.child_mask)
- ts, dts = self._ts[grid.id][mask], self._dts[grid.id][mask]
-
- if field == 'dts':
- return dts
- if field == 't':
- return ts
-
- gf = grid[field]
- if not iterable(gf):
- gf = gf * np.ones(grid.child_mask.shape)
- return gf[mask]
-
- def _get_cut_mask(self, grid):
- if self.pf.geometry == "cylindrical":
- _ = clyindrical_ray_trace(self.start_point, self.end_point,
- grid.LeftEdge, grid.RightEdge)
- ts, s, rzt, mask = _
- dts = np.empty(ts.shape, dtype='float64')
- dts[0], dts[1:] = 0.0, ts[1:] - ts[:-1]
- grid['r'], grid['z'], grid['theta'] = rzt[:,0], rzt[:,1], rzt[:,2]
- grid['s'] = s
- else:
- mask = np.zeros(grid.ActiveDimensions, dtype='int')
- dts = np.zeros(grid.ActiveDimensions, dtype='float64')
- ts = np.zeros(grid.ActiveDimensions, dtype='float64')
- VoxelTraversal(mask, ts, dts, grid.LeftEdge, grid.RightEdge,
- grid.dds, self.center, self.vec)
- dts = np.abs(dts)
- ts = np.abs(ts)
- self._dts[grid.id] = dts
- self._ts[grid.id] = ts
- self._masks[grid.id] = mask
- return mask
-
-
class YTSliceBase(YTSelectionContainer2D):
"""
This is a data object corresponding to a slice through the simulation
@@ -249,10 +205,6 @@
else:
raise KeyError(field)
- def _gen_node_name(self):
- return "%s/%s_%s" % \
- (self._top_node, self.axis, self.coord)
-
@property
def _mrep(self):
return MinimalSliceData(self)
@@ -520,156 +472,6 @@
frb = ObliqueFixedResolutionBuffer(self, bounds, resolution)
return frb
-class YTFixedResCuttingPlaneBase(YTSelectionContainer2D):
- """
- The fixed resolution Cutting Plane slices at an oblique angle,
- where we use the *normal* vector at the *center* to define the
- viewing plane. The plane is *width* units wide. The 'up'
- direction is guessed at automatically if not given.
- """
- _top_node = "/FixedResCuttingPlanes"
- _type_name = "fixed_res_cutting"
- _con_args = ('normal', 'center', 'width', 'dims')
- def __init__(self, normal, center, width, dims, pf = None,
- node_name = None, field_parameters = None):
- #
- # Taken from Cutting Plane
- #
- YTSelectionContainer2D.__init__(self, 4, pf, field_parameters)
- self._set_center(center)
- self.width = width
- self.dims = dims
- self.dds = self.width / self.dims
- self.bounds = np.array([0.0,1.0,0.0,1.0])
-
- self.set_field_parameter('center', center)
- # Let's set up our plane equation
- # ax + by + cz + d = 0
- self._norm_vec = normal/np.sqrt(np.dot(normal,normal))
- self._d = -1.0 * np.dot(self._norm_vec, self.center)
- # First we try all three, see which has the best result:
- vecs = np.identity(3)
- _t = np.cross(self._norm_vec, vecs).sum(axis=1)
- ax = _t.argmax()
- self._x_vec = np.cross(vecs[ax,:], self._norm_vec).ravel()
- self._x_vec /= np.sqrt(np.dot(self._x_vec, self._x_vec))
- self._y_vec = np.cross(self._norm_vec, self._x_vec).ravel()
- self._y_vec /= np.sqrt(np.dot(self._y_vec, self._y_vec))
- self._rot_mat = np.array([self._x_vec,self._y_vec,self._norm_vec])
- self._inv_mat = np.linalg.pinv(self._rot_mat)
- self.set_field_parameter('cp_x_vec',self._x_vec)
- self.set_field_parameter('cp_y_vec',self._y_vec)
- self.set_field_parameter('cp_z_vec',self._norm_vec)
-
- # Calculate coordinates of each pixel
- _co = self.dds * \
- (np.mgrid[-self.dims/2 : self.dims/2,
- -self.dims/2 : self.dims/2] + 0.5)
- self._coord = self.center + np.outer(_co[0,:,:], self._x_vec) + \
- np.outer(_co[1,:,:], self._y_vec)
- self._pixelmask = np.ones(self.dims*self.dims, dtype='int8')
-
- if node_name is not False:
- if node_name is True: self._deserialize()
- else: self._deserialize(node_name)
-
- @property
- def normal(self):
- return self._norm_vec
-
- def _get_list_of_grids(self):
- # Just like the Cutting Plane but restrict the grids to be
- # within width/2 of the center.
- vertices = self.hierarchy.gridCorners
- # Shape = (8,3,n_grid)
- D = np.sum(self._norm_vec.reshape((1,3,1)) * vertices, axis=1) + self._d
- valid_grids = np.where(np.logical_not(np.all(D<0,axis=0) |
- np.all(D>0,axis=0) ))[0]
- # Now restrict these grids to a rect. prism that bounds the slice
- sliceCorners = np.array([ \
- self.center + 0.5*self.width * (+self._x_vec + self._y_vec),
- self.center + 0.5*self.width * (+self._x_vec - self._y_vec),
- self.center + 0.5*self.width * (-self._x_vec - self._y_vec),
- self.center + 0.5*self.width * (-self._x_vec + self._y_vec) ])
- sliceLeftEdge = sliceCorners.min(axis=0)
- sliceRightEdge = sliceCorners.max(axis=0)
- # Check for bounding box and grid overlap
- leftOverlap = np.less(self.hierarchy.gridLeftEdge[valid_grids],
- sliceRightEdge).all(axis=1)
- rightOverlap = np.greater(self.hierarchy.gridRightEdge[valid_grids],
- sliceLeftEdge).all(axis=1)
- self._grids = self.hierarchy.grids[valid_grids[
- np.where(leftOverlap & rightOverlap)]]
- self._grids = self._grids[::-1]
-
- def _generate_coords(self):
- self['px'] = self._coord[:,0].ravel()
- self['py'] = self._coord[:,1].ravel()
- self['pz'] = self._coord[:,2].ravel()
- self['pdx'] = self.dds * 0.5
- self['pdy'] = self.dds * 0.5
- #self['pdz'] = self.dds * 0.5
-
- def _get_data_from_grid(self, grid, field):
- if not self.pf.field_info[field].particle_type:
- pointI = self._get_point_indices(grid)
- if len(pointI) == 0: return
- vc = self._calc_vertex_centered_data(grid, field)
- bds = np.array(zip(grid.LeftEdge,
- grid.RightEdge)).ravel()
- interp = TrilinearFieldInterpolator(vc, bds, ['x', 'y', 'z'])
- self[field][pointI] = interp( \
- dict(x=self._coord[pointI,0],
- y=self._coord[pointI,1],
- z=self._coord[pointI,2])).ravel()
-
- # Mark these pixels to speed things up
- self._pixelmask[pointI] = 0
-
- return
- else:
- raise SyntaxError("Making a fixed resolution slice with "
- "particles isn't supported yet.")
-
- def get_data(self, fields):
- """
- Iterates over the list of fields and generates/reads them all.
- """
- self._get_list_of_grids()
- if not self.has_key('pdx'):
- self._generate_coords()
- fields_to_get = ensure_list(fields)
- temp_data = {}
- _size = self.dims * self.dims
- for field in fields_to_get:
- if self.field_data.has_key(field): continue
- if field not in self.hierarchy.field_list:
- if self._generate_field(field):
- continue # A "True" return means we did it
- self[field] = np.zeros(_size, dtype='float64')
- for grid in self._get_grids():
- self._get_data_from_grid(grid, field)
- self[field] = self.comm.mpi_allreduce(\
- self[field], op='sum').reshape([self.dims]*2).transpose()
-
- def _calc_vertex_centered_data(self, grid, field):
- #return grid.retrieve_ghost_zones(1, field, smoothed=False)
- return grid.get_vertex_centered_data(field)
-
- def _get_point_indices(self, grid):
- if self._pixelmask.max() == 0: return []
- k = planar_points_in_volume(self._coord, self._pixelmask,
- grid.LeftEdge, grid.RightEdge,
- grid.child_mask, just_one(grid['dx']))
- return k
-
- def _gen_node_name(self):
- cen_name = ("%s" % (self.center,)).replace(" ","_")[1:-1]
- L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1]
- return "%s/c%s_L%s" % \
- (self._top_node, cen_name, L_name)
-
-
class YTDiskBase(YTSelectionContainer3D):
"""
By providing a *center*, a *normal*, a *radius* and a *height* we
@@ -687,113 +489,6 @@
self._radius = fix_length(radius, self.pf)
self._d = -1.0 * np.dot(self._norm_vec, self.center)
- def _get_list_of_grids(self):
- H = np.sum(self._norm_vec.reshape((1,3,1)) * self.pf.h.grid_corners,
- axis=1) + self._d
- D = np.sqrt(np.sum((self.pf.h.grid_corners -
- self.center.reshape((1,3,1)))**2.0,axis=1))
- R = np.sqrt(D**2.0-H**2.0)
- self._grids = self.hierarchy.grids[
- ( (np.any(np.abs(H)<self._height,axis=0))
- & (np.any(R<self._radius,axis=0)
- & (np.logical_not((np.all(H>0,axis=0) | (np.all(H<0, axis=0)))) )
- ) ) ]
- self._grids = self.hierarchy.grids
-
- def _is_fully_enclosed(self, grid):
- corners = grid._corners.reshape((8,3,1))
- H = np.sum(self._norm_vec.reshape((1,3,1)) * corners,
- axis=1) + self._d
- D = np.sqrt(np.sum((corners -
- self.center.reshape((1,3,1)))**2.0,axis=1))
- R = np.sqrt(D**2.0-H**2.0)
- return (np.all(np.abs(H) < self._height, axis=0) \
- and np.all(R < self._radius, axis=0))
-
- def _get_cut_mask(self, grid):
- if self._is_fully_enclosed(grid):
- return True
- else:
- h = grid['x'] * self._norm_vec[0] \
- + grid['y'] * self._norm_vec[1] \
- + grid['z'] * self._norm_vec[2] \
- + self._d
- d = np.sqrt(
- (grid['x'] - self.center[0])**2.0
- + (grid['y'] - self.center[1])**2.0
- + (grid['z'] - self.center[2])**2.0
- )
- r = np.sqrt(d**2.0-h**2.0)
- cm = ( (np.abs(h) <= self._height)
- & (r <= self._radius))
- return cm
-
-
-class YTInclinedBoxBase(YTSelectionContainer3D):
- """
- A rectangular prism with arbitrary alignment to the computational
- domain. *origin* is the origin of the box, while *box_vectors* is an
- array of ordering [ax, ijk] that describes the three vectors that
- describe the box. No checks are done to ensure that the box satisfies
- a right-hand rule, but if it doesn't, behavior is undefined.
- """
- _type_name="inclined_box"
- _con_args = ('origin','box_vectors')
-
- def __init__(self, origin, box_vectors, fields=None,
- pf=None, **kwargs):
- self.origin = np.array(origin)
- self.box_vectors = np.array(box_vectors, dtype='float64')
- self.box_lengths = (self.box_vectors**2.0).sum(axis=1)**0.5
- center = origin + 0.5*self.box_vectors.sum(axis=0)
- YTSelectionContainer3D.__init__(self, center, fields, pf, **kwargs)
- self._setup_rotation_parameters()
-
- def _setup_rotation_parameters(self):
- xv = self.box_vectors[0,:]
- yv = self.box_vectors[1,:]
- zv = self.box_vectors[2,:]
- self._x_vec = xv / np.sqrt(np.dot(xv, xv))
- self._y_vec = yv / np.sqrt(np.dot(yv, yv))
- self._z_vec = zv / np.sqrt(np.dot(zv, zv))
- self._rot_mat = np.array([self._x_vec,self._y_vec,self._z_vec])
- self._inv_mat = np.linalg.pinv(self._rot_mat)
-
- def _get_list_of_grids(self):
- if self._grids is not None: return
- GLE = self.pf.h.grid_left_edge
- GRE = self.pf.h.grid_right_edge
- goodI = find_grids_in_inclined_box(self.box_vectors, self.center,
- GLE, GRE)
- cgrids = self.pf.h.grids[goodI.astype('bool')]
- # find_grids_in_inclined_box seems to be broken.
- cgrids = self.pf.h.grids[:]
- grids = []
- for i,grid in enumerate(cgrids):
- v = grid_points_in_volume(self.box_lengths, self.origin,
- self._rot_mat, grid.LeftEdge,
- grid.RightEdge, grid.dds,
- grid.child_mask, 1)
- if v: grids.append(grid)
- self._grids = np.empty(len(grids), dtype='object')
- for gi, g in enumerate(grids): self._grids[gi] = g
-
-
- def _is_fully_enclosed(self, grid):
- # This should be written at some point.
- # We'd rotate all eight corners into the space of the box, then check to
- # see if all are enclosed.
- return False
-
- def _get_cut_mask(self, grid):
- if self._is_fully_enclosed(grid):
- return True
- pm = np.zeros(grid.ActiveDimensions, dtype='int32')
- grid_points_in_volume(self.box_lengths, self.origin,
- self._rot_mat, grid.LeftEdge,
- grid.RightEdge, grid.dds, pm, 0)
- return pm
-
class YTRegionBase(YTSelectionContainer3D):
"""A 3D region of data with an arbitrary center.
diff -r 97b4dd0e60c14fc770dbcf4c6bfbaff3dac3bb8e -r 374af9f92c7dab96028195b697eab23529361926 yt/visualization/plot_collection.py
--- a/yt/visualization/plot_collection.py
+++ b/yt/visualization/plot_collection.py
@@ -589,99 +589,6 @@
p["Axis"] = "CuttingPlane"
return p
- def add_fixed_res_cutting_plane(self, field, normal, width, res=512,
- center=None, use_colorbar=True, figure = None, axes = None,
- fig_size=None, obj=None, field_parameters = None):
- r"""Create a fixed resolution cutting plane, from that a plot, and add
- it to the current collection.
-
- A cutting plane is an oblique slice through the simulation volume,
- oriented by a specified normal vector that is perpendicular to the
- image plane. This function will slice through, but instead of
- retaining all the data necessary to rescale the cutting plane at any
- width, it only retains the pixels for a single width. This function
- will generate a `yt.data_objects.api.YTFixedResCuttingPlaneBase` from the given
- parameters. This image buffer then gets passed to a
- `yt.visualization.plot_types.FixedResolutionPlot`, and the resultant plot is added to the
- current collection. Various parameters allow control of the way the
- slice is displayed, as well as how the plane is generated.
-
- Parameters
- ----------
- field : string
- The initial field to slice and display.
- normal : array_like
- The vector that defines the desired plane. For instance, the
- angular momentum of a sphere.
- width : float
- The width, in code units, of the image plane.
- res : int
- The returned image buffer must be square; this number is how many
- pixels on a side it will have.
- center : array_like, optional
- The center to be used for things like radius and radial velocity.
- Defaults to the center of the plot collection.
- use_colorbar : bool, optional
- Whether we should leave room for and create a colorbar.
- figure : `matplotlib.figure.Figure`, optional
- The figure onto which the axes will be placed. Typically not used
- unless *axes* is also specified.
- axes : `matplotlib.axes.Axes`, optional
- The axes object which will be used to create the image plot.
- Typically used for things like multiplots and the like.
- fig_size : tuple of floats
- This parameter can act as a proxy for the manual creation of a
- figure. By specifying it, you can create plots with an arbitrarily
- large or small size. It is in inches, defaulting to 100 dpi.
- obj : `YTCuttingPlaneBase`, optional
- If you would like to use an existing cutting plane, you may specify
- it here, in which case a new cutting plane will not be created.
- field_parameters : dict, optional
- This set of parameters will be passed to the cutting plane upon
- creation, which can be used for passing variables to derived
- fields.
-
- Returns
- -------
- plot : `yt.visualization.plot_types.FixedResolutionPlot`
- The plot that has been added to the PlotCollection.
-
- See Also
- --------
- yt.data_objects.api.YTFixedResCuttingPlaneBase : This is the type created by this
- function.
-
- Examples
- --------
-
- Here's a simple mechanism for getting the angular momentum of a
- collapsing cloud and generating a cutting plane aligned with the
- angular momentum vector.
-
- >>> pf = load("RD0005-mine/RedshiftOutput0005")
- >>> v, c = pf.h.find_max("Density")
- >>> sp = pf.h.sphere(c, 1000.0/pf['au'])
- >>> L = sp.quantities["AngularMomentumVector"]()
- >>> pc = PlotCollection(pf)
- >>> p = pc.add_fixed_res_cutting_plane("Density", L, 1000.0/pf['au'])
- """
- if center == None:
- center = self.c
- if not obj:
- if field_parameters is None: field_parameters = {}
- data = self.pf.hierarchy.fixed_res_cutting \
- (normal, center, width, res, **field_parameters)
- #data = frc[field]
- else:
- data = obj
- p = self._add_plot(FixedResolutionPlot(data, field,
- use_colorbar=use_colorbar, axes=axes, figure=figure,
- size=fig_size))
- mylog.info("Added fixed-res plane of %s with 'center' = %s and "
- "normal = %s", field, list(center), list(normal))
- p["Axis"] = "CuttingPlane"
- return p
-
def add_projection(self, field, axis, weight_field=None,
data_source = None,
center=None, use_colorbar=True,
https://bitbucket.org/yt_analysis/yt-3.0/commits/4ab973491fb1/
Changeset: 4ab973491fb1
Branch: yt-3.0
User: MatthewTurk
Date: 2013-09-18 23:12:41
Summary: Refactoring the AMRGridPatch object.
This removes a number of routines that are largely not needed anymore and which
served to create confusion. I could find no uses of them in the code.
I've also switched one of the camera.py functions (which itself is currently
returning NotImplementedError) to use .blocks instead of a child_mask on a
grid.
Affected #: 3 files
diff -r 374af9f92c7dab96028195b697eab23529361926 -r 4ab973491fb1cebf5cc249531680f3eefca35599 yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -70,7 +70,7 @@
"""
if self.start_index is not None:
return self.start_index
- if self.Parent == None:
+ if self.Parent is None:
left = self.LeftEdge - self.pf.domain_left_edge
start_index = left / self.dds
return np.rint(start_index).astype('int64').ravel()
@@ -131,51 +131,6 @@
if self.pf.dimensionality < 2: self.dds[1] = self.pf.domain_right_edge[1] - self.pf.domain_left_edge[1]
if self.pf.dimensionality < 3: self.dds[2] = self.pf.domain_right_edge[2] - self.pf.domain_left_edge[2]
- @property
- def _corners(self):
- return np.array([ # Unroll!
- [self.LeftEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.RightEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.RightEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.RightEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.LeftEdge[1], self.RightEdge[2]],
- [self.RightEdge[0], self.LeftEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.RightEdge[1], self.LeftEdge[2]],
- ], dtype='float64')
-
- def _generate_overlap_masks(self, axis, LE, RE):
- """
- Generate a mask that shows which cells overlap with arbitrary arrays
- *LE* and *RE*) of edges, typically grids, along *axis*.
- Use algorithm described at http://www.gamedev.net/reference/articles/article735.asp
-
- """
- x = x_dict[axis]
- y = y_dict[axis]
- cond = self.RightEdge[x] >= LE[:,x]
- cond = np.logical_and(cond, self.LeftEdge[x] <= RE[:,x])
- cond = np.logical_and(cond, self.RightEdge[y] >= LE[:,y])
- cond = np.logical_and(cond, self.LeftEdge[y] <= RE[:,y])
- return cond
-
- def is_in_grid(self, x, y, z) :
- """
- Generate a mask that shows which points in *x*, *y*, and *z*
- fall within this grid's boundaries.
- """
- xcond = np.logical_and(x >= self.LeftEdge[0],
- x < self.RightEdge[0])
- ycond = np.logical_and(y >= self.LeftEdge[1],
- y < self.RightEdge[1])
- zcond = np.logical_and(z >= self.LeftEdge[2],
- z < self.RightEdge[2])
-
- cond = np.logical_and(xcond, ycond)
- cond = np.logical_and(zcond, cond)
-
- return cond
-
def __repr__(self):
return "AMRGridPatch_%04i" % (self.id)
@@ -189,13 +144,8 @@
"""
super(AMRGridPatch, self).clear_data()
- self._del_child_mask()
- self._del_child_indices()
self._setup_dx()
- def check_child_masks(self):
- return self._child_mask, self._child_indices
-
def _prepare_grid(self):
""" Copies all the appropriate attributes from the hierarchy. """
# This is definitely the slowest part of generating the hierarchy
@@ -211,89 +161,12 @@
#self.Time = h.gridTimes[my_ind,0]
self.NumberOfParticles = h.grid_particle_count[my_ind, 0]
- def find_max(self, field):
- """ Returns value, index of maximum value of *field* in this grid. """
- coord1d = (self[field] * self.child_mask).argmax()
- coord = np.unravel_index(coord1d, self[field].shape)
- val = self[field][coord]
- return val, coord
-
- def find_min(self, field):
- """ Returns value, index of minimum value of *field* in this grid. """
- coord1d = (self[field] * self.child_mask).argmin()
- coord = np.unravel_index(coord1d, self[field].shape)
- val = self[field][coord]
- return val, coord
-
def get_position(self, index):
""" Returns center position of an *index*. """
pos = (index + 0.5) * self.dds + self.LeftEdge
return pos
- def clear_all(self):
- """
- Clears all datafields from memory and calls
- :meth:`clear_derived_quantities`.
-
- """
- for key in self.keys():
- del self.field_data[key]
- del self.field_data
- if hasattr(self,"retVal"):
- del self.retVal
- self.field_data = YTFieldData()
- self.clear_derived_quantities()
- del self.child_mask
- del self.child_ind
-
- def _set_child_mask(self, newCM):
- if self._child_mask != None:
- mylog.warning("Overriding child_mask attribute! This is probably unwise!")
- self._child_mask = newCM
-
- def _set_child_indices(self, newCI):
- if self._child_indices != None:
- mylog.warning("Overriding child_indices attribute! This is probably unwise!")
- self._child_indices = newCI
-
- def _get_child_mask(self):
- if self._child_mask == None:
- self.__generate_child_mask()
- return self._child_mask
-
- def _get_child_indices(self):
- if self._child_indices == None:
- self.__generate_child_mask()
- return self._child_indices
-
- def _del_child_indices(self):
- try:
- del self._child_indices
- except AttributeError:
- pass
- self._child_indices = None
-
- def _del_child_mask(self):
- try:
- del self._child_mask
- except AttributeError:
- pass
- self._child_mask = None
-
- def _get_child_index_mask(self):
- if self._child_index_mask is None:
- self.__generate_child_index_mask()
- return self._child_index_mask
-
- def _del_child_index_mask(self):
- try:
- del self._child_index_mask
- except AttributeError:
- pass
- self._child_index_mask = None
-
- #@time_execution
- def __fill_child_mask(self, child, mask, tofill, dlevel = 1):
+ def _fill_child_mask(self, child, mask, tofill, dlevel = 1):
rf = self.pf.refine_by
if dlevel != 1:
rf = rf**dlevel
@@ -306,61 +179,37 @@
startIndex[1]:endIndex[1],
startIndex[2]:endIndex[2]] = tofill
- def __generate_child_mask(self):
+ @property
+ def child_mask(self):
"""
Generates self.child_mask, which is zero where child grids exist (and
thus, where higher resolution data is available).
"""
- self._child_mask = np.ones(self.ActiveDimensions, 'bool')
+ child_mask = np.ones(self.ActiveDimensions, 'bool')
for child in self.Children:
- self.__fill_child_mask(child, self._child_mask, 0)
- if self.OverlappingSiblings is not None:
- for sibling in self.OverlappingSiblings:
- self.__fill_child_mask(sibling, self._child_mask, 0)
-
- self._child_indices = (self._child_mask==0) # bool, possibly redundant
+ self._fill_child_mask(child, child_mask, 0)
+ for sibling in self.OverlappingSiblings or []:
+ self._fill_child_mask(sibling, child_mask, 0)
+ return child_mask
- def __generate_child_index_mask(self):
+ @property
+ def child_indices(self):
+ return (self.child_mask == 0)
+
+ @property
+ def child_index_mask(self):
"""
Generates self.child_index_mask, which is -1 where there is no child,
and otherwise has the ID of the grid that resides there.
"""
- self._child_index_mask = np.zeros(self.ActiveDimensions, 'int32') - 1
+ child_index_mask = np.zeros(self.ActiveDimensions, 'int32') - 1
for child in self.Children:
- self.__fill_child_mask(child, self._child_index_mask,
- child.id)
- if self.OverlappingSiblings is not None:
- for sibling in self.OverlappingSiblings:
- self.__fill_child_mask(sibling, self._child_index_mask,
- sibling.id)
-
- def _get_coords(self):
- if self.__coords == None: self._generate_coords()
- return self.__coords
-
- def _set_coords(self, new_c):
- if self.__coords != None:
- mylog.warning("Overriding coords attribute! This is probably unwise!")
- self.__coords = new_c
-
- def _del_coords(self):
- del self.__coords
- self.__coords = None
-
- def _generate_coords(self):
- """
- Creates self.coords, which is of dimensions (3, ActiveDimensions)
-
- """
- ind = np.indices(self.ActiveDimensions)
- left_shaped = np.reshape(self.LeftEdge, (3, 1, 1, 1))
- self['x'], self['y'], self['z'] = (ind + 0.5) * self.dds + left_shaped
-
- child_mask = property(fget=_get_child_mask, fdel=_del_child_mask)
- child_index_mask = property(fget=_get_child_index_mask, fdel=_del_child_index_mask)
- child_indices = property(fget=_get_child_indices, fdel = _del_child_indices)
+ self._fill_child_mask(child, child_index_mask, child.id)
+ for sibling in self.OverlappingSiblings or []:
+ self._fill_child_mask(sibling, child_index_mask, sibling.id)
+ return child_index_mask
def retrieve_ghost_zones(self, n_zones, fields, all_levels=False,
smoothed=False):
diff -r 374af9f92c7dab96028195b697eab23529361926 -r 4ab973491fb1cebf5cc249531680f3eefca35599 yt/utilities/lib/tests/test_grid_tree.py
--- a/yt/utilities/lib/tests/test_grid_tree.py
+++ b/yt/utilities/lib/tests/test_grid_tree.py
@@ -88,15 +88,16 @@
for ind, ixx, iyy, izz in zip(range(num_points), randx, randy, randz):
+ pos = np.array([ixx, iyy, izz])
pt_level = -1
for grid in test_pf.h.grids:
- if grid.is_in_grid(ixx, iyy, izz):
-
- if grid.Level > pt_level:
- pt_level = grid.Level
- grid_inds[ind] = grid.id - grid._id_offset
+ if np.all(pos >= grid.LeftEdge) and \
+ np.all(pos <= grid.RightEdge) and \
+ grid.Level > pt_level:
+ pt_level = grid.Level
+ grid_inds[ind] = grid.id - grid._id_offset
yield assert_equal, point_grid_inds, grid_inds
diff -r 374af9f92c7dab96028195b697eab23529361926 -r 4ab973491fb1cebf5cc249531680f3eefca35599 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -2043,29 +2043,17 @@
positions += inner_radius * dx * vs
vs *= radius
uv = np.ones(3, dtype='float64')
- if data_source is not None:
- grids = data_source._grids
- else:
- grids = pf.h.sphere(center, radius)._grids
+ if data_source is None:
+ data_source = pf.h.sphere(center, radius)
sampler = ProjectionSampler(positions, vs, center, (0.0, 0.0, 0.0, 0.0),
image, uv, uv, np.zeros(3, dtype='float64'))
- pb = get_pbar("Sampling ", len(grids))
- for i,grid in enumerate(grids):
- if data_source is not None:
- data = [grid[field] * data_source._get_cut_mask(grid) * \
- grid.child_mask.astype('float64')
- for field in fields]
- else:
- data = [grid[field] * grid.child_mask.astype('float64')
- for field in fields]
+ for i, (grid, mask) in enumerate(data_source.blocks):
+ data = [(grid[field] * mask).astype("float64") for field in fields]
pg = PartitionedGrid(
grid.id, data,
grid.LeftEdge, grid.RightEdge,
grid.ActiveDimensions.astype("int64"))
- grid.clear_data()
sampler(pg)
- pb.update(i)
- pb.finish()
image = sampler.aimage
dd = self.pf.h.all_data()
field = dd._determine_fields([field])[0]
https://bitbucket.org/yt_analysis/yt-3.0/commits/3c52df9a894a/
Changeset: 3c52df9a894a
Branch: yt-3.0
User: samskillman
Date: 2013-09-25 23:38:57
Summary: Merged in MatthewTurk/yt-3.0 (pull request #102)
Refactoring AMR Grid Patch code and removing dead data objects
Affected #: 5 files
diff -r 2176d83193f2471755399d84ad03894f3ac2da1c -r 3c52df9a894a07495e562c37e9becf280fe6225e yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -70,7 +70,7 @@
"""
if self.start_index is not None:
return self.start_index
- if self.Parent == None:
+ if self.Parent is None:
left = self.LeftEdge - self.pf.domain_left_edge
start_index = left / self.dds
return np.rint(start_index).astype('int64').ravel()
@@ -131,51 +131,6 @@
if self.pf.dimensionality < 2: self.dds[1] = self.pf.domain_right_edge[1] - self.pf.domain_left_edge[1]
if self.pf.dimensionality < 3: self.dds[2] = self.pf.domain_right_edge[2] - self.pf.domain_left_edge[2]
- @property
- def _corners(self):
- return np.array([ # Unroll!
- [self.LeftEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.LeftEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.RightEdge[1], self.LeftEdge[2]],
- [self.RightEdge[0], self.RightEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.RightEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.LeftEdge[1], self.RightEdge[2]],
- [self.RightEdge[0], self.LeftEdge[1], self.RightEdge[2]],
- [self.LeftEdge[0], self.RightEdge[1], self.LeftEdge[2]],
- ], dtype='float64')
-
- def _generate_overlap_masks(self, axis, LE, RE):
- """
- Generate a mask that shows which cells overlap with arbitrary arrays
- *LE* and *RE*) of edges, typically grids, along *axis*.
- Use algorithm described at http://www.gamedev.net/reference/articles/article735.asp
-
- """
- x = x_dict[axis]
- y = y_dict[axis]
- cond = self.RightEdge[x] >= LE[:,x]
- cond = np.logical_and(cond, self.LeftEdge[x] <= RE[:,x])
- cond = np.logical_and(cond, self.RightEdge[y] >= LE[:,y])
- cond = np.logical_and(cond, self.LeftEdge[y] <= RE[:,y])
- return cond
-
- def is_in_grid(self, x, y, z) :
- """
- Generate a mask that shows which points in *x*, *y*, and *z*
- fall within this grid's boundaries.
- """
- xcond = np.logical_and(x >= self.LeftEdge[0],
- x < self.RightEdge[0])
- ycond = np.logical_and(y >= self.LeftEdge[1],
- y < self.RightEdge[1])
- zcond = np.logical_and(z >= self.LeftEdge[2],
- z < self.RightEdge[2])
-
- cond = np.logical_and(xcond, ycond)
- cond = np.logical_and(zcond, cond)
-
- return cond
-
def __repr__(self):
return "AMRGridPatch_%04i" % (self.id)
@@ -189,13 +144,8 @@
"""
super(AMRGridPatch, self).clear_data()
- self._del_child_mask()
- self._del_child_indices()
self._setup_dx()
- def check_child_masks(self):
- return self._child_mask, self._child_indices
-
def _prepare_grid(self):
""" Copies all the appropriate attributes from the hierarchy. """
# This is definitely the slowest part of generating the hierarchy
@@ -211,89 +161,12 @@
#self.Time = h.gridTimes[my_ind,0]
self.NumberOfParticles = h.grid_particle_count[my_ind, 0]
- def find_max(self, field):
- """ Returns value, index of maximum value of *field* in this grid. """
- coord1d = (self[field] * self.child_mask).argmax()
- coord = np.unravel_index(coord1d, self[field].shape)
- val = self[field][coord]
- return val, coord
-
- def find_min(self, field):
- """ Returns value, index of minimum value of *field* in this grid. """
- coord1d = (self[field] * self.child_mask).argmin()
- coord = np.unravel_index(coord1d, self[field].shape)
- val = self[field][coord]
- return val, coord
-
def get_position(self, index):
""" Returns center position of an *index*. """
pos = (index + 0.5) * self.dds + self.LeftEdge
return pos
- def clear_all(self):
- """
- Clears all datafields from memory and calls
- :meth:`clear_derived_quantities`.
-
- """
- for key in self.keys():
- del self.field_data[key]
- del self.field_data
- if hasattr(self,"retVal"):
- del self.retVal
- self.field_data = YTFieldData()
- self.clear_derived_quantities()
- del self.child_mask
- del self.child_ind
-
- def _set_child_mask(self, newCM):
- if self._child_mask != None:
- mylog.warning("Overriding child_mask attribute! This is probably unwise!")
- self._child_mask = newCM
-
- def _set_child_indices(self, newCI):
- if self._child_indices != None:
- mylog.warning("Overriding child_indices attribute! This is probably unwise!")
- self._child_indices = newCI
-
- def _get_child_mask(self):
- if self._child_mask == None:
- self.__generate_child_mask()
- return self._child_mask
-
- def _get_child_indices(self):
- if self._child_indices == None:
- self.__generate_child_mask()
- return self._child_indices
-
- def _del_child_indices(self):
- try:
- del self._child_indices
- except AttributeError:
- pass
- self._child_indices = None
-
- def _del_child_mask(self):
- try:
- del self._child_mask
- except AttributeError:
- pass
- self._child_mask = None
-
- def _get_child_index_mask(self):
- if self._child_index_mask is None:
- self.__generate_child_index_mask()
- return self._child_index_mask
-
- def _del_child_index_mask(self):
- try:
- del self._child_index_mask
- except AttributeError:
- pass
- self._child_index_mask = None
-
- #@time_execution
- def __fill_child_mask(self, child, mask, tofill, dlevel = 1):
+ def _fill_child_mask(self, child, mask, tofill, dlevel = 1):
rf = self.pf.refine_by
if dlevel != 1:
rf = rf**dlevel
@@ -306,61 +179,37 @@
startIndex[1]:endIndex[1],
startIndex[2]:endIndex[2]] = tofill
- def __generate_child_mask(self):
+ @property
+ def child_mask(self):
"""
Generates self.child_mask, which is zero where child grids exist (and
thus, where higher resolution data is available).
"""
- self._child_mask = np.ones(self.ActiveDimensions, 'bool')
+ child_mask = np.ones(self.ActiveDimensions, 'bool')
for child in self.Children:
- self.__fill_child_mask(child, self._child_mask, 0)
- if self.OverlappingSiblings is not None:
- for sibling in self.OverlappingSiblings:
- self.__fill_child_mask(sibling, self._child_mask, 0)
-
- self._child_indices = (self._child_mask==0) # bool, possibly redundant
+ self._fill_child_mask(child, child_mask, 0)
+ for sibling in self.OverlappingSiblings or []:
+ self._fill_child_mask(sibling, child_mask, 0)
+ return child_mask
- def __generate_child_index_mask(self):
+ @property
+ def child_indices(self):
+ return (self.child_mask == 0)
+
+ @property
+ def child_index_mask(self):
"""
Generates self.child_index_mask, which is -1 where there is no child,
and otherwise has the ID of the grid that resides there.
"""
- self._child_index_mask = np.zeros(self.ActiveDimensions, 'int32') - 1
+ child_index_mask = np.zeros(self.ActiveDimensions, 'int32') - 1
for child in self.Children:
- self.__fill_child_mask(child, self._child_index_mask,
- child.id)
- if self.OverlappingSiblings is not None:
- for sibling in self.OverlappingSiblings:
- self.__fill_child_mask(sibling, self._child_index_mask,
- sibling.id)
-
- def _get_coords(self):
- if self.__coords == None: self._generate_coords()
- return self.__coords
-
- def _set_coords(self, new_c):
- if self.__coords != None:
- mylog.warning("Overriding coords attribute! This is probably unwise!")
- self.__coords = new_c
-
- def _del_coords(self):
- del self.__coords
- self.__coords = None
-
- def _generate_coords(self):
- """
- Creates self.coords, which is of dimensions (3, ActiveDimensions)
-
- """
- ind = np.indices(self.ActiveDimensions)
- left_shaped = np.reshape(self.LeftEdge, (3, 1, 1, 1))
- self['x'], self['y'], self['z'] = (ind + 0.5) * self.dds + left_shaped
-
- child_mask = property(fget=_get_child_mask, fdel=_del_child_mask)
- child_index_mask = property(fget=_get_child_index_mask, fdel=_del_child_index_mask)
- child_indices = property(fget=_get_child_indices, fdel = _del_child_indices)
+ self._fill_child_mask(child, child_index_mask, child.id)
+ for sibling in self.OverlappingSiblings or []:
+ self._fill_child_mask(sibling, child_index_mask, sibling.id)
+ return child_index_mask
def retrieve_ghost_zones(self, n_zones, fields, all_levels=False,
smoothed=False):
diff -r 2176d83193f2471755399d84ad03894f3ac2da1c -r 3c52df9a894a07495e562c37e9becf280fe6225e yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -141,50 +141,6 @@
else:
raise KeyError(field)
- def _get_data_from_grid(self, grid, field):
- if self.pf.geometry == "cylindrical":
- if grid.id in self._masks:
- mask = self._masks[grid.id]
- else:
- mask = self._get_cut_mask(grid)
- ts, dts = self._ts[grid.id], self._dts[grid.id]
- else:
- mask = np.logical_and(self._get_cut_mask(grid), grid.child_mask)
- ts, dts = self._ts[grid.id][mask], self._dts[grid.id][mask]
-
- if field == 'dts':
- return dts
- if field == 't':
- return ts
-
- gf = grid[field]
- if not iterable(gf):
- gf = gf * np.ones(grid.child_mask.shape)
- return gf[mask]
-
- def _get_cut_mask(self, grid):
- if self.pf.geometry == "cylindrical":
- _ = clyindrical_ray_trace(self.start_point, self.end_point,
- grid.LeftEdge, grid.RightEdge)
- ts, s, rzt, mask = _
- dts = np.empty(ts.shape, dtype='float64')
- dts[0], dts[1:] = 0.0, ts[1:] - ts[:-1]
- grid['r'], grid['z'], grid['theta'] = rzt[:,0], rzt[:,1], rzt[:,2]
- grid['s'] = s
- else:
- mask = np.zeros(grid.ActiveDimensions, dtype='int')
- dts = np.zeros(grid.ActiveDimensions, dtype='float64')
- ts = np.zeros(grid.ActiveDimensions, dtype='float64')
- VoxelTraversal(mask, ts, dts, grid.LeftEdge, grid.RightEdge,
- grid.dds, self.center, self.vec)
- dts = np.abs(dts)
- ts = np.abs(ts)
- self._dts[grid.id] = dts
- self._ts[grid.id] = ts
- self._masks[grid.id] = mask
- return mask
-
-
class YTSliceBase(YTSelectionContainer2D):
"""
This is a data object corresponding to a slice through the simulation
@@ -249,10 +205,6 @@
else:
raise KeyError(field)
- def _gen_node_name(self):
- return "%s/%s_%s" % \
- (self._top_node, self.axis, self.coord)
-
@property
def _mrep(self):
return MinimalSliceData(self)
@@ -520,156 +472,6 @@
frb = ObliqueFixedResolutionBuffer(self, bounds, resolution)
return frb
-class YTFixedResCuttingPlaneBase(YTSelectionContainer2D):
- """
- The fixed resolution Cutting Plane slices at an oblique angle,
- where we use the *normal* vector at the *center* to define the
- viewing plane. The plane is *width* units wide. The 'up'
- direction is guessed at automatically if not given.
- """
- _top_node = "/FixedResCuttingPlanes"
- _type_name = "fixed_res_cutting"
- _con_args = ('normal', 'center', 'width', 'dims')
- def __init__(self, normal, center, width, dims, pf = None,
- node_name = None, field_parameters = None):
- #
- # Taken from Cutting Plane
- #
- YTSelectionContainer2D.__init__(self, 4, pf, field_parameters)
- self._set_center(center)
- self.width = width
- self.dims = dims
- self.dds = self.width / self.dims
- self.bounds = np.array([0.0,1.0,0.0,1.0])
-
- self.set_field_parameter('center', center)
- # Let's set up our plane equation
- # ax + by + cz + d = 0
- self._norm_vec = normal/np.sqrt(np.dot(normal,normal))
- self._d = -1.0 * np.dot(self._norm_vec, self.center)
- # First we try all three, see which has the best result:
- vecs = np.identity(3)
- _t = np.cross(self._norm_vec, vecs).sum(axis=1)
- ax = _t.argmax()
- self._x_vec = np.cross(vecs[ax,:], self._norm_vec).ravel()
- self._x_vec /= np.sqrt(np.dot(self._x_vec, self._x_vec))
- self._y_vec = np.cross(self._norm_vec, self._x_vec).ravel()
- self._y_vec /= np.sqrt(np.dot(self._y_vec, self._y_vec))
- self._rot_mat = np.array([self._x_vec,self._y_vec,self._norm_vec])
- self._inv_mat = np.linalg.pinv(self._rot_mat)
- self.set_field_parameter('cp_x_vec',self._x_vec)
- self.set_field_parameter('cp_y_vec',self._y_vec)
- self.set_field_parameter('cp_z_vec',self._norm_vec)
-
- # Calculate coordinates of each pixel
- _co = self.dds * \
- (np.mgrid[-self.dims/2 : self.dims/2,
- -self.dims/2 : self.dims/2] + 0.5)
- self._coord = self.center + np.outer(_co[0,:,:], self._x_vec) + \
- np.outer(_co[1,:,:], self._y_vec)
- self._pixelmask = np.ones(self.dims*self.dims, dtype='int8')
-
- if node_name is not False:
- if node_name is True: self._deserialize()
- else: self._deserialize(node_name)
-
- @property
- def normal(self):
- return self._norm_vec
-
- def _get_list_of_grids(self):
- # Just like the Cutting Plane but restrict the grids to be
- # within width/2 of the center.
- vertices = self.hierarchy.gridCorners
- # Shape = (8,3,n_grid)
- D = np.sum(self._norm_vec.reshape((1,3,1)) * vertices, axis=1) + self._d
- valid_grids = np.where(np.logical_not(np.all(D<0,axis=0) |
- np.all(D>0,axis=0) ))[0]
- # Now restrict these grids to a rect. prism that bounds the slice
- sliceCorners = np.array([ \
- self.center + 0.5*self.width * (+self._x_vec + self._y_vec),
- self.center + 0.5*self.width * (+self._x_vec - self._y_vec),
- self.center + 0.5*self.width * (-self._x_vec - self._y_vec),
- self.center + 0.5*self.width * (-self._x_vec + self._y_vec) ])
- sliceLeftEdge = sliceCorners.min(axis=0)
- sliceRightEdge = sliceCorners.max(axis=0)
- # Check for bounding box and grid overlap
- leftOverlap = np.less(self.hierarchy.gridLeftEdge[valid_grids],
- sliceRightEdge).all(axis=1)
- rightOverlap = np.greater(self.hierarchy.gridRightEdge[valid_grids],
- sliceLeftEdge).all(axis=1)
- self._grids = self.hierarchy.grids[valid_grids[
- np.where(leftOverlap & rightOverlap)]]
- self._grids = self._grids[::-1]
-
- def _generate_coords(self):
- self['px'] = self._coord[:,0].ravel()
- self['py'] = self._coord[:,1].ravel()
- self['pz'] = self._coord[:,2].ravel()
- self['pdx'] = self.dds * 0.5
- self['pdy'] = self.dds * 0.5
- #self['pdz'] = self.dds * 0.5
-
- def _get_data_from_grid(self, grid, field):
- if not self.pf.field_info[field].particle_type:
- pointI = self._get_point_indices(grid)
- if len(pointI) == 0: return
- vc = self._calc_vertex_centered_data(grid, field)
- bds = np.array(zip(grid.LeftEdge,
- grid.RightEdge)).ravel()
- interp = TrilinearFieldInterpolator(vc, bds, ['x', 'y', 'z'])
- self[field][pointI] = interp( \
- dict(x=self._coord[pointI,0],
- y=self._coord[pointI,1],
- z=self._coord[pointI,2])).ravel()
-
- # Mark these pixels to speed things up
- self._pixelmask[pointI] = 0
-
- return
- else:
- raise SyntaxError("Making a fixed resolution slice with "
- "particles isn't supported yet.")
-
- def get_data(self, fields):
- """
- Iterates over the list of fields and generates/reads them all.
- """
- self._get_list_of_grids()
- if not self.has_key('pdx'):
- self._generate_coords()
- fields_to_get = ensure_list(fields)
- temp_data = {}
- _size = self.dims * self.dims
- for field in fields_to_get:
- if self.field_data.has_key(field): continue
- if field not in self.hierarchy.field_list:
- if self._generate_field(field):
- continue # A "True" return means we did it
- self[field] = np.zeros(_size, dtype='float64')
- for grid in self._get_grids():
- self._get_data_from_grid(grid, field)
- self[field] = self.comm.mpi_allreduce(\
- self[field], op='sum').reshape([self.dims]*2).transpose()
-
- def _calc_vertex_centered_data(self, grid, field):
- #return grid.retrieve_ghost_zones(1, field, smoothed=False)
- return grid.get_vertex_centered_data(field)
-
- def _get_point_indices(self, grid):
- if self._pixelmask.max() == 0: return []
- k = planar_points_in_volume(self._coord, self._pixelmask,
- grid.LeftEdge, grid.RightEdge,
- grid.child_mask, just_one(grid['dx']))
- return k
-
- def _gen_node_name(self):
- cen_name = ("%s" % (self.center,)).replace(" ","_")[1:-1]
- L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1]
- return "%s/c%s_L%s" % \
- (self._top_node, cen_name, L_name)
-
-
class YTDiskBase(YTSelectionContainer3D):
"""
By providing a *center*, a *normal*, a *radius* and a *height* we
@@ -687,113 +489,6 @@
self._radius = fix_length(radius, self.pf)
self._d = -1.0 * np.dot(self._norm_vec, self.center)
- def _get_list_of_grids(self):
- H = np.sum(self._norm_vec.reshape((1,3,1)) * self.pf.h.grid_corners,
- axis=1) + self._d
- D = np.sqrt(np.sum((self.pf.h.grid_corners -
- self.center.reshape((1,3,1)))**2.0,axis=1))
- R = np.sqrt(D**2.0-H**2.0)
- self._grids = self.hierarchy.grids[
- ( (np.any(np.abs(H)<self._height,axis=0))
- & (np.any(R<self._radius,axis=0)
- & (np.logical_not((np.all(H>0,axis=0) | (np.all(H<0, axis=0)))) )
- ) ) ]
- self._grids = self.hierarchy.grids
-
- def _is_fully_enclosed(self, grid):
- corners = grid._corners.reshape((8,3,1))
- H = np.sum(self._norm_vec.reshape((1,3,1)) * corners,
- axis=1) + self._d
- D = np.sqrt(np.sum((corners -
- self.center.reshape((1,3,1)))**2.0,axis=1))
- R = np.sqrt(D**2.0-H**2.0)
- return (np.all(np.abs(H) < self._height, axis=0) \
- and np.all(R < self._radius, axis=0))
-
- def _get_cut_mask(self, grid):
- if self._is_fully_enclosed(grid):
- return True
- else:
- h = grid['x'] * self._norm_vec[0] \
- + grid['y'] * self._norm_vec[1] \
- + grid['z'] * self._norm_vec[2] \
- + self._d
- d = np.sqrt(
- (grid['x'] - self.center[0])**2.0
- + (grid['y'] - self.center[1])**2.0
- + (grid['z'] - self.center[2])**2.0
- )
- r = np.sqrt(d**2.0-h**2.0)
- cm = ( (np.abs(h) <= self._height)
- & (r <= self._radius))
- return cm
-
-
-class YTInclinedBoxBase(YTSelectionContainer3D):
- """
- A rectangular prism with arbitrary alignment to the computational
- domain. *origin* is the origin of the box, while *box_vectors* is an
- array of ordering [ax, ijk] that describes the three vectors that
- describe the box. No checks are done to ensure that the box satisfies
- a right-hand rule, but if it doesn't, behavior is undefined.
- """
- _type_name="inclined_box"
- _con_args = ('origin','box_vectors')
-
- def __init__(self, origin, box_vectors, fields=None,
- pf=None, **kwargs):
- self.origin = np.array(origin)
- self.box_vectors = np.array(box_vectors, dtype='float64')
- self.box_lengths = (self.box_vectors**2.0).sum(axis=1)**0.5
- center = origin + 0.5*self.box_vectors.sum(axis=0)
- YTSelectionContainer3D.__init__(self, center, fields, pf, **kwargs)
- self._setup_rotation_parameters()
-
- def _setup_rotation_parameters(self):
- xv = self.box_vectors[0,:]
- yv = self.box_vectors[1,:]
- zv = self.box_vectors[2,:]
- self._x_vec = xv / np.sqrt(np.dot(xv, xv))
- self._y_vec = yv / np.sqrt(np.dot(yv, yv))
- self._z_vec = zv / np.sqrt(np.dot(zv, zv))
- self._rot_mat = np.array([self._x_vec,self._y_vec,self._z_vec])
- self._inv_mat = np.linalg.pinv(self._rot_mat)
-
- def _get_list_of_grids(self):
- if self._grids is not None: return
- GLE = self.pf.h.grid_left_edge
- GRE = self.pf.h.grid_right_edge
- goodI = find_grids_in_inclined_box(self.box_vectors, self.center,
- GLE, GRE)
- cgrids = self.pf.h.grids[goodI.astype('bool')]
- # find_grids_in_inclined_box seems to be broken.
- cgrids = self.pf.h.grids[:]
- grids = []
- for i,grid in enumerate(cgrids):
- v = grid_points_in_volume(self.box_lengths, self.origin,
- self._rot_mat, grid.LeftEdge,
- grid.RightEdge, grid.dds,
- grid.child_mask, 1)
- if v: grids.append(grid)
- self._grids = np.empty(len(grids), dtype='object')
- for gi, g in enumerate(grids): self._grids[gi] = g
-
-
- def _is_fully_enclosed(self, grid):
- # This should be written at some point.
- # We'd rotate all eight corners into the space of the box, then check to
- # see if all are enclosed.
- return False
-
- def _get_cut_mask(self, grid):
- if self._is_fully_enclosed(grid):
- return True
- pm = np.zeros(grid.ActiveDimensions, dtype='int32')
- grid_points_in_volume(self.box_lengths, self.origin,
- self._rot_mat, grid.LeftEdge,
- grid.RightEdge, grid.dds, pm, 0)
- return pm
-
class YTRegionBase(YTSelectionContainer3D):
"""A 3D region of data with an arbitrary center.
diff -r 2176d83193f2471755399d84ad03894f3ac2da1c -r 3c52df9a894a07495e562c37e9becf280fe6225e yt/utilities/lib/tests/test_grid_tree.py
--- a/yt/utilities/lib/tests/test_grid_tree.py
+++ b/yt/utilities/lib/tests/test_grid_tree.py
@@ -88,15 +88,16 @@
for ind, ixx, iyy, izz in zip(range(num_points), randx, randy, randz):
+ pos = np.array([ixx, iyy, izz])
pt_level = -1
for grid in test_pf.h.grids:
- if grid.is_in_grid(ixx, iyy, izz):
-
- if grid.Level > pt_level:
- pt_level = grid.Level
- grid_inds[ind] = grid.id - grid._id_offset
+ if np.all(pos >= grid.LeftEdge) and \
+ np.all(pos <= grid.RightEdge) and \
+ grid.Level > pt_level:
+ pt_level = grid.Level
+ grid_inds[ind] = grid.id - grid._id_offset
yield assert_equal, point_grid_inds, grid_inds
diff -r 2176d83193f2471755399d84ad03894f3ac2da1c -r 3c52df9a894a07495e562c37e9becf280fe6225e yt/visualization/plot_collection.py
--- a/yt/visualization/plot_collection.py
+++ b/yt/visualization/plot_collection.py
@@ -589,99 +589,6 @@
p["Axis"] = "CuttingPlane"
return p
- def add_fixed_res_cutting_plane(self, field, normal, width, res=512,
- center=None, use_colorbar=True, figure = None, axes = None,
- fig_size=None, obj=None, field_parameters = None):
- r"""Create a fixed resolution cutting plane, from that a plot, and add
- it to the current collection.
-
- A cutting plane is an oblique slice through the simulation volume,
- oriented by a specified normal vector that is perpendicular to the
- image plane. This function will slice through, but instead of
- retaining all the data necessary to rescale the cutting plane at any
- width, it only retains the pixels for a single width. This function
- will generate a `yt.data_objects.api.YTFixedResCuttingPlaneBase` from the given
- parameters. This image buffer then gets passed to a
- `yt.visualization.plot_types.FixedResolutionPlot`, and the resultant plot is added to the
- current collection. Various parameters allow control of the way the
- slice is displayed, as well as how the plane is generated.
-
- Parameters
- ----------
- field : string
- The initial field to slice and display.
- normal : array_like
- The vector that defines the desired plane. For instance, the
- angular momentum of a sphere.
- width : float
- The width, in code units, of the image plane.
- res : int
- The returned image buffer must be square; this number is how many
- pixels on a side it will have.
- center : array_like, optional
- The center to be used for things like radius and radial velocity.
- Defaults to the center of the plot collection.
- use_colorbar : bool, optional
- Whether we should leave room for and create a colorbar.
- figure : `matplotlib.figure.Figure`, optional
- The figure onto which the axes will be placed. Typically not used
- unless *axes* is also specified.
- axes : `matplotlib.axes.Axes`, optional
- The axes object which will be used to create the image plot.
- Typically used for things like multiplots and the like.
- fig_size : tuple of floats
- This parameter can act as a proxy for the manual creation of a
- figure. By specifying it, you can create plots with an arbitrarily
- large or small size. It is in inches, defaulting to 100 dpi.
- obj : `YTCuttingPlaneBase`, optional
- If you would like to use an existing cutting plane, you may specify
- it here, in which case a new cutting plane will not be created.
- field_parameters : dict, optional
- This set of parameters will be passed to the cutting plane upon
- creation, which can be used for passing variables to derived
- fields.
-
- Returns
- -------
- plot : `yt.visualization.plot_types.FixedResolutionPlot`
- The plot that has been added to the PlotCollection.
-
- See Also
- --------
- yt.data_objects.api.YTFixedResCuttingPlaneBase : This is the type created by this
- function.
-
- Examples
- --------
-
- Here's a simple mechanism for getting the angular momentum of a
- collapsing cloud and generating a cutting plane aligned with the
- angular momentum vector.
-
- >>> pf = load("RD0005-mine/RedshiftOutput0005")
- >>> v, c = pf.h.find_max("Density")
- >>> sp = pf.h.sphere(c, 1000.0/pf['au'])
- >>> L = sp.quantities["AngularMomentumVector"]()
- >>> pc = PlotCollection(pf)
- >>> p = pc.add_fixed_res_cutting_plane("Density", L, 1000.0/pf['au'])
- """
- if center == None:
- center = self.c
- if not obj:
- if field_parameters is None: field_parameters = {}
- data = self.pf.hierarchy.fixed_res_cutting \
- (normal, center, width, res, **field_parameters)
- #data = frc[field]
- else:
- data = obj
- p = self._add_plot(FixedResolutionPlot(data, field,
- use_colorbar=use_colorbar, axes=axes, figure=figure,
- size=fig_size))
- mylog.info("Added fixed-res plane of %s with 'center' = %s and "
- "normal = %s", field, list(center), list(normal))
- p["Axis"] = "CuttingPlane"
- return p
-
def add_projection(self, field, axis, weight_field=None,
data_source = None,
center=None, use_colorbar=True,
diff -r 2176d83193f2471755399d84ad03894f3ac2da1c -r 3c52df9a894a07495e562c37e9becf280fe6225e yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -2043,29 +2043,17 @@
positions += inner_radius * dx * vs
vs *= radius
uv = np.ones(3, dtype='float64')
- if data_source is not None:
- grids = data_source._grids
- else:
- grids = pf.h.sphere(center, radius)._grids
+ if data_source is None:
+ data_source = pf.h.sphere(center, radius)
sampler = ProjectionSampler(positions, vs, center, (0.0, 0.0, 0.0, 0.0),
image, uv, uv, np.zeros(3, dtype='float64'))
- pb = get_pbar("Sampling ", len(grids))
- for i,grid in enumerate(grids):
- if data_source is not None:
- data = [grid[field] * data_source._get_cut_mask(grid) * \
- grid.child_mask.astype('float64')
- for field in fields]
- else:
- data = [grid[field] * grid.child_mask.astype('float64')
- for field in fields]
+ for i, (grid, mask) in enumerate(data_source.blocks):
+ data = [(grid[field] * mask).astype("float64") for field in fields]
pg = PartitionedGrid(
grid.id, data,
grid.LeftEdge, grid.RightEdge,
grid.ActiveDimensions.astype("int64"))
- grid.clear_data()
sampler(pg)
- pb.update(i)
- pb.finish()
image = sampler.aimage
dd = self.pf.h.all_data()
field = dd._determine_fields([field])[0]
Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/
--
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