read

read(filename, attrs=None, force_ext=None, file_format=None)

Read any file type supported by vtk or meshio.

Automatically determines the correct reader to use then wraps the corresponding mesh as a pyvista object. Attempts native vtk readers first then tries to use meshio.

Supports the following formats:

Standard dataset readers:

  • '.vtk'

  • '.pvtk'

  • '.vti'

  • '.pvti'

  • '.vtr'

  • '.pvtr'

  • '.vtu'

  • '.pvtu'

  • '.ply'

  • '.obj'

  • '.stl'

  • '.vtp'

  • '.vts'

  • '.vtm'

  • '.vtmb'

  • '.case'

Image formats:

  • '.bmp'

  • '.dem'

  • '.dcm'

  • '.img'

  • '.jpeg'

  • '.jpg'

  • '.mhd'

  • '.nrrd'

  • '.nhdr'

  • '.png'

  • '.pnm'

  • '.slc'

  • '.tiff'

  • '.tif'

Other formats:

  • '.byu'

  • '.g'

  • '.p3d'

  • '.pts'

  • '.tri'

  • '.inp'

Note

There is limited support for OpenFoam format files. pyvista.read will automatically return only the first dataset in a single-element pyvista.MultiBlock. These files include:

  • '.facet'

  • '.cas'

  • '.res'

  • '.foam'

Note

See https://github.com/nschloe/meshio for formats supported by meshio.

Parameters
filenamestr

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 separate block in the dataset.

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

force_extstr, optional

If specified, the reader will be chosen by an extension which is different to its actual extension. For example, '.vts', '.vtu'.

file_formatstr, optional

Format of file to read with meshio.

Returns
pyvista.DataSet

Wrapped PyVista dataset.

Examples

Load an example mesh.

>>> import pyvista
>>> from pyvista import examples
>>> mesh = pyvista.read(examples.antfile)
>>> mesh.plot(cpos='xz')
../../../_images/pyvista-read-1_00_00.png

Load a vtk file.

>>> mesh = pyvista.read('my_mesh.vtk')  

Load a meshio file.

>>> mesh = pyvista.read("mesh.obj")