pyvista_zstd.Reader#
- class pyvista_zstd.Reader(filename: Path | str | None = None, *, buffer: bytes | bytearray | memoryview | NDArray[Any] | None = None, backend: str | None = None)#
Class to control pyvista-zstd file decompression.
Use this class in lieu of
pyvista_zstd.read()to fine-tune reading in compressed files. With this you can:Inspect the dataset before reading it.
Control which arrays to read in.
For files containing a
pyvista.MultiBlock, select which blocks to read in.
A container already resident is read by passing
bufferinstead offilename– an archive member, a response body, or a build with no filesystem to open a path on. Those bytes are borrowed rather than copied and are held for the reader’s life, so they must not be modified meanwhile. Writing into them is not detected: the arrays read afterwards hold undefined contents, and no error is raised to say so. Resizing them is detected – the borrow pins the buffer, so a resize raisesBufferErrorrather than corrupting anything.A reader holds the file mapped, or the caller’s buffer alive, until
close()– whichwithcalls on the way out:with pyvista_zstd.Reader(buffer=raw) as reader: ds = reader.read()
- Parameters:
- filenamepathlib.Path | str, optional
Path to the file. Must end in
.pv.- bufferbytes | bytearray | memoryview | numpy.ndarray, optional
A whole container, contiguous. Exactly one of filename and buffer is given; a buffer has no suffix to check, so its bytes decide whether it is a container.
- backendstr, optional
Deprecated and ignored; passing it raises a
DeprecationWarning.
- Attributes:
available_cell_arraysReturn a set of all cell array names available in the dataset.
available_field_arraysReturn a set of all field array names available in the dataset.
available_point_arraysReturn a set of all point array names available in the dataset.
decompressed_sizesReturn decompressed frame sizes.
nbytesReturn the size of the decompressed dataset.
selected_cell_arraysReturn the set of currently selected cell arrays to read.
selected_field_arraysReturn the set of currently selected field arrays to read.
selected_point_arraysReturn the set of currently selected point arrays to read.
Methods
close()Release the container.
read([n_threads])Read in the dataset from the pyvista-zstd file.
Return a table showing compression statistics for each frame in the dataset.
Examples
First write out an example dataset.
>>> import pyvista as pv >>> import pyvista_zstd >>> ds = pv.Sphere() >>> pyvista_zstd.write(ds, "sphere.pv")
Create a reader.
>>> reader = pyvista_zstd.Reader("sphere.pv") >>> reader pyvista_zstd.Reader (0x7f1ed1496c00) File: sphere.pv File Version: 0 Compression: zstandard Compression Level: 3 Dataset Type: PolyData N Points: 842 (<class 'numpy.float32'>) N Cells: 1680 Point arrays: Normals float32 (842, 3)
Disable reading in point arrays and read the dataset.
>>> reader.selected_point_arrays = set() >>> ds_in = reader.read() >>> ds_in PolyData (0x7f1ece066ce0) N Cells: 1680 N Points: 842 N Strips: 0 X Bounds: -4.993e-01, 4.993e-01 Y Bounds: -4.965e-01, 4.965e-01 Z Bounds: -5.000e-01, 5.000e-01 N Arrays: 0
Read the same container out of memory instead of off disk.
>>> from pathlib import Path >>> raw = Path("sphere.pv").read_bytes() >>> ds_in = pyvista_zstd.Reader(buffer=raw).read()
Methods
Reader.__init__([filename, buffer, backend])Initialize the decompressor.
Release the container.
Reader.read([n_threads])Read in the dataset from the pyvista-zstd file.
Return a table showing compression statistics for each frame in the dataset.
Attributes
Return a set of all cell array names available in the dataset.
Return a set of all field array names available in the dataset.
Return a set of all point array names available in the dataset.
Return decompressed frame sizes.
Return the size of the decompressed dataset.
Return the set of currently selected cell arrays to read.
Return the set of currently selected field arrays to read.
Return the set of currently selected point arrays to read.