Hi, I am trying to export a set of points with corresponding value at each point using WriteVTK.jl. More precisely, I am trying to convert following codes given here.
from evtk.hl import pointsToVTK
import numpy as np
npoints = 100
x = np.random.rand(npoints)
y = np.random.rand(npoints)
z = np.random.rand(npoints)
pressure = np.random.rand(npoints)
temp = np.random.rand(npoints)
pointsToVTK("./points", x, y, z, data = {"temp" : temp, "pressure" : pressure})
I have reviewed this WriteVTK page but I could not find corresponding codes for the above python codes.
Any help is appreciated.
Hi, the above Python code exports an unstructured dataset (.vtu format), where each point corresponds to a “vertex” cell.
Unfortunately the equivalent in WriteVTK is a bit more verbose, as there is no direct analogous to pointsToVTK (but feel free to open an issue or PR for that!). For reference you should look at the unstructured datasets section of the README.
The following code is the equivalent to your example in Julia:
using WriteVTK
npoints = 100
x = rand(npoints)
y = rand(npoints)
z = rand(npoints)
pressure = rand(npoints)
temp = rand(npoints)
cells = [MeshCell(VTKCellTypes.VTK_VERTEX, (i, )) for i = 1:npoints]
vtk_grid("./points", x, y, z, cells) do vtk
vtk["pressure", VTKPointData()] = pressure
vtk["temp", VTKPointData()] = temp
end