-
Notifications
You must be signed in to change notification settings - Fork 3
/
uniq_orients.py
68 lines (55 loc) · 1.91 KB
/
uniq_orients.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
from __future__ import print_function, division
from ImageD11 import sym_u, columnfile, grain
import sys, numpy as np, pylab as pl
symmetry = sys.argv[1]
grp = getattr( sym_u, symmetry )()
ubifile = sys.argv[2]
uniqfile = sys.argv[3]
if ubifile[-3:] == "flt":
c = columnfile.columnfile( ubifile )
print("Got c.nrows",c.nrows)
ubis = np.zeros( (c.nrows, 3, 3), np.float)
for i in range(3):
for j in range(3):
ubis[:,i,j] = c.getcolumn( "UBI%d%d"%(i,j) )
del c
else:
c = grain.read_grain_file( ubifile )
ubis = np.array( [g.ubi for g in c] )
del c
ubis.shape = len(ubis), 9
# First is to cluster without symmetry
def removeone( ubis, testubi, tol=None):
diffs = abs(ubis - testubi).sum(axis=1)
if tol is None:
pl.hist(diffs,bins=1024)
pl.show()
tol = float( input("Tolerance?"))
matching = diffs < tol
# iterate in case this was not the centre of the bunch
ubi = ubis[matching].mean(axis=0)
diffs = abs(ubis - ubi).sum(axis=1)
matching = diffs < tol
ubi = ubis[matching].mean(axis=0)
remaining = ubis[~matching]
return ubi, remaining, tol
ubiall = ubis.copy()
tol = None
uniqs = []
while len( ubis > 0 ):
uniq, ubis, tol = removeone( ubis, ubis[0], tol )
print(uniq, len(ubis))
uniqs.append( uniq )
# now check if any uniqs have a collision due to symmetry:
uniqs = np.array( uniqs )
for i in range(len(uniqs)):
for operator in grp.group[1:]: # skip the identity
symubi = np.dot( operator, uniqs[i].reshape(3,3) ).ravel()
scors = abs(uniqs - symubi).sum(axis=1)
found = scors < tol
if found.sum() > 0:
print("Symmetry collision!")
print( i, operator.ravel(),
scors[found], np.arange(len(uniqs))[found])
grain.write_grain_file( uniqfile, [ grain.grain( ubi.reshape(3,3), (0,0,0) )
for ubi in uniqs ] )