use OptionParse to parse the command-line options, add help information, format the header of output file, now the output file can be used by hydribIA_linODFsampling.py directly

This commit is contained in:
Haiming Zhang 2015-03-05 17:04:16 +00:00
parent 4fd7e0165e
commit d188f35c17
1 changed files with 52 additions and 12 deletions

View File

@ -1,14 +1,54 @@
#!/usr/bin/env python
#!/usr/bin/python
# -*- coding: UTF-8 no BOM -*-
import os,sys,re
import os,string,sys,re
from optparse import OptionParser
import damask
try:
inName = sys.argv[1]
outName = os.path.splitext(inName)[0]+'.linearODF'
nPhi1,nPHI,nPhi2 = map(int,sys.argv[2:5])
except:
print "\nusage:",sys.argv[0],"file nPhi1 nPHI nPhi2\n"
sys.exit(1)
scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1]
sampleSym = { 'Orthotropic' : (90,90,90),
'Triclinic' : (360,180,360)
}
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
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",
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', \
help='file name')
parser.add_option('-s', '--symmetry', dest='symmetry', choices=sampleSym.keys(),\
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(step = None)
options = parser.parse_args()[0]
if options.step is None:
options.step= [sampleSym[options.symmetry][i]/5 for i in xrange(3)]
if not os.path.exists(options.file):
parser.error('texture file does not exist'); sys.exit()
inName = options.file
outName = os.path.splitext(inName)[0]+'.linearODF'
nPhi1,nPHI,nPhi2 = options.step
dPhi1,dPHI,dPhi2 = [sampleSym[options.symmetry][i]/options.step[i] for i in xrange(3)]
N = (nPhi1-1)*(nPHI-1)*(nPhi2-1)
@ -54,9 +94,9 @@ for iPhi1 in range(nPhi1-1):
inFile.close()
outFile.write('rangePhi1?\trangePHI?\trangePhi2?\n')
outFile.write('%i\t%i\t%i needs to be converted to angular steps\n'%(nPhi1-1,nPHI-1,nPhi2-1))
outFile.write('%-6i%-6i%-6i #Ranges of phi1, Phi, phi2\n'%sampleSym[options.symmetry])
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')