-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_Cpxrdanalysis_2dplotswithcoloredcomp.py
184 lines (156 loc) · 5.55 KB
/
plot_Cpxrdanalysis_2dplotswithcoloredcomp.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import os
os.chdir('C:/Users/JohnnyG/Documents/PythonCode/ternaryplot')
from myternaryutility import TernaryPlot
import time, copy
import os
import sys
import numpy
import h5py
#from PnSC_ui import *
#from PnSC_dataimport import *
from PnSC_SCui import *
#from PnSC_math import *
from PnSC_h5io import *
from PnSC_main import *
from matplotlib.ticker import FuncFormatter
import scipy.integrate
from scipy.interpolate import griddata
import matplotlib.cm as cm
selectcell=25
p='C:/Users/JohnnyG/Documents/PythonCode/Vlassak/NanoCalorimetry/AuSiCu_pnsc_all.h5'
def myexpformat(x, pos):
for ndigs in range(2):
lab=(('%.'+'%d' %ndigs+'e') %x).replace('e+0','e').replace('e+','e').replace('e0','').replace('e-0','e-')
if eval(lab)==x:
return lab
return lab
ExpTickLabels=FuncFormatter(myexpformat)
def make_ticklabels_invisible(ax, x=True, y=True):
if x:
for tl in ax.get_xticklabels():
tl.set_visible(False)
if y:
for tl in ax.get_yticklabels():
tl.set_visible(False)
cycleindex=0
#p=mm.h5path
#f=h5py.File(p, mode='r+')
#f=h5py.File(p, mode='r')
savef='C:/Users/JohnnyG/Documents/HarvardWork/MG/PnSCplots/batchplotbycell_June2'
plotTlim=(50., 700.)
f=h5py.File(p, mode='r')
comp=f['CompThick/atfrac'][:, :]
metadictlists=[]
for selectcell in range(1, 26):
metadictlist=[]
#allsegdict=[]
if `selectcell` in f['calbycellmetadata']:
cg=f['calbycellmetadata'][`selectcell`]
for mg in cg.itervalues():
if isinstance(mg, h5py.Group) and 'Cpregions_enthalpy' in mg.attrs.keys():
d={}
for k, v in mg.attrs.iteritems():
d[k]=v
# if selectcell==1 and d['name'].startswith('heat1'):#heat1a was botched and heat1b we don't know cooling rate and the XRd for heat0 was questionable anyway
# continue
metadictlist+=[d]
#allsegdict+=[CreateHeatProgSegDictList(p, d['name'], d['h5hpname'])]
metadictlists+=[metadictlist]
xrddictlists=[]
for selectcell in range(1, 26):
xrddictlist=[]
if 'xrdbycell' in f and `selectcell` in f['xrdbycell']:
cg=f['xrdbycell'][`selectcell`]
for mg in cg.itervalues():
if isinstance(mg, h5py.Group):
d={}
for k, v in mg.attrs.iteritems():
d[k]=v
xrddictlist+=[d]
xrddictlists+=[xrddictlist]
f.close()
x_cell=[]
y_cell=[]
z_cell=[]
c_cell=[]
cell_cell=[]
x=[]
y=[]
z=[]
d=[]
c=[]
cells=[]
for cell, cv, mdl, xdl in zip(range(1, 26), comp, metadictlists, xrddictlists):
xtemp=[]
ytemp=[]
ztemp=[]
ctemp=[]
celltemp=-1
for md in mdl:
if not 'prevcoolrate_320C' in md.keys():
continue
pcal=md['prevname'][:5]
cal=md['name'][:5]
if pcal!=cal:#if previous scan was in same heat# as scan then there was no xrd in between
for xd in xdl:
if xd['name']==pcal:#use xrd that happened after the prev scan
x+=[numpy.abs(md['prevcoolrate_320C'])]
y+=[xd['amfrac']]
z+=[xd['othfrac']]
c+=[cv]
cells+=[cell]
xtemp+=[numpy.abs(md['prevcoolrate_320C'])]
ytemp+=[xd['amfrac']]
ztemp+=[xd['othfrac']]
ctemp+=[cv]
celltemp=cell
break
if len(ctemp)>0:
x_cell+=[xtemp]
y_cell+=[ytemp]
z_cell+=[ztemp]
c_cell+=[ctemp]
cell_cell+=[celltemp]
c=numpy.array(c)
y=numpy.array(y)
x=numpy.array(x)
z=numpy.array(z)
pylab.figure(figsize=(10, 6))
ax=pylab.subplot(111)
stp = TernaryPlot(ax, ellabels=['Au', 'Si', 'Cu'])
celllist=[1, 2]+range(4, 21)+[22]+[24, 25]
minlist=[c.min() for c in comp[numpy.array(celllist)-1, :].T]
rangelist=numpy.float32([[m, 1.-numpy.concatenate([minlist[:i], minlist[i+1:]]).sum()] for i, m in enumerate(minlist)])
colors=stp.color_comp_calc(comp[numpy.array(celllist)-1, :], rangelist=rangelist)
pylab.clf()
for cell, xv, yv, zv in zip(cell_cell, x_cell, y_cell, z_cell):
xv=numpy.array(xv)
yv=numpy.array(yv)
zv=numpy.array(zv)
sortarr=numpy.argsort(xv)
#pylab.plot(xv[sortarr], yv[sortarr], '.', color=colors[celllist.index(cell)], markersize=16)
#pylab.plot(xv[sortarr], yv[sortarr], '-', color=colors[celllist.index(cell)], linewidth=1, alpha=.5)
a=yv[sortarr]
#a=yv[sortarr]/(yv[sortarr]+zv[sortarr])
pylab.plot(xv[sortarr], a, '.', color=colors[celllist.index(cell)], markersize=16)
pylab.plot(xv[sortarr], a, '-', color=colors[celllist.index(cell)], linewidth=1, alpha=.5)
if numpy.any(a[1:]<a[:-1]):
print cell, xv[sortarr], a
# for xx, yy in zip(xv, yv):
# pylab.text(xx, yy, `cell`, ha='center', va='center', color=colors[celllist.index(cell)], fontsize=12)
pylab.gca().set_xscale('log')
xmin=x.min()-.05*(x.max()-x.min())
xmax=x.max()+.05*(x.max()-x.min())
a=y
#a=y/(y+z)
ymin=a.min()-.05*(a.max()-a.min())
ymax=a.max()+.05*(a.max()-a.min())
pylab.ylabel('amorphous fraction after cooling', fontsize=14)
#pylab.ylabel('amorph / amorph+phaseB', fontsize=14)
pylab.xlabel('cooling rate at 320C (K/s)', fontsize=14)
pylab.title('colored by composition', fontsize=14)
#pylab.ylabel(, fontsize=14)
pylab.xlim(xmin, xmax)
pylab.ylim(ymin, ymax)
#pylab.savefig(os.path.join(os.path.join(savef, 'cell%02d' %selectcell), 'HeatRatestack_cell%02d_%s.png' %(selectcell, metadict['name'])))
pylab.show()