DataObject.save#
- DataObject.save(
- filename: Path | str,
- binary: bool = True,
- texture: NumpyArray[np.uint8] | str | None = None,
- compression: _CompressionOptions = 'zlib',
- **writer_kwargs: Any,
Save this vtk object to file.
Tip
A native
.pvbinary format withzstdcompression is available via the pyvista-zstd companion package, included in theioextra (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 viapyvista.register_writer().ImageDataFile FormatsFile Format
File Extension(s)
BMP
.bmpDEM
.demDICOM
.dcm,.imgGaussianCube
.cubeGESigna
.mrGIF
.gifHDF
.hdf,.vtkhdfHDR
.hdrJPEG
.jpeg,.jpgMeta
.mha,.mhdMINC
.mncNIFTI
.nii,.nii.gzNRRD
.nhdr,.nrrdPNG
.pngPNM
.pnmSegY
.segy,.sgySeries
.seriesSLC
.slcTIFF
.tif,.tiffVTK
.vtkVTKP
.pvtkXML
.vtiXMLP
.pvtiRectilinearGridFile FormatsStructuredGridFile FormatsPolyDataFile FormatsUnstructuredGridFile FormatsMultiBlockFile FormatsPartitionedDataSetFile FormatsAdded in version 0.45: Support saving pickled meshes
- Parameters:
- filename
str,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.- texture
str,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.
- compression
strorNone, default: ‘zlib’ The compression type to use when
binaryisTrueand VTK writer is of type vtkXMLWriter. This argument has no effect otherwise. Acceptable values are'zlib','lz4','lzma', andNone.Noneindicates no compression.Added in version 0.47.
- **writer_kwargs
dict,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 raisesTypeError— PyVista never silently drops writer options.Added in version 0.48.
- filename
- Raises:
TypeErrorIf
**writer_kwargsare provided but the target extension does not dispatch to a registered custom writer.ValueErrorIf
file_extis not a supported extension.
See also
Notes
Binary files write much faster than ASCII and have a smaller file size.