StructuredGrid.extract_subset

StructuredGrid.extract_subset#

StructuredGrid.extract_subset(
voi: VectorLikeInt,
rate: VectorLikeInt = (1, 1, 1),
*,
boundary: bool = False,
) → StructuredGrid[source]#

Select piece (for example, volume of interest).

To use this filter set the VOI ivar which are i-j-k min/max indices that specify a rectangular region in the data. They are in the same index space as the extent, so they include the offset. You can also specify a sampling rate to subsample the data, which divides the extent of each sampled axis by its rate, as for pyvista.ImageDataFilters.extract_subset().

Typical applications of this filter are to extract a slice from a volume for image processing, subsampling large volumes to reduce data size, or extracting regions of a volume with interesting data.

Parameters:
voiVectorLikeInt

Length 6 iterable of ints: (x_min, x_max, y_min, y_max, z_min, z_max). These bounds specify the volume of interest in i-j-k min/max indices. Must be within this mesh’s extent.

rateVectorLikeInt, default: (1, 1, 1)

Length 3 iterable of ints: (xrate, yrate, zrate).

boundarybool, default: False

Control whether to enforce that the “boundary” of the grid is output in the subsampling process. (This only has effect when the rate in any direction is not equal to 1). When this is on, the subsampling will always include the boundary of the grid even if the sample rate is not an even multiple of the grid dimensions.

Returns:
pyvista.StructuredGrid

StructuredGrid with extracted subset.

Examples#

Download Python source code | Download Jupyter notebook

Split a grid in half.

>>> import numpy as np
>>> import pyvista as pv
>>> from pyvista import examples
>>> grid = examples.load_structured()
>>> voi_1 = grid.extract_subset([0, 80, 0, 40, 0, 1], boundary=True)
>>> voi_2 = grid.extract_subset([0, 80, 40, 80, 0, 1], boundary=True)

For fun, add the two grids back together and show they are identical to the original grid.