VTK Files

Below are the main classes representing VTK Files and their methods.

class py2vtk.core.vtkfiles.VtkFileType(name, ext)

Wrapper class for serial VTK file types.

Parameters

namestr

Data name.

extstr

File extension.

class py2vtk.core.vtkfiles.VtkParallelFileType(vtkftype)

A wrapper class for parallel VTK file types.

Parameters

vtkftypeVtkFileType

Vtk file type

class py2vtk.core.vtkfiles.VtkDataType(size, name)

Wrapper class for VTK data types.

Parameters

sizeint

Size in byte.

namestr

Type name.

class py2vtk.core.vtkfiles.VtkFile(filepath, ftype, direct_format='ascii', appended_format='raw', compression=False, compressor='zlib')

Class for a serial VTK file.

Parameters

filepathstr

filename without extension.

ftypestr

file type, e.g. VtkImageData, etc.

direct_format: str in {“ascii”, “binary”}, default=”binary”

format of the non appended data.

appended_formatstr in {“base64”, “raw”}, default=”raw”

format of the appended data.

compressionbool or int, default=False

Whether and how much to compress the binary data.

compressorstr in {‘zlib’, ‘lzma’}, default=’zlib’

compressor to use to compress binary data.

addData(name, data, append=True)

Add array description to xml header section and writes the array directly if the append is False

Parameters

namestr

data array name.

dataarray-like

one numpy array or a tuple with 3 numpy arrays. If a tuple, the individual arrays must represent the components of a vector field. All arrays must be one dimensional or three-dimensional.

appendbool, default=True

If True, the data is going to be written in the appended section.

closeData(nodeType)

Close data section.

Parameters

nodeTypestr

“Point”, “Cell” or “Field”.

closeElement(tagName)

Close an element.

closeGrid()

Close grid element.

closePiece()

Close Piece.

getFileName()

Return absolute path to this file.

openData(nodeType, scalars=None, vectors=None, normals=None, tensors=None, tcoords=None)

Open data section.

Parameters

nodeTypestr

Either “Point”, “Cell” or “Field”.

scalarsstr, optional

default data array name for scalar data.

vectorsstr, optional

default data array name for vector data.

normalsstr, optional

default data array name for normals data.

tensorsstr, optional

default data array name for tensors data.

tcoordsstr, optional

default data array name for tcoords data.

openElement(tagName)

Open an element. Useful to add elements such as: Coordinates, Points, Verts, etc.

openGrid(start=None, end=None, origin=None, spacing=None)

Open grid section.

Parameters

startarray-like, optional

array or list of start indexes. Required for Structured, Rectilinear and ImageData grids. The default is None.

endarray-like, optional

array or list of end indexes. Required for Structured, Rectilinear and ImageData grids. The default is None.

originarray-like, optional

3D array or list with grid origin. Only required for ImageData grids. The default is None.

spacingarray-like, optional

3D array or list with grid spacing. Only required for ImageData grids. The default is None.

openPiece(start=None, end=None, npoints=None, ncells=None, nverts=None, nlines=None, nstrips=None, npolys=None)

Open piece section.

Parameters

startarray-like, optional

array or list with start indexes in each direction. Must be given with end.

endarray-like, optional

array or list with end indexes in each direction. Must be given with start.

npointsint, optional

number of points in piece

ncellsint, optional

number of cells in piece. If present, npoints must also be given.

nvertsint, optional

number of vertices.

nlinesint, optional

number of lines.

nstripsint, optional

number of stripes.

npolysint, optional

number of poly.

save()

Close file.

class py2vtk.core.vtkfiles.VtkParallelFile(filepath, ftype, format='binary')

Class for a VTK parallel file.

Parameters

filepathstr

filename without extension

ftype : VtkParallelFileType

addData(name, data)

Add array description to xml header section and writes the array directly

Parameters

namestr

data array name.

dataarray-like

one numpy array or a tuple with 3 numpy arrays. If a tuple, the individual arrays must represent the components of a vector field. All arrays must be one dimensional or three-dimensional.

addPData(name, dtype, ncomp)

Add data array to the parallel vtk file.

Parameters

namestr

data array name.

dtypestr

data type.

ncompint

number of components, 1 (=scalar) and 3 (=vector).

addPiece(source=None, start=None, end=None)

Add piece section with extent and source.

Parameters

startarray-like, optional

array or list with start indexes in each direction. Must be given with end.

endarray-like, optional

array or list with end indexes in each direction. Must be given with start.

sourcestr

Source of this piece

closeData(nodeType)

Close data section.

Parameters

nodeTypestr

“Point”, “Cell” or “Field”.

closeGrid()

Close grid element.

getFileName()

Return absolute path to this file.

openData(nodeType, scalars=None, vectors=None, normals=None, tensors=None, tcoords=None)

Open data section.

Parameters

nodeTypestr

Either “Point”, “Cell” or “Field”.

scalarsstr, optional

default data array name for scalar data.

vectorsstr, optional

default data array name for vector data.

normalsstr, optional

default data array name for normals data.

tensorsstr, optional

default data array name for tensors data.

tcoordsstr, optional

default data array name for tcoords data.

openElement(tagName)

Open an element. Useful to add elements such as: Coordinates, Points, Verts, etc.

openGrid(start=None, end=None, origin=None, spacing=None, ghostlevel=0)

Open grid section.

Parameters

startarray-like, optional

array or list of start indexes. Required for Structured, Rectilinear and ImageData grids. The default is None.

endarray-like, optional

array or list of end indexes. Required for Structured, Rectilinear and ImageData grids. The default is None.

originarray-like, optional

3D array or list with grid origin. Only required for ImageData grids. The default is None.

spacingarray-like, optional

3D array or list with grid spacing. Only required for ImageData grids. The default is None.

ghostlevelint

Number of ghost-levels by which the extents in the individual pieces overlap.

save()

Close file.