improved stability for geom_fromAng. no longer depends on correct header information.

geom_fromVPSC with correct size determination now
This commit is contained in:
Yannick Naunheim 2015-06-11 10:06:53 +00:00
parent 40701cedc4
commit c45a0ce55e
3 changed files with 59 additions and 41 deletions

View File

@ -70,47 +70,53 @@ else:
'output':open(name+'_tmp','w'), 'output':open(name+'_tmp','w'),
'croak':sys.stdout, 'croak':sys.stdout,
}) })
#--- loop over input files ------------------------------------------------------------------------ #--- loop over input files ------------------------------------------------------------------------
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')
info = { info = {
'grid': np.ones (3,'i'), 'grid': np.zones(3,'i'),
'size': np.zeros(3,'d'), 'size': np.zeros(3,'d'),
'origin': np.zeros(3,'d'), 'origin': np.zeros(3,'d'),
'microstructures': 0, 'microstructures': 0,
'homogenization': options.homogenization, 'homogenization': options.homogenization
} }
step = [0,0] coords = [{},{},{1:True}]
point = 0 pos = {'min':[ float("inf"), float("inf")],
'max':[-float("inf"),-float("inf")]}
phase = []
eulerangles = []
# --------------- read data -----------------------------------------------------------------------
for line in file['input']: for line in file['input']:
if line.strip():
words = line.split() words = line.split()
if len(words) == 0: continue # ignore empty lines
if words[0] == '#': # process initial comments/header block if words[0] == '#': # process initial comments/header block
if len(words) > 2: if len(words) > 2:
if words[2].lower() == 'hexgrid': if words[2].lower() == 'hexgrid':
file['croak'].write('The file has HexGrid format. Please first convert to SquareGrid...\n') file['croak'].write('The file has HexGrid format. Please first convert to SquareGrid...\n')
break break
if words[1] == 'XSTEP:': step[0] = float(words[2]) else:
if words[1] == 'YSTEP:': step[1] = float(words[2]) currPos = words[3:5]
if words[1] == 'NCOLS_ODD:': # ignore order of NROWS/NCOLS for i in xrange(2):
info['grid'][0] = int(words[2]) coords[i][currPos[i]] = True
eulerangles = np.empty((info['grid'].prod(),3),dtype='f') currPos = map(float,currPos)
phase = np.empty(info['grid'].prod(),dtype='i') for i in xrange(2):
if words[1] == 'NROWS:': # ignore order of NROWS/NCOLS pos['min'][i] = min(pos['min'][i],currPos[i])
info['grid'][1] = int(words[2]) pos['max'][i] = max(pos['max'][i],currPos[i])
eulerangles = np.empty((info['grid'].prod(),3),dtype='f') eulerangles.append(map(math.degrees,map(float,words[:3])))
phase = np.empty(info['grid'].prod(),dtype='i') phase.append(options.phase[int(float(words[options.column-1]) > options.threshold)])
else: # finished with comments block
phase[point] = options.phase[int(float(words[options.column-1]) > options.threshold)] # --------------- determine size and grid ---------------------------------------------------------
eulerangles[point,...] = map(lambda x: math.degrees(float(x)), words[:3]) info['grid'] = np.array(map(len,coords),'i')
point += 1 info['size'][0:2] = info['grid'][0:2]/(info['grid'][0:2]-1.0)* \
np.array([pos['max'][0]-pos['min'][0],
pos['max'][1]-pos['min'][1]],'d')
info['size'][2]=info['size'][0]/info['grid'][0]
eulerangles = np.array(eulerangles,dtype='f').reshape(info['grid'].prod(),3)
phase = np.array(phase,dtype='i').reshape(info['grid'].prod())
if info['grid'].prod() != point:
file['croak'].write('Error: found %s microstructures. Header info in ang file might be wrong.\n'%point)
continue
limits = [360,180,360] limits = [360,180,360]
if any([np.any(eulerangles[:,i]>=limits[i]) for i in [0,1,2]]): if any([np.any(eulerangles[:,i]>=limits[i]) for i in [0,1,2]]):
file['croak'].write('Error: euler angles out of bound. Ang file might contain unidexed poins.\n') file['croak'].write('Error: euler angles out of bound. Ang file might contain unidexed poins.\n')
@ -128,7 +134,7 @@ for file in files:
euleranglesRadInt = (eulerangles*10**int(options.precision)).astype('int') # scale by desired precision and convert to int euleranglesRadInt = (eulerangles*10**int(options.precision)).astype('int') # scale by desired precision and convert to int
eulerKeys = np.array([int(''.join(map(formatString.format,euleranglesRadInt[i,:]))) \ eulerKeys = np.array([int(''.join(map(formatString.format,euleranglesRadInt[i,:]))) \
for i in xrange(info['grid'].prod())]) # create unique integer key from three euler angles by concatenating the string representation with leading zeros and store as integer for i in xrange(info['grid'].prod())]) # create unique integer key from three euler angles by concatenating the string representation with leading zeros and store as integer
devNull, texture, eulerKeys_idx = np.unique(eulerKeys, return_index = True, return_inverse=True)# search unique euler angle keys. Texture IDs are the indices of the first occurence, the inverse is used to construct the microstructure devNull, texture, eulerKeys_idx = np.unique(eulerKeys, return_index = True, return_inverse=True)# search unique euler angle keys. Texture IDs are the indices of the first occurrence, the inverse is used to construct the microstructure
msFull = np.array([[eulerKeys_idx[i],phase[i]] for i in xrange(info['grid'].prod())],'i8') # create a microstructure (texture/phase pair) for each point using unique texture IDs. Use longInt (64bit, i8) because the keys might be long msFull = np.array([[eulerKeys_idx[i],phase[i]] for i in xrange(info['grid'].prod())],'i8') # create a microstructure (texture/phase pair) for each point using unique texture IDs. Use longInt (64bit, i8) because the keys might be long
devNull,msUnique,matPoints = np.unique(msFull.view('c16'),True,True) devNull,msUnique,matPoints = np.unique(msFull.view('c16'),True,True)
matPoints+=1 matPoints+=1
@ -155,7 +161,6 @@ for file in files:
] ]
info['microstructures'] = len(microstructure) info['microstructures'] = len(microstructure)
info['size'] = step[0]*info['grid'][0],step[1]*info['grid'][1],min(step)
#--- report --------------------------------------------------------------------------------------- #--- report ---------------------------------------------------------------------------------------
file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) + file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) +

View File

@ -90,7 +90,8 @@ for file in files:
"homogenization\t%i"%info['homogenization'], "homogenization\t%i"%info['homogenization'],
] ]
file['output'].write('\n'.join(['%i\theader'%(len(header))] + header) + '\n') file['output'].write('\n'.join(['%i\theader'%(len(header))] + header) + '\n')
np.savetxt(file['output'],imarray.reshape([info['grid'][1]*info['grid'][2],info['grid'][0]]),fmt='%03d') np.savetxt(file['output'],imarray.reshape([info['grid'][1]*info['grid'][2],info['grid'][0]]),
fmt='%0'+str(1+int(math.log10(np.amax(imarray))))+'d'
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------
if file['name'] != 'STDIN': if file['name'] != 'STDIN':

View File

@ -75,20 +75,32 @@ for file in files:
'homogenization': options.homogenization 'homogenization': options.homogenization
} }
coords = [{},{},{}]
pos = {'min':[ float("inf"), float("inf"), float("inf")],
'max':[-float("inf"),-float("inf"),-float("inf")]}
phase = [] phase = []
eulerangles = [] eulerangles = []
point = 0 # --------------- read data -----------------------------------------------------------------------
for line in file['input']: for line in file['input']:
if line.strip(): if line.strip():
words = line.split() words = line.split()
currPos = map(float,words[3:6]) currPos = words[3:6]
for i in xrange(3): for i in xrange(3):
if currPos[i] > info['grid'][i]: coords[i][currPos[i]] = True
info['size'][i] = currPos[i] currPos = map(float,currPos)
info['grid'][i]+=1 for i in xrange(3):
eulerangles.append(map(float,words[:3])) pos['min'][i] = min(pos['min'][i],currPos[i])
pos['max'][i] = max(pos['max'][i],currPos[i])
eulerangles.append(map(math.degrees,map(float,words[:3])))
phase.append(options.phase[int(float(words[options.column-1]) > options.threshold)]) phase.append(options.phase[int(float(words[options.column-1]) > options.threshold)])
# --------------- determine size and grid ---------------------------------------------------------
info['grid'] = np.array(map(len,coords),'i')
info['size'] = info['grid']/np.maximum(np.ones(3,'d'),info['grid']-1.0)* \
np.array([pos['max'][0]-pos['min'][0],
pos['max'][1]-pos['min'][1],
pos['max'][2]-pos['min'][2]],'d')
eulerangles = np.array(eulerangles,dtype='f').reshape(info['grid'].prod(),3) eulerangles = np.array(eulerangles,dtype='f').reshape(info['grid'].prod(),3)
phase = np.array(phase,dtype='i').reshape(info['grid'].prod()) phase = np.array(phase,dtype='i').reshape(info['grid'].prod())
@ -164,7 +176,7 @@ for file in files:
] ]
file['output'].write('\n'.join(['%i\theader'%(len(header))] + header) + '\n') file['output'].write('\n'.join(['%i\theader'%(len(header))] + header) + '\n')
if options.compress: if options.compress:
matPoints = matPoints.reshape((info['grid'][1],info['grid'][0])) matPoints = matPoints.reshape([info['grid'][1]*info['grid'][2],info['grid'][0]])
np.savetxt(file['output'],matPoints,fmt='%0'+str(1+int(math.log10(np.amax(matPoints))))+'d') np.savetxt(file['output'],matPoints,fmt='%0'+str(1+int(math.log10(np.amax(matPoints))))+'d')
else: else:
file['output'].write("1 to %i\n"%(info['microstructures'])) file['output'].write("1 to %i\n"%(info['microstructures']))