-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mean of orientations, with symmetry #434
Comments
Hi Dorian, you have indeed encountered a somewhat surprising result, from a user standpoint. Do you get the desired results with this approach? >>> from orix.quaternion import Orientation, symmetry
>>> s = symmetry.Oh
>>> o = Orientation.from_euler([[0, 0, 0], [1, 89, 0], [1, 1, 89]], symmetry=s, degrees=True)
>>> o2 = o.map_into_symmetry_reduced_zone()
>>> obar2 = o2.mean()
>>> obar2.to_euler(degrees=True)
array([[179.9955333 , 0.32750355, 180.00737556]]) The above is basically the approach we should use in |
Thank you @hakonanes for this hack. Seems good! |
Glad it solves your immediate problem! Please report back here if it does not or you thought of something else related to this issue... I suggest we leave this open until we make |
Hello @hakonanes, o = Orientation.from_euler([[80, 42, 10]], degrees=True, symmetry=s)
o2 = o.map_into_symmetry_reduced_zone()
obar2 = o2.mean()
print(obar2.to_euler(degrees=True))
os = Orientation((o.data[0],obar2.data[0]),symmetry=o.symmetry)
print(os.get_distance_matrix(degrees=True)) you get:
As you can see here, the mean of a single orientation is not equal to this orientation. This is evidenced by the non-zero misorientation angle between o and its own mean. Am I doing or understanding something wrong? Rgds |
Very good point. I've made a change to from orix.quaternion import Orientation, symmetry
s = symmetry.Oh
o = Orientation.from_euler([80, 42, 10], degrees=True, symmetry=s)
o2 = o.reduce()
obar2 = o2.mean()
print(obar2.to_euler(degrees=True))
# [[ 80. 42. 280.]]
os = Orientation((o.data[0], obar2.data[0]), symmetry=o.symmetry)
print(os.get_distance_matrix(degrees=True))
# [[0. 0.]
# [0. 0.]] I would be very grateful if you could check out the branch in that PR and try out |
Hello @hakonanes , |
No problem, I don't think we will release this change within two weeks anyway. |
Hello @hakonanes , from orix.quaternion import Quaternion,Orientation, symmetry
import numpy as np
def mean_orientation(o, weights=None):
if weights is None:
weights=np.ones((1,o.shape[0]))
else:
# Force weights to be a 2d array
weights=np.array(weights, ndmin=2)
o2 = o.reduce()
q = o2.data
qq = np.einsum('pi,ij,ik->pjk', weights, q, q)
w, v = np.linalg.eig(qq)
w_max = np.argmax(w, axis=1)
q_mean= v[np.arange(weights.shape[0]), :, w_max]
return Orientation(Quaternion(q_mean), o.symmetry)
ori = Orientation.from_axes_angles(
[[1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 1, 0], [0, 0, 1], [0, 0, 1]],
[30, -30, 30, -30, 30, -30],
symmetry=symmetry.Oh,
degrees=True
)
print(ori.to_euler(degrees=True))
weights=[[1, 1, 1, 1, 1, 1],[1000, 1, 1, 1, 1, 1],[1, 1000, 1, 1, 1, 1],[1,1,1000,1,1,1]]
# Compute weighted mean orientation, wrt. the weighting matrix
ori_w = mean_orientation(ori, weights=weights)
# Print each weighted mean and its misorientation wrt. the initial orientations
for i,w in enumerate(weights):
print(' ')
print('Weights: {}'.format(w))
print('Mean Euler angles: {}'.format(ori_w[i].to_euler(degrees=True)))
os = Orientation(np.vstack((ori.data,ori_w.data[i])),symmetry=ori.symmetry)
d=os.get_distance_matrix(degrees=True)
print('Misorientation angles from weighted mean:')
print(d[-1,:])
Great job! |
Good! Thank you for doing the tests. Maintainer resources are in short supply, so we just have to wait a bit for #442 to be reviewed. |
Hello there!
It seems that the mean() method for orientations actually doesn't take the orientations' symmetry into account. For instance, let's consider the m-3m symmetry and a set of 3 close orientations:
Thus, the output is:
The result is quite strange. Indeed, the same computation on MTEX
gives
Still, the same with
CS=crystalSymmetry('1')
leads to:Am I doing something wrong? I have looked into MTEX's code, and I understand that the mean() method actually relies on the project2FundamentalRegion function. I have tried to implement it in orix, but without any success.
Thank you in advance.
The text was updated successfully, but these errors were encountered: