DAMASK_EICMD/processing/post/shiftData.py

52 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
2019-11-27 17:01:32 +05:30
from io import StringIO
from optparse import OptionParser
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
2019-02-17 12:30:26 +05:30
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
Uniformly shift column values by given offset.
""", version = scriptID)
parser.add_option('-l','--label',
2019-12-05 15:07:13 +05:30
dest = 'labels',
action = 'extend', metavar = '<string LIST>',
help ='column(s) to shift')
parser.add_option('-o','--offset',
dest = 'offset',
action = 'extend', metavar='<float LIST>',
help = 'offset(s) per column')
parser.set_defaults(label = [],
2019-12-05 15:07:13 +05:30
offset = [])
(options,filenames) = parser.parse_args()
2019-11-27 17:01:32 +05:30
if filenames == []: filenames = [None]
if len(options.label) != len(options.offset):
2019-11-27 17:01:32 +05:30
parser.error('number of column labels and offsets do not match.')
for name in filenames:
2019-11-27 17:01:32 +05:30
damask.util.report(scriptName,name)
2019-11-27 17:01:32 +05:30
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
2019-12-05 15:07:13 +05:30
for i,label in enumerate(options.labels):
2019-12-05 10:40:27 +05:30
table.set(label,
table.get(label)+float(options.offset[i]),
scriptID+' '+' '.join(sys.argv[1:]))
2019-11-27 17:01:32 +05:30
table.to_ASCII(sys.stdout if name is None else name)