# [vtkusers] Compute vorticity from imagedata

David E DeMarle dave.demarle at kitware.com
Wed Jun 10 18:24:33 EDT 2015

```Use a writer to write out the input data set to a different file.
Are the two files the same size?

In paraview, how many arrays are there in each file?

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909

On Wed, Jun 10, 2015 at 6:15 PM, Stephen Hamilton <
stephenshamilton at gmail.com> wrote:

> Hi,
>
> I'm fairly new to VTK, but I've been stuck for over a day on trying to
> figure out a fairly simple task.
>
> I have a numpy array that I'm trying to convert to image data (structured
> grid), compute the vorticity, and use the cellderivatives to create an
> array of vorticity magnitude.  I can do this easily in Paraview, but in
> python the cell derivatives never seem to compute.
>
> Here is what I have so far:
> vtkdata = numpy_support.numpy_to_vtk(h5file[i][:,:,:,:].ravel(),
> deep=True, array_type=vtk.VTK_FLOAT)
> vtkdata.SetNumberOfComponents(3)
> image = vtk.vtkImageData()
> image.SetDimensions(xl, yl, zl)   #This is set above and matches the numpy
> array
>
> At this point, if I write the vti file using vtkXMLImageDataWriter(), I
> get what I expect in Paraview when I load it.
>
> Here is where I have problems:
>
> vorticity = vtk.vtkCellDerivatives()
> vorticity.SetVectorModeToComputeVorticity()
> vorticity.SetInputData(image)
> vorticity.Update()
> vwriter = vtk.vtkXMLImageDataWriter()
> vwriter.SetInputData(vorticity.GetOutput())
> vwriter.SetFileName("vorticity.vti")
>
> When I check the vorticity file, it is basically the same as if I never
> applied the cell derivative filter.  I've tried using the imagestreamer,
> and basically still get the same results.  I can't seem to find a good vtk6
> example on the web that is close enough to what I'm trying.  I also tried
> the threshold function, and got the same thing, so I think I'm applying the
> filter incorrectly (not at all in the case).
>
> Any help would be much appreciated!
>
> Thanks.
> Stephen
> PhD Student, Johns Hopkins University
>
>
> _______________________________________________
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>