当前位置: 首页>>代码示例>>Python>>正文


Python pyvista.StructuredGrid方法代码示例

本文整理汇总了Python中pyvista.StructuredGrid方法的典型用法代码示例。如果您正苦于以下问题:Python pyvista.StructuredGrid方法的具体用法?Python pyvista.StructuredGrid怎么用?Python pyvista.StructuredGrid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyvista的用法示例。


在下文中一共展示了pyvista.StructuredGrid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grid_from_sph_coords

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def grid_from_sph_coords(theta, phi, r):
    """Create a structured grid from arrays of spherical coordinates.

    Parameters
    ----------
    theta: array-like
        Azimuthal angle in degrees [0, 360)
    phi: array-like
        Polar (zenith) angle in degrees [0, 180]
    r: array-like
        Distance (radius) from the point of origin

    Return
    ------
    pyvista.StructuredGrid

    """
    x, y, z = np.meshgrid(np.radians(theta), np.radians(phi), r)
    # Transform grid to cartesian coordinates
    x_cart = z * np.sin(y) * np.cos(x)
    y_cart = z * np.sin(y) * np.sin(x)
    z_cart = z * np.cos(y)
    # Make a grid object
    return pyvista.StructuredGrid(x_cart, y_cart, z_cart) 
开发者ID:pyvista,项目名称:pyvista,代码行数:26,代码来源:features.py

示例2: __curvilinear_mesh_to_vtk

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def __curvilinear_mesh_to_vtk(mesh, models=None):
        """
        Constructs a :class:`pyvista.StructuredGrid` of this mesh and the given
        models as ``cell_arrays`` of that object.

        Parameters
        ----------

        mesh : discretize.CurvilinearMesh
            The curvilinear mesh to convert to a :class:`pyvista.StructuredGrid`

        models : dict(numpy.ndarray)
            Name('s) and array('s). Match number of cells

        """
        ptsMat = InterfaceVTK.__get_rotated_nodes(mesh)
        dims = [mesh.nCx, mesh.nCy, mesh.nCz]
        return InterfaceVTK.__create_structured_grid(ptsMat, dims, models=models) 
开发者ID:simpeg,项目名称:discretize,代码行数:20,代码来源:vtkModule.py

示例3: test

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test(self):
        """`BuildSurfaceFromPoints`: make sure no errors arise"""
        x = np.arange(100)
        y = 0.01*x**2
        points = np.c_[x,y,np.zeros_like(x)]
        z_range = np.arange(20)
        mesh = BuildSurfaceFromPoints.create_surface(points, z_range)
        assert isinstance(mesh, pyvista.StructuredGrid)
        assert mesh.dimensions == [len(z_range), len(points), 1]
        poly = pyvista.PolyData(points)
        mesh = BuildSurfaceFromPoints(zcoords=z_range).apply(poly)
        assert isinstance(mesh, pyvista.StructuredGrid)
        assert mesh.dimensions == [len(z_range), len(points), 1]
        return True


###############################################################################
###############################################################################
############################################################################### 
开发者ID:OpenGeoVis,项目名称:PVGeo,代码行数:21,代码来源:filters_test.py

示例4: plot_scalar_surfaces_3D

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def plot_scalar_surfaces_3D(self, surfaces_nr: int = 10):
        """Plot scalar field as surfaces

        Args:
            surfaces_nr: Number of plotted scalar field isosurfaces

        Returns:

        """
        regular_grid = self.model._grid.regular_grid

        grid_values = regular_grid.values
        grid_3d = grid_values.reshape(*regular_grid.resolution, 3).T
        mesh = pv.StructuredGrid(*grid_3d)

        values = self.model.solutions.scalar_field_matrix.reshape(self.model._grid.regular_grid.resolution)
        mesh["vol"] = values.flatten()
        contours = mesh.contour(np.linspace(values.min(), values.max(), surfaces_nr + 2))
        self.p.add_mesh(contours, show_scalar_bar=True, label="scalar_field_main") 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:21,代码来源:_vista.py

示例5: make_cube

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def make_cube():
    x = np.linspace(-0.5, 0.5, 25)
    grid = pv.StructuredGrid(*np.meshgrid(x, x, x))
    return grid.extract_surface().triangulate()

# Create to examplee PolyData meshes for boolean operations 
开发者ID:pyvista,项目名称:pyvista,代码行数:8,代码来源:boolean-operations.py

示例6: test_project_points_to_plane

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test_project_points_to_plane():
    # Define a simple Gaussian surface
    n = 20
    x = np.linspace(-200,200, num=n) + np.random.uniform(-5, 5, size=n)
    y = np.linspace(-200,200, num=n) + np.random.uniform(-5, 5, size=n)
    xx, yy = np.meshgrid(x, y)
    A, b = 100, 100
    zz = A*np.exp(-0.5*((xx/b)**2. + (yy/b)**2.))
    poly = pyvista.StructuredGrid(xx, yy, zz).extract_geometry()
    poly['elev'] = zz.ravel(order='f')

    # Wrong normal length
    with pytest.raises(TypeError):
        poly.project_points_to_plane(normal=(0, 0, 1, 1))
    # allow Sequence but not Iterable
    with pytest.raises(TypeError):
        poly.project_points_to_plane(normal={0, 1, 2})

    # Test the filter
    projected = poly.project_points_to_plane(origin=poly.center, normal=(0,0,1))
    assert np.allclose(projected.points[:,-1], poly.center[-1])
    projected = poly.project_points_to_plane(normal=(0,1,1))
    assert projected.n_points

    # finally, test inplace
    poly.project_points_to_plane(normal=(0,1,1), inplace=True)
    assert np.allclose(poly.points, projected.points) 
开发者ID:pyvista,项目名称:pyvista,代码行数:29,代码来源:test_polydata.py

示例7: struct_grid

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def struct_grid():
    x, y, z = np.meshgrid(np.arange(-10, 10, 2),
                          np.arange(-10, 10, 2),
                          np.arange(-10, 10, 2))
    return pyvista.StructuredGrid(x, y, z) 
开发者ID:pyvista,项目名称:pyvista,代码行数:7,代码来源:conftest.py

示例8: test_init_structured

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test_init_structured(struct_grid):
    xrng = np.arange(-10, 10, 2)
    yrng = np.arange(-10, 10, 2)
    zrng = np.arange(-10, 10, 2)
    x, y, z = np.meshgrid(xrng, yrng, zrng)
    grid = pyvista.StructuredGrid(x, y, z)
    assert np.allclose(struct_grid.x, x)
    assert np.allclose(struct_grid.y, y)
    assert np.allclose(struct_grid.z, z)

    grid_a = pyvista.StructuredGrid(grid)
    assert np.allclose(grid_a.points, grid.points) 
开发者ID:pyvista,项目名称:pyvista,代码行数:14,代码来源:test_grid.py

示例9: test_invalid_init_structured

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test_invalid_init_structured():
    xrng = np.arange(-10, 10, 2)
    yrng = np.arange(-10, 10, 2)
    zrng = np.arange(-10, 10, 2)
    x, y, z = np.meshgrid(xrng, yrng, zrng)
    z = z[:, :, :2]
    with pytest.raises(ValueError):
        grid = pyvista.StructuredGrid(x, y, z) 
开发者ID:pyvista,项目名称:pyvista,代码行数:10,代码来源:test_grid.py

示例10: test_load_structured_bad_filename

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test_load_structured_bad_filename():
    with pytest.raises(FileNotFoundError):
        pyvista.StructuredGrid('not a file')

    filename = os.path.join(test_path, 'test_grid.py')
    with pytest.raises(ValueError):
        grid = pyvista.StructuredGrid(filename) 
开发者ID:pyvista,项目名称:pyvista,代码行数:9,代码来源:test_grid.py

示例11: test_cast_rectilinear_grid

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test_cast_rectilinear_grid():
    grid = pyvista.read(examples.rectfile)
    structured = grid.cast_to_structured_grid()
    assert isinstance(structured, pyvista.StructuredGrid)
    assert structured.n_points == grid.n_points
    assert structured.n_cells == grid.n_cells
    assert np.allclose(structured.points, grid.points)
    for k, v in grid.point_arrays.items():
        assert np.allclose(structured.point_arrays[k], v)
    for k, v in grid.cell_arrays.items():
        assert np.allclose(structured.cell_arrays[k], v) 
开发者ID:pyvista,项目名称:pyvista,代码行数:13,代码来源:test_grid.py

示例12: test_multi_block_init_vtk

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def test_multi_block_init_vtk():
    multi = vtk.vtkMultiBlockDataSet()
    multi.SetBlock(0, vtk.vtkRectilinearGrid())
    multi.SetBlock(1, vtk.vtkStructuredGrid())
    multi = MultiBlock(multi)
    assert isinstance(multi, MultiBlock)
    assert multi.n_blocks == 2
    assert isinstance(multi.GetBlock(0), RectilinearGrid)
    assert isinstance(multi.GetBlock(1), StructuredGrid)
    multi = vtk.vtkMultiBlockDataSet()
    multi.SetBlock(0, vtk.vtkRectilinearGrid())
    multi.SetBlock(1, vtk.vtkStructuredGrid())
    multi = MultiBlock(multi, deep=True)
    assert isinstance(multi, MultiBlock)
    assert multi.n_blocks == 2
    assert isinstance(multi.GetBlock(0), RectilinearGrid)
    assert isinstance(multi.GetBlock(1), StructuredGrid)
    # Test nested structure
    multi = vtk.vtkMultiBlockDataSet()
    multi.SetBlock(0, vtk.vtkRectilinearGrid())
    multi.SetBlock(1, vtk.vtkImageData())
    nested = vtk.vtkMultiBlockDataSet()
    nested.SetBlock(0, vtk.vtkUnstructuredGrid())
    nested.SetBlock(1, vtk.vtkStructuredGrid())
    multi.SetBlock(2, nested)
    # Wrap the nested structure
    multi = MultiBlock(multi)
    assert isinstance(multi, MultiBlock)
    assert multi.n_blocks == 3
    assert isinstance(multi.GetBlock(0), RectilinearGrid)
    assert isinstance(multi.GetBlock(1), UniformGrid)
    assert isinstance(multi.GetBlock(2), MultiBlock) 
开发者ID:pyvista,项目名称:pyvista,代码行数:34,代码来源:test_composite.py

示例13: load_structured

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def load_structured():
    """Load a simple StructuredGrid."""
    x = np.arange(-10, 10, 0.25)
    y = np.arange(-10, 10, 0.25)
    x, y = np.meshgrid(x, y)
    r = np.sqrt(x**2 + y**2)
    z = np.sin(r)
    return pyvista.StructuredGrid(x, y, z) 
开发者ID:pyvista,项目名称:pyvista,代码行数:10,代码来源:examples.py

示例14: hide_cells

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def hide_cells(self, ind):
        """Hide cells without deleting them.

        Hides cells by setting the ghost_cells array to HIDDEN_CELL.

        Parameters
        ----------
        ind : iterable
            List or array of cell indices to be hidden.  The array can
            also be a boolean array of the same size as the number of
            cells.

        Examples
        --------
        Hide part of the middle of a structured surface.

        >>> import pyvista as pv
        >>> import numpy as np
        >>> x = np.arange(-10, 10, 0.25)
        >>> y = np.arange(-10, 10, 0.25)
        >>> z = 0
        >>> x, y, z = np.meshgrid(x, y, z)
        >>> grid = pv.StructuredGrid(x, y, z)
        >>> grid.hide_cells(range(79*30, 79*50))
        """
        if isinstance(ind, np.ndarray):
            if ind.dtype == np.bool_ and ind.size != self.n_cells:
                raise ValueError('Boolean array size must match the '
                                 'number of cells (%d)' % self.n_cells)
        ghost_cells = np.zeros(self.n_cells, np.uint8)
        ghost_cells[ind] = vtk.vtkDataSetAttributes.HIDDENCELL

        # NOTE: cells cannot be removed from a structured grid, only
        # hidden setting ghost_cells to a value besides
        # vtk.vtkDataSetAttributes.HIDDENCELL will not hide them
        # properly, additionally, calling self.RemoveGhostCells will
        # have no effect

        self.cell_arrays[vtk.vtkDataSetAttributes.GhostArrayName()] = ghost_cells 
开发者ID:pyvista,项目名称:pyvista,代码行数:41,代码来源:pointset.py

示例15: cast_to_structured_grid

# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import StructuredGrid [as 别名]
def cast_to_structured_grid(self):
        """Cast this rectilinear grid to a :class:`pyvista.StructuredGrid`."""
        alg = vtk.vtkRectilinearGridToPointSet()
        alg.SetInputData(self)
        alg.Update()
        return _get_output(alg) 
开发者ID:pyvista,项目名称:pyvista,代码行数:8,代码来源:grid.py


注:本文中的pyvista.StructuredGrid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。