reworked use of "labels" property to proper methods for access.

This commit is contained in:
Aritra Chakraborty 2016-05-16 19:55:06 -04:00
parent dc6260be58
commit 515b8ee457
6 changed files with 24 additions and 23 deletions

View File

@ -64,10 +64,10 @@ for name in filenames:
errors = []
remarks = []
if table.label_dimension(options.pos) != 3: errors.append('coordinates {} are not a vector.'.format(options.pos))
if table.label_dimension(options.pos) != 3: errors.append('coordinates "{}" are not a vector.'.format(options.pos))
else: colCoord = table.label_index(options.pos)
if table.label_dimension(options.defgrad) != 9: errors.append('deformation gradient {} is not a tensor.'.format(options.defgrad))
if table.label_dimension(options.defgrad) != 9: errors.append('deformation gradient "{}" is not a tensor.'.format(options.defgrad))
else: colF = table.label_index(options.defgrad)
if remarks != []: damask.util.croak(remarks)
@ -96,16 +96,16 @@ for name in filenames:
N = grid.prod()
# --------------- figure out columns to process ---------------------------------------------------
key = '1_%s'%options.defgrad
if key not in table.labels:
file['croak'].write('column %s not found...\n'%key)
key = '1_'+options.defgrad
if table.label_index(key) == -1:
damask.util.croak('column "{}" not found...'.format(key))
continue
else:
column = table.labels.index(key) # remember columns of requested data
column = table.label_index(key) # remember columns of requested data
# ------------------------------------------ assemble header ---------------------------------------
if options.shape: table.labels_append(['shapeMismatch(%s)' %options.defgrad])
if options.volume: table.labels_append(['volMismatch(%s)'%options.defgrad])
if options.shape: table.labels_append(['shapeMismatch({})'.format(options.defgrad)])
if options.volume: table.labels_append(['volMismatch({})'.format(options.defgrad)])
table.head_write()
# ------------------------------------------ read deformation gradient field -----------------------

View File

@ -165,7 +165,8 @@ for name in filenames:
table.info_clear()
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
table.labels = ['bin_%s'%options.data[0],'bin_%s'%options.data[1],'z']
table.labels_clear()
table.labels_append(['bin_%s'%options.data[0],'bin_%s'%options.data[1],'z'])
table.head_write()
# --- output result ---------------------------------------------------------------------------------

View File

@ -63,7 +63,7 @@ for name in filenames:
errors = []
remarks = []
if table.label_dimension(options.pos) != 3: errors.append('coordinates {} are not a vector.'.format(options.pos))
if table.label_dimension(options.pos) != 3: errors.append('coordinates "{}" are not a vector.'.format(options.pos))
else: colCoord = table.label_index(options.pos)
colElem = table.label_index('elem')
@ -96,7 +96,7 @@ for name in filenames:
# ------------------------------------------ process data -------------------------------------------
data = np.zeros(outSize.tolist()+[len(table.labels)])
data = np.zeros(outSize.tolist()+[len(table.labels(raw = True))])
p = np.zeros(3,'i')
for p[2] in xrange(grid[2]):

View File

@ -79,7 +79,7 @@ for name in filenames:
labels = []
positions = []
for position,label in enumerate(table.labels):
for position,label in enumerate(table.labels(raw = True)):
if (options.whitelist is None or any([ position in table.label_indexrange(needle) \
or fnmatch.fnmatch(label,needle) for needle in options.whitelist])) \
and (options.blacklist is None or not any([ position in table.label_indexrange(needle) \
@ -103,17 +103,17 @@ for name in filenames:
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]+'#',
{ '': '{%i}'%position,
's#':'"{%i}"'%position}[operand[1]])
{ '': '{{{}}}' .format(position),
's#':'"{{{}}}"'.format(position)}[operand[1]])
if operand[2] in specials: # special label ?
interpolator += ['specials["%s"]'%operand[2]]
interpolator += ['specials["{}"]'.format(operand[2])]
else:
try:
interpolator += ['%s(table.data[%i])'%({ '':'float',
interpolator += ['{}(table.data[{}])'.format({ '':'float',
's#':'str'}[operand[1]],
table.labels.index(operand[2]))]
table.label_index(operand[2]))]
except:
parser.error('column %s not found...\n'%operand[2])
parser.error('column "{}" not found...\n'.format(operand[2]))
evaluator = "'" + condition + "'.format(" + ','.join(interpolator) + ")"

View File

@ -64,11 +64,11 @@ for name in filenames:
indices = table.label_index (options.label)
dimensions = table.label_dimension(options.label)
for i,index in enumerate(indices):
if index == -1: remarks.append('label {} not present...'.format(options.label[i]))
if index == -1: remarks.append('label "{}" not present...'.format(options.label[i]))
else:
m = pattern[dimensions[i]>1].match(table.labels[index]) # isolate label name
m = pattern[dimensions[i]>1].match(table.tags[index]) # isolate label name
for j in xrange(dimensions[i]):
table.labels[index+j] = table.labels[index+j].replace(m.group(2),options.substitute[i]) # replace name with substitute
table.tags[index+j] = table.tags[index+j].replace(m.group(2),options.substitute[i]) # replace name with substitute
if remarks != []: damask.util.croak(remarks)
if errors != []:

View File

@ -56,7 +56,7 @@ for name in filenames:
table.data_readArray()
keys = table.labels[::-1] if options.keys is None else options.keys[::-1] # numpy sorts with most significant column as last
keys = table.labels(raw = True)[::-1] if options.keys is None else options.keys[::-1] # numpy sorts with most significant column as last
cols = []
remarks = []