2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-06-06 20:05:37 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2020-01-15 11:07:53 +05:30
|
|
|
from io import StringIO
|
2014-07-25 01:51:18 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-07-25 01:51:18 +05:30
|
|
|
import damask
|
2014-06-06 20:05:37 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-06-06 20:05:37 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-11-30 03:00:07 +05:30
|
|
|
Add data in column(s) of mapped ASCIItable selected from the row indexed by the value in a mapping column.
|
|
|
|
Row numbers start at 1.
|
2014-06-06 20:05:37 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2014-06-06 20:05:37 +05:30
|
|
|
|
2016-11-30 03:00:07 +05:30
|
|
|
parser.add_option('--index',
|
|
|
|
dest = 'index',
|
2015-08-08 00:33:26 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2016-11-30 03:00:07 +05:30
|
|
|
help = 'column label containing row index')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-o','--offset',
|
|
|
|
dest = 'offset',
|
|
|
|
type = 'int', metavar = 'int',
|
2016-11-30 03:00:07 +05:30
|
|
|
help = 'constant offset for index column value [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-l','--label',
|
|
|
|
dest = 'label',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
2016-11-30 01:14:34 +05:30
|
|
|
help = 'column label(s) to be appended')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-a','--asciitable',
|
|
|
|
dest = 'asciitable',
|
|
|
|
type = 'string', metavar = 'string',
|
2016-11-29 19:59:26 +05:30
|
|
|
help = 'indexed ASCIItable')
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
parser.set_defaults(offset = 0,
|
|
|
|
)
|
2014-06-06 20:05:37 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2020-01-15 11:07:53 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2014-06-06 20:05:37 +05:30
|
|
|
|
2016-03-02 01:41:43 +05:30
|
|
|
if options.label is None:
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.error('no data columns specified.')
|
2016-11-30 03:00:07 +05:30
|
|
|
if options.index is None:
|
|
|
|
parser.error('no index column given.')
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2020-01-15 11:07:53 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2014-06-06 20:05:37 +05:30
|
|
|
|
2020-01-15 11:07:53 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
indexedTable = damask.Table.from_ASCII(options.asciitable)
|
|
|
|
idx = np.reshape(table.get(options.index).astype(int) + options.offset,(-1))-1
|
2020-09-03 20:49:19 +05:30
|
|
|
|
2020-01-15 11:07:53 +05:30
|
|
|
for data in options.label:
|
2020-03-19 01:19:39 +05:30
|
|
|
table.add(data+'_addIndexed',indexedTable.get(data)[idx],scriptID+' '+' '.join(sys.argv[1:]))
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2020-09-03 20:49:19 +05:30
|
|
|
table.to_file(sys.stdout if name is None else name)
|