add the option of exporting '.ctf' format file.

This commit is contained in:
Haiming Zhang 2015-04-28 18:09:07 +00:00
parent c05df20370
commit afe7225357
1 changed files with 75 additions and 45 deletions

View File

@ -22,9 +22,8 @@ def positiveRadians(angle):
return angle return angle
def getHeader(sizeX,sizeY,step,format):
def getHeader(sizeX,sizeY,step): if format == 'ang':
return [ return [
'# TEM_PIXperUM 1.000000', '# TEM_PIXperUM 1.000000',
'# x-star 0.509548', '# x-star 0.509548',
@ -59,13 +58,31 @@ def getHeader(sizeX,sizeY,step):
'# SCANID: ', '# SCANID: ',
'#' '#'
] ]
else: # ctf format
return [ \
'Channel Text File',
'Prj X:\\xxx\\xxxx.cpr',
'Author [MPIE-DAMASK]',
'JobMode Grid',
'XCells '+ str(sizeX),
'YCells '+ str(sizeY),
'XStep '+ str(step),
'YStep '+ str(step),
'AcqE1 0',
'AcqE2 90',
'AcqE3 0',
'Euler angles refer to Sample Coordinate system (CS0)! Mag 300 Coverage 100 Device 0 KV 20 TiltAngle 70 TiltAxis 0',
'Phases 1',
'4.05;4.05;4.05 90;90;90 Aluminium 11 225 3803863129_5.0.6.3 -2102160418 Cryogenics18,54-55',
'Phase X Y Bands Error Euler1 Euler2 Euler3 MAD BC BS'
]
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# MAIN # MAIN
# -------------------------------------------------------------------- # --------------------------------------------------------------------
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 linear binned data into Euler angles. output the Euler angles in the format supported by TSL (.ang or .ctf).
""", version = scriptID) """, version = scriptID)
@ -73,9 +90,12 @@ parser.add_option("-c", "--column", type="int", dest="column",
help="starting column of Euler triplet") help="starting column of Euler triplet")
parser.add_option("-s", "--skip", type="int", dest="skip", parser.add_option("-s", "--skip", type="int", dest="skip",
help="skip this many lines of heading info [%default]") help="skip this many lines of heading info [%default]")
parser.add_option("-f", "--format", type="string", dest="format",
help="the format of the output file [%default]")
parser.set_defaults (column = 1) parser.set_defaults (column = 1)
parser.set_defaults (skip = 1) parser.set_defaults (skip = 1)
parser.set_defaults (format = 'ang')
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
options.column -= 1 options.column -= 1
@ -104,20 +124,30 @@ for file in files:
if m != None and options.skip == 0: options.skip = int(m.group(1))+1 if m != None and options.skip == 0: options.skip = int(m.group(1))+1
# extract orientation angles # extract orientation angles
if options.format == 'ang': # 'ang' file, radian
angles = [map(positiveRadians,line.split()[options.column:options.column+3]) for line in content[options.skip:]] angles = [map(positiveRadians,line.split()[options.column:options.column+3]) for line in content[options.skip:]]
else: # 'ctf' file, degree
angles = [line.split()[options.column:options.column+3] for line in content[options.skip:]]
nPoints = len(angles) nPoints = len(angles)
sizeY = integerFactorization(nPoints) sizeY = integerFactorization(nPoints)
sizeX = nPoints / sizeY sizeX = nPoints / sizeY
file['croak'].write('%s: %i*%i = %i (== %i)\n'%(file['name'],sizeX,sizeY,sizeX*sizeY,nPoints) ) file['croak'].write('%s: %i*%i = %i (== %i)\n'%(file['name'],sizeX,sizeY,sizeX*sizeY,nPoints) )
# write ang file # write ang/ctf file
for line in getHeader(sizeX,sizeY,1.0): for line in getHeader(sizeX,sizeY,1.0,options.format):
file['output'].write(line + '\n') file['output'].write(line + '\n')
for counter,point in enumerate(angles): for counter,point in enumerate(angles):
if options.format == 'ang':
file['output'].write(''.join(['%10.5f'%angle for angle in point])+ file['output'].write(''.join(['%10.5f'%angle for angle in point])+
''.join(['%10.5f'%coord for coord in [counter%sizeX,counter//sizeX]])+ ''.join(['%10.5f'%coord for coord in [counter%sizeX,counter//sizeX]])+
' 100.0 1.0 0 1 1.0\n') ' 100.0 1.0 0 1 1.0\n')
else:
file['output'].write('1 '+
' '.join(['%6.1f'%coord for coord in [counter%sizeX,counter//sizeX]])+
' 5 0 '+
' '.join(['%10.5f'%float(angle) for angle in point])+
' 0.5000 100 0\n')
if file['name'] != 'STDIN': if file['name'] != 'STDIN':
file['output'].close() file['output'].close()
os.rename(file['name']+'_tmp', os.path.splitext(file['name'])[0]+'.ang' ) os.rename(file['name']+'_tmp', os.path.splitext(file['name'])[0]+'.'+options.format )