question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving numpy meshgrid to vtk file

See original GitHub issue

I am looking through vtkplotter examples to find an example on how to write a numpy array as a structured grid to a VTK file. But unfortunately, I couldn’t find it.

  • Is it possible to write a vtk file from a numpy array? Here is an example:
import numpy as np

X, Y = np.meshgrid(np.linspace(0, 2, 10), np.linspace(0, 1, 5))
x = X.ravel()
y = Y.ravel()
z = np.zeros_like(x)

# Is it possible to use vtkplotter to save these arrays (x,  y, z) as  a vtk file assuming a structured topology?

The expected result is a vtk file as shown here:

vtkfile

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Dec 18, 2019

Thank you very much 🥇 🥇 🥇

0reactions
marcomusycommented, Dec 18, 2019

I’ve integrated this functionality in shapes.Grid, so from the next release on you can do things like:

from vtkplotter import *

xcoords = arange(0, 2, 0.2)
ycoords = arange(0, 1,  0.2)
sqrtx = sqrt(xcoords)

grid = Grid(sx=sqrtx, sy=ycoords)
grid.show(axes=8, bg='w')

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving numpy meshgrid to vtk file · Issue #86 · marcomusy/vedo
I am looking through vtkplotter examples to find an example on how to write a numpy array as a structured grid to a...
Read more >
Exporting a 3D numpy to a VTK file for viewing in Paraview ...
Therefore my question is: How can one use the from vtk.util import numpy_support function to export a 3D array (the function itself doesn't...
Read more >
Converting your NumPy arrays to VTK arrays and files
The first way is using the vtk.util.numpy_support module that comes with VTK and allows you to 'easily' convert your data. The second way...
Read more >
Read/write VTK files (Unstructured grid with data)
Read/write VTK files (Unstructured grid with data) ; In [1]:. import numpy as np ; In [17]:. def create_cell_scalars(ncells): ; In [30]:. writer...
Read more >
How to convert 3D numpy array to vtk and save the .vtk file?
I have a scalar volume (3D numpy array) 1646504309(1) I want to add some information describing the image and then save it as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found