From 8bf7a7ef6a6a6a9ec8db5c4d2ecd845885276958 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 10 May 2015 10:58:32 +0000 Subject: [PATCH] some beautifications --- processing/post/rotateData.py | 15 ++++++--------- processing/post/showTable.py | 29 +++++++++++++++++------------ processing/post/tagLabel.py | 3 +-- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/processing/post/rotateData.py b/processing/post/rotateData.py index 6b3d2357c..de68d57ab 100755 --- a/processing/post/rotateData.py +++ b/processing/post/rotateData.py @@ -20,16 +20,13 @@ Rotate vector and/or tensor column data by given angle around given axis. """, version = scriptID) parser.add_option('-v','--vector', dest = 'vector', action = 'extend', metavar = '', - help = 'column heading of vector to rotate') + help = 'column heading of vector to rotate') parser.add_option('-t','--tensor', dest = 'tensor', action = 'extend', metavar = '', - help = 'column heading of tensor to rotate') + help = 'column heading of tensor to rotate') parser.add_option('-r', '--rotation',dest = 'rotation', type = 'float', nargs = 4, metavar = ' '.join(['float']*4), - help = 'angle and axis to rotate data %default') + help = 'angle and axis to rotate data [%default]') parser.add_option('-d', '--degrees', dest = 'degrees', action = 'store_true', - help = 'angles are given in degrees [%default]') - -parser.set_defaults(vector = []) -parser.set_defaults(tensor = []) + help = 'angles are given in degrees [%default]') parser.set_defaults(rotation = (0.,1.,1.,1.)) # no rotation about 1,1,1 parser.set_defaults(degrees = False) @@ -42,8 +39,8 @@ datainfo = { 'label':[]}, } -if options.vector != []: datainfo['vector']['label'] += options.vector -if options.tensor != []: datainfo['tensor']['label'] += options.tensor +if options.vector != None: datainfo['vector']['label'] += options.vector +if options.tensor != None: datainfo['tensor']['label'] += options.tensor toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians r = damask.Quaternion().fromAngleAxis(toRadians*options.rotation[0],options.rotation[1:]) diff --git a/processing/post/showTable.py b/processing/post/showTable.py index 0319cd167..98df1f49e 100755 --- a/processing/post/showTable.py +++ b/processing/post/showTable.py @@ -18,17 +18,22 @@ Show components of given ASCIItable(s). """, version = scriptID) -parser.add_option('-a','--head', dest='head', action='store_true', help='output all heading (info + labels)') -parser.add_option('-i','--info', dest='info', action='store_true', help='output info lines') -parser.add_option('-l','--labels', dest='labels', action='store_true', help='output labels') -parser.add_option('-d','--data', dest='data', action='store_true', help='output data') -parser.add_option('-c','--column', dest='col', action='store_true', help='switch to label column format') -parser.add_option('--nolabels', dest='nolabels', action='store_true', help='table has no labels') - +parser.add_option('-a','--head', dest='head', action='store_true', + help='output all heading (info + labels)') +parser.add_option('-i','--info', dest='info', action='store_true', + help='output info lines') +parser.add_option('-l','--labels', dest='labels', action='store_true', + help='output labels') +parser.add_option('-d','--data', dest='data', action='store_true', + help='output data') +parser.add_option('-c','--column', dest='col', action='store_true', + help='switch to label column format') +parser.add_option('--nolabels', dest='nolabels', action='store_true', + help='table has no labels') parser.set_defaults(col = False) parser.set_defaults(nolabels = False) -(options,filenames) = parser.parse_args() +(options,filenames) = parser.parse_args() # ------------------------------------------ setup file handles --------------------------------------- @@ -46,16 +51,16 @@ for file in files: if file['name'] != 'STDIN': file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n') else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n') - table = damask.ASCIItable(file['input'],file['output'],buffered=False,labels=not options.nolabels) # make unbuffered ASCII_table - table.head_read() # read ASCII header info + table = damask.ASCIItable(file['input'],file['output'],buffered=False,labels=not options.nolabels)# make unbuffered ASCII_table + table.head_read() # read ASCII header info if options.head or options.info: file['output'].write('\n'.join(table.info)+'\n') if options.head or options.labels: file['output'].write({True:'\n',False:'\t'}[options.col].join(table.labels)+'\n') # ------------------------------------------ output data --------------------------------------- outputAlive = options.data - while outputAlive and table.data_read(): # read next data line of ASCII table - outputAlive = table.data_write() # output line + while outputAlive and table.data_read(): # read next data line of ASCII table + outputAlive = table.data_write() # output line outputAlive and table.output_flush() diff --git a/processing/post/tagLabel.py b/processing/post/tagLabel.py index 0c7cbb591..67dcececa 100755 --- a/processing/post/tagLabel.py +++ b/processing/post/tagLabel.py @@ -79,8 +79,7 @@ for file in files: else: # tag individual candidates for datatype,info in datainfo.items(): for label in info['label']: - key = {True :'1_%s', - False:'%s' }[info['len']>1]%label + key = '1_%s' if [info['len']>1]%label else '%' if key not in table.labels: sys.stderr.write('column %s not found...\n'%key) else: