From 4ff3efb1a56b45ff73bca70cdd8fd92a87f6299f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 13 Jun 2019 23:14:40 +0200 Subject: [PATCH] to 'stack' tables --- processing/post/addTable.py | 8 +-- processing/post/concatenateTable.py | 79 +++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 3 deletions(-) create mode 100755 processing/post/concatenateTable.py diff --git a/processing/post/addTable.py b/processing/post/addTable.py index eb61b43dc..7af1dcf35 100755 --- a/processing/post/addTable.py +++ b/processing/post/addTable.py @@ -1,19 +1,21 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- -import os,sys +import os +import sys from optparse import OptionParser + import damask scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ -Append data of ASCIItable(s). +Append data of ASCIItable(s) column-wise. """, version = scriptID) diff --git a/processing/post/concatenateTable.py b/processing/post/concatenateTable.py new file mode 100755 index 000000000..361ea5764 --- /dev/null +++ b/processing/post/concatenateTable.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +import os +import sys +from optparse import OptionParser + +import numpy as np + +import damask + +scriptName = os.path.splitext(os.path.basename(__file__))[0] +scriptID = ' '.join([scriptName,damask.version]) + + +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- + +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ +Append data of ASCIItable(s) row-wise. + +""", version = scriptID) + +parser.add_option('-a', '--add','--table', + dest = 'table', + action = 'extend', metavar = '', + help = 'tables to add') + +(options,filenames) = parser.parse_args() + +if options.table is None: + parser.error('no table specified.') + + +# --- loop over input files ------------------------------------------------------------------------- + +if filenames == []: filenames = [None] + +for name in filenames: + try: table = damask.ASCIItable(name = name, + buffered = False) + except: continue + + damask.util.report(scriptName,name) + + tables = [] + for addTable in options.table: + try: tables.append(damask.ASCIItable(name = addTable, + buffered = False, + readonly = True) + ) + except: continue + +# ------------------------------------------ read headers ------------------------------------------ + + table.head_read() + for addTable in tables: addTable.head_read() + +# ------------------------------------------ assemble header -------------------------------------- + + table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) + + table.head_write() + +# ------------------------------------------ process data ------------------------------------------ + + table.data_readArray() + data = table.data + for addTable in tables: + addTable.data_readArray(table.labels(raw = True)) + data = np.vstack((data,addTable.data)) + table.data = data + table.data_writeArray() + +# ------------------------------------------ output finalization ----------------------------------- + + table.close() # close ASCII tables + for addTable in tables: + addTable.close()