some more changes improving the post processing scripts
This commit is contained in:
parent
1707f7d367
commit
e5dc9e79cc
|
@ -274,7 +274,7 @@ parser.add_option('-v', '--vector', action='extend', dest='vector', type='string
|
||||||
help='list of vectors to visualize', metavar = '<string LIST>')
|
help='list of vectors to visualize', metavar = '<string LIST>')
|
||||||
parser.add_option('-t', '--tensor', action='extend', dest='tensor', type='string', \
|
parser.add_option('-t', '--tensor', action='extend', dest='tensor', type='string', \
|
||||||
help='list of tensors to visualize', metavar = '<string LIST>')
|
help='list of tensors to visualize', metavar = '<string LIST>')
|
||||||
parser.add_option('-d', '--deformation', dest='defgrad', type='string', \
|
parser.add_option('-d', '--deformation', dest='defgrad', action='store', type='string', \
|
||||||
help='heading of deformation gradient columns [%default]', metavar = 'string')
|
help='heading of deformation gradient columns [%default]', metavar = 'string')
|
||||||
parser.add_option('--reference', dest='undeformed', action='store_true',\
|
parser.add_option('--reference', dest='undeformed', action='store_true',\
|
||||||
help='map results to reference (undeformed) configuration [%default]')
|
help='map results to reference (undeformed) configuration [%default]')
|
||||||
|
@ -290,15 +290,15 @@ parser.add_option('--points', dest='output_points', action='store_true', \
|
||||||
help='produce VTK points file [%default]')
|
help='produce VTK points file [%default]')
|
||||||
parser.add_option('--nopoints', dest='output_points', action='store_false', \
|
parser.add_option('--nopoints', dest='output_points', action='store_false', \
|
||||||
help='omit VTK points file')
|
help='omit VTK points file')
|
||||||
parser.add_option('--separator', dest='separator', type='string', \
|
parser.add_option('--separator', dest='separator', action='store', type='string', \
|
||||||
help='data separator (t(ab), n(ewline), s(pace)) [%default]', metavar = 'string')
|
help='data separator (t(ab), n(ewline), s(pace)) [%default]', metavar = 'string')
|
||||||
parser.add_option('--scaling', dest='scaling', action='extend', type='string', \
|
parser.add_option('--scaling', dest='scaling', action='extend', type='string', \
|
||||||
help='scaling of fluctuation', metavar = '<float LIST>')
|
help='scaling of fluctuation', metavar = '<float LIST>')
|
||||||
parser.add_option('-u', '--unitlength', dest='unitlength', type='float', \
|
parser.add_option('-u', '--unitlength', dest='unitlength', action='store', type='float', \
|
||||||
help='set unit length for 2D model [%default]', metavar = 'float')
|
help='set unit length for 2D model [%default]', metavar = 'float')
|
||||||
parser.add_option('--filenodalcoords', dest='filenodalcoords', type='string', \
|
parser.add_option('--filenodalcoords', dest='filenodalcoords', action='store', type='string', \
|
||||||
help='ASCII table containing nodal coords', metavar = 'string')
|
help='ASCII table containing nodal coords', metavar = 'string')
|
||||||
parser.add_option('--labelnodalcoords', dest='labelnodalcoords', type='string', nargs=3, \
|
parser.add_option('--labelnodalcoords', dest='labelnodalcoords', action='store', type='string', nargs=3, \
|
||||||
help='labels of nodal coords in ASCII table %default', metavar = 'string string string')
|
help='labels of nodal coords in ASCII table %default', metavar = 'string string string')
|
||||||
parser.add_option('-l', '--linear', dest='linearreconstruction', action='store_true',\
|
parser.add_option('-l', '--linear', dest='linearreconstruction', action='store_true',\
|
||||||
help='use linear reconstruction of geometry [%default]')
|
help='use linear reconstruction of geometry [%default]')
|
||||||
|
|
|
@ -21,9 +21,9 @@ deformation gradient and first Piola--Kirchhoff stress.
|
||||||
""", version = string.replace(scriptID,'\n','\\n')
|
""", version = string.replace(scriptID,'\n','\\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_option('-f','--defgrad', dest='defgrad', type='string', metavar='string', \
|
parser.add_option('-f','--defgrad', dest='defgrad', action='store', type='string', metavar='string', \
|
||||||
help='heading of columns containing deformation gradient [%default]')
|
help='heading of columns containing deformation gradient [%default]')
|
||||||
parser.add_option('-p','--stress', dest='stress', type='string', metavar='string', \
|
parser.add_option('-p','--stress', dest='stress', action='store', type='string', metavar='string', \
|
||||||
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
|
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
|
||||||
parser.set_defaults(defgrad = 'f')
|
parser.set_defaults(defgrad = 'f')
|
||||||
parser.set_defaults(stress = 'p')
|
parser.set_defaults(stress = 'p')
|
||||||
|
|
|
@ -24,9 +24,9 @@ parser.add_option('--no-shape','-s', dest='noShape', action='store_false', \
|
||||||
help='do not calcuate shape mismatch [%default]')
|
help='do not calcuate shape mismatch [%default]')
|
||||||
parser.add_option('--no-volume','-v', dest='noVolume', action='store_false', \
|
parser.add_option('--no-volume','-v', dest='noVolume', action='store_false', \
|
||||||
help='do not calculate volume mismatch [%default]')
|
help='do not calculate volume mismatch [%default]')
|
||||||
parser.add_option('-c','--coordinates', dest='coords', type='string', metavar='string', \
|
parser.add_option('-c','--coordinates', dest='coords', action='store', type='string', metavar='string', \
|
||||||
help='column heading for coordinates [%default]')
|
help='column heading for coordinates [%default]')
|
||||||
parser.add_option('-f','--deformation', dest='defgrad', type='string', metavar='string ', \
|
parser.add_option('-f','--deformation', dest='defgrad', action='store', type='string', metavar='string ', \
|
||||||
help='column heading for coordinates [%defgrad]')
|
help='column heading for coordinates [%defgrad]')
|
||||||
parser.set_defaults(noVolume = False)
|
parser.set_defaults(noVolume = False)
|
||||||
parser.set_defaults(noShape = False)
|
parser.set_defaults(noShape = False)
|
||||||
|
|
|
@ -22,7 +22,7 @@ Deals with both vector- and tensor-valued fields.
|
||||||
""", version = string.replace(scriptID,'\n','\\n')
|
""", version = string.replace(scriptID,'\n','\\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_option('-c','--coordinates', dest='coords', type='string', metavar='string', \
|
parser.add_option('-c','--coordinates', dest='coords', action='store', type='string', metavar='string', \
|
||||||
help='column heading for coordinates [%default]')
|
help='column heading for coordinates [%default]')
|
||||||
parser.add_option('-v','--vector', dest='vector', action='extend', type='string', metavar='<string LIST>', \
|
parser.add_option('-v','--vector', dest='vector', action='extend', type='string', metavar='<string LIST>', \
|
||||||
help='heading of columns containing vector field values')
|
help='heading of columns containing vector field values')
|
||||||
|
|
|
@ -21,9 +21,9 @@ Operates on periodic ordered three-dimensional data sets.
|
||||||
""", version = string.replace(scriptID,'\n','\\n')
|
""", version = string.replace(scriptID,'\n','\\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_option('-c','--coordinates', dest='coords', type='string', metavar='string', \
|
parser.add_option('-c','--coordinates', dest='coords', action='store', type='string', metavar='string', \
|
||||||
help='column heading for coordinates [%default]')
|
help='column heading for coordinates [%default]')
|
||||||
parser.add_option('-d','--defgrad', dest='defgrad', type='string', metavar='string', \
|
parser.add_option('-d','--defgrad', dest='defgrad', action='store', type='string', metavar='string', \
|
||||||
help='heading of columns containing tensor field values')
|
help='heading of columns containing tensor field values')
|
||||||
parser.add_option('-l', '--linear', dest='linearreconstruction', action='store_true',\
|
parser.add_option('-l', '--linear', dest='linearreconstruction', action='store_true',\
|
||||||
help='use linear reconstruction of geometry [%default]')
|
help='use linear reconstruction of geometry [%default]')
|
||||||
|
|
|
@ -27,7 +27,7 @@ parser.add_option('--fdm', dest='accuracy', action='extend', type='
|
||||||
help='degree of central difference accuracy (%s)'%(','.join(accuracyChoices)))
|
help='degree of central difference accuracy (%s)'%(','.join(accuracyChoices)))
|
||||||
parser.add_option('--fft', dest='fft', action='store_true', \
|
parser.add_option('--fft', dest='fft', action='store_true', \
|
||||||
help='calculate divergence in Fourier space')
|
help='calculate divergence in Fourier space')
|
||||||
parser.add_option('-c','--coordinates', dest='coords', type='string', metavar = 'string', \
|
parser.add_option('-c','--coordinates', dest='coords', action='store', type='string', metavar = 'string', \
|
||||||
help='column heading for coordinates [%default]')
|
help='column heading for coordinates [%default]')
|
||||||
parser.add_option('-v','--vector', dest='vector', action='extend', type='string', metavar='<string LIST>', \
|
parser.add_option('-v','--vector', dest='vector', action='extend', type='string', metavar='<string LIST>', \
|
||||||
help='heading of columns containing vector field values')
|
help='heading of columns containing vector field values')
|
||||||
|
|
|
@ -1,39 +1,25 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,re,sys,math,numpy,string,damask
|
import os,re,sys,math,string
|
||||||
|
import numpy as np
|
||||||
|
from optparse import OptionParser
|
||||||
from scipy import ndimage
|
from scipy import ndimage
|
||||||
from optparse import OptionParser, Option
|
import damask
|
||||||
|
|
||||||
# -----------------------------
|
|
||||||
class extendableOption(Option):
|
|
||||||
# -----------------------------
|
|
||||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
|
||||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
|
||||||
|
|
||||||
ACTIONS = Option.ACTIONS + ("extend",)
|
|
||||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
||||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
||||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
|
||||||
|
|
||||||
def take_action(self, action, dest, opt, value, values, parser):
|
|
||||||
if action == "extend":
|
|
||||||
lvalue = value.split(",")
|
|
||||||
values.ensure_value(dest, []).extend(lvalue)
|
|
||||||
else:
|
|
||||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
|
||||||
|
|
||||||
|
scriptID = '$Id$'
|
||||||
|
scriptName = scriptID.split()[1]
|
||||||
|
|
||||||
def periodic_3Dpad(array, rimdim=(1,1,1)):
|
def periodic_3Dpad(array, rimdim=(1,1,1)):
|
||||||
|
|
||||||
rimdim = numpy.array(rimdim,'i')
|
rimdim = np.array(rimdim,'i')
|
||||||
size = numpy.array(array.shape,'i')
|
size = np.array(array.shape,'i')
|
||||||
padded = numpy.empty(size+2*rimdim,array.dtype)
|
padded = np.empty(size+2*rimdim,array.dtype)
|
||||||
padded[rimdim[0]:rimdim[0]+size[0],
|
padded[rimdim[0]:rimdim[0]+size[0],
|
||||||
rimdim[1]:rimdim[1]+size[1],
|
rimdim[1]:rimdim[1]+size[1],
|
||||||
rimdim[2]:rimdim[2]+size[2]] = array
|
rimdim[2]:rimdim[2]+size[2]] = array
|
||||||
|
|
||||||
p = numpy.zeros(3,'i')
|
p = np.zeros(3,'i')
|
||||||
for side in xrange(3):
|
for side in xrange(3):
|
||||||
for p[(side+2)%3] in xrange(padded.shape[(side+2)%3]):
|
for p[(side+2)%3] in xrange(padded.shape[(side+2)%3]):
|
||||||
for p[(side+1)%3] in xrange(padded.shape[(side+1)%3]):
|
for p[(side+1)%3] in xrange(padded.shape[(side+1)%3]):
|
||||||
|
@ -56,7 +42,7 @@ features = [ \
|
||||||
]
|
]
|
||||||
|
|
||||||
neighborhoods = {
|
neighborhoods = {
|
||||||
'neumann':numpy.array([
|
'neumann':np.array([
|
||||||
[-1, 0, 0],
|
[-1, 0, 0],
|
||||||
[ 1, 0, 0],
|
[ 1, 0, 0],
|
||||||
[ 0,-1, 0],
|
[ 0,-1, 0],
|
||||||
|
@ -64,7 +50,7 @@ neighborhoods = {
|
||||||
[ 0, 0,-1],
|
[ 0, 0,-1],
|
||||||
[ 0, 0, 1],
|
[ 0, 0, 1],
|
||||||
]),
|
]),
|
||||||
'moore':numpy.array([
|
'moore':np.array([
|
||||||
[-1,-1,-1],
|
[-1,-1,-1],
|
||||||
[ 0,-1,-1],
|
[ 0,-1,-1],
|
||||||
[ 1,-1,-1],
|
[ 1,-1,-1],
|
||||||
|
@ -95,22 +81,22 @@ neighborhoods = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Add column(s) containing Euclidean distance to grain structural features:
|
Add column(s) containing Euclidean distance to grain structural features:
|
||||||
boundaries, triple lines, and quadruple points.
|
boundaries, triple lines, and quadruple points.
|
||||||
|
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""", version = string.replace(scriptID,'\n','\\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_option('-i','--identifier', dest='id', action='store', type='string', \
|
parser.add_option('-c','--coordinates', dest='coords', action='store', type='string', metavar='string', \
|
||||||
help='heading of column containing grain identifier [%default]', \
|
help='column heading for coordinates [%default]')
|
||||||
metavar='<label>')
|
parser.add_option('-i','--identifier', dest='id', action='store', type='string', metavar = 'string', \
|
||||||
parser.add_option('-t','--type', dest='type', action='extend', type='string', \
|
help='heading of column containing grain identifier [%default]')
|
||||||
|
parser.add_option('-t','--type', dest='type', action='extend', type='string', metavar='<string LIST>', \
|
||||||
help='feature type (%s)'%(', '.join(map(lambda x:', '.join(x['names']),features))))
|
help='feature type (%s)'%(', '.join(map(lambda x:', '.join(x['names']),features))))
|
||||||
parser.add_option('-n','--neighborhood', dest='neigborhood', action='store', type='string', \
|
parser.add_option('-n','--neighborhood',dest='neigborhood', action='store', type='string', metavar='int', \
|
||||||
help='type of neighborhood (%s)'%(', '.join(neighborhoods.keys())), \
|
help='type of neighborhood (%s)'%(', '.join(neighborhoods.keys())))
|
||||||
metavar='<int>')
|
parser.set_defaults(coords = 'ip')
|
||||||
|
|
||||||
parser.set_defaults(type = [])
|
parser.set_defaults(type = [])
|
||||||
parser.set_defaults(id = 'texture')
|
parser.set_defaults(id = 'texture')
|
||||||
parser.set_defaults(neighborhood = 'neumann')
|
parser.set_defaults(neighborhood = 'neumann')
|
||||||
|
@ -129,32 +115,33 @@ for i,feature in enumerate(features):
|
||||||
feature_list.append(i) # remember valid features
|
feature_list.append(i) # remember valid features
|
||||||
break
|
break
|
||||||
|
|
||||||
# ------------------------------------------ setup file handles ---------------------------------------
|
# ------------------------------------------ setup file handles -----------------------------------
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
if filenames == []:
|
|
||||||
files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr})
|
|
||||||
else:
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if os.path.exists(name):
|
if os.path.exists(name):
|
||||||
files.append({'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr})
|
files.append({'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr})
|
||||||
|
|
||||||
# ------------------------------------------ loop over input files ---------------------------------------
|
# ------------------------------------------ loop over input files ---------------------------------
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
if file['name'] != 'STDIN': file['croak'].write(file['name']+'\n')
|
file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
|
||||||
|
|
||||||
table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table
|
table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table
|
||||||
table.head_read() # read ASCII header info
|
table.head_read() # read ASCII header info
|
||||||
table.info_append(string.replace('$Id$','\n','\\n') + \
|
table.info_append(string.replace(scriptID,'\n','\\n') + '\t' + ' '.join(sys.argv[1:]))
|
||||||
'\t' + ' '.join(sys.argv[1:]))
|
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
# --------------- figure out position of labels and coordinates ------------------------------------
|
||||||
|
try:
|
||||||
|
locationCol = table.labels.index('%s.x'%options.coords) # columns containing location data
|
||||||
|
except ValueError:
|
||||||
|
file['croak'].write('no coordinate data found...\n'%key)
|
||||||
|
continue
|
||||||
|
|
||||||
if options.id not in table.labels:
|
if options.id not in table.labels:
|
||||||
file['croak'].write('column %s not found...\n'%options.id)
|
file['croak'].write('column %s not found...\n'%options.id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# ------------------------------------------ assemble header ---------------------------------------
|
||||||
for feature in feature_list:
|
for feature in feature_list:
|
||||||
table.labels_append('ED_%s(%s)'%(features[feature]['names'][0],options.id)) # extend ASCII header with new labels
|
table.labels_append('ED_%s(%s)'%(features[feature]['names'][0],options.id)) # extend ASCII header with new labels
|
||||||
|
|
||||||
|
@ -162,24 +149,24 @@ for file in files:
|
||||||
|
|
||||||
# ------------------------------------------ process data ---------------------------------------
|
# ------------------------------------------ process data ---------------------------------------
|
||||||
|
|
||||||
table.data_readArray(['ip.x','ip.y','ip.z',options.id])
|
table.data_readArray([options.coords+'.x',options.coords+'.y',options.coords+'.z',options.id])
|
||||||
|
|
||||||
grid = [{},{},{}]
|
grid = [{},{},{}]
|
||||||
for i in xrange(len(table.data)):
|
for i in xrange(len(table.data)):
|
||||||
for j in xrange(3):
|
for j in xrange(3):
|
||||||
grid[j][str(table.data[i,j])] = True
|
grid[j][str(table.data[i,j])] = True
|
||||||
|
|
||||||
resolution = numpy.array(map(len,grid),'i')
|
resolution = np.array(map(len,grid),'i')
|
||||||
unitlength = 0.0
|
unitlength = 0.0
|
||||||
for i,r in enumerate(resolution):
|
for i,r in enumerate(resolution):
|
||||||
if r > 1: unitlength = max(unitlength,(max(map(float,grid[i].keys()))-min(map(float,grid[i].keys())))/(r-1.0))
|
if r > 1: unitlength = max(unitlength,(max(map(float,grid[i].keys()))-min(map(float,grid[i].keys())))/(r-1.0))
|
||||||
|
|
||||||
neighborhood = neighborhoods[options.neighborhood]
|
neighborhood = neighborhoods[options.neighborhood]
|
||||||
convoluted = numpy.empty([len(neighborhood)]+list(resolution+2),'i')
|
convoluted = np.empty([len(neighborhood)]+list(resolution+2),'i')
|
||||||
microstructure = periodic_3Dpad(numpy.array(table.data[:,3].reshape(resolution),'i'))
|
microstructure = periodic_3Dpad(np.array(table.data[:,3].reshape(resolution),'i'))
|
||||||
|
|
||||||
for i,p in enumerate(neighborhood):
|
for i,p in enumerate(neighborhood):
|
||||||
stencil = numpy.zeros((3,3,3),'i')
|
stencil = np.zeros((3,3,3),'i')
|
||||||
stencil[1,1,1] = -1
|
stencil[1,1,1] = -1
|
||||||
stencil[p[0]+1,
|
stencil[p[0]+1,
|
||||||
p[1]+1,
|
p[1]+1,
|
||||||
|
@ -187,36 +174,34 @@ for file in files:
|
||||||
|
|
||||||
convoluted[i,:,:,:] = ndimage.convolve(microstructure,stencil)
|
convoluted[i,:,:,:] = ndimage.convolve(microstructure,stencil)
|
||||||
|
|
||||||
distance = numpy.ones((len(feature_list),resolution[0],resolution[1],resolution[2]),'d')
|
distance = np.ones((len(feature_list),resolution[0],resolution[1],resolution[2]),'d')
|
||||||
|
|
||||||
convoluted = numpy.sort(convoluted,axis=0)
|
convoluted = np.sort(convoluted,axis=0)
|
||||||
uniques = numpy.zeros(resolution)
|
uniques = np.zeros(resolution)
|
||||||
check = numpy.empty(resolution)
|
check = np.empty(resolution)
|
||||||
check[:,:,:] = numpy.nan
|
check[:,:,:] = np.nan
|
||||||
for i in xrange(len(neighborhood)):
|
for i in xrange(len(neighborhood)):
|
||||||
uniques += numpy.where(convoluted[i,1:-1,1:-1,1:-1] == check,0,1)
|
uniques += np.where(convoluted[i,1:-1,1:-1,1:-1] == check,0,1)
|
||||||
check = convoluted[i,1:-1,1:-1,1:-1]
|
check = convoluted[i,1:-1,1:-1,1:-1]
|
||||||
for i,feature_id in enumerate(feature_list):
|
for i,feature_id in enumerate(feature_list):
|
||||||
distance[i,:,:,:] = numpy.where(uniques > features[feature_id]['aliens'],0.0,1.0)
|
distance[i,:,:,:] = np.where(uniques > features[feature_id]['aliens'],0.0,1.0)
|
||||||
|
|
||||||
for i in xrange(len(feature_list)):
|
for i in xrange(len(feature_list)):
|
||||||
distance[i,:,:,:] = ndimage.morphology.distance_transform_edt(distance[i,:,:,:])*[unitlength]*3
|
distance[i,:,:,:] = ndimage.morphology.distance_transform_edt(distance[i,:,:,:])*[unitlength]*3
|
||||||
distance.shape = (len(feature_list),resolution.prod())
|
distance.shape = (len(feature_list),resolution.prod())
|
||||||
|
|
||||||
|
# ------------------------------------------ process data ---------------------------------------
|
||||||
table.data_rewind()
|
table.data_rewind()
|
||||||
l = 0
|
l = 0
|
||||||
while table.data_read():
|
while table.data_read():
|
||||||
for i in xrange(len(feature_list)):
|
for i in xrange(len(feature_list)):
|
||||||
table.data_append(distance[i,l]) # add all distance fields
|
table.data_append(distance[i,l]) # add all distance fields
|
||||||
table.data_write() # output processed line
|
outputAlive = table.data_write() # output processed line
|
||||||
l += 1
|
l += 1
|
||||||
|
|
||||||
# ------------------------------------------ output result ---------------------------------------
|
# ------------------------------------------ output result ---------------------------------------
|
||||||
|
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||||
|
|
||||||
table.output_flush() # just in case of buffered ASCII table
|
file['input'].close() # close input ASCII table (works for stdin)
|
||||||
|
file['output'].close() # close output ASCII table (works for stdout)
|
||||||
if file['name'] != 'STDIN':
|
|
||||||
file['input'].close() # close input ASCII table
|
|
||||||
file['output'].close() # close output ASCII table
|
|
||||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||||
|
|
|
@ -1,36 +1,23 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string,re,math,numpy
|
import os,re,sys,math,string
|
||||||
import damask
|
import numpy as np
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
from optparse import OptionParser
|
||||||
|
import damask
|
||||||
|
|
||||||
scriptID = '$Id$'
|
scriptID = '$Id$'
|
||||||
scriptName = scriptID.split()[1]
|
scriptName = scriptID.split()[1]
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
class extendedOption(Option):
|
# MAIN
|
||||||
#--------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
|
||||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
|
||||||
|
|
||||||
ACTIONS = Option.ACTIONS + ("extend",)
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
||||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
||||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
|
||||||
|
|
||||||
def take_action(self, action, dest, opt, value, values, parser):
|
|
||||||
if action == "extend":
|
|
||||||
lvalue = value.split(",")
|
|
||||||
values.ensure_value(dest, []).extend(lvalue)
|
|
||||||
else:
|
|
||||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
|
||||||
|
|
||||||
|
|
||||||
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
|
||||||
Add RGB color value corresponding to TSL-OIM scheme for inverse pole figures.
|
Add RGB color value corresponding to TSL-OIM scheme for inverse pole figures.
|
||||||
""" + string.replace(scriptID,'\n','\\n')
|
|
||||||
|
""", version = string.replace(scriptID,'\n','\\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_option('-p', '--pole', dest='pole', type='float', nargs=3, metavar='X Y Z',
|
parser.add_option('-p', '--pole', dest='pole', type='float', nargs=3, metavar='X Y Z',
|
||||||
|
@ -75,8 +62,8 @@ if options.matrix != None: datainfo['tensor']['label'] += [options.matrix];
|
||||||
if options.quaternion != None: datainfo['quaternion']['label'] += [options.quaternion]; input = 'quaternion'
|
if options.quaternion != None: datainfo['quaternion']['label'] += [options.quaternion]; input = 'quaternion'
|
||||||
|
|
||||||
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
|
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
|
||||||
pole = numpy.array(options.pole)
|
pole = np.array(options.pole)
|
||||||
pole /= numpy.linalg.norm(pole)
|
pole /= np.linalg.norm(pole)
|
||||||
|
|
||||||
# ------------------------------------------ setup file handles ---------------------------------------
|
# ------------------------------------------ setup file handles ---------------------------------------
|
||||||
|
|
||||||
|
@ -124,15 +111,15 @@ for file in files:
|
||||||
while table.data_read(): # read next data line of ASCII table
|
while table.data_read(): # read next data line of ASCII table
|
||||||
|
|
||||||
if input == 'eulers':
|
if input == 'eulers':
|
||||||
o = damask.Orientation(Eulers=toRadians*numpy.array(map(float,table.data[column['vector'][options.eulers]:\
|
o = damask.Orientation(Eulers=toRadians*np.array(map(float,table.data[column['vector'][options.eulers]:\
|
||||||
column['vector'][options.eulers]+datainfo['vector']['len']])),
|
column['vector'][options.eulers]+datainfo['vector']['len']])),
|
||||||
symmetry=options.symmetry).reduced()
|
symmetry=options.symmetry).reduced()
|
||||||
elif input == 'matrix':
|
elif input == 'matrix':
|
||||||
o = damask.Orientation(matrix=numpy.array([map(float,table.data[column['tensor'][options.matrix]:\
|
o = damask.Orientation(matrix=np.array([map(float,table.data[column['tensor'][options.matrix]:\
|
||||||
column['tensor'][options.matrix]+datainfo['tensor']['len']])]),
|
column['tensor'][options.matrix]+datainfo['tensor']['len']])]),
|
||||||
symmetry=options.symmetry).reduced()
|
symmetry=options.symmetry).reduced()
|
||||||
elif input == 'frame':
|
elif input == 'frame':
|
||||||
o = damask.Orientation(matrix=numpy.array([map(float,table.data[column['vector'][options.a]:\
|
o = damask.Orientation(matrix=np.array([map(float,table.data[column['vector'][options.a]:\
|
||||||
column['vector'][options.a]+datainfo['vector']['len']] + \
|
column['vector'][options.a]+datainfo['vector']['len']] + \
|
||||||
table.data[column['vector'][options.b]:\
|
table.data[column['vector'][options.b]:\
|
||||||
column['vector'][options.b]+datainfo['vector']['len']] + \
|
column['vector'][options.b]+datainfo['vector']['len']] + \
|
||||||
|
@ -141,19 +128,17 @@ for file in files:
|
||||||
)]).reshape(3,3),
|
)]).reshape(3,3),
|
||||||
symmetry=options.symmetry).reduced()
|
symmetry=options.symmetry).reduced()
|
||||||
elif input == 'quaternion':
|
elif input == 'quaternion':
|
||||||
o = damask.Orientation(quaternion=numpy.array(map(float,table.data[column['quaternion'][options.quaternion]:\
|
o = damask.Orientation(quaternion=np.array(map(float,table.data[column['quaternion'][options.quaternion]:\
|
||||||
column['quaternion'][options.quaternion]+datainfo['quaternion']['len']])),
|
column['quaternion'][options.quaternion]+datainfo['quaternion']['len']])),
|
||||||
symmetry=options.symmetry).reduced()
|
symmetry=options.symmetry).reduced()
|
||||||
|
|
||||||
table.data_append(o.IPFcolor(pole))
|
table.data_append(o.IPFcolor(pole))
|
||||||
|
outputAlive = table.data_write() # output processed line
|
||||||
table.data_write() # output processed line
|
|
||||||
|
|
||||||
# ------------------------------------------ output result ---------------------------------------
|
# ------------------------------------------ output result ---------------------------------------
|
||||||
|
outputAlive and table.output_flush() # just in case of buffered ASCII table
|
||||||
|
|
||||||
table.output_flush() # just in case of buffered ASCII table
|
file['input'].close() # close input ASCII table (works for stdin)
|
||||||
|
file['output'].close() # close output ASCII table (works for stdout)
|
||||||
if file['name'] != 'STDIN':
|
if file['name'] != 'STDIN':
|
||||||
file['input'].close() # close input ASCII table
|
|
||||||
file['output'].close() # close output ASCII table
|
|
||||||
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new
|
||||||
|
|
Loading…
Reference in New Issue