Skip to content
Snippets Groups Projects
Commit 754469ec authored by Tom Fischer's avatar Tom Fischer
Browse files

script for merging two scalar data arrays into a 2d data array.

parent 6dbd3c0e
No related branches found
No related tags found
1 merge request!1script for merging two scalar data arrays into a 2d data array.
#!/usr/bin/env python2
from vtk import *
from sys import argv, exit
if len(argv) < 6:
print "Usage:", argv[0], "input.vtu scalar1 scalar2 vector_2d output.vtu"
exit(1)
input_file = argv[1]
output_file = argv[5]
print("Reading from", input_file)
print("Writing to", output_file)
r = vtkXMLUnstructuredGridReader()
r.SetFileName(input_file)
r.Update()
m = r.GetOutput()
point_data = m.GetPointData()
scalar_array_1 = point_data.GetArray(argv[2])
scalar_array_2 = point_data.GetArray(argv[3])
new_array = vtkDoubleArray()
new_array.SetNumberOfComponents(2)
new_array.SetNumberOfTuples(scalar_array_1.GetNumberOfTuples())
new_array.SetName(argv[4])
new_array.CopyComponent(0, scalar_array_1, 0)
new_array.CopyComponent(1, scalar_array_2, 0)
point_data.AddArray(new_array)
point_data.RemoveArray(argv[2])
point_data.RemoveArray(argv[3])
w = vtkXMLUnstructuredGridWriter()
w.SetFileName(output_file)
w.SetInputData(m)
w.SetDataModeToAscii()
w.SetCompressorTypeToNone()
w.Update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment