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

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

Series

.series

SLC

.slc

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

Xdmf

.xdmf

XMLP

.pvtr

XML

.vtr

StructuredGrid File Formats

File Format

File Extension(s)

read()

save()

SegY

.segy, .sgy

Series

.series

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

Series

.series

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

FRD

.frd

Gambit

.neu

HDF

.hdf, .vtkhdf

MFIX

.res

Nek5000

.nek5000

ProStar

.vrt

Series

.series

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

Series

.series

Tecplot

.dat

Xdmf

.xdmf

XML

.vtm, .vtmb

PartitionedDataSet File Formats

File Format

File Extension(s)

read()

save()

HDF

.hdf, .vtkhdf

Series

.series

XML

.vtpd

Added in version 0.45: Support saving pickled meshes

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 or to the pickle path, 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.