change reading in to standard loop over files
getting bins now from header information format of linearODF now standard ASCII table style with header/keyword/label
This commit is contained in:
parent
f43afa13d8
commit
4581e22a0f
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import os,string,sys,re
|
import os,string,sys,re
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import numpy as np
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptID = string.replace('$Id$','\n','\\n')
|
scriptID = string.replace('$Id$','\n','\\n')
|
||||||
|
@ -17,90 +18,88 @@ sampleSym = { 'Orthotropic' : (90,90,90),
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Transform the OIM texture data into linear ODF data, the input file can be generated by software "TSL OIM Analysis",
|
Transform the binned texture data from "TSL OIM Analysis" into linear ODF data,
|
||||||
and the output file can be used by the script: "hybridIA_linODFsampling.py"
|
|
||||||
""", version=string.replace(scriptID,'\n','\\n')
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_option('-f', '--file', dest='file', type='string', metavar = 'string', \
|
""", version = scriptID)
|
||||||
help='file name')
|
|
||||||
parser.add_option('-s', '--symmetry', dest='symmetry', choices=sampleSym.keys(),\
|
parser.add_option('-s', '--symmetry', dest='symmetry', choices=sampleSym.keys(),
|
||||||
help='Sample symmetry, the default is [%default]')
|
help='Sample symmetry, the default is [%default]')
|
||||||
parser.add_option('--step', dest='step', type='int', nargs=3,
|
|
||||||
help='''Angle steps of: phi1, Phi, phi2. For example, if the
|
|
||||||
range of phi1 is 360 degree, and the desired interval
|
|
||||||
is 5 degree, then the angle step of phi1 is 72, but
|
|
||||||
we will discard the 72th step, because 360 is
|
|
||||||
identical with 0, the default depends on the sample
|
|
||||||
symmetry. ''', \
|
|
||||||
metavar='int int int')
|
|
||||||
|
|
||||||
parser.set_defaults(symmetry = 'Triclinic')
|
parser.set_defaults(symmetry = 'Triclinic')
|
||||||
parser.set_defaults(step = None)
|
|
||||||
options = parser.parse_args()[0]
|
|
||||||
|
|
||||||
if options.step is None:
|
(options,filenames) = parser.parse_args()
|
||||||
options.step= [sampleSym[options.symmetry][i]/5 for i in xrange(3)]
|
|
||||||
|
|
||||||
if not os.path.exists(options.file):
|
#--- setup file handles ---------------------------------------------------------------------------
|
||||||
parser.error('texture file does not exist'); sys.exit()
|
files = []
|
||||||
|
if filenames == []:
|
||||||
|
files.append({'name':'STDIN',
|
||||||
|
'input':sys.stdin,
|
||||||
|
'output':sys.stdout,
|
||||||
|
'croak':sys.stderr,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
for name in filenames:
|
||||||
|
if os.path.exists(name):
|
||||||
|
files.append({'name':name,
|
||||||
|
'input':open(name),
|
||||||
|
'output':open(name+'_tmp','w'),
|
||||||
|
'croak':sys.stdout,
|
||||||
|
})
|
||||||
|
|
||||||
inName = options.file
|
#--- loop over input files ------------------------------------------------------------------------
|
||||||
outName = os.path.splitext(inName)[0]+'.linearODF'
|
for file in files:
|
||||||
nPhi1,nPHI,nPhi2 = options.step
|
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
||||||
dPhi1,dPHI,dPhi2 = [sampleSym[options.symmetry][i]/float(options.step[i]) for i in xrange(3)]
|
|
||||||
|
|
||||||
N = (nPhi1-1)*(nPHI-1)*(nPhi2-1)
|
while True: # read header (forward and get bin Size)
|
||||||
|
line = file['input'].readline()
|
||||||
|
words = line.split()
|
||||||
|
if len(words)>=3:
|
||||||
|
if words[1]=='Bin' and words[2]=='Size:': binSize=float(words[3][:-1])
|
||||||
|
if not line.startswith('#'): break
|
||||||
|
|
||||||
try:
|
delta = [sampleSym[options.symmetry][i]/binSize for i in xrange(3)]
|
||||||
inFile = open(inName,'r')
|
|
||||||
content = inFile.readlines()
|
|
||||||
except:
|
|
||||||
print 'unable to read:',inName
|
|
||||||
sys.exit(1)
|
|
||||||
try:
|
|
||||||
outFile = open(outName,'w')
|
|
||||||
except:
|
|
||||||
print 'unable to write:',outName
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
ODF = [[[[None] for k in range(nPhi2)] for j in range(nPHI)] for i in range(nPhi1)]
|
nPhi1,nPHI,nPhi2 = map(int,delta)
|
||||||
linear = [None]*N
|
dPhi1,dPHI,dPhi2 = [sampleSym[options.symmetry][i]/delta[i] for i in xrange(3)]
|
||||||
line = 0
|
|
||||||
|
|
||||||
while (content[line].startswith('#')): # skip comments at start of file
|
N = (nPhi1-1)*(nPHI-1)*(nPhi2-1)
|
||||||
line += 1
|
|
||||||
|
|
||||||
for iPhi1 in range(nPhi1):
|
|
||||||
for iPHI in range(nPHI):
|
|
||||||
for iPhi2 in range(nPhi2):
|
|
||||||
words = content[line].split()
|
|
||||||
ODF[iPhi1][iPHI][iPhi2] = float(words[3]) # extract intensity (in column 4)
|
|
||||||
line += 1
|
|
||||||
|
|
||||||
for iPhi1 in range(nPhi1-1):
|
|
||||||
for iPHI in range(nPHI-1):
|
|
||||||
for iPhi2 in range(nPhi2-1):
|
|
||||||
linear[iPhi1*(nPHI-1)*(nPhi2-1)+iPHI*(nPhi2-1)+iPhi2] = (\
|
|
||||||
ODF[iPhi1 ][iPHI ][iPhi2 ] + \
|
|
||||||
ODF[iPhi1 ][iPHI ][iPhi2+1] + \
|
|
||||||
ODF[iPhi1 ][iPHI+1][iPhi2 ] + \
|
|
||||||
ODF[iPhi1 ][iPHI+1][iPhi2+1] + \
|
|
||||||
ODF[iPhi1+1][iPHI ][iPhi2 ] + \
|
|
||||||
ODF[iPhi1+1][iPHI ][iPhi2+1] + \
|
|
||||||
ODF[iPhi1+1][iPHI+1][iPhi2 ] + \
|
|
||||||
ODF[iPhi1+1][iPHI+1][iPhi2+1] \
|
|
||||||
) / 8.0
|
|
||||||
|
|
||||||
|
|
||||||
inFile.close()
|
ODF = [[[[None] for k in range(nPhi2)] for j in range(nPHI)] for i in range(nPhi1)]
|
||||||
outFile.write('%-6i%-6i%-6i #Ranges of phi1, Phi, phi2\n'%sampleSym[options.symmetry])
|
linear = [None]*N
|
||||||
outFile.write('%-6.2f%-6.2f%-6.2f #Deltas of phi1, Phi, phi2\n'%(dPhi1,dPHI,dPhi2))
|
|
||||||
#outFile.write('%-6i%-6i%-6i #Angular steps needed to be converted\n'%(nPhi1-1,nPHI-1,nPhi2-1))
|
|
||||||
outFile.write('cell-centered data\n')
|
|
||||||
outFile.write('\n')
|
|
||||||
|
|
||||||
for i in range(N):
|
ODF = np.empty([nPhi1,nPHI,nPhi2],'d')
|
||||||
outFile.write('%g\n'%(linear[i]))
|
|
||||||
|
for iPhi1 in range(nPhi1):
|
||||||
|
for iPHI in range(nPHI):
|
||||||
|
for iPhi2 in range(nPhi2):
|
||||||
|
ODF[iPhi1,iPHI,iPhi2] = float(line.split()[3])*0.125 # extract intensity (in column 4) and weight by 1/8 (since we convert from the 8 corners to the center later on)
|
||||||
|
line = file['input'].readline()
|
||||||
|
|
||||||
|
for iPhi1 in range(nPhi1-1):
|
||||||
|
for iPHI in range(nPHI-1):
|
||||||
|
for iPhi2 in range(nPhi2-1):
|
||||||
|
linear[iPhi1*(nPHI-1)*(nPhi2-1)+iPHI*(nPhi2-1)+iPhi2] =\
|
||||||
|
ODF[iPhi1 ,iPHI ,iPhi2 ] +\
|
||||||
|
ODF[iPhi1 ,iPHI ,iPhi2+1] +\
|
||||||
|
ODF[iPhi1 ,iPHI+1,iPhi2 ] +\
|
||||||
|
ODF[iPhi1 ,iPHI+1,iPhi2+1] +\
|
||||||
|
ODF[iPhi1+1,iPHI ,iPhi2 ] +\
|
||||||
|
ODF[iPhi1+1,iPHI ,iPhi2+1] +\
|
||||||
|
ODF[iPhi1+1,iPHI+1,iPhi2 ] +\
|
||||||
|
ODF[iPhi1+1,iPHI+1,iPhi2+1]
|
||||||
|
|
||||||
|
|
||||||
|
file['output'].write('4 header\n')
|
||||||
|
file['output'].write('limit phi1 %-6.2f Phi %-6.2f phi2 %-6.2f\n'%sampleSym[options.symmetry])
|
||||||
|
file['output'].write('delta phi1 %-6.2f Phi %-6.2f phi2 %-6.2f\n'%(dPhi1,dPHI,dPhi2))
|
||||||
|
file['output'].write('centration cell-centered\n')
|
||||||
|
file['output'].write('density\n')
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
file['output'].write('%g\n'%(linear[i]))
|
||||||
|
|
||||||
outFile.close()
|
#--- output finalization --------------------------------------------------------------------------
|
||||||
|
if file['name'] != 'STDIN':
|
||||||
|
file['output'].close()
|
||||||
|
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] +'.linearODF')
|
||||||
|
|
Loading…
Reference in New Issue