General Utilities

Utilities routines.

pyvista.set_error_output_file(filename)

Set a file to write out the VTK errors.

pyvista.trans_from_matrix(matrix)

Convert a vtk matrix to a numpy.ndarray.

pyvista.is_inside_bounds(point, bounds)

Check if a point is inside a set of bounds.

This is implemented through recursion so that this is N-dimensional.

Object Conversions

pyvista.wrap(vtkdataset)

Wrap any given VTK data object to its appropriate PyVista data object.

Other formats that are supported include: * 2D numpy.ndarray of XYZ vertices * 3D numpy.ndarray representing a volume. Values will be scalars.

pyvista.is_pyvista_dataset(obj)

Return True if the Object is a PyVista wrapped dataset.

pyvista.image_to_texture(image)

Convert vtkImageData (pyvista.UniformGrid) to a vtkTexture.

pyvista.numpy_to_texture(image)

Convert a NumPy image array to a vtk.vtkTexture.

File IO

pyvista.read(filename, attrs=None, file_format=None)

Read any VTK file.

It will figure out what reader to use then wrap the VTK object for use in PyVista.

Parameters
  • filename (str) – The string path to the file to read. If a list of files is given, a pyvista.MultiBlock dataset is returned with each file being a seperate block in the dataset.

  • attrs (dict, optional) – A dictionary of attributes to call on the reader. Keys of dictionary are the attribute/method names and values are the arguments passed to those calls. If you do not have any attributes to call, pass None as the value.

  • file_format (str, optional) – Format of file to read with meshio.

pyvista.read_exodus(filename, animate_mode_shapes=True, apply_displacements=True, displacement_magnitude=1.0, enabled_sidesets=None)

Read an ExodusII file ('.e' or '.exo').

pyvista.read_texture(filename, attrs=None)

Load a vtkTexture from an image file.

pyvista.read_legacy(filename)

Use VTK’s legacy reader to read a file.

pyvista.save_meshio(filename, mesh, file_format=None, **kwargs)

Save mesh to file using meshio.

Parameters
  • mesh (pyvista.Common) – Any PyVista mesh/spatial data type.

  • file_format (str) – File type for meshio to save.

Mesh Creation

pyvista.lines_from_points(points)

Make a connected line set given an array of points.

Parameters

points (np.ndarray) –

Points representing the vertices of the connected segments. For example, two line segments would be represented as:

np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0]])

Returns

lines – PolyData with lines and cells.

Return type

pyvista.PolyData

pyvista.vtk_points(points, deep=True)

Convert numpy points to a vtkPoints object.

pyvista.vector_poly_data(orig, vec)

Create a vtkPolyData object composed of vectors.

pyvista.fit_plane_to_points(points, return_meta=False)

Fit a plane to a set of points.

Parameters
  • points (np.ndarray) – Size n by 3 array of points to fit a plane through

  • return_meta (bool) – If true, also returns the center and normal used to generate the plane

Array Access

pyvista.get_array(mesh, name, preference='cell', info=False, err=False)

Search point, cell and field data for an array.

Parameters
  • name (str) – The name of the array to get the range.

  • preference (str, optional) – When scalars is specified, this is the perfered array type to search for in the dataset. Must be either 'point', 'cell', or 'field'

  • info (bool) – Return info about the array rather than the array itself.

  • err (bool) – Boolean to control whether to throw an error if array is not present.

pyvista.convert_array(arr, name=None, deep=0, array_type=None)

Convert a NumPy array to a vtkDataArray or vice versa.

Parameters
  • arr (ndarray or vtkDataArry) – A numpy array or vtkDataArry to convert

  • name (str) – The name of the data array for VTK

  • deep (bool) – if input is numpy array then deep copy values

Returns

the converted array (if input is a NumPy ndaray then returns vtkDataArray or is input is vtkDataArray then returns NumPy ndarray). If pdf==True and the input is vtkDataArry, return a pandas DataFrame.

Return type

vtkDataArray, ndarray, or DataFrame

pyvista.point_array(mesh, name)

Return point array of a vtk object.

pyvista.cell_array(mesh, name)

Return cell array of a vtk object.

pyvista.field_array(mesh, name)

Return field array of a vtk object.

pyvista.get_vtk_type(typ)

Look up the VTK type for a give python data type.

Corrects for string type mapping issues.

Returns

int

Return type

the integer type id specified in vtkType.h

pyvista.vtk_bit_array_to_char(vtkarr_bint)

Cast vtk bit array to a char array.

pyvista.convert_string_array(arr, name=None)

Convert a numpy array of strings to a vtkStringArray or vice versa.

Note that this is terribly inefficient - inefficient support is better than no support :). If you have ideas on how to make this faster, please consider opening a pull request.