Merge remote-tracking branch 'origin/addCumulative-option-product' into development
This commit is contained in:
commit
129920cbf8
|
@ -26,6 +26,10 @@ parser.add_option('-l','--label',
|
||||||
action = 'extend', metavar = '<string LIST>',
|
action = 'extend', metavar = '<string LIST>',
|
||||||
help = 'columns to cumulate')
|
help = 'columns to cumulate')
|
||||||
|
|
||||||
|
parser.add_option('-p','--product',
|
||||||
|
dest='product', action = 'store_true',
|
||||||
|
help = 'product of values instead of sum')
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
if options.label is None:
|
if options.label is None:
|
||||||
|
@ -38,8 +42,8 @@ if filenames == []: filenames = [None]
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
try:
|
||||||
table = damask.ASCIItable(name = name,
|
table = damask.ASCIItable(name = name,
|
||||||
buffered = False)
|
buffered = False)
|
||||||
except: continue
|
except IOError: continue
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# ------------------------------------------ read header ------------------------------------------
|
# ------------------------------------------ read header ------------------------------------------
|
||||||
|
@ -52,6 +56,7 @@ for name in filenames:
|
||||||
remarks = []
|
remarks = []
|
||||||
columns = []
|
columns = []
|
||||||
dims = []
|
dims = []
|
||||||
|
how = 'prod' if options.product else 'sum'
|
||||||
|
|
||||||
for what in options.label:
|
for what in options.label:
|
||||||
dim = table.label_dimension(what)
|
dim = table.label_dimension(what)
|
||||||
|
@ -59,8 +64,8 @@ for name in filenames:
|
||||||
else:
|
else:
|
||||||
dims.append(dim)
|
dims.append(dim)
|
||||||
columns.append(table.label_index(what))
|
columns.append(table.label_index(what))
|
||||||
table.labels_append('cum({})'.format(what) if dim == 1 else
|
table.labels_append('cum_{}({})'.format(how,what) if dim == 1 else
|
||||||
['{}_cum({})'.format(i+1,what) for i in range(dim)] ) # extend ASCII header with new labels
|
['{}_cum_{}({})'.format(i+1,how,what) for i in range(dim)] ) # extend ASCII header with new labels
|
||||||
|
|
||||||
if remarks != []: damask.util.croak(remarks)
|
if remarks != []: damask.util.croak(remarks)
|
||||||
if errors != []:
|
if errors != []:
|
||||||
|
@ -76,12 +81,16 @@ for name in filenames:
|
||||||
# ------------------------------------------ process data ------------------------------------------
|
# ------------------------------------------ process data ------------------------------------------
|
||||||
mask = []
|
mask = []
|
||||||
for col,dim in zip(columns,dims): mask += range(col,col+dim) # isolate data columns to cumulate
|
for col,dim in zip(columns,dims): mask += range(col,col+dim) # isolate data columns to cumulate
|
||||||
cumulated = np.zeros(len(mask),dtype=float) # prepare output field
|
cumulated = np.ones(len(mask)) if options.product else np.zeros(len(mask)) # prepare output field
|
||||||
|
|
||||||
outputAlive = True
|
outputAlive = True
|
||||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||||
for i,col in enumerate(mask):
|
if options.product:
|
||||||
cumulated[i] += float(table.data[col]) # cumulate values
|
for i,col in enumerate(mask):
|
||||||
|
cumulated[i] *= float(table.data[col]) # cumulate values (multiplication)
|
||||||
|
else:
|
||||||
|
for i,col in enumerate(mask):
|
||||||
|
cumulated[i] += float(table.data[col]) # cumulate values (addition)
|
||||||
table.data_append(cumulated)
|
table.data_append(cumulated)
|
||||||
|
|
||||||
outputAlive = table.data_write() # output processed line
|
outputAlive = table.data_write() # output processed line
|
||||||
|
|
Loading…
Reference in New Issue