How can I write a velocity field to a VTI image with anaconda Python?
Question: I am trying to write a VTK Image Data file (.vti) with python. For my python
coding I am using the Anaconda distribution. I am using the evtk package,
which has the ability to write a vtk file.

The data I need to write is a velocity for which I have the 3d X,Y,Z and U,V,W
3d arrays. I have found some sample code which uses the evtk package to write
a .vti file.(<http://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python>)

The problem is that the sample code and built in functions only take scalar
point or cell data. So I am able to write a file with scalars, but I need it
to have the data as vectors.

I am digging through the actual package files and trying to find a solution or
tools to code one.I would extremely appreciate if somebody had suggestions or
solutions to give me a hand.

I enclose the test code I have written from info on the wiki just in case I am
missing a way of inputing to the function, but I fear I am going to need to
start from scratch.

Thanks in advance

(removed the code since the one bellow is more recent)

Managed to write an unstructured file (.vtu), but I would really like to be a
able to write an Image Data file.(Found the following link helpful during the
process.
<http://www.aero.iitb.ac.in/~prabhu/tmp/python_cep07/course_handouts/viz3d_handout.pdf>)

Thanks again in advance

I attach the code to see if anybody has any suggestions.

    
    
    from tvtk.api import tvtk, write_data
    

import numpy as N

    
    
    ##Generation of data
    #array of x,y,z coordinates
    [Z,Y,X] = N.mgrid[-2.:2+1, -2.:2+1, -2.:2+1]
    #array of zeros to add the u,v,w components 
    [W,V,U] = N.zeros_like([Z,Y,X],dtype=float) 
    #loop through data to have correct format
    points = N.array([N.zeros(3) for i in range(len(Z)*len(Z[0])*len(Z[0][0]))])
    velF = N.zeros_like(points)
    c=0
    for k in range(len(Z)):
        for j in range(len(Z[0])):
            for i in range(len(Z[0][0])):
                #coordinates of point
                x = X[k][j][i]
                y = Y[k][j][i]
                z = Z[k][j][i]
                points[c] = N.array([x,y,z])
                #test velocity field               
                u = k -2.
                v = 0.
                w = 0.
                velF[c] = N.array([u,v,w])
                #update counter            
                c = c+1
    ##Generate and write the vtk file    
    Ugrid = tvtk.UnstructuredGrid()
    Ugrid.points = points
    Ugrid.point_data.vectors = velF
    Ugrid.point_data.vectors.name = 'velocity'
    write_data(Ugrid, 'vtktest.vtu')
    


Answer: If you want to write the unstructured grids using **evtk** , here you can find
a full demo with point and cell data (both vector and scalar fields):
<https://gist.github.com/dromanov/0fb8bacff5342a56a690>.

Description of the technique and explanations are here:
<http://spikard.blogspot.ru/2015/07/visualization-of-unstructured-grid-
data.html>.

Good luck!

