Skip to content

VTK Export

MicPy can export field data to the Visualization Toolkit (VTK) ImageData format (.vti). The resulting files can be visualized in applications such as ParaView or processed further using Python libraries built on VTK.

ParaView Plugin

MicPy also provides a dedicated ParaView plugin that can open MICRESS binary files directly, without converting them to VTK first. See the ParaView plugin documentation for details.

Exporting a Field

A Field can be converted into a vtkImageData object using Field.as_vti().

The data_mode parameter controls how the field values are represented in the VTK dataset.

Data Modes

Stores each field value (x0, x1, x2, x3) as VTK CellData, with one value per MICRESS cell. This preserves the field’s cell-based representation.

Converts the field to VTK PointData by averaging adjacent cell values at each grid point, e.g. p11 = average(x0, x1, x2, x3). Additional boundary points are generated so that the original spatial extent and dataset bounds are preserved.

Stores the field values (x0, x1, x2, x3) directly as VTK PointData, without averaging or generating additional boundary points. Consequently, the dataset contains one fewer cell along each non-degenerate axis, reducing its spatial extent by one grid spacing in those directions.

Creating a VTK ImageData object

from micpy.bin import read

# Read the last time step
field = read("A019_01_MgAl6_D_Dendritic_3D_TQ.frac", -1)

# Default: CellData
vti = field.as_vti()

# Averaged PointData
vti = field.as_vti(data_mode="point_average")

# Direct PointData
vti = field.as_vti(data_mode="point_direct")

Saving to a .vti File

# Save as CellData (default)
field.save_vti("A019_01_MgAl6_D_Dendritic_3D_TQ.vti")

# Save averaged PointData
field.save_vti("A019_01_MgAl6_D_Dendritic_3D_TQ.vti", data_mode="point_average")

# Save direct PointData
field.save_vti("A019_01_MgAl6_D_Dendritic_3D_TQ.vti", data_mode="point_direct")

API Reference

micpy.bin.Field.as_vti(name='values', data_mode='cell', length_unit='cm', *, point_data=None)

Convert the field to a VTK ImageData object.

Parameters:

Name Type Description Default
name str

Name of the VTK data array.

'values'
data_mode DataMode

How MICRESS cell values are represented: - "cell": Store the original values as VTK CellData. - "point_average": Convert the cell values to PointData by averaging adjacent cells. - "point_direct": Store each original field value directly as a VTK point value, without averaging.

'cell'
length_unit str

The unit of length for the VTK image spacing. Supported units are "um" (micrometers), "mm" (millimeters), "cm" (centimeters), and "m" (meters).

'cm'
point_data bool | None

Deprecated. Use data_mode instead.

None

Returns:

Type Description
vtkImageData

A vtkImageData object containing the field values.

micpy.bin.Field.save_vti(filename, name='values', data_mode='cell', file_format='xml', *, point_data=None)

Save the field as VTK ImageData.

Parameters:

Name Type Description Default
filename str

Filename of the VTK file.

required
name str

Name of the VTK data array.

'values'
data_mode DataMode

How MICRESS cell values are represented: - "cell": Store the original values as VTK CellData. - "point_average": Convert the cell values to PointData by averaging adjacent cells. - "point_direct": Store each original field value directly as a VTK point value, without averaging.

'cell'
file_format VTKFileFormat

VTK file format: - "xml": VTK XML ImageData format (.vti). - "legacy": Legacy VTK file format (typically .vtk).

'xml'
point_data bool | None

Deprecated. Use data_mode instead.

None

Returns:

Type Description
str

The filename of the saved VTK file.