How to use the pyvista.RectilinearGrid function in pyvista

To help you get started, we’ve selected a few pyvista examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyvista / pyvista / tests / test_filters.py View on Github external
def test_clip_surface():
    surface = pyvista.Cone(direction=(0,0,-1),
                  height=3.0, radius=1, resolution=50, )
    xx = yy = zz = 1 - np.linspace(0, 51, 51) * 2 / 50
    dataset = pyvista.RectilinearGrid(xx, yy, zz)
    clipped = dataset.clip_surface(surface, invert=False)
    assert clipped.n_points < dataset.n_points
    clipped = dataset.clip_surface(surface, invert=False, compute_distance=True)
    assert clipped.n_points < dataset.n_points
    assert 'implicit_distance' in clipped.array_names
github pyvista / pyvista / tests / test_composite.py View on Github external
"""This puts all of the example data objects into a a MultiBlock container"""
    multi = pyvista.MultiBlock()
    # Add examples
    multi.append(ex.load_ant())
    multi.append(ex.load_sphere())
    multi.append(ex.load_uniform())
    multi.append(ex.load_airplane())
    multi.append(ex.load_rectilinear())
    # Now check everything
    assert multi.n_blocks == 5
    assert multi.bounds is not None
    assert isinstance(multi[0], pyvista.PolyData)
    assert isinstance(multi[1], pyvista.PolyData)
    assert isinstance(multi[2], pyvista.UniformGrid)
    assert isinstance(multi[3], pyvista.PolyData)
    assert isinstance(multi[4], pyvista.RectilinearGrid)
    # Now overwrite a block
    multi[4] = pyvista.Sphere()
    assert isinstance(multi[4], pyvista.PolyData)
    multi[4] = vtk.vtkUnstructuredGrid()
    assert isinstance(multi[4], pyvista.UnstructuredGrid)
github pyvista / pyvista / tests / test_grid.py View on Github external
def test_create_rectilinear_grid_from_specs():
    # 3D example
    xrng = np.arange(-10, 10, 2)
    yrng = np.arange(-10, 10, 5)
    zrng = np.arange(-10, 10, 1)
    grid = pyvista.RectilinearGrid(xrng, yrng, zrng)
    assert grid.n_cells == 9*3*19
    assert grid.n_points == 10*4*20
    assert grid.bounds == [-10.0,8.0, -10.0,5.0, -10.0,9.0]
    # 2D example
    cell_spacings = np.array([1., 1., 2., 2., 5., 10.])
    x_coordinates = np.cumsum(cell_spacings)
    y_coordinates = np.cumsum(cell_spacings)
    grid = pyvista.RectilinearGrid(x_coordinates, y_coordinates)
    assert grid.n_cells == 5*5
    assert grid.n_points == 6*6
    assert grid.bounds == [1.,21., 1.,21., 0.,0.]
github GeoStat-Framework / GSTools / gstools / tools / export.py View on Github external
fields : :class:`dict` or :class:`numpy.ndarray`
        Structured fields to be saved.
        Either a single numpy array as returned by SRF,
        or a dictionary of fields with theirs names as keys.

    Returns
    -------
    :class:`pyvista.RectilinearGrid`
        A PyVista rectilinear grid of the structured field data. Data arrays
        live on the point data of this PyVista dataset.
    """
    x, y, z, fields = _vtk_structured_helper(pos=pos, fields=fields)
    try:
        import pyvista as pv

        grid = pv.RectilinearGrid(x, y, z)
        grid.point_arrays.update(fields)
    except ImportError:
        raise ImportError("Please install PyVista to create VTK datasets.")
    return grid
github pyvista / pyvista / pyvista / core / grid.py View on Github external
def cast_to_rectilinear_grid(self):
        """Cast this uniform grid to a :class:`pyvista.RectilinearGrid`"""
        def gen_coords(i):
            coords = np.cumsum(np.insert(np.full(self.dimensions[i] - 1,
                                                 self.spacing[i]), 0, 0)
                               ) + self.origin[i]
            return coords
        xcoords = gen_coords(0)
        ycoords = gen_coords(1)
        zcoords = gen_coords(2)
        grid = pyvista.RectilinearGrid(xcoords, ycoords, zcoords)
        grid.point_arrays.update(self.point_arrays)
        grid.cell_arrays.update(self.cell_arrays)
        grid.field_arrays.update(self.field_arrays)
        grid.copy_meta_from(self)
        return grid
github pyvista / pyvista / pyvista / examples / examples.py View on Github external
def load_rectilinear():
    """ Loads a sample uniform grid """
    return pyvista.RectilinearGrid(rectfile)
github pyvista / pyvista / examples / 01-filter / clipping.py View on Github external
p.show()


###############################################################################
# Clip with Surface
# +++++++++++++++++
#
# Clip any PyVista dataset by a :class:`pyvista.PolyData` surface mesh using
# the :func:`pyvista.DataSet.Filters.clip_surface` filter.
surface = pv.Cone(direction=(0,0,-1), height=3.0, radius=1,
                  resolution=50, capping=False)

# Make a gridded dataset
n = 51
xx = yy = zz = 1 - np.linspace(0, n, n) * 2 / (n-1)
dataset = pv.RectilinearGrid(xx, yy, zz)

# Preview the problem
p = pv.Plotter()
p.add_mesh(surface, color='w', label='Surface')
p.add_mesh(dataset, color='gold', show_edges=True,
           opacity=0.75, label='To Clip')
p.add_legend()
p.show()

###############################################################################
# Clip the rectilinear grid dataset using the :class:`pyvista.PolyData`
# surface mesh:
clipped = dataset.clip_surface(surface, invert=False)

# Visualize the results
p = pv.Plotter()
github GeoStat-Framework / GSTools / gstools / field / mesh.py View on Github external
fields : :class:`dict` or :class:`numpy.ndarray`
            Structured fields to be saved.
            Either a single numpy array as returned by SRF,
            or a dictionary of fields with theirs names as keys.

        Returns
        -------
        :class:`pyvista.RectilinearGrid`
            A PyVista rectilinear grid of the structured field data. Data arrays
            live on the point data of this PyVista dataset.
        """
        x, y, z, fields = self._vtk_structured_reshape(fields=fields)
        try:
            import pyvista as pv

            grid = pv.RectilinearGrid(x, y, z)
            grid.point_arrays.update(fields)
        except ImportError:
            raise ImportError("Please install PyVista to create VTK datasets.")
        return grid