2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2020-03-17 13:10:03 +05:30
|
|
|
from io import StringIO
|
2014-08-07 22:21:26 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-08-07 22:21:26 +05:30
|
|
|
import damask
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-05-27 13:38:10 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 12:30:26 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2015-03-29 21:07:40 +05:30
|
|
|
Rotate vector and/or tensor column data by given angle around given axis.
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2014-08-07 22:21:26 +05:30
|
|
|
""", version = scriptID)
|
|
|
|
|
2018-12-09 11:40:31 +05:30
|
|
|
parser.add_option('-d', '--data',
|
|
|
|
dest = 'data',
|
2015-08-08 00:33:26 +05:30
|
|
|
action = 'extend', metavar = '<string LIST>',
|
2018-12-09 11:40:31 +05:30
|
|
|
help = 'vector/tensor value(s) label(s)')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-r', '--rotation',
|
|
|
|
dest = 'rotation',
|
|
|
|
type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
2019-03-10 00:28:17 +05:30
|
|
|
help = 'axis and angle to rotate data [%default]')
|
2018-12-09 11:40:31 +05:30
|
|
|
parser.add_option('--degrees',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'degrees',
|
|
|
|
action = 'store_true',
|
2019-02-16 19:23:56 +05:30
|
|
|
help = 'angles are given in degrees')
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-03-10 00:28:17 +05:30
|
|
|
parser.set_defaults(rotation = (1.,1.,1.,0), # no rotation about (1,1,1)
|
2015-08-08 00:33:26 +05:30
|
|
|
degrees = False,
|
|
|
|
)
|
2020-05-16 13:10:44 +05:30
|
|
|
|
2014-05-27 13:38:10 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2020-03-17 13:10:03 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2018-12-09 11:40:31 +05:30
|
|
|
if options.data is None:
|
2020-05-16 13:10:44 +05:30
|
|
|
parser.error('no data column specified.')
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2020-05-16 13:10:44 +05:30
|
|
|
r = damask.Rotation.from_axis_angle(options.rotation,options.degrees,normalise=True)
|
2015-02-11 22:52:47 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2020-03-17 13:10:03 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2020-05-16 13:10:44 +05:30
|
|
|
|
2020-03-17 13:10:03 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
|
|
|
|
for data in options.data:
|
|
|
|
d = table.get(data)
|
|
|
|
if table.shapes[data] == (9,): d=d.reshape(-1,3,3)
|
2020-05-16 13:10:44 +05:30
|
|
|
d = r.broadcast_to(d.shape[0:1]) @ d
|
2020-03-17 13:10:03 +05:30
|
|
|
if table.shapes[data] == (9,): d=d.reshape(-1,9)
|
2020-05-16 13:10:44 +05:30
|
|
|
|
2020-03-17 13:10:03 +05:30
|
|
|
table.set(data,d,scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
|
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|