# Create ImageData

**URL:** https://discourse.paraview.org/t/create-imagedata/8883
**Category:** ParaView Support
**Created:** [February 2, 2022, 6:18pm UTC](https://discourse.paraview.org/t/create-imagedata/8883 "2022-02-02T18:18:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [February 2, 2022, 6:18pm UTC](https://discourse.paraview.org/t/create-imagedata/8883/1 "2022-02-02T18:18:22Z")

</div>

I’m writing a filter that creates a 2D ImageData based on a 3D ImageData input. It seems to be working correctly, but the new structure won’t render as a surface. It looks correct as Gaussian Points.

I believe I simply haven’t finished creating the new structure, but I’m not sure what is missing. The following works as a programmable filter with the Wavelet source, to show what I mean.

```auto
from vtk.util.numpy_support import vtk_to_numpy, numpy_to_vtk
nx, ny, nz = inputs[0].GetDimensions()
dx, dy, dz = inputs[0].GetSpacing()
integrand = vtk_to_numpy(inputs[0].PointData['RTData']).reshape(nz, ny, nx)
out_numpy = numpy.add.reduce(integrand, axis=0, keepdims=True)*dz
out_vtk = numpy_to_vtk(out_numpy.flatten(), deep=1)
out_vtk.SetName('out')
out_vtk.SetNumberOfComponents(1)
out_vtk.SetNumberOfTuples(nx*ny*1)
out = self.GetOutput()
out.SetDimensions(nx, ny, 1)
out.SetOrigin(inputs[0].GetOrigin())
out.SetSpacing(inputs[0].GetSpacing()) 
out.GetPointData().AddArray(out_vtk)

```

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [February 3, 2022, 7:35am UTC](https://discourse.paraview.org/t/create-imagedata/8883/2 "2022-02-03T07:35:46Z")

</div>

the missing part was the RequestInformationScript where the extents needs to be set. I also streamlined the data access of your numpy arrays since the PointData dictionnary gives direct access to them.  
[state.py](https://discourse.paraview.org/uploads/short-url/wf9WDm2N6T1jqqLZR6GbsXv3ze1.py) (2.9 KB)

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [February 4, 2022, 4:57pm UTC](https://discourse.paraview.org/t/create-imagedata/8883/3 "2022-02-04T16:57:17Z")

</div>

When I copy the RequestInformation script into my pipeline, it works on my data. Unfortunately, it fails on reload, with the upstream pipeline object missing all of its Point and Cell Data fields. The same behavior happens when using the simpler version from: [Python Programmable Filter - KitwarePublic (paraview.org)](https://www.paraview.org/Wiki/Python_Programmable_Filter#:~:text=The%20python%20programmable%20filter%20is%20a%20general%20purpose,to%20wrap%20paraview%27s%20classes%20into%20python%20callable%20format.).

````auto
pdi = self.GetInput()
exts = pdi.GetExtent()[:4]+(0,0) 
util.SetOutputWholeExtent(self, exts)```
````

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [February 8, 2022, 9:07pm UTC](https://discourse.paraview.org/t/create-imagedata/8883/4 "2022-02-08T21:07:57Z")

</div>

Does anyone know how to resolve this issue? I am able to use the Slice representation as a workaround, but I would like to know how to create this object cleanly and correctly, especially since Slice doesn’t work once I convert the Image to a Structured Grid.

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [February 9, 2022, 9:57pm UTC](https://discourse.paraview.org/t/create-imagedata/8883/5 "2022-02-09T21:57:34Z")

</div>

I think that I’ve figured it out. The answer was very close to what @jfavre suggested, and he correctly diagnosed the problem.

The extents of the data need to be set in the RequestInformationScript, like this:

```auto
outInfo = executive.GetOutputInformation(0)
inInfo = executive.GetInputInformation(0,0)
exts = inInfo.Get(executive.WHOLE_EXTENT())
outInfo.Set(executive.WHOLE_EXTENT(), *exts[:4],0,0)

```

The key difference is that the extents of the input must be obtained from the executive, rather than from the input data using e.g. `inputs[0]` or `self.GetInput()`. I think that this is because the input data object is empty the first time this filter is called. It’s easy to miss in development, because at that point the data object is cached from earlier invocations.
