Incorrect array rebuild vtk-> numpy?

I am reading uniform VTK grid in python. When I look at a piece of data in Paraview, I get the following (correct) image:

VTK screenshot

Then I visualize the slice using numpy and pylab using the following script:

import vtk from vtk.util.numpy_support import vtk_to_numpy import pylab imr=vtk.vtkXMLImageDataReader() imr.SetFileName('flow.vti') imr.Update() im=imr.GetOutput() nx,ny,nz=im.GetDimensions() orig=im.GetOrigin() extent=im.GetExtent() spacing=im.GetSpacing() flowVtk=im.GetPointData().GetArray("|flow|") flow=vtk_to_numpy(flowVtk).reshape(nx,ny,nz) # bottom z-slice flowZ0=flow[:,:,0] # set extent so that axes units are physical img=pylab.imshow(flowZ0,extent=[orig[0],orig[0]+extent[1]*spacing[0],orig[1],orig[1]+extent[3]*spacing[1]],cmap=pylab.gray()) img.set_clim(vmin=0,vmax=1000) pylab.show() 

pylab output

which seems incompatible. I tried resizing in reshape(...) , he did something, but he never showed the data that he should show.

Is there something clearly wrong?

EDIT: I also tried reshape((nx,ny,nz),order="F") (fortran ordering), and now I get a much better image (with a color map of the jets for better clarity) reshape with fortran ordering , which is almost correct, but the data is suspiciously rotated 90 Β°, plus I would like to get some authoritative explanation, which orders to use and why (which one is used by VTK inside?).

EDIT2: to get the same view as in Paraview, I had to do pylab.imshow(np.rot90(flowZ0)) ; I don’t know why, so the question is still open:

fortran and rotated by 90 deg

+6
source share

Source: https://habr.com/ru/post/989513/


All Articles