當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。