I have a problem trying to extract data from a .vtu file.
I have the file and I would like to do some post-processing, in particular I would like to write .npy files for the grid and some variables of interest. I past here the part of the code.
import vtk
from vtk.util import numpy_support
from vtk.util.numpy_support import vtk_to_numpy
import numpy as np
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(“myfile.vtu”)
reader.SetPointArrayStatus(“H”, 1)
#------------------------#
outline of the dataset
#------------------------#
get_polydata = vtk.vtkGeometryFilter()
get_polydata.SetInputConnection(reader.GetOutputPort())
outline = vtk.vtkExtractEdges()
outline.SetInputConnection(get_polydata.GetOutputPort())
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(0.5, 1.0, 0.5)
outline_actor.GetProperty().SetOpacity(0.25)
output = reader.GetOutput()
potential = output.GetPointData().GetArray(“density”)
array = potential.GetData()
density = vtk_to_numpy(array)
print density
Traceback (most recent call last):
File “”, line 29, in
array = potential.GetData()
AttributeError: ‘NoneType’ object has no attribute ‘GetData’
What can I do to extract the field?
Thanks a lot in advance