# Get attributes and type data associated with points/cells

**URL:** https://discourse.vtk.org/t/get-attributes-and-type-data-associated-with-points-cells/11956
**Category:** Support
**Tags:** tractography, attribute, streamline, python
**Created:** [July 17, 2023, 8:06pm UTC](https://discourse.vtk.org/t/get-attributes-and-type-data-associated-with-points-cells/11956 "2023-07-17T20:06:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [July 17, 2023, 8:06pm UTC](https://discourse.vtk.org/t/get-attributes-and-type-data-associated-with-points-cells/11956/1 "2023-07-17T20:06:23Z")

</div>

Hi,  
I am trying to extract the attributes associated with the point and cell data from a `vtp` file that contains tractography streamlines, together with some associated scalar and tensor data.

So far I have been able to extract the names of the attributes with the code I am attaching (I’m using Python). I would like to:

1. Get the attribute type associated with each one.
2. Get the actual data associated with each one.

How can I do this?

Relevant code snippet:

```auto
import vtk
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(in_fname)
reader.Update()

in_data = reader.GetOutput()
vtk_data = in_data.GetPointData()
# vtk_data = in_data.GetCellData()

names = []
if vtk_data.GetNumberOfArrays() > 0:
    point_data_arr_idx = list(range(vtk_data.GetNumberOfArrays()))
    for idx in point_data_arr_idx:
        array = vtk_data.GetArray(idx)
        names.append(array.GetName())

```

The test data I am using is attached.

Thanks.

[T\_CC1.vtp](https://discourse.vtk.org/uploads/short-url/nC2RjJgTerpHKR0jD02Na6BRHVl.vtp) (724.2 KB)

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [July 18, 2023, 2:08pm UTC](https://discourse.vtk.org/t/get-attributes-and-type-data-associated-with-points-cells/11956/2 "2023-07-18T14:08:37Z")

</div>

Try:

```py
import vtk
from vtkmodules.util.numpy_support import vtk_to_numpy

reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(in_fname)
reader.Update()

in_data = reader.GetOutput()
vtk_pdata = in_data.GetPointData()

for idx in range(vtk_pdata.GetNumberOfArrays()):
    array = vtk_pdata.GetArray(idx)
    print(array.GetName(), array.GetDataType(), vtk_to_numpy(array).dtype)

```

with `vedo` or `pyvista` with similar syntax:

```py
from vedo import *
lines = load("https://discourse.vtk.org/uploads/short-url/nC2RjJgTerpHKR0jD02Na6BRHVl.vtp")
for k in lines.pointdata.keys(): 
    print("array:", k, lines.pointdata[k].dtype)
lines.cmap("rainbow", "cluster_idx")
show(lines, axes=1, bg='blackboard')

```

 ![Screenshot from 2023-07-18 15-08-27](https://discourse.vtk.org/uploads/default/original/2X/a/ab5c16466441b0b25911e3b9fb4f1a0616c02f3d.png)

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [July 19, 2023, 3:29pm UTC](https://discourse.vtk.org/t/get-attributes-and-type-data-associated-with-points-cells/11956/3 "2023-07-19T15:29:25Z")

</div>

Works like a charm. Thanks @marcomusy.
