pyvista.read

Contents

pyvista.read#

read(
filename: PathStrSeq,
force_ext: str | None = None,
file_format: str | None = None,
progress_bar: bool = False,
) DataObject[source]#

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. Pickled meshes ('.pkl' or '.pickle') are also supported.

See pyvista.get_reader() for list of vtk formats supported.

ImageData File Formats

File Format

File Extension(s)

read()

save()

BMP

.bmp

DEM

.dem

DICOM

.dcm, .img

GaussianCube

.cube

GESigna

.mr

GIF

.gif

HDF

.hdf, .vtkhdf

HDR

.hdr

JPEG

.jpeg, .jpg

Meta

.mha, .mhd

MINC

.mnc

NIFTI

.nii, .nii.gz

NRRD

.nhdr, .nrrd

PNG

.png

PNM

.pnm

SegY

.segy, .sgy

SLC

.slc

TIFF

.tif, .tiff

VTK

.vtk

VTKP

.pvtk

XML

.vti

XMLP

.pvti

RectilinearGrid File Formats

File Format

File Extension(s)

read()

save()

VTK

.vtk

VTKP

.pvtk

Xdmf

.xdmf

XMLP

.pvtr

XML

.vtr

StructuredGrid File Formats

File Format

File Extension(s)

read()

save()

SegY

.segy, .sgy

VTK

.vtk

VTKP

.pvtk

Xdmf

.xdmf

XML

.vts

PolyData File Formats

File Format

File Extension(s)

read()

save()

BinaryMarchingCubes

.tri

BYU

.g

Facet

.facet

GaussianCube

.cube

HDF

.hdf, .vtkhdf

OBJ

.obj

Particle

.raw

PDB

.pdb

PLY

.ply

PTS

.pts

STL

.stl

VTK

.vtk

VTKP

.pvtk

XML

.vtp

Houdini

.geo

IV

.iv

UnstructuredGrid File Formats

File Format

File Extension(s)

read()

save()

AVSucd

.inp

Fluent

.cas

Gambit

.neu

HDF

.hdf, .vtkhdf

MFIX

.res

Nek5000

.nek5000

ProStar

.vrt

VTK

.vtk

VTKP

.pvtk

Xdmf

.xdmf

XMLP

.pvtu

XML

.vtu

MultiBlock File Formats

File Format

File Extension(s)

read()

save()

CGNS

.cgns

EnSight

.case

ExodusII

.e, .ex2, .exii, .exo

FLUENTCFF

.h5

GLTF

.glb, .gltf

HDF

.hdf, .vtkhdf

Plot3DMeta

.p3d

POpenFOAM

.foam

PVD

.pvd

Tecplot

.dat

Xdmf

.xdmf

XML

.vtm, .vtmb

PartitionedDataSet File Formats

File Format

File Extension(s)

read()

save()

HDF

.hdf, .vtkhdf

XML

.vtpd

Note

See nschloe/meshio for formats supported by meshio. Be sure to install meshio with pip install meshio if you wish to use it.

Added in version 0.45: Support reading pickled meshes.

Warning

The pickle module is not secure. Only read pickled mesh files ('.pkl' or '.pickle') you trust. See pickle for details.

Parameters:
filenamestr, Path, Sequence[str | Path]

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.

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.

progress_barbool, default: False

Optionally show a progress bar. Ignored when using meshio.

Returns:
pyvista.DataSet

Wrapped PyVista dataset.

See also

pyvista.DataObject.save

Save a mesh to file.

Examples

Load an example mesh.

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

Load a vtk file.

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

Load a meshio file.

>>> mesh = pv.read('mesh.obj')

Load a pickled mesh file.

>>> mesh = pv.read('mesh.pkl')