# Distributed volume rendering using VTK's numpy support

**URL:** https://discourse.paraview.org/t/distributed-volume-rendering-using-vtks-numpy-support/5399
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [September 22, 2020, 9:17pm UTC](https://discourse.paraview.org/t/distributed-volume-rendering-using-vtks-numpy-support/5399 "2020-09-22T21:17:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NickLeaf](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nickleaf/32/5002_2.png) [@NickLeaf](https://discourse.paraview.org/u/NickLeaf)
#### Post date: [September 22, 2020, 9:17pm UTC](https://discourse.paraview.org/t/distributed-volume-rendering-using-vtks-numpy-support/5399/1 "2020-09-22T21:17:29Z")

</div>

I have a workflow using Dask-MPI to move data distributed across multiple nodes into VTK for rendering. The source data is a regular grid fp32 supernova dataset that is pre-partitioned by Dask. Each MPI rank gets one partition of the data, stored in numpy format, which it uses to locally build a vtkImageData. I then use the vtkImageData object to initialize a trivial producer. I’m getting hung up on setting the data extents properly, however.

Here’s a snippet of the python code I’m using for processing the data, with just two ranks for testing. `ar` is the numpy array storing the volume data (originally 3D), `dims` are the dimensions of the local chunk, and `wdims` are the dimensions of the entire volume. For this simple case, I’m just splitting along the z-axis. Persistent objects like producers and `paraview.simple` are stored in the wrapping class for this code.  
print(“Rank”, self.rank, “has array with local/global dims”, dims, wdims)  
ar = np.reshape(ar, dims[0]\*dims[1]\*dims[2])

```
ext = [0,dims[0]-1, 0,dims[1]-1, max(self.rank*dims[2]-1,0),(self.rank+1)*dims[2]-1]
wext = [0,wdims[0]-1, 0,wdims[1]-1, 0,wdims[2]-1]

vtkimg = vtk.vtkImageData()
vtkimg.Initialize()
vtkimg.SetExtent(ext)
vtkimg.SetSpacing([1,1,1])

#set the extent for the whole dataset
vi = vtk.vtkInformation()
vtkimg.CopyInformationToPipeline(vi)
vi.Set(vtk.vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(), wext[0],wext[1],wext[2],wext[3],wext[4],wext[5])
vtkimg.CopyInformationFromPipeline(vi)

varnm = 'E' #'E' is entropy for this data
vtkarr = vtknp.numpy_to_vtk(ar)
vtkarr.SetName(varnm)
vtkimg.GetPointData().AddArray(vtkarr)
vtkimg.GetPointData().SetScalars(vtkarr)

self.TP = self.pvs.TrivialProducer()
self.TP.GetClientSideObject().SetOutput(vtkimg)
self.TP.UpdatePipeline()

```

This mostly works, but I’m getting junk data aligned with the split axis (see the image below) or sometimes a segfault. That looks like a pretty clear off-by-one case to me. I’ve verified that the local and global dimensions are correct–(432,432,216) and (432,432,432), respectively–so I must be specifying them incorrectly in VTK. I notice that I’m not getting a visible seam between partitions, however, which I would expect if data at the partition boundary were wrong or missing ghost cells. Unfortunately, search results for this topic are a bit of a minefield and bring up a lot of hits for old, obsolete methods.

 ![image](https://discourse.paraview.org/uploads/default/original/2X/2/2f5b82db47c30e5ec9bd785c253ee58fd0b40686.jpeg)

---

<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: [September 23, 2020, 6:50am UTC](https://discourse.paraview.org/t/distributed-volume-rendering-using-vtks-numpy-support/5399/2 "2020-09-23T06:50:06Z")

</div>

Hello Nick

I don’t see a line like this in your code…

> vi.Set(vtk.vtkAlgorithm.CAN\_PRODUCE\_SUB\_EXTENT(), 1)

---

<div class="post-metadata">

### Author: ![NickLeaf](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nickleaf/32/5002_2.png) [@NickLeaf](https://discourse.paraview.org/u/NickLeaf)
#### Post date: [September 25, 2020, 5:32pm UTC](https://discourse.paraview.org/t/distributed-volume-rendering-using-vtks-numpy-support/5399/3 "2020-09-25T17:32:25Z")

</div>

I fixed the off-by-one error, though I am still getting a seam on the partition boundary (presumably due to missing ghost cells). Is there a point at which VTK exchanges ghost cells? If not, I can easily supply them myself, but how do I set up the metadata for the vtkImageData to recognize them? Is it possible to accomplish this with VTK + a TrivialProducer?

> I don’t see a line like this in your code…

> vi.Set(vtk.vtkAlgorithm.CAN\_PRODUCE\_SUB\_EXTENT(), 1)

Hi Jean, thanks for the suggestion. I added a line to set the value for the key you suggested, but it doesn’t seem to have fixed the issue.
