-
Notifications
You must be signed in to change notification settings - Fork 0
/
genplatemap_6elementsingleplate_v2_156separatedcomps.py
128 lines (101 loc) · 3.47 KB
/
genplatemap_6elementsingleplate_v2_156separatedcomps.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import time, copy, pickle
import os, os.path
import sys
import numpy, pylab
from fcns_generatecompositions import *
sys.path.append('Z:/Documents/PythonCode/JCAP')
from readplatemap import *
modelpath='Z:/Documents/CaltechWork/platemaps/Epson6Elementcombinations_singleplate/template_2topfiducials.txt'
newpath='Z:/Documents/CaltechWork/platemaps/Epson6Elementcombinations_singleplate/Epson6Elementcombinations_4els_10steps_156compsseparate.txt'
writelines=[]
f=open(modelpath, mode='r')
ls=f.readlines()[:2]
writelines+=[l.strip() for l in ls]
f.close()
dlist=readsingleplatemaptxt(modelpath, returnfiducials=False)
updatecomp=lambda d, c:d.update(dict([(s, v) for s, v in zip(['A', 'B', 'C', 'D', 'E','F', 'G', 'H'], c)]))
#put the binary compositions as code 100 at the last row and last columns except for right-most ref column
bincompinds=numpy.arange(2176-22-41,2176-1-41)
indstemp=[[i,j] for i in range(6) for j in range(i,6)]
for inds, dlistind in zip(indstemp, bincompinds):
z=numpy.zeros(6, dtype='float32')
z[inds]=1.
z/=z.sum()
updatecomp(dlist[dlistind], z)
dlist[dlistind]['code']=200
#comp refs as code 3 or 4 at right-most ref column
comprefinds=numpy.arange(34)*64#+63
indstemp=[i for i in range(-1, 6)]
indstemp=indstemp*5
indstemp=indstemp[1:]
#indstemp=indstemp[::-1]#reverse so AB.. at bottom right and ..DEF at top
ccompref=[]
for inds, dlistind in zip(indstemp, comprefinds):
z=numpy.zeros(6, dtype='float32')
if inds>=0:
z[inds]=1.
updatecomp(dlist[dlistind], z)
dlist[dlistind]['code']=2 if inds<4 else 3
#
#
#
c6=[]
for fcn in [combi_6el_inner1, combi_6el_inner2, combi_6el_inner3, combi_6el_inner4]:
c6+=list(fcn(10))
comps=numpy.array(c6)
selcomps=get_custom_select_comps_6els_5intervs()
cmpfcn=lambda x:True in [numpy.all(x==v) for v in selcomps]
selboolarr=numpy.bool_([cmpfcn(c) for c in comps])
selcompinds=[i+j for i in (numpy.arange(6)*64) for j in (numpy.arange(26)+19)]
ccompref=[]
for c, dlistind in zip(comps[selboolarr], selcompinds):
updatecomp(dlist[dlistind], c)
dlist[dlistind]['code']=0
comps2pop=copy.copy(list(comps[numpy.logical_not(selboolarr)]))
for count, d in enumerate(dlist):
if count in comprefinds or count in bincompinds or count in selcompinds:
continue
updatecomp(d, comps2pop.pop(0))
d['code']=100
k_f=[\
('Sample','%04d'),\
('x','%.2f'),\
('y','%.2f'),\
('dx','%.2f'),\
('dx','%.2f'),\
('A','%.3f'),\
('B','%.3f'),\
('C','%.3f'),\
('D','%.3f'),\
('E','%.3f'),\
('F','%.3f'),\
('G','%.3f'),\
('H','%.3f'),\
('code','%d'),\
]
writelines+=[', '.join([f %d[k] for k, f in k_f]) for d in dlist]
if 1:
f=open(newpath, mode='w')
f.write('\n'.join(writelines))
f.close()
sys.path.append('Z:/Documents/PythonCode/ternaryplot')
from myquaternaryutility import QuaternaryPlot
from myternaryutility import TernaryPlot
for d in dlist:
c=numpy.array([d[el] for el in ['A', 'B', 'C', 'D']])
if c.sum()>0:
c/=c.sum()
d['compositions']=c
carr=numpy.array([d['compositions'] for d in dlist])
stpq=QuaternaryPlot(111)
stpq.scatter(carr)
pylab.figure()
x, y=numpy.array([[d['x'], d['y']] for d in dlist if (d['code'])==0]).T
x2, y2=numpy.array([[d['x'], d['y']] for d in dlist if (d['code'])==100]).T
x3, y3=numpy.array([[d['x'], d['y']] for d in dlist if (d['code'])==200]).T
xn, yn=numpy.array([[d['x'], d['y']] for d in dlist if (d['code']%100)!=0]).T
pylab.plot(x, y, 'rs')
pylab.plot(x2, y2, 'gs')
pylab.plot(x3, y3, 'bs')
pylab.plot(xn, yn, 'k.')
pylab.show()