Exemplo n.º 1
0
 def test_05NodeValue(self):
     import numpy
     import CGNS.PAT.cgnsutils as CGU
     import CGNS.PAT.cgnserrors as CGE
     import CGNS.PAT.cgnskeywords as CGK
     self.genTree()
     v = CGU.getValueByPath(self.T, '/CGNSTree/CGNSLibraryVersion')
     self.assertEqual(v, numpy.array(3.2))
     n = ['ZoneType', numpy.array(['S', 't', 'r', 'u', 'c', 't', 'u', 'r', 'e', 'd'], dtype='S', order='C'), [],
          'ZoneType_t']
     self.assertTrue(CGU.stringValueMatches(n, 'Structured'))
     # set*AsArray
     self.assertEqual(CGU.setStringAsArray('Structured').tostring().decode('ascii'), 'Structured')
     self.assertEqual(CGU.setIntegerAsArray(1), numpy.array(1, dtype='int32'))
     self.assertTrue((CGU.setIntegerAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='int32')).all())
     self.assertEqual(CGU.setLongAsArray(1), numpy.array(1, dtype='int64'))
     self.assertTrue((CGU.setLongAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='int64')).all())
     self.assertEqual(CGU.setFloatAsArray(1), numpy.array(1, dtype='float32'))
     self.assertTrue((CGU.setFloatAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='float32')).all())
     self.assertEqual(CGU.setDoubleAsArray(1), numpy.array(1, dtype='float64'))
     self.assertTrue((CGU.setDoubleAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='float64')).all())
     self.assertTrue((CGU.setDoubleAsArray(tuple(range(10, 1010, 10))) == numpy.array(tuple(range(10, 1010, 10)),
                                                                                      dtype='float64')).all())
     n = ['ZoneType', None, [], 'ZoneType_t']
     # set*ByPath
     self.assertTrue(CGU.stringValueMatches(CGU.setStringByPath(n, '/', 'Structured'), 'Structured'))
     self.assertEqual(CGU.setIntegerByPath(n, '/', 1)[1], numpy.array(1, dtype='int32'))
     self.assertTrue(numpy.array_equal(CGU.setIntegerByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='int32')))
     self.assertEqual(CGU.setLongByPath(n, '/', 1)[1], numpy.array(1, dtype='int64'))
     self.assertTrue(numpy.array_equal(CGU.setLongByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='int64')))
     self.assertEqual(CGU.setFloatByPath(n, '/', 1)[1], numpy.array(1, dtype='float32'))
     self.assertTrue(numpy.array_equal(CGU.setFloatByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='float32')))
     self.assertEqual(CGU.setDoubleByPath(n, '/', 1)[1], numpy.array(1, dtype='float64'))
     self.assertTrue(numpy.array_equal(CGU.setDoubleByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='float64')))
     self.assertTrue(numpy.array_equal(CGU.setDoubleByPath(n, '/', range(10, 1010, 10))[1],
                                       numpy.array([range(10, 1010, 10)], dtype='float64')))
Exemplo n.º 2
0
import CGNS.PAT.cgnskeywords as CGK

import time

# - load a single node in a tree
#   Nothing else but the target node and its ancestors are load
#   You load what you need, see below to get tree structure without data

path = '/Disk/zone1/GridCoordinates/CoordinateZ'
(tree, lk) = CGNS.MAP.load("data/T0.cgns", CGNS.MAP.S2P_DEFAULT, 0, path, [], None)
print(tree)
print('-' * 50)

updict = {}
path = '/Disk/zone1/GridCoordinates/CoordinateZ'
updict[path] = CGU.getValueByPath(tree, path)
path = '/Disk/zone2/GridCoordinates/CoordinateX'
updict[path] = CGU.getValueByPath(tree, path)

(tree, lk) = CGNS.MAP.load("data/T0.cgns", CGNS.MAP.S2P_DEFAULT, 0, None, [], updict)
print(tree)
print('-' * 50)

# - load only up to argument depth
#   Useful in case you only want the layout of the tree, if you want to
#   make links to already existing trees
#   If you set depth to 0 there is no depth limit
#   A level of 1 means only CGNSTree_t
#   A level of 2 means CGNSLibraryVersion_t, CGNSBase_t...
#   and so on
depth = 3