PySDM_examples.utils.read_vtk_1d

 1import platform
 2
 3import numpy as np
 4
 5if platform.architecture()[0] != "32bit":
 6    import vtk
 7
 8    # pylint: disable = import-error, no-name-in-module
 9    from vtk.util import numpy_support as VN
10
11    # pylint: enable = import-error, no-name-in-module
12
13
14def readVTK_1d(file):
15    if platform.architecture()[0] == "32bit":
16        raise NotImplementedError("Not implemented for system arcitucture 32bit!")
17
18    reader = vtk.vtkXMLUnstructuredGridReader()  # pylint: disable = no-member
19    reader.SetFileName(file)
20    reader.Update()
21
22    vtk_output = reader.GetOutput()
23
24    z = np.zeros(vtk_output.GetNumberOfPoints())
25    for i in range(vtk_output.GetNumberOfPoints()):
26        z[i] = vtk_output.GetPoint(i)[2]
27
28    data = {}
29    data["z"] = z
30    for i in range(vtk_output.GetPointData().GetNumberOfArrays()):
31        data[vtk_output.GetPointData().GetArrayName(i)] = VN.vtk_to_numpy(
32            vtk_output.GetPointData().GetArray(i)
33        )
34
35    return data
def readVTK_1d(file):
15def readVTK_1d(file):
16    if platform.architecture()[0] == "32bit":
17        raise NotImplementedError("Not implemented for system arcitucture 32bit!")
18
19    reader = vtk.vtkXMLUnstructuredGridReader()  # pylint: disable = no-member
20    reader.SetFileName(file)
21    reader.Update()
22
23    vtk_output = reader.GetOutput()
24
25    z = np.zeros(vtk_output.GetNumberOfPoints())
26    for i in range(vtk_output.GetNumberOfPoints()):
27        z[i] = vtk_output.GetPoint(i)[2]
28
29    data = {}
30    data["z"] = z
31    for i in range(vtk_output.GetPointData().GetNumberOfArrays()):
32        data[vtk_output.GetPointData().GetArrayName(i)] = VN.vtk_to_numpy(
33            vtk_output.GetPointData().GetArray(i)
34        )
35
36    return data