extract_subset

StructuredGrid.extract_subset(voi, rate=(1, 1, 1), boundary=False)

Select piece (e.g., 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. (Note that these are 0-offset.) You can also specify a sampling rate to subsample the data.

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
voituple(int)

Length 6 iterable of ints: (xmin, xmax, ymin, ymax, zmin, zmax). These bounds specify the volume of interest in i-j-k min/max indices.

ratetuple(int), optional

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

boundarybool, optional

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. By default this is False.

Returns
pyvista.StructuredGrid

StructuredGrid with extracted subset.

Examples

Split a grid in half.

>>> import numpy as np
>>> import pyvista
>>> 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.

>>> joined = voi_1.concatenate(voi_2, axis=1)
>>> assert np.allclose(grid.points, joined.points)