From e6cc948ddf8171d1d6c7c57a05f49c1328f6dfb9 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Fri, 11 Aug 2017 15:19:47 -0400 Subject: [PATCH 1/2] added vector-valued conditions and cleaned obsolete code --- processing/post/addCalculation.py | 3 +-- processing/post/filterTable.py | 44 ++++++++++++++++++------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/processing/post/addCalculation.py b/processing/post/addCalculation.py index 66ea66a02..85c52621b 100755 --- a/processing/post/addCalculation.py +++ b/processing/post/addCalculation.py @@ -77,7 +77,6 @@ for name in filenames: # --------------------------------------- evaluate condition --------------------------------------- if options.condition is not None: - interpolator = [] condition = options.condition # copy per file, since might be altered inline breaker = False @@ -162,7 +161,7 @@ for name in filenames: # -------------------------------------- evaluate formulas ----------------------------------------- - if options.condition is None or eval(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 table.data[table.label_index(veteran): table.label_index(veteran)+table.label_dimension(veteran)] = \ diff --git a/processing/post/filterTable.py b/processing/post/filterTable.py index 52d23194b..f513e6bdc 100755 --- a/processing/post/filterTable.py +++ b/processing/post/filterTable.py @@ -51,7 +51,7 @@ parser.add_option('-c','--condition', dest = 'condition', metavar='string', help = 'condition to filter rows') -parser.set_defaults(condition = '', +parser.set_defaults(condition = None, ) (options,filenames) = parser.parse_args() @@ -98,23 +98,29 @@ for name in filenames: else: order = range(len(labels)) # maintain original order of labels - interpolator = [] - condition = options.condition # copy per file, might be altered - for position,operand in enumerate(set(re.findall(r'#(([s]#)?(.+?))#',condition))): # find three groups - condition = condition.replace('#'+operand[0]+'#', - { '': '{{{}}}' .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) + ")" +# --------------------------------------- evaluate condition --------------------------------------- + if options.condition is not None: + condition = options.condition # copy per file, since might be altered inline + breaker = False + + 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 --------------------------------------- @@ -129,7 +135,7 @@ for name in filenames: outputAlive = True while outputAlive and table.data_read(): # read next data line of ASCII table 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 outputAlive = table.data_write() # output processed line From 16445ebf80ef0dd971e7aeee44479d5b51cc355e Mon Sep 17 00:00:00 2001 From: Test User Date: Sat, 12 Aug 2017 17:04:28 +0200 Subject: [PATCH 2/2] [skip ci] updated version information after successful test of v2.0.1-841-ge6cc948 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index a000cbdc4..e3ccc3461 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.1-833-ga28b4b3 +v2.0.1-841-ge6cc948