# Model class 'TransferFunctionModel' from module 'k3d' is loaded but can not be instantiated

**URL:** https://discourse.vtk.org/t/model-class-transferfunctionmodel-from-module-k3d-is-loaded-but-can-not-be-instantiated/10312
**Category:** Support
**Tags:** python, code, file-formats
**Created:** [December 26, 2022, 6:53am UTC](https://discourse.vtk.org/t/model-class-transferfunctionmodel-from-module-k3d-is-loaded-but-can-not-be-instantiated/10312 "2022-12-26T06:53: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 26, 2022, 6:53am UTC](https://discourse.vtk.org/t/model-class-transferfunctionmodel-from-module-k3d-is-loaded-but-can-not-be-instantiated/10312/1 "2022-12-26T06:53:43Z")

</div>

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'))

```

I get the following error

```auto
[Open Browser Console for more detailed log - Double click to close this message]
Model class 'TransferFunctionModel' from module 'k3d' is loaded but can not be instantiated
TypeError: o._deserialize_state is not a function
    at u._make_model (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20221226115526:2:747339)

```

There was a problem in downloading the input file directly using  
`filename = download('https://vedo.embl.es/examples/data/embryo.slc')`

so I uploaded the file in jupyter

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/cc96de1e44612e4207e385c6a3eb6dd1695baa94.png)

and assigned the filename to `filename` variable.

```auto

filename = 'embryo.slc'

```

But I don’t see the volume in the output

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/1a482a717d675caa26363955bb8398184eecd5a7.png)

Suggestions on how to fix the error will be of great help.

---

<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, 2:30pm UTC](https://discourse.vtk.org/t/model-class-transferfunctionmodel-from-module-k3d-is-loaded-but-can-not-be-instantiated/10312/2 "2022-12-26T14:30:39Z")

</div>

Any suggestions?

---

<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 28, 2022, 3:08pm UTC](https://discourse.vtk.org/t/model-class-transferfunctionmodel-from-module-k3d-is-loaded-but-can-not-be-instantiated/10312/3 "2022-12-28T15:08:26Z")

</div>

This error does not look like a VTK error. See this discussion of compatibility problems between older versions of ipywidgets and newer versions of jupyter: [Breaking changes in ipywidgets v8 and jupyterlab-widgets v3 · Issue #3607 · jupyter-widgets/ipywidgets · GitHub](https://github.com/jupyter-widgets/ipywidgets/issues/3607)
