DataSetFilters.remove_nan_cells

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,
) → PointSet | UnstructuredGrid[source]#

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() with all_scalars=True and the default (auto-computed) value range, which uses numpy.nanmin() and numpy.nanmax() to exclude NaN values from the bounds. It is provided as a convenience because threshold defaults to preference='cell' and all_scalars=False, which does not reliably remove NaN cells from point data.

Parameters:
scalarsstr, optional

Name of scalars to check for NaN values. Defaults to the currently active scalars.

preferencestr, default: ‘point’

When scalars is 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 by component. 'all' drops a cell if any component is NaN. 'any' keeps a cell as long as at least one component is finite.

componentint, 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.

Returns:
pyvista.UnstructuredGrid | pyvista.PointSet

Dataset with NaN cells removed. A PointSet input returns a PointSet with 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#

threshold

Threshold a dataset by value. remove_nan_cells is 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.