2019-02-15 03:26:39 +05:30
|
|
|
#!/usr/bin/env python3
|
2015-08-21 01:10:45 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-22 00:48:33 +05:30
|
|
|
from io import StringIO
|
2015-08-21 01:10:45 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2015-08-21 01:10:45 +05:30
|
|
|
import damask
|
|
|
|
|
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])
|
2015-08-21 01:10:45 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2015-08-21 01:10:45 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2015-08-21 01:10:45 +05:30
|
|
|
Add cumulative (sum of first to current row) values for given label(s).
|
|
|
|
""", version = scriptID)
|
|
|
|
|
|
|
|
parser.add_option('-l','--label',
|
2019-12-22 00:48:33 +05:30
|
|
|
dest='labels',
|
2015-08-21 01:10:45 +05:30
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'columns to cumulate')
|
2019-10-17 22:49:51 +05:30
|
|
|
parser.add_option('-p','--product',
|
|
|
|
dest='product', action = 'store_true',
|
|
|
|
help = 'product of values instead of sum')
|
|
|
|
|
2015-08-21 01:10:45 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2019-12-22 00:48:33 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-21 01:10:45 +05:30
|
|
|
|
2019-12-22 00:48:33 +05:30
|
|
|
if options.labels is None:
|
2015-08-21 01:10:45 +05:30
|
|
|
parser.error('no data column(s) specified.')
|
|
|
|
|
|
|
|
for name in filenames:
|
2019-12-22 00:48:33 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-21 01:10:45 +05:30
|
|
|
|
2019-12-22 00:48:33 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
for label in options.labels:
|
|
|
|
table.add('cum_{}({})'.format('prod' if options.product else 'sum',label),
|
|
|
|
np.cumprod(table.get(label),0) if options.product else np.cumsum(table.get(label),0),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2015-08-21 01:10:45 +05:30
|
|
|
|
2020-09-03 20:49:19 +05:30
|
|
|
table.to_file(sys.stdout if name is None else name)
|