fixed (potentially) buggy rotation of tensors. convention is:
with A v = b v' = R v A' = R A R^T such that A' v' = R A R^T R v = R A v (= R b = b', i.e. old result transformed into other coordinate basis)
This commit is contained in:
parent
df27115472
commit
99e3c9a397
|
@ -23,7 +23,7 @@ parser.add_option('-v','--vector', dest = 'vector', action = 'extend', metavar=
|
|||
help = 'column heading of vector to scale')
|
||||
parser.add_option('-t','--tensor', dest = 'tensor', action = 'extend', metavar = 'string',
|
||||
help = 'column heading of tensor to scale')
|
||||
parser.add_option('-r', '--rotation',dest = 'rotation', type = 'float', nargs = 4, metavar='int int int int',
|
||||
parser.add_option('-r', '--rotation',dest = 'rotation', type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
|
||||
help = 'angle and axis to rotate data %default')
|
||||
parser.add_option('-d', '--degrees', dest = 'degrees', action = 'store_true',
|
||||
help = 'angles are given in degrees [%default]')
|
||||
|
@ -86,7 +86,9 @@ for file in files:
|
|||
# ------------------------------------------ process data ------------------------------------------
|
||||
outputAlive = True
|
||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||
|
||||
datatype = 'vector'
|
||||
|
||||
for label in active[datatype] if datatype in active else []: # loop over all requested labels
|
||||
table.data[column[datatype][label]:column[datatype][label]+datainfo[datatype]['len']] = \
|
||||
r * np.array(map(float,
|
||||
|
@ -96,11 +98,13 @@ for file in files:
|
|||
datatype = 'tensor'
|
||||
|
||||
for label in active[datatype] if datatype in active else []: # loop over all requested labels
|
||||
table.data[column[datatype][label]:column[datatype][label]+datainfo[datatype]['len']] = \
|
||||
(np.array(map(float,table.data[column[datatype][label]:\
|
||||
A = np.array(map(float,table.data[column[datatype][label]:\
|
||||
column[datatype][label]+datainfo[datatype]['len']])).\
|
||||
reshape(np.sqrt(datainfo[datatype]['len']),\
|
||||
np.sqrt(datainfo[datatype]['len'])) * R).reshape(datainfo[datatype]['len'])
|
||||
reshape(np.sqrt(datainfo[datatype]['len']),
|
||||
np.sqrt(datainfo[datatype]['len']))
|
||||
table.data[column[datatype][label]:\
|
||||
column[datatype][label]+datainfo[datatype]['len']] = \
|
||||
np.dot(R,np.dot(A,R.transpose())).reshape(datainfo[datatype]['len'])
|
||||
outputAlive = table.data_write() # output processed line
|
||||
|
||||
# ------------------------------------------ output result -----------------------------------------
|
||||
|
|
Loading…
Reference in New Issue