quickpaver.RectilinearGrid.to_pyvista#
- RectilinearGrid.to_pyvista(cell_data: dict[str, ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[int64]]] | None = None, representation: Literal['image', 'rectilinear', 'structured'] = 'image', apply_rotation: bool = True) object[source]#
Convert the grid to a PyVista dataset.
The preferred representation is
"image", which returns a compactpyvista.ImageDataobject. Since this grid has uniform cell spacing along each local axis,ImageDatais the most memory-efficient PyVista representation.If rotations are enabled and
representation="image", the grid orientation is stored using the PyVistadirection_matrixargument. This preserves a compact image-data representation while representing the rotated coordinate frame.- Parameters:
cell_data (Optional[dict[str, Union[NDArrayFloat, NDArrayInt]]], optional) –
Optional mapping of cell-data names to arrays. Each array must contain exactly
n_grid_cellsvalues, either as a flattened one-dimensional array or as an array with shape(nx, ny, nz). Arrays are flattened using Fortran order so that their order is consistent with the grid numbering convention:node_number = ix + iy * nx + iz * ny * nxIf
None, no cell data are attached. By defaultNone.representation (Literal["image", "rectilinear", "structured"], optional) –
PyVista representation to return:
"image"returns a compactpyvista.ImageData."rectilinear"returns apyvista.RectilinearGrid.
This is only valid for non-rotated grids. -
"structured"returns apyvista.StructuredGrid. This representation explicitly stores all grid points and supports rotations through PyVista geometry transforms.By default
"image".apply_rotation (bool, optional) – Whether to apply the grid Euler rotations. If
False, the returned PyVista grid is axis-aligned. By defaultTrue.
- Returns:
PyVista dataset. Depending on
representation, this is usually one of:pyvista.ImageDatapyvista.RectilinearGridpyvista.StructuredGrid
- Return type:
- Raises:
ImportError – If PyVista is not installed.
ValueError – If
representationis invalid.ValueError – If
representation="rectilinear"is requested for a rotated grid.ValueError – If a cell-data array does not contain exactly
n_grid_cellsvalues.RuntimeError – If rotated
ImageDatais requested with a PyVista version that does not supportdirection_matrix.
Notes
PyVista is imported locally so that it remains an optional dependency.
The PyVista grid is built from vertices, not cell centres. Therefore, the PyVista point dimensions are
(nx + 1, ny + 1, nz + 1)and the number of cells isnx * ny * nz.The rotation order is consistent with
_rotate_coords():R_x(psi) @ R_y(phi) @ R_z(theta)For
representation="structured", rotations are applied sequentially using PyVista as z, then y, then x rotations aroundself.rot_center.