-
Notifications
You must be signed in to change notification settings - Fork 1
/
corientation_test.py
executable file
·70 lines (55 loc) · 2.02 KB
/
corientation_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
import time,sys
import numpy as np
from cyxtal import Quaternion, Orientation
#import damask.orientation.Orientation as pOrientation
###########################xs
# Testing Quaternion class
print "*"*10+"Test Quaternion"+"*"*10
a = Quaternion.fromRandom()
b = Quaternion.fromRandom()
c = Quaternion(a)
print "a:{}\nb:{}\nc:{}\n".format(a,b,c)
print "a**2 : {}".format(a**2)
print "a/=2 : {}".format(a/2)
print "a+b : {}".format(a+b)
print "a-b : {}".format(a-b)
print "a*b : {}".format(a*b)
print "-a : {}".format(-a)
print "|a| : {}".format(abs(a))
print "|a|^2: {}".format(a.magnitude_squared())
print "a==b : {}".format(a==b)
print "a!=c : {}; a==c : {}".format(a!=c, a==c)
print "Identity:{}".format(Quaternion.fromIdentity())
print "a inversed: {}".format(a.inverse())
print "as list: {}".format(a.asList())
############################
# Testing for Symmetry class
print "*"*10+"Test Symmetry"+"*"*10
############################
# Testing for Orientation class
print "*"*10+"Test Orientation"+"*"*10
a = Orientation(quaternion=Quaternion([0.2230, 0.9533, 0.2004, 0.0374]),
symmetry='hexagonal')
b = Orientation(quaternion=Quaternion([0.2662, -0.8247,-0.1579, 0.4734]),
symmetry='hexagonal')
print np.degrees(a.disorientation(b).asEulers())
###################
# Testing for Speed
print "*"*10+"Test Speed"+"*"*10
start = time.clock()
N = int(sys.argv[1]) # testing size
data = [Orientation(random=True, symmetry='hexagonal') for i in range(N)]
ref = Orientation(random=True, symmetry='hexagonal')
for item in data:
ref.disorientation(item)
runtime = time.clock() - start
print "Total runtime: {}s".format(runtime)
###################
# Testing IPF color
a = np.random.random((5,3)) * 180
co = [ Orientation(Eulers=np.radians(a[i]), symmetry=3).IPFcolor(np.array([0,1.0,0])) for i in range(5)]
#po = [pOrientation(Eulers=np.radians(a[i]), symmetry='hexagonal').IPFcolor(np.array([0,1.0,0])) for i in range(5)]
for i in range(5):
print co[i]#, po[i]