some polishing (numpy —> np, theTable —> table)
This commit is contained in:
parent
0bc3eacbd6
commit
0077177c05
|
@ -64,14 +64,14 @@ else:
|
||||||
for file in files:
|
for file in files:
|
||||||
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
||||||
|
|
||||||
theTable = damask.ASCIItable(file['input'],file['output'],labels=False)
|
table = damask.ASCIItable(file['input'],file['output'],labels=False)
|
||||||
theTable.head_read()
|
table.head_read()
|
||||||
|
|
||||||
#--- interpret header ----------------------------------------------------------------------------
|
#--- interpret header ----------------------------------------------------------------------------
|
||||||
info = {
|
info = {
|
||||||
'grid': numpy.zeros(3,'i'),
|
'grid': np.zeros(3,'i'),
|
||||||
'size': numpy.zeros(3,'d'),
|
'size': np.zeros(3,'d'),
|
||||||
'origin': numpy.zeros(3,'d'),
|
'origin': np.zeros(3,'d'),
|
||||||
'homogenization': 0,
|
'homogenization': 0,
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ for file in files:
|
||||||
}
|
}
|
||||||
extra_header = []
|
extra_header = []
|
||||||
|
|
||||||
for header in theTable.info:
|
for header in table.info:
|
||||||
headitems = map(str.lower,header.split())
|
headitems = map(str.lower,header.split())
|
||||||
if len(headitems) == 0: continue
|
if len(headitems) == 0: continue
|
||||||
if headitems[0] in mappings.keys():
|
if headitems[0] in mappings.keys():
|
||||||
|
@ -99,19 +99,19 @@ for file in files:
|
||||||
'homogenization: %i\n'%info['homogenization'] + \
|
'homogenization: %i\n'%info['homogenization'] + \
|
||||||
'microstructures: %i\n'%info['microstructures'])
|
'microstructures: %i\n'%info['microstructures'])
|
||||||
|
|
||||||
if numpy.any(info['grid'] < 1):
|
if np.any(info['grid'] < 1):
|
||||||
file['croak'].write('invalid grid a b c.\n')
|
file['croak'].write('invalid grid a b c.\n')
|
||||||
continue
|
continue
|
||||||
if numpy.any(info['size'] <= 0.0):
|
if np.any(info['size'] <= 0.0):
|
||||||
file['croak'].write('invalid size x y z.\n')
|
file['croak'].write('invalid size x y z.\n')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#--- read data ------------------------------------------------------------------------------------
|
#--- read data ------------------------------------------------------------------------------------
|
||||||
microstructure = numpy.zeros(info['grid'].prod(),'i')
|
microstructure = np.zeros(info['grid'].prod(),'i')
|
||||||
i = 0
|
i = 0
|
||||||
theTable.data_rewind()
|
table.data_rewind()
|
||||||
while theTable.data_read():
|
while table.data_read():
|
||||||
items = theTable.data
|
items = table.data
|
||||||
if len(items) > 2:
|
if len(items) > 2:
|
||||||
if items[1].lower() == 'of': items = [int(items[2])]*int(items[0])
|
if items[1].lower() == 'of': items = [int(items[2])]*int(items[0])
|
||||||
elif items[1].lower() == 'to': items = xrange(int(items[0]),1+int(items[2]))
|
elif items[1].lower() == 'to': items = xrange(int(items[0]),1+int(items[2]))
|
||||||
|
@ -127,7 +127,7 @@ for file in files:
|
||||||
if options.offset == 0:
|
if options.offset == 0:
|
||||||
options.offset = microstructure.max()
|
options.offset = microstructure.max()
|
||||||
|
|
||||||
microstructure = numpy.where(ndimage.filters.maximum_filter(microstructure,size=1+2*options.vicinity,mode='wrap') ==
|
microstructure = np.where(ndimage.filters.maximum_filter(microstructure,size=1+2*options.vicinity,mode='wrap') ==
|
||||||
ndimage.filters.minimum_filter(microstructure,size=1+2*options.vicinity,mode='wrap'),
|
ndimage.filters.minimum_filter(microstructure,size=1+2*options.vicinity,mode='wrap'),
|
||||||
microstructure, microstructure + options.offset)
|
microstructure, microstructure + options.offset)
|
||||||
|
|
||||||
|
@ -136,9 +136,9 @@ for file in files:
|
||||||
file['croak'].write('--> microstructures: %i\n'%newInfo['microstructures'])
|
file['croak'].write('--> microstructures: %i\n'%newInfo['microstructures'])
|
||||||
|
|
||||||
#--- write header ---------------------------------------------------------------------------------
|
#--- write header ---------------------------------------------------------------------------------
|
||||||
theTable.labels_clear()
|
table.labels_clear()
|
||||||
theTable.info_clear()
|
table.info_clear()
|
||||||
theTable.info_append(extra_header+[
|
table.info_append(extra_header+[
|
||||||
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
||||||
"grid\ta %i\tb %i\tc %i"%(info['grid'][0],info['grid'][1],info['grid'][2],),
|
"grid\ta %i\tb %i\tc %i"%(info['grid'][0],info['grid'][1],info['grid'][2],),
|
||||||
"size\tx %f\ty %f\tz %f"%(info['size'][0],info['size'][1],info['size'][2],),
|
"size\tx %f\ty %f\tz %f"%(info['size'][0],info['size'][1],info['size'][2],),
|
||||||
|
@ -146,13 +146,13 @@ for file in files:
|
||||||
"homogenization\t%i"%info['homogenization'],
|
"homogenization\t%i"%info['homogenization'],
|
||||||
"microstructures\t%i"%(newInfo['microstructures']),
|
"microstructures\t%i"%(newInfo['microstructures']),
|
||||||
])
|
])
|
||||||
theTable.head_write()
|
table.head_write()
|
||||||
theTable.output_flush()
|
table.output_flush()
|
||||||
|
|
||||||
# --- write microstructure information ------------------------------------------------------------
|
# --- write microstructure information ------------------------------------------------------------
|
||||||
formatwidth = int(math.floor(math.log10(microstructure.max())+1))
|
formatwidth = int(math.floor(math.log10(microstructure.max())+1))
|
||||||
theTable.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
|
table.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
|
||||||
theTable.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
|
table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
|
||||||
|
|
||||||
#--- output finalization --------------------------------------------------------------------------
|
#--- output finalization --------------------------------------------------------------------------
|
||||||
if file['name'] != 'STDIN':
|
if file['name'] != 'STDIN':
|
||||||
|
|
Loading…
Reference in New Issue