Filter: partial reading/writing of files
Preamble
This module provides services for partially reading or writing cgns files (HDF or ADF).
To use the module:
import Converter.Filter as Filter
List of functions
– Low layer
Converter.Filter.convertFile2SkeletonTree (…) |
Read a file and return a skeleton tree. |
Converter.Filter.readNodesFromPaths (…[, …]) |
Read nodes from file given their paths. |
Converter.Filter.writeNodesFromPaths (…[, …]) |
Write nodes to file given their paths. |
Converter.Filter.deletePaths (fileName, paths) |
Delete paths in file given their paths. |
– High layer
Contents
Per node reading/writing
-
Converter.Filter.
convertFile2SkeletonTree
(fileName, format=None, maxFloatSize=5, maxDepth=-1) Read a skeleton tree. If float data array size of DataArray_t type nodes is lower than maxFloatSize then the array is loaded. Otherwise it is set to None. If maxDepth is specified, load is limited to maxDepth levels.
Parameters: - fileName (string) – file name to read from
- format (string) – bin_cgns, bin_adf, bin_hdf (optional)
- maxFloatSize (int) – the maxSize of float array to load
- maxDepth (int) – max depth of load
Returns: Skeleton tree
Return type: pyTree node
Example of use:
# - convertFile2SkeletonTree (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Converter.Mpi as Cmpi import Converter.Internal as Internal if Cmpi.rank == 0: a = G.cart((0.,0.,0.),(0.1,0.1,0.1),(11,11,11)) t = C.newPyTree(['Base', a]) C.convertPyTree2File(t, 'in.cgns') Cmpi.barrier() t1 = Cmpi.convertFile2SkeletonTree('in.cgns'); Internal.printTree(t1) #>> ['CGNSTree',None,[2 sons],'CGNSTree_t'] #>> |_['CGNSLibraryVersion',array([3.0999999046325684],dtype='float64'),[0 son],'CGNSLibraryVersion_t'] #>> |_['Base',array(shape=(2,),dtype='int32',order='F'),[1 son],'CGNSBase_t'] #>> |_['cart',array(shape=(3, 3),dtype='int32',order='F'),[2 sons],'Zone_t'] #>> |_['ZoneType',array('Structured',dtype='|S1'),[0 son],'ZoneType_t'] #>> |_['GridCoordinates',None,[3 sons],'GridCoordinates_t'] #>> |_['CoordinateX',None,[0 son],'DataArray_t'] #>> |_['CoordinateY',None,[0 son],'DataArray_t'] #>> |_['CoordinateZ',None,[0 son],'DataArray_t']
-
Converter.Filter.
readNodesFromPaths
(fileName, paths, format=None, maxFloatSize=-1, maxDepth=-1) Read nodes specified by their paths.
Parameters: - fileName (string) – file name to read from
- paths (list of strings) – paths to read
- format (string) – bin_cgns, bin_adf, bin_hdf (optional)
- maxFloatSize (int) – the maxSize of float array to load
- maxDepth (int) – max depth of load
Returns: read nodes
Return type: pyTree node list
Example of use:
# - readNodesFromPaths (pyTree) - import Converter.PyTree as C import Converter.Filter as Filter import Converter.Internal as Internal import Generator.PyTree as G # Cree le fichier test a = G.cart((0,0,0), (1,1,1), (10,10,10)) b = G.cart((12,0,0), (1,1,1), (10,10,10)) t = C.newPyTree(['Base',a,b]) C.convertPyTree2File(t, 'test.hdf') # Relit les noeuds par leur paths nodes = Filter.readNodesFromPaths('test.hdf', ['CGNSTree/Base/cart/GridCoordinates']) Internal.printTree(nodes)
-
Converter.Filter.
writeNodesFromPaths
(fileName, paths, nodes, format=None, maxDepth=-1, mode=0) Write given nodes to specified paths in file. If mode=0 (append), nodes are appened to path location. If mode=1 (replace), nodes are replaced to path location. If maxDepth>0, replace mode kill children of replaced node. If maxDepth=0, replace mode replace value and type of node (not the name).
Parameters: - fileName (string) – file name to write to
- paths (list of strings) – paths to write to
- nodes (list of pyTree nodes) – nodes to write
- format (string) – bin_cgns, bin_adf, bin_hdf (optional)
- maxDepth (int) – max depth to write
- mode – writing mode (0: append, 1: replace)
Type: int
Example of use:
# - writeNodesFromPaths (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Converter.Filter as Filter t = C.newPyTree(['Base']) C.convertPyTree2File(t, 'out.adf') # Append a = G.cart((0,0,0), (1,1,1), (10,10,10)) Filter.writeNodesFromPaths('out.adf', 'CGNSTree/Base', a) # Append and replace a = G.cart((1,1,1), (1,1,1), (10,10,10)); a[0] = 'cart' Filter.writeNodesFromPaths('out.adf', 'CGNSTree/Base', a)
-
Converter.Filter.
_readPyTreeFromPaths
(a, fileName, paths, format=None, maxFloatSize=-1, maxDepth=-1) Read nodes specified by their paths and stored it in a (in place).
Parameters: - a ([pyTree, base, Zone, list of Zones]) – input data
- fileName (string) – file name to read from
- paths (list of strings) – paths to read (relative to a)
- format (string) – bin_cgns, bin_adf, bin_hdf (optional)
- maxFloatSize (int) – the maxSize of float array to load
- maxDepth (int) – max depth of load
Example of use:
# - readPyTreeFromPaths (pyTree) - import Converter.PyTree as C import Converter.Filter as Filter import Converter.Internal as Internal import Generator.PyTree as G # Cree le fichier test a = G.cart((0,0,0), (1,1,1), (10,10,10)) b = G.cart((12,0,0), (1,1,1), (10,10,10)) t = C.newPyTree(['Base',a,b]) C.convertPyTree2File(t, 'test.adf') t = Filter.convertFile2SkeletonTree('test.adf', maxDepth=3) # Complete t par leur paths Filter._readPyTreeFromPaths(t, 'test.adf', ['/Base/cart/GridCoordinates', 'Base/cart.0/GridCoordinates']) Internal.printTree(t) C.convertPyTree2File(t, 'out.cgns')
-
Converter.Filter.
deletePaths
(fileName, paths, format=None) Delete paths in file.
Parameters: - fileName (string) – file name to read from
- paths (list of strings) – paths to read (relative to a)
- format (string) – bin_cgns, bin_adf, bin_hdf (optional)
Example of use:
# - deletePaths (pyTree) - import Converter.PyTree as C import Converter.Filter as Filter t = C.newPyTree(['Base']) C.convertPyTree2File(t, 'out.adf') # Delete paths Filter.deletePaths('out.adf', 'CGNSTree/Base')