Hello all,
I want to extract the points and data of a slice from my simulation to write it into an ASCII file. For simplicity of further representation I converted my data to point data (cellDatatoPointData1) so that I have a data value for every point of the slice. I managed to do it but i cannot convert the data of the VTKArray into simple python float. I have seen many things on the internet to convert VTKDataArray to numpy array, but unfortunately it does not work for the VTKArray type. I can see the value when I print slice_data[var] but I cannot convert it into float. Does anyone know what I’m missing to convert my VTK arrays ?
My script is the following:
from paraview import servermanager as sm
from paraview.vtk.numpy_interface import dataset_adapter as dsa
vtk_data = sm.Fetch(cellDatatoPointData1)
vtk_data = dsa.WrapDataObject(vtk_data)
# Coordinates extraction
slice_points = vtk_data.GetPoints()
# Data extraction
slice_data = dict()
for var in Vars:
slice_data[var] = vtk_data.GetPointData[var]
size = slice_data[var].GetSize()
...
# Writing X, Y, Z, var
for i in range(size):
print(vtkToNumpy(slice_points[i]))
Str_Val = " {0: 1.12e}".format(slice_points[i][0])
Str_Val += " {0: 1.12e}".format(slice_points[i][1])
Str_Val += " {0: 1.12e}".format(slice_points[i][2])
Str_Val += " {0: 1.12e}".format(slice_data[var][i])