# Extract field data from .vtu file

**URL:** https://discourse.vtk.org/t/extract-field-data-from-vtu-file/5254
**Category:** Support
**Created:** [February 25, 2021, 10:34am UTC](https://discourse.vtk.org/t/extract-field-data-from-vtu-file/5254 "2021-02-25T10:34:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tont\_fe](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/7ba0ec/32.png) [@tont\_fe](https://discourse.vtk.org/u/tont_fe)
#### Post date: [February 25, 2021, 10:34am UTC](https://discourse.vtk.org/t/extract-field-data-from-vtu-file/5254/1 "2021-02-25T10:34:17Z")

</div>

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
