DataSetFilters.remove_nan_cells#
- DataSetFilters.remove_nan_cells(
- *,
- scalars: str | None = None,
- preference: PointLiteral | CellLiteral = 'point',
- component_mode: Literal['component', 'all', 'any'] = 'all',
- component: int = 0,
- progress_bar: bool = False,
Remove cells whose scalar values are NaN.
A cell is considered NaN if any of its associated scalar values are NaN. For point data, this means any cell containing a NaN point is dropped; for cell data, cells whose value is NaN are dropped.
Added in version 0.48.
Note
This filter is equivalent to calling
threshold()withall_scalars=Trueand the default (auto-computed) value range, which usesnumpy.nanmin()andnumpy.nanmax()to exclude NaN values from the bounds. It is provided as a convenience becausethresholddefaults topreference='cell'andall_scalars=False, which does not reliably remove NaN cells from point data.- Parameters:
- scalars
str, optional Name of scalars to check for NaN values. Defaults to the currently active scalars.
- preference
str, default: ‘point’ When
scalarsis specified, this is the preferred array type to search for in the dataset. Must be either'point'or'cell'.- component_mode{‘component’, ‘all’, ‘any’}, default: ‘all’
The method to satisfy the criteria for multi-component scalars.
'component'uses only the single component specified bycomponent.'all'drops a cell if any component is NaN.'any'keeps a cell as long as at least one component is finite.- component
int, default: 0 When using
component_mode='component', this sets which component to check for NaN values.- progress_barbool, default:
False Display a progress bar to indicate progress.
- scalars
- Returns:
pyvista.UnstructuredGrid|pyvista.PointSetDataset with NaN cells removed. A
PointSetinput returns aPointSetwith its NaN points removed.
Examples#
Download Python source code | Download Jupyter notebook
Create a small grid with some NaN point values and remove the affected cells.
>>> import numpy as np
>>> import pyvista as pv
>>> grid = pv.ImageData(dimensions=(5, 5, 5))
>>> values = np.arange(grid.n_points, dtype=float)
>>> values[::7] = np.nan
>>> grid.point_data['values'] = values
>>> cleaned = grid.remove_nan_cells(scalars='values')
>>> cleaned.n_cells < grid.n_cells
True
>>> bool(np.any(np.isnan(cleaned.point_data['values'])))
False
See Also#
thresholdThreshold a dataset by value.
remove_nan_cellsis a thin wrapper around this filter.extract_cells()Extract a subset of cells by index.
extract_values()Threshold-like filter for extracting specific values and ranges.
Used In#
Gallery Examples