Merge branch 'development' of magit1.mpie.de:damask/DAMASK into development
This commit is contained in:
commit
72da494370
|
@ -41,7 +41,7 @@ parser.add_option('-f','--formula',
|
||||||
|
|
||||||
parser.add_option('-c','--condition',
|
parser.add_option('-c','--condition',
|
||||||
dest = 'condition', metavar='string',
|
dest = 'condition', metavar='string',
|
||||||
help = 'condition to filter rows')
|
help = 'condition to alter existing column data')
|
||||||
|
|
||||||
parser.set_defaults(condition = None,
|
parser.set_defaults(condition = None,
|
||||||
)
|
)
|
||||||
|
@ -77,29 +77,28 @@ for name in filenames:
|
||||||
|
|
||||||
# --------------------------------------- evaluate condition ---------------------------------------
|
# --------------------------------------- evaluate condition ---------------------------------------
|
||||||
if options.condition is not None:
|
if options.condition is not None:
|
||||||
interpolator = []
|
|
||||||
condition = options.condition # copy per file, since might be altered inline
|
condition = options.condition # copy per file, since might be altered inline
|
||||||
breaker = False
|
breaker = False
|
||||||
|
|
||||||
for position,operand in enumerate(set(re.findall(r'#(([s]#)?(.+?))#',condition))): # find three groups
|
for position,(all,marker,column) in enumerate(set(re.findall(r'#(([s]#)?(.+?))#',condition))): # find three groups
|
||||||
condition = condition.replace('#'+operand[0]+'#',
|
idx = table.label_index(column)
|
||||||
{ '': '{%i}'%position,
|
dim = table.label_dimension(column)
|
||||||
's#':'"{%i}"'%position}[operand[1]])
|
if idx < 0 and column not in specials:
|
||||||
if operand[2] in specials: # special label
|
damask.util.croak('column "{}" not found.'.format(column))
|
||||||
interpolator += ['specials["%s"]'%operand[2]]
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
interpolator += ['%s(table.data[%i])'%({ '':'float',
|
|
||||||
's#':'str'}[operand[1]],
|
|
||||||
table.label_index(operand[2]))] # could be generalized to indexrange as array lookup
|
|
||||||
except:
|
|
||||||
damask.util.croak('column "{}" not found.'.format(operand[2]))
|
|
||||||
breaker = True
|
breaker = True
|
||||||
|
else:
|
||||||
|
if column in specials:
|
||||||
|
replacement = 'specials["{}"]'.format(column)
|
||||||
|
elif dim == 1: # scalar input
|
||||||
|
replacement = '{}(table.data[{}])'.format({ '':'float',
|
||||||
|
's#':'str'}[marker],idx) # take float or string value of data column
|
||||||
|
elif dim > 1: # multidimensional input (vector, tensor, etc.)
|
||||||
|
replacement = 'np.array(table.data[{}:{}],dtype=float)'.format(idx,idx+dim) # use (flat) array representation
|
||||||
|
|
||||||
|
condition = condition.replace('#'+all+'#',replacement)
|
||||||
|
|
||||||
if breaker: continue # found mistake in condition evaluation --> next file
|
if breaker: continue # found mistake in condition evaluation --> next file
|
||||||
|
|
||||||
evaluator_condition = "'" + condition + "'.format(" + ','.join(interpolator) + ")"
|
|
||||||
|
|
||||||
# ------------------------------------------ build formulas ----------------------------------------
|
# ------------------------------------------ build formulas ----------------------------------------
|
||||||
|
|
||||||
evaluator = {}
|
evaluator = {}
|
||||||
|
@ -162,7 +161,7 @@ for name in filenames:
|
||||||
|
|
||||||
# -------------------------------------- evaluate formulas -----------------------------------------
|
# -------------------------------------- evaluate formulas -----------------------------------------
|
||||||
|
|
||||||
if options.condition is None or eval(eval(evaluator_condition)): # condition for veteran replacement fulfilled
|
if options.condition is None or eval(condition): # condition for veteran replacement fulfilled
|
||||||
for veteran in veterans: # evaluate formulas that overwrite
|
for veteran in veterans: # evaluate formulas that overwrite
|
||||||
table.data[table.label_index(veteran):
|
table.data[table.label_index(veteran):
|
||||||
table.label_index(veteran)+table.label_dimension(veteran)] = \
|
table.label_index(veteran)+table.label_dimension(veteran)] = \
|
||||||
|
|
|
@ -51,7 +51,7 @@ parser.add_option('-c','--condition',
|
||||||
dest = 'condition', metavar='string',
|
dest = 'condition', metavar='string',
|
||||||
help = 'condition to filter rows')
|
help = 'condition to filter rows')
|
||||||
|
|
||||||
parser.set_defaults(condition = '',
|
parser.set_defaults(condition = None,
|
||||||
)
|
)
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
@ -98,23 +98,29 @@ for name in filenames:
|
||||||
else:
|
else:
|
||||||
order = range(len(labels)) # maintain original order of labels
|
order = range(len(labels)) # maintain original order of labels
|
||||||
|
|
||||||
interpolator = []
|
# --------------------------------------- evaluate condition ---------------------------------------
|
||||||
condition = options.condition # copy per file, might be altered
|
if options.condition is not None:
|
||||||
for position,operand in enumerate(set(re.findall(r'#(([s]#)?(.+?))#',condition))): # find three groups
|
condition = options.condition # copy per file, since might be altered inline
|
||||||
condition = condition.replace('#'+operand[0]+'#',
|
breaker = False
|
||||||
{ '': '{{{}}}' .format(position),
|
|
||||||
's#':'"{{{}}}"'.format(position)}[operand[1]])
|
|
||||||
if operand[2] in specials: # special label ?
|
|
||||||
interpolator += ['specials["{}"]'.format(operand[2])]
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
interpolator += ['{}(table.data[{}])'.format({ '':'float',
|
|
||||||
's#':'str'}[operand[1]],
|
|
||||||
table.label_index(operand[2]))]
|
|
||||||
except:
|
|
||||||
parser.error('column "{}" not found...\n'.format(operand[2]))
|
|
||||||
|
|
||||||
evaluator = "'" + condition + "'.format(" + ','.join(interpolator) + ")"
|
for position,(all,marker,column) in enumerate(set(re.findall(r'#(([s]#)?(.+?))#',condition))): # find three groups
|
||||||
|
idx = table.label_index(column)
|
||||||
|
dim = table.label_dimension(column)
|
||||||
|
if idx < 0 and column not in specials:
|
||||||
|
damask.util.croak('column "{}" not found.'.format(column))
|
||||||
|
breaker = True
|
||||||
|
else:
|
||||||
|
if column in specials:
|
||||||
|
replacement = 'specials["{}"]'.format(column)
|
||||||
|
elif dim == 1: # scalar input
|
||||||
|
replacement = '{}(table.data[{}])'.format({ '':'float',
|
||||||
|
's#':'str'}[marker],idx) # take float or string value of data column
|
||||||
|
elif dim > 1: # multidimensional input (vector, tensor, etc.)
|
||||||
|
replacement = 'np.array(table.data[{}:{}],dtype=float)'.format(idx,idx+dim) # use (flat) array representation
|
||||||
|
|
||||||
|
condition = condition.replace('#'+all+'#',replacement)
|
||||||
|
|
||||||
|
if breaker: continue # found mistake in condition evaluation --> next file
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
# ------------------------------------------ assemble header ---------------------------------------
|
||||||
|
|
||||||
|
@ -129,7 +135,7 @@ for name in filenames:
|
||||||
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
|
||||||
specials['_row_'] += 1 # count row
|
specials['_row_'] += 1 # count row
|
||||||
if condition == '' or eval(eval(evaluator)): # valid row ?
|
if options.condition is None or eval(condition): # valid row ?
|
||||||
table.data = [table.data[position] for position in positions] # retain filtered columns
|
table.data = [table.data[position] for position in positions] # retain filtered columns
|
||||||
outputAlive = table.data_write() # output processed line
|
outputAlive = table.data_write() # output processed line
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue