Bug reading VTK ascii file in python

Hello,
Just to report a strange behavior that I observed using vtk in python.

I have vtk ascii file build using a given software. When I read it in python for post processing I can only see 2 variable. If I convert it in binairy I can read all the variable.

Here is a minimum example of this:

from paraview.simple import *
import vtk

# function to convert vtk ascci to binary
def vtk_ascii2binary(adr_disp):
    # Create a temporary file
    DSC_vtk = LegacyVTKReader(registrationName=adr_disp.split('/')[-1], FileNames=[adr_disp])
    # save data
    SaveData('vtk_binary.vtk', proxy=DSC_vtk, ChooseArraysToWrite=0,FileType='Binary')

    return

# function to print cell variable
def print_cell_variable(file_vtk):
    reader = vtk.vtkDataSetReader()
    reader.SetFileName(file_vtk)
    reader.Update()

    # Get the output
    ug = reader.GetOutput()
    # Get cell data
    cell_data = ug.GetCellData()

    # Get the number of arrays in the cell data
    num_cell_arrays = cell_data.GetNumberOfArrays()

    # Iterate over arrays and print their names
    print("Cell Data:")
    for i in range(num_cell_arrays):
        array_name = cell_data.GetArrayName(i)
        print("Array {}: {}".format(i, array_name))

# Evaluation
adr='DSC_0103-DSC_0105-ldic.vtk'
# print variable from ascii file
print_cell_variable(adr)
# build binary file
vtk_ascii2binary(adr)
#print variable from binary file
vtk_ascii2binary('vtk_binary.vtk')

Output

Cell Data:
Array 0: displacements
Array 1: error
Cell Data:
Array 0: error
Array 1: displacements
Array 2: iterations
Array 3: returnStatus
Array 4: deltaPhiNorm

Package :

  • paraview 5.11.2

  • ascii file : As a new user I cannot upload file. But have you ever seen something like this ?

I have a work around converting ascii to binary but I still wanted to report this. Is it a bug or I am missing something ?

Best
Thomas