2013-11-26 00:41:02 +05:30
|
|
|
#!/usr/bin/env python
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-01-05 02:32:17 +05:30
|
|
|
import os,sys,string,math
|
2014-07-22 19:51:49 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
scriptID = string.replace('$Id$','\n','\\n')
|
2014-11-18 20:50:10 +05:30
|
|
|
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2014-07-22 19:51:49 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2013-11-26 00:41:02 +05:30
|
|
|
Add RGB color value corresponding to TSL-OIM scheme for inverse pole figures.
|
2014-07-22 19:51:49 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-p', '--pole',
|
|
|
|
dest = 'pole',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'lab frame direction for inverse pole figure [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-s', '--symmetry',
|
|
|
|
dest = 'symmetry',
|
|
|
|
type = 'choice', choices = damask.Symmetry.lattices[1:], metavar='string',
|
|
|
|
help = 'crystal symmetry [%default] {{{}}} '.format(', '.join(damask.Symmetry.lattices[1:])))
|
|
|
|
parser.add_option('-e', '--eulers',
|
|
|
|
dest = 'eulers',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'Euler angles label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-d', '--degrees',
|
|
|
|
dest = 'degrees',
|
|
|
|
action = 'store_true',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'Euler angles are given in degrees [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-m', '--matrix',
|
|
|
|
dest = 'matrix',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'orientation matrix label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-a',
|
|
|
|
dest = 'a',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'crystal frame a vector label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-b',
|
|
|
|
dest = 'b',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'crystal frame b vector label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-c',
|
|
|
|
dest = 'c',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'crystal frame c vector label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-q', '--quaternion',
|
|
|
|
dest = 'quaternion',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-05-09 18:31:31 +05:30
|
|
|
help = 'quaternion label')
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-06-16 22:51:24 +05:30
|
|
|
parser.set_defaults(pole = (0.0,0.0,1.0),
|
2015-08-08 00:33:26 +05:30
|
|
|
symmetry = damask.Symmetry.lattices[-1],
|
2015-06-16 22:51:24 +05:30
|
|
|
degrees = False,
|
|
|
|
)
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-06-16 22:51:24 +05:30
|
|
|
(options, filenames) = parser.parse_args()
|
2014-08-04 23:23:41 +05:30
|
|
|
|
2015-06-16 22:51:24 +05:30
|
|
|
input = [options.eulers != None,
|
|
|
|
options.a != None and \
|
|
|
|
options.b != None and \
|
|
|
|
options.c != None,
|
|
|
|
options.matrix != None,
|
|
|
|
options.quaternion != None,
|
|
|
|
]
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
if np.sum(input) != 1: parser.error('needs exactly one input format.')
|
2015-06-16 22:51:24 +05:30
|
|
|
|
|
|
|
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
|
|
|
([options.a,options.b,options.c],[3,3,3],'frame'),
|
|
|
|
(options.matrix,9,'matrix'),
|
|
|
|
(options.quaternion,4,'quaternion'),
|
2015-08-08 00:33:26 +05:30
|
|
|
][np.where(input)[0][0]] # select input label that was requested
|
2014-07-25 01:51:18 +05:30
|
|
|
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
|
2014-07-22 19:51:49 +05:30
|
|
|
pole = np.array(options.pole)
|
|
|
|
pole /= np.linalg.norm(pole)
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over input files ------------------------------------------------------------------------
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-06-16 22:51:24 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-08-21 01:12:05 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
|
|
|
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else ''))
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
2015-06-16 22:51:24 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-06-16 22:51:24 +05:30
|
|
|
if not np.all(table.label_dimension(label) == dim):
|
2015-08-08 00:33:26 +05:30
|
|
|
table.croak('input {} has wrong dimension {}.'.format(label,dim))
|
2015-06-16 22:51:24 +05:30
|
|
|
table.close(dismiss = True) # close ASCIItable and remove empty file
|
2014-08-04 23:23:41 +05:30
|
|
|
continue
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-06-16 22:51:24 +05:30
|
|
|
column = table.label_index(label)
|
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-06-16 22:51:24 +05:30
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2015-08-08 00:33:26 +05:30
|
|
|
table.labels_append(['{}_IPF_{}{}{}_{sym}'.format(i+1,*options.pole,sym = options.symmetry.lower()) for i in xrange(3)])
|
2013-11-26 00:41:02 +05:30
|
|
|
table.head_write()
|
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2014-07-25 01:51:18 +05:30
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2015-06-16 22:51:24 +05:30
|
|
|
if inputtype == 'eulers':
|
2015-08-08 00:33:26 +05:30
|
|
|
o = damask.Orientation(Eulers = np.array(map(float,table.data[column:column+3]))*toRadians,
|
|
|
|
symmetry = options.symmetry).reduced()
|
2015-06-16 22:51:24 +05:30
|
|
|
elif inputtype == 'matrix':
|
2015-08-08 00:33:26 +05:30
|
|
|
o = damask.Orientation(matrix = np.array(map(float,table.data[column:column+9])).reshape(3,3).transpose(),
|
|
|
|
symmetry = options.symmetry).reduced()
|
2015-06-16 22:51:24 +05:30
|
|
|
elif inputtype == 'frame':
|
2015-08-08 00:33:26 +05:30
|
|
|
o = damask.Orientation(matrix = np.array(map(float,table.data[column[0]:column[0]+3] + \
|
|
|
|
table.data[column[1]:column[1]+3] + \
|
|
|
|
table.data[column[2]:column[2]+3])).reshape(3,3),
|
|
|
|
symmetry = options.symmetry).reduced()
|
2015-06-16 22:51:24 +05:30
|
|
|
elif inputtype == 'quaternion':
|
2015-08-08 00:33:26 +05:30
|
|
|
o = damask.Orientation(quaternion = np.array(map(float,table.data[column:column+4])),
|
|
|
|
symmetry = options.symmetry).reduced()
|
2013-11-26 00:41:02 +05:30
|
|
|
|
|
|
|
table.data_append(o.IPFcolor(pole))
|
2014-07-22 19:51:49 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2013-11-26 00:41:02 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close() # close ASCII tables
|