Skip to content
Snippets Groups Projects
Commit 79f6be6b authored by Tom Fischer's avatar Tom Fischer Committed by GitHub
Browse files

Merge pull request #1 from ufz/MergeDataArrays

script for merging two scalar data arrays into a 2d data array.
parents 2cc3dcc9 f5094c4a
No related branches found
No related tags found
No related merge requests found
Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the OpenGeoSys Community.
4. Neither the name of the OpenGeoSys Community nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
5. Attribute the OpenGeoSys Community, preferably citing an appropriate
paper listed on the OpenGeoSys Community homepage:
http://www.opengeosys.org/papers
THIS SOFTWARE IS PROVIDED BY THE OpenGeoSys Community ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE OpenGeoSys Community BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# \copyright
# Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
# Distributed under a Modified BSD License.
# See accompanying file LICENSE.txt or
# http://www.opengeosys.org/project/license
#
#!/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