DataObject.save#
- DataObject.save(
- filename: Path | str,
- *,
- binary: bool = True,
- texture: NDArray[np.uint8] | str | None = None,
- compression: _CompressionOptions = 'zlib',
- **writer_kwargs: Any,
Save this vtk object to file.
Note
Reading a file and saving it in another format is also available via command-line interface. See pyvista convert for details.
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 Image
.bmpDICOM
.dcm,.imgDigital Elevation Model
.demGaussian Cube
.cubeGE Signa MR
.mrGIF Image
.gifJPEG Image
.jpeg,.jpgLegacy VTK
.vtkLegacy VTK (partitioned)
.pvtkMetaImage
.mha,.mhdMINC Image
.mncNIfTI
.nii,.nii.gzNRRD
.nhdr,.nrrdPNG Image
.pngPNM Image
.pnmRadiance HDR
.hdrSEG-Y
.segy,.sgySLC Volume
.slcTIFF Image
.tif,.tiffVTK File Series
.seriesVTK ImageData
.vtiVTK ImageData (partitioned)
.pvtiVTKHDF
.hdf,.vtkhdfRectilinearGridFile FormatsStructuredGridFile FormatsPolyDataFile FormatsFile Format
File Extension(s)
Binary Marching Cubes
.triFacet Polygonal Data
.facetGaussian Cube
.cubeHoudini Geometry
.geoLegacy VTK
.vtkLegacy VTK (partitioned)
.pvtkMOVIE.BYU
.gOpen Inventor
.ivProtein Data Bank
.pdbPTS Point Cloud
.ptsStanford PLY
.plyStereolithography
.stlVTK File Series
.seriesVTK Particle
.rawVTK PolyData
.vtpVTKHDF
.hdf,.vtkhdfWavefront OBJ
.objUnstructuredGridFile FormatsFile Format
File Extension(s)
AVS UCD
.inpEnSight
.caseFluent Case
.casGAMBIT Neutral
.neuLegacy VTK
.vtkLegacy VTK (partitioned)
.pvtkMFIX
.resNek5000
.nek5000proSTAR
.vrtVTK File Series
.seriesVTK UnstructuredGrid
.vtuVTK UnstructuredGrid (partitioned)
.pvtuVTKHDF
.hdf,.vtkhdfXDMF
.xdmfExplicitStructuredGridFile FormatsMultiBlockFile FormatsFile Format
File Extension(s)
3D Studio
.3dsCGNS
.cgnsEnSight
.caseExodus II
.e,.ex2,.exii,.exoExodus II (partitioned)
.e.N.p,.n.N.pFluent CFF Case
.h5glTF 2.0
.glb,.gltfOpenFOAM
.foamParaView Data
.pvdPLOT3D Meta
.p3dTecplot
.datVRML 2.0
.vrml,.wrlVTK File Series
.seriesVTK MultiBlock
.vtm,.vtmbVTKHDF
.hdf,.vtkhdfXDMF
.xdmfPartitionedDataSetFile FormatsWarning
.pkl/.pickleextensions 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 installpyvista-zstdfor the.pvsingle-blob format.Changed in version 0.49.0: Saving to an extension served by a companion package that is not installed raises
ImportErrorrather thanValueError.- 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, 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.ImportErrorIf
file_extis served by a companion package that PyVista cannot import, such as.pvandpyvista-zstd.ValueErrorIf
file_extis not a supported extension.
Notes#
Binary files write much faster than ASCII and have a smaller file size.
See Also#
Used In#
API Examples
XMLPartitionedDataSetReader(1 use)