threshold#
- UnstructuredGrid.threshold(value=None, scalars=None, invert=False, continuous=False, preference='cell', all_scalars=False, progress_bar=False, component_mode='all', component=0)#
Apply a
vtkThreshold
filter to the input dataset.This filter will apply a
vtkThreshold
filter to the input dataset and return the resulting object. This extracts cells where the scalar value in each cell satisfies the threshold criterion. Ifscalars
isNone
, the input’s active scalars array is used.- Parameters
- value
float
or sequence,optional
Single value or (min, max) to be used for the data threshold. If a sequence, then length must be 2. If no value is specified, the non-NaN data range will be used to remove any NaN values.
- scalars
str
,optional
Name of scalars to threshold on. Defaults to currently active scalars.
- invertbool,
optional
If value is a single value, when invert is
True
cells are kept when their values are below parameter"value"
. When invert isFalse
cells are kept when their value is above the threshold"value"
. Default isFalse
: yielding above the threshold"value"
.- continuousbool,
optional
When True, the continuous interval [minimum cell scalar, maximum cell scalar] will be used to intersect the threshold bound, rather than the set of discrete scalar values from the vertices.
- preference
str
,optional
When
scalars
is specified, this is the preferred array type to search for in the dataset. Must be either'point'
or'cell'
.- all_scalarsbool,
optional
If using scalars from point data, all scalars for all points in a cell must satisfy the threshold when this value is
True
. WhenFalse
, any point of the cell with a scalar value satisfying the threshold criterion will extract the cell.- progress_barbool,
optional
Display a progress bar to indicate progress.
- component_mode{‘selected’, ‘all’, ‘any’}
The method to satisfy the criteria for the threshold of multicomponent scalars. ‘selected’ (default) uses only the
component
. ‘all’ requires all components to meet criteria. ‘any’ is when any component satisfies the criteria.- component
int
When using
component_mode='selected'
, this sets which component to threshold on. Default is0
.
- value
- Returns
pyvista.UnstructuredGrid
Dataset containing geometry that meets the threshold requirements.
Examples
>>> import pyvista >>> import numpy as np >>> volume = np.zeros([10, 10, 10]) >>> volume[:3] = 1 >>> vol = pyvista.wrap(volume) >>> threshed = vol.threshold(0.1) >>> threshed UnstructuredGrid (0x7f00f9983fa0) N Cells: 243 N Points: 400 X Bounds: 0.000e+00, 3.000e+00 Y Bounds: 0.000e+00, 9.000e+00 Z Bounds: 0.000e+00, 9.000e+00 N Arrays: 1
Apply the threshold filter to Perlin noise. First generate the structured grid.
>>> import pyvista >>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0)) >>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0], ... dim=(20, 20, 20)) >>> grid.plot(cmap='gist_earth_r', show_scalar_bar=True, show_edges=False)
Next, apply the threshold.
>>> import pyvista >>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0)) >>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0], ... dim=(20, 20, 20)) >>> threshed = grid.threshold(value=0.02) >>> threshed.plot(cmap='gist_earth_r', show_scalar_bar=False, show_edges=True)
See Using Common Filters for more examples using this filter.