# Error while trying to use \`vtk\_to\_numpy\`

**URL:** https://discourse.vtk.org/t/error-while-trying-to-use-vtk-to-numpy/10290
**Category:** Support
**Tags:** python, code
**Created:** [December 21, 2022, 5:08pm UTC](https://discourse.vtk.org/t/error-while-trying-to-use-vtk-to-numpy/10290 "2022-12-21T17:08:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Deepa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/deepa/32/1680_2.png) [@Deepa](https://discourse.vtk.org/u/Deepa)
#### Post date: [December 21, 2022, 5:08pm UTC](https://discourse.vtk.org/t/error-while-trying-to-use-vtk-to-numpy/10290/1 "2022-12-21T17:08:43Z")

</div>

Hi All,

I am trying to run the following example ([K3D-jupyter/volume\_renderer.ipynb at 3fef1ea419a84a51c8aed56cb285b9fcf0a18c9a · K3D-tools/K3D-jupyter · GitHub](https://github.com/K3D-tools/K3D-jupyter/blob/3fef1ea419a84a51c8aed56cb285b9fcf0a18c9a/examples/volume_renderer.ipynb)) in jupyter notebook.

```auto
import k3d
import math
import numpy as np
import nibabel as nib
from k3d.helpers import download
import ipywidgets as widgets
import vtk
from vtkmodules.util import numpy_support
basic_color_maps = [(attr, getattr(k3d.basic_color_maps, attr)) for attr in dir(k3d.basic_color_maps) if
                    not attr.startswith('__')]
paraview_color_maps = [(attr, getattr(k3d.paraview_color_maps, attr)) for attr in dir(k3d.paraview_color_maps) if
                       not attr.startswith('__')]
matplotlib_color_maps = [(attr, getattr(k3d.matplotlib_color_maps, attr)) for attr in dir(k3d.matplotlib_color_maps)
                         if not attr.startswith('__')]
colormaps = basic_color_maps + paraview_color_maps + matplotlib_color_maps

filename = download('https://vedo.embl.es/examples/data/embryo.slc')
reader = vtk.vtkSLCReader()
reader.SetFileName(filename)
reader.Update()
vti = reader.GetOutput()

bounds = vti.GetBounds()
x, y, z = vti.GetDimensions()
img = numpy_support.vtk_to_numpy(vti.GetPointData().GetArray(0)).reshape(-1, y, x)

tf_editor = k3d.transfer_function_editor()
volume = k3d.volume(img.astype(np.float16))

@widgets.interact(x=widgets.Dropdown(options=colormaps, description='ColorMap:'))
def g(x):
    tf_editor.color_map = np.array(x, dtype=np.float32)

plot = k3d.plot()
plot += volume
tf_editor.display()
plot.display()

a = widgets.jslink((tf_editor, 'color_map'), (volume, 'color_map'))
a = widgets.jslink((tf_editor, 'opacity_function'), (volume, 'opacity_function'))

```

and I get the following error

```auto
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [1], in <cell line: 25>()
     23 bounds = vti.GetBounds()
     24 x, y, z = vti.GetDimensions()
---> 25 img = numpy_support.vtk_to_numpy(vti.GetPointData().GetArray(0)).reshape(-1, y, x)
     27 tf_editor = k3d.transfer_function_editor()
     28 volume = k3d.volume(img.astype(np.float16))

File ~\anaconda3\envs\differential_networks\lib\site-packages\vtkmodules\util\numpy_support.py:215, in vtk_to_numpy(vtk_array)
    200 def vtk_to_numpy(vtk_array):
    201 """Converts a VTK data array to a numpy array.
    202 
    203 Given a subclass of vtkDataArray, this function returns an
   (...)
    213 
    214 """
--> 215 typ = vtk_array.GetDataType()
    216 assert typ in get_vtk_to_numpy_typemap().keys(), \
    217 "Unsupported array type %s"%typ
    218 assert typ != vtkConstants.VTK_BIT, 'Bit arrays are not supported.'

AttributeError: 'NoneType' object has no attribute 'GetDataType'

```

I am not sure how to fix this error. Suggestions will be really helpful.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 21, 2022, 8:57pm UTC](https://discourse.vtk.org/t/error-while-trying-to-use-vtk-to-numpy/10290/2 "2022-12-21T20:57:43Z")

</div>

From the error, it looks like `vtk_to_numpy()` received `None` as its argument.

This means that the dataset returned by the reader is probably empty. Which means that the `download()` function was probably unable to download the data. There were probably warnings about the data that you did not see (maybe jupyter didn’t show them?)

Try downloading the data manually, by entering the ‘[https://vedo.embl.es/examples/data/embryo.slc](https://vedo.embl.es/examples/data/embryo.slc)’ into your web browser.

---

<div class="post-metadata">

### Author: ![Deepa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/deepa/32/1680_2.png) [@Deepa](https://discourse.vtk.org/u/Deepa)
#### Post date: [December 26, 2022, 7:19am UTC](https://discourse.vtk.org/t/error-while-trying-to-use-vtk-to-numpy/10290/3 "2022-12-26T07:19:56Z")

</div>

Could you please have a look at  
[Model class 'TransferFunctionModel' from module 'k3d' is loaded but can not be instantiated](https://discourse.vtk.org/t/model-class-transferfunctionmodel-from-module-k3d-is-loaded-but-can-not-be-instantiated/10312) ?
