DataObject.save

Contents

DataObject.save#

DataObject.save(
filename: Path | str,
binary: bool = True,
texture: NumpyArray[np.uint8] | str | None = None,
compression: _CompressionOptions = 'zlib',
**writer_kwargs: Any,
) None[source]#

Save this vtk object to file.

Tip

A native .pv binary format with zstd compression is available via the pyvista-zstd companion package, included in the io extra (pip install pyvista[io]). It is a compact, multi-threaded alternative to the built-in VTK formats below when file size or I/O latency matters. Third-party packages can register additional custom writers via pyvista.register_writer().

ImageData File Formats

File Format

File Extension(s)

read()

save()

BMP

.bmp

DEM

.dem

DICOM

.dcm, .img

GESigna

.mr

GIF

.gif

GaussianCube

.cube

HDF

.hdf, .vtkhdf

HDR

.hdr

JPEG

.jpeg, .jpg

MINC

.mnc

Meta

.mha, .mhd

NIFTI

.nii, .nii.gz

NRRD

.nhdr, .nrrd

PNG

.png

PNM

.pnm

SLC

.slc

SegY

.segy, .sgy

Series

.series

TIFF

.tif, .tiff

VTK

.vtk

VTKP

.pvtk

XML

.vti

XMLP

.pvti

RectilinearGrid File Formats

File Format

File Extension(s)

read()

save()

Series

.series

VTK

.vtk

VTKP

.pvtk

XML

.vtr

XMLP

.pvtr

Xdmf

.xdmf

StructuredGrid File Formats

File Format

File Extension(s)

read()

save()

SegY

.segy, .sgy

Series

.series

VTK

.vtk

VTKP

.pvtk

XML

.vts

Xdmf

.xdmf

PolyData File Formats

File Format

File Extension(s)

read()

save()

BYU

.g

BinaryMarchingCubes

.tri

Facet

.facet

GaussianCube

.cube

HDF

.hdf, .vtkhdf

Houdini

.geo

IV

.iv

OBJ

.obj

PDB

.pdb

PLY

.ply

PTS

.pts

Particle

.raw

STL

.stl

Series

.series

VTK

.vtk

VTKP

.pvtk

XML

.vtp

UnstructuredGrid File Formats

File Format

File Extension(s)

read()

save()

AVSucd

.inp

FRD

.frd

Fluent

.cas

Gambit

.neu

HDF

.hdf, .vtkhdf

MFIX

.res

Nek5000

.nek5000

ProStar

.vrt

Series

.series

VTK

.vtk

VTKP

.pvtk

XML

.vtu

XMLP

.pvtu

Xdmf

.xdmf

ExplicitStructuredGrid File Formats

File Format

File Extension(s)

read()

save()

GRDECL

.grdecl

Series

.series

VTK

.vtk

XML

.vtu

MultiBlock File Formats

File Format

File Extension(s)

read()

save()

3DS

.3ds

CGNS

.cgns

EnSight

.case

ExodusII

.e, .ex2, .exii, .exo

FLUENTCFF

.h5

GLTF

.glb, .gltf

HDF

.hdf, .vtkhdf

POpenFOAM

.foam

PVD

.pvd

Plot3DMeta

.p3d

Series

.series

Tecplot

.dat

VRML

.vrml, .wrl

XML

.vtm, .vtmb

Xdmf

.xdmf

PartitionedDataSet File Formats

File Format

File Extension(s)

read()

save()

HDF

.hdf, .vtkhdf

Series

.series

XML

.vtpd

Warning

.pkl / .pickle extensions are not supported and will be refused. Pickle is a Python serialization protocol, not a mesh file format (CWE-502). Use a real mesh format or install pyvista-zstd for the .pv single-blob format.

Parameters:
filenamestr, pathlib.Path

Filename of output file. Writer type is inferred from the extension of the filename.

binarybool, default: True

If True, write as binary. Otherwise, write as ASCII.

texturestr, np.ndarray, optional

Write a single texture array to file when using a PLY file. Texture array must be a 3 or 4 component array with the datatype np.uint8. Array may be a cell array or a point array, and may also be a string if the array already exists in the PolyData.

If a string is provided, the texture array will be saved to disk as that name. If an array is provided, the texture array will be saved as 'RGBA'

Note

This feature is only available when saving PLY files.

compressionstr or None, default: ‘zlib’

The compression type to use when binary is True and VTK writer is of type vtkXMLWriter. This argument has no effect otherwise. Acceptable values are 'zlib', 'lz4', 'lzma', and None. None indicates no compression.

Added in version 0.47.

**writer_kwargsdict, optional

Additional keyword arguments forwarded verbatim to a custom writer registered via pyvista.register_writer(). Use these to expose format-specific options such as compression level or thread count. When the target extension dispatches to a built-in VTK writer, passing any extra keyword arguments raises TypeError — PyVista never silently drops writer options.

Added in version 0.48.

Raises:
TypeError

If **writer_kwargs are provided but the target extension does not dispatch to a registered custom writer.

ValueError

If file_ext is not a supported extension.

See also

pyvista.read

Notes

Binary files write much faster than ASCII and have a smaller file size.