Skip to content

read_vtk builtin

read_vtk(
    path, *, point_data=False, nodata=None, length_unit=None
)

Reads a VTK XML .vtp, .vtu, .vti, .vtr or .vts file.

Parameters:

Name Type Description Default
path str or Path

The file, in ASCII, binary or appended encoding, zlib-compressed or not.

required
point_data bool

Return the points (grid nodes) with the point data as a PointSet, whatever the cells.

False
nodata sequence of float

Values read as null, default -99, -999 and 1e21. NaN is always null.

None
length_unit str

Unit of the coordinates.

None

Returns:

Type Description
(PointSet, Polylines, Mesh or BlockModel)

In .vtp and .vtu files, surface cells (triangles, strips, quads, polygons) give a Mesh with point data as vertex columns and cell data as face columns. Otherwise line cells give Polylines, one part per cell, closed when it ends where it starts; cells sharing a feature value form one feature and cell data become feature columns. Otherwise cells that are all hexahedra or voxels are read as blocks, and anything else gives the points with their point data.

Grid files and hexahedra give a BlockModel of the cell data when the cells are equal boxes on a lattice, rotated by the grid axes (the Direction of a .vti). The model is masked when cells are missing or hidden by vtkGhostType. Other grids give a PointSet of the cell centers. A grid file with point data and no cell data gives the PointSet of its nodes: point values are never taken as cell values. A flat axis (one node layer) makes cells one spacing thick (1 in .vtr and .vts) centered on the nodes.

Arrays with several components become name_0, name_1, ...; float32 arrays stay float32, the rest become float64. Values whose <name>_valid array is 0 are null.

Used in