critdist = 0.04 withintriangle = False elif examplenum == 1: compvert2 = numpy.array([0.125, 0.125, 0.6, 0.15]) compvert0 = numpy.array([0.2, 0.2, 0.0, 0.6]) compvert1 = numpy.array([1.0, 0.0, 0.0, 0]) critdist = 0.04 withintriangle = True q.scatter(comps, c=comps[:, 3]) q.label(ha="center", va="center", fontsize=16) q.set_projection(azim=-17, elev=-6) inds, distfromplane, xyparr, xyp_verts, intriangle = q2.filterbydistancefromplane( comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=False, returnall=True ) indsnot = q2.filterbydistancefromplane( comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=True ) print len(inds), " points" q2.scatter(comps[inds], c=comps[inds, 3]) q2.scatter(comps[indsnot], c="grey", marker=".", s=5) q2.line(compvert0, compvert1) q2.line(compvert1, compvert2) q2.line(compvert2, compvert0) q2.label(ha="center", va="center", fontsize=16) q2.set_projection(azim=-17, elev=-6)
quatxfig=pylab.figure() quatx=QuaternaryPlot(111, ellabels=ellabels, offset=0) cbax=quatxfig.add_axes((.83, .3, .04, .4)) quatx.label() compverts=[[.5,.5, 0, 0], [.5, 0, .5, 0], [0, 0, .1, .9]] calctype=1 critdist=.05 betweenbool=1 invertbool=0 if calctype==0: selectinds, distfromlin, lineparameter=quatx.filterbydistancefromline(compsall[code0inds], compverts[0], compverts[1], critdist, betweenpoints=betweenbool, invlogic=invertbool, returnall=True) lineparameter=lineparameter[selectinds] elif calctype==1: selectinds, distfromplane, xyparr, xyp_verts,intriangle=quatx.filterbydistancefromplane(compsall[code0inds], compverts[0], compverts[1], compverts[2], critdist, withintriangle=betweenbool, invlogic=invertbool, returnall=True) xyparr=xyparr[selectinds] fomselectx=fomall[code0inds][selectinds] compsselectx=compsall[code0inds][selectinds] xsecfig=pylab.figure() xsecax=pylab.subplot(111) if calctype==0: quatx.line(compverts[0], compverts[1]) quatx.plotfomalonglineparameter(xsecax, lineparameter, fomselectx, compend1=compverts[0], compend2=compverts[1], lineparticks=numpy.linspace(0, 1, 4), ls='none', marker='.') elif calctype==1: quatx.plotfominselectedplane(xsecax, xyparr, fomselectx, xyp_verts=xyp_verts, vertcomps_labels=[compverts[0], compverts[1], compverts[2]], s=20, edgecolor='none', cmap=cmap, norm=norm) quatx.line(compverts[0], compverts[1]) quatx.line(compverts[0], compverts[2]) quatx.line(compverts[2], compverts[1])
class quatsliceDialog(QDialog): def __init__(self, parent, echem30_select, echem30_all, title="", folderpath=None, ellabels=["A", "B", "C", "D"]): super(quatsliceDialog, self).__init__(parent) self.parent = parent self.echem30_select = echem30_select self.echem30_all = echem30_all self.ellabels = ellabels self.dataclass = fomdatapreset() self.plotw_quat = plotwidget(self, projection3d=True) self.plotw_tern = plotwidget(self) axrect = [0.85, 0.1, 0.04, 0.8] self.plotw_tern.fig.subplots_adjust(left=0.1, right=axrect[0] - 0.08) self.cbax_tern = self.plotw_tern.fig.add_axes(axrect) QObject.connect(self.plotw_tern, SIGNAL("genericclickonplot"), self.ternclickprocess) self.plotw_quat.fig.subplots_adjust(left=0, right=axrect[0] - 0.08) self.cbax_quat = self.plotw_quat.fig.add_axes(axrect) ternskipComboBoxLabel = QLabel() ternskipComboBoxLabel.setText("Exclude for ternary:") self.ternskipComboBox = QComboBox() for i, l in enumerate(["A", "B", "C", "D"]): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(i) ternskiplayout = QHBoxLayout() ternskiplayout.addWidget(ternskipComboBoxLabel) ternskiplayout.addWidget(self.ternskipComboBox) self.compcutComboBox = QComboBox() for i, nam in enumerate(["1-D (pseudobinary)", "2-D (pseudoternnary)"]): self.compcutComboBox.insertItem(i, nam) self.compcutComboBox.setCurrentIndex(0) self.systemsComboBox = QComboBox() self.systemsinds = [-1, 0] self.systemsComboBox.insertItem(999, "select files") self.systemsComboBox.insertItem(999, "update style") for ind, nam in self.dataclass.systemoptions: self.systemsComboBox.insertItem(999, nam) self.systemsinds += [ind] self.systemsComboBox.setCurrentIndex(0) sl = ["0.", "0.", "1.", "0.", "0.", "0."] self.complineeditlist = [] for i in range(3): self.complineeditlist += [QLineEdit()] self.complineeditlist[-1].setText(", ".join(sl[2 - i : 2 - i + 4])) compLabel = QLabel() compLabel.setText("Composition points") folderButton = QPushButton() folderButton.setText("select\nfolder") QObject.connect(folderButton, SIGNAL("pressed()"), self.selectfolder) plotButton = QPushButton() plotButton.setText("update\nfigures") QObject.connect(plotButton, SIGNAL("pressed()"), self.calcandplot) saveButton = QPushButton() saveButton.setText("Save figs\n+ Samples") QObject.connect(saveButton, SIGNAL("pressed()"), self.save) templab = QLabel() templab.setText("Crit Comp. Dist") self.critdistSpinBox = QDoubleSpinBox() self.critdistSpinBox.setDecimals(3) critdistlayout = QHBoxLayout() critdistlayout.addWidget(templab) critdistlayout.addWidget(self.critdistSpinBox) self.compboundCheckBox = QCheckBox() self.compboundCheckBox.setText("restrict composition\nselection boundaries") self.invertCheckBox = QCheckBox() self.invertCheckBox.setText("invert selection") self.revcmapCheckBox = QCheckBox() self.revcmapCheckBox.setText("reverse cmap?") templab = QLabel() templab.setText("min,max colorbar") self.vminmaxLineEdit = QLineEdit() vminmaxlayout = QVBoxLayout() vminmaxlayout.addWidget(templab) vminmaxlayout.addWidget(self.vminmaxLineEdit) templab = QLabel() templab.setText("azim,elev tetr.") self.azimelevLineEdit = QLineEdit() azimelevlayout = QVBoxLayout() azimelevlayout.addWidget(templab) azimelevlayout.addWidget(self.azimelevLineEdit) self.azimelevLineEdit.setText("-159,30") templab = QLabel() templab.setText('below,above range colors:\nEnter a char,0-1 gray,tuple,\n"None" for ignore') self.aboverangecolLineEdit = QLineEdit() self.aboverangecolLineEdit.setText("k") self.belowrangecolLineEdit = QLineEdit() self.belowrangecolLineEdit.setText("0.9") outrangecollayout = QGridLayout() outrangecollayout.addWidget(templab, 0, 0, 2, 1) outrangecollayout.addWidget(self.belowrangecolLineEdit, 0, 1) outrangecollayout.addWidget(self.aboverangecolLineEdit, 1, 1) templab = QLabel() templab.setText("FOM shift:") self.fomshiftSpinBox = QDoubleSpinBox() self.fomshiftSpinBox.setDecimals(3) fomshiftlayout = QHBoxLayout() fomshiftlayout.addWidget(templab) fomshiftlayout.addWidget(self.fomshiftSpinBox) templab = QLabel() templab.setText("FOM scaling:") self.fomscaleSpinBox = QDoubleSpinBox() self.fomscaleSpinBox.setMaximum(1000.0) self.fomscaleSpinBox.setMinimum(-1000.0) self.fomscaleSpinBox.setValue(1.0) fomscalelayout = QHBoxLayout() fomscalelayout.addWidget(templab) fomscalelayout.addWidget(self.fomscaleSpinBox) mainlayout = QGridLayout() ctrllayout = QGridLayout() ctrllayout.addWidget(plotButton, 0, 0) ctrllayout.addWidget(self.compcutComboBox, 0, 1) ctrllayout.addWidget(saveButton, 0, 2) ctrllayout.addWidget(self.systemsComboBox, 0, 3) ctrllayout.addWidget(compLabel, 1, 0) ctrllayout.addWidget(self.complineeditlist[0], 1, 1) ctrllayout.addWidget(self.complineeditlist[1], 1, 2) ctrllayout.addWidget(self.complineeditlist[2], 1, 3) ctrllayout.addWidget(self.compboundCheckBox, 2, 0) ctrllayout.addWidget(self.invertCheckBox, 2, 1) ctrllayout.addLayout(critdistlayout, 2, 2, 1, 2) ctrllayout.addWidget(self.revcmapCheckBox, 3, 0) ctrllayout.addLayout(vminmaxlayout, 3, 1) ctrllayout.addLayout(outrangecollayout, 3, 2, 1, 2) ctrllayout.addLayout(ternskiplayout, 4, 0) # ctrllayout.addLayout(fomshiftlayout, 4, 1) # ctrllayout.addLayout(fomscalelayout, 4, 2) ctrllayout.addLayout(azimelevlayout, 4, 1, 1, 2) mainlayout.addLayout(ctrllayout, 0, 0, 2, 1) mainlayout.addWidget(self.plotw_quat, 3, 0) mainlayout.addWidget(self.plotw_tern, 4, 0) # mainlayout.addWidget(self.plotw_30select, 0, 1, 2, 8) # mainlayout.addWidget(self.plotw_30all, 2, 1, 2, 8) self.setLayout(mainlayout) self.folderpath = folderpath self.ternskipComboBox.clear() for i, l in enumerate(self.ellabels): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(3) self.selectsystem = None self.quatcalc = QuaternaryPlot(111, ellabels=self.ellabels) self.resize(600, 850) def selectfolder(self, folder=None): if folder is None: self.folderpath = mygetdir(self, markstr="for saving") else: self.folderpath = folder def calcandplot(self): print "0" i = self.systemsinds[self.systemsComboBox.currentIndex()] if self.selectsystem is None or i == -1 or (i != 0 and i != self.selectsystem): self.selectsystem = i self.dataclass.readdata(self.selectsystem, qparent=self) self.comps = self.dataclass.compsall self.fom = self.dataclass.fomall self.smp = self.dataclass.smpsall self.code = self.dataclass.codeall # self.codeorig=self.dataclass.codeorig # self.smpsorig=self.dataclass.smpsorig self.ellabels = self.dataclass.ellabels self.vminmaxLineEdit.setText(` self.dataclass.vmin ` + "," + ` self.dataclass.vmax `) for le, v in zip( [self.belowrangecolLineEdit, self.aboverangecolLineEdit], [self.dataclass.belowrangecolstr, self.dataclass.aboverangecolstr], ): le.setText(` v `) i0 = self.ternskipComboBox.currentIndex() self.ternskipComboBox.clear() for i, l in enumerate(self.ellabels): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(i0) self.calctype = self.compcutComboBox.currentIndex() critdist = self.critdistSpinBox.value() print "1" self.compverts = [] for i in range(2 + self.calctype): sl = str(self.complineeditlist[i].text()).split(",") c = [myeval(s.strip()) for s in sl] c = c[:4] c += [0.0] * (4 - len(c)) c = numpy.float64(c) c /= c.sum() self.compverts += [c] betweenbool = self.compboundCheckBox.isChecked() invertbool = self.invertCheckBox.isChecked() if self.calctype == 0: self.selectinds, distfromlin, self.lineparameter = self.quatcalc.filterbydistancefromline( self.comps, self.compverts[0], self.compverts[1], critdist, betweenpoints=betweenbool, invlogic=invertbool, returnall=True, ) self.lineparameter = self.lineparameter[self.selectinds] elif self.calctype == 1: self.selectinds, distfromplane, self.xyparr, self.xyp_verts, intriangle = self.quatcalc.filterbydistancefromplane( self.comps, self.compverts[0], self.compverts[1], self.compverts[2], critdist, withintriangle=betweenbool, invlogic=invertbool, returnall=True, ) self.xyparr = self.xyparr[self.selectinds] self.selectcomps = self.comps[self.selectinds] self.plot() def plot(self): s = 25 self.plotw_tern.axes.cla() self.plotw_quat.axes.cla() self.cbax_quat.cla() self.cbax_tern.cla() fom = self.fom azim = -159.0 elev = 30.0 vstr = str(self.azimelevLineEdit.text()).strip() if "," in vstr: a, b, c = vstr.partition(",") try: a = myeval(a.strip()) c = myeval(c.strip()) self.vmin = a self.vmax = c except: pass if self.revcmapCheckBox.isChecked(): cmap = cm.jet_r else: cmap = cm.jet clip = True skipoutofrange = [False, False] self.vmin = fom.min() self.vmax = fom.max() vstr = str(self.vminmaxLineEdit.text()).strip() if "," in vstr: a, b, c = vstr.partition(",") try: a = myeval(a.strip()) c = myeval(c.strip()) self.vmin = a self.vmax = c for count, (fcn, le) in enumerate( zip([cmap.set_under, cmap.set_over], [self.belowrangecolLineEdit, self.aboverangecolLineEdit]) ): vstr = str(le.text()).strip() vstr = vstr.replace('"', "").replace("'", "") print "^^^", vstr, "none" in vstr or "None" in vstr if "none" in vstr or "None" in vstr: skipoutofrange[count] = True continue if len(vstr) == 0: continue c = col_string(vstr) try: fcn(c) clip = False except: print "color entry not understood:", vstr except: pass print "4" norm = colors.Normalize(vmin=self.vmin, vmax=self.vmax, clip=clip) print "fom min, max, mean, std:", fom.min(), fom.max(), fom.mean(), fom.std() comps = self.comps # comment out this skipoutofrange becuase it could mess up the indexing # print 'skipoutofrange', skipoutofrange # print len(fom) # if skipoutofrange[0]: # inds=numpy.where(fom>=self.vmin) # fom=fom[inds] # comps=comps[inds] # print len(fom) # if skipoutofrange[1]: # inds=numpy.where(fom<=self.vmax) # fom=fom[inds] # comps=comps[inds] # print len(fom) if numpy.any(fom > self.vmax): if numpy.any(fom < self.vmin): extend = "both" else: extend = "max" elif numpy.any(fom < self.vmin): extend = "min" else: extend = "neither" print "extend ", extend i = self.ternskipComboBox.currentIndex() inds = [j for j in range(4) if j != i][:3] terncomps = numpy.array([c[inds] / c[inds].sum() for c in comps]) reordercomps = comps[:, inds + [i]] reorderlabels = [self.ellabels[j] for j in inds + [i]] fomselect = fom[self.selectinds] compsselect = comps[self.selectinds] reordercompsselect = reordercomps[self.selectinds] fomlabel = self.dataclass.fomlabel self.stackedternplotdict = dict( [ ("comps", reordercomps), ("fom", fom), ("cmap", cmap), ("norm", norm), ("ellabels", reorderlabels), ("fomlabel", fomlabel), ("extend", extend), ] ) self.echem30_all.clearandplot(self.stackedternplotdict, cb=True, ellabels=reorderlabels) print len(fomselect), " samples selected" if len(fomselect) > 0: self.stackedternplotdictselect = dict( [ ("comps", reordercompsselect), ("fom", fomselect), ("cmap", cmap), ("norm", norm), ("ellabels", reorderlabels), ("fomlabel", fomlabel), ("extend", extend), ] ) self.echem30_select.clearandplot(self.stackedternplotdictselect, cb=True, ellabels=reorderlabels) quat = QuaternaryPlot(self.plotw_quat.axes, ellabels=self.ellabels, offset=0) quat.label() quat.scatter( compsselect, c=fomselect, s=s, cmap=cmap, norm=norm, edgecolor="none" ) # vmin=self.vmin, vmax=self.vmax, cb = self.plotw_quat.fig.colorbar( quat.mappable, cax=self.cbax_quat, extend=extend, format=autocolorbarformat((fom.min(), fom.max())) ) cb.set_label(fomlabel, fontsize=18) quat.set_projection(azim=azim, elev=elev) if self.calctype == 0: quat.line(self.compverts[0], self.compverts[1]) self.quatcalc.plotfomalonglineparameter( self.plotw_tern.axes, self.lineparameter, fomselect, compend1=self.compverts[0], compend2=self.compverts[1], lineparticks=numpy.linspace(0, 1, 4), ls="none", marker=".", ) elif self.calctype == 1: self.quatcalc.plotfominselectedplane( self.plotw_tern.axes, self.xyparr, fomselect, xyp_verts=self.xyp_verts, vertcomps_labels=[self.compverts[0], self.compverts[1], self.compverts[2]], s=20, edgecolor="none", cmap=cmap, norm=norm, ) quat.line(self.compverts[0], self.compverts[1]) quat.line(self.compverts[0], self.compverts[2]) quat.line(self.compverts[2], self.compverts[1]) cb = self.plotw_tern.fig.colorbar( quat.mappable, cax=self.cbax_tern, extend=extend, format=autocolorbarformat((fom.min(), fom.max())) ) cb.set_label(fomlabel, fontsize=18) self.plotw_quat.axes.mouse_init() self.plotw_quat.axes.set_axis_off() self.plotw_tern.fig.canvas.draw() self.plotw_quat.fig.canvas.draw() def ternclickprocess(self, coords_button): xc, yc, button = coords_button if self.calctype == 0: clickindsel = numpy.argmin((self.lineparameter - xc) ** 2) elif self.calctype == 1: clickindsel = numpy.argmin([(x - xc) ** 2 + (y - yc) ** 2 for x, y in self.xyparr]) cmp = self.selectcomps[clickindsel] clickind = numpy.argmin([((cmp - c) ** 2).sum() for c in self.comps]) s = self.smp[clickind] print "clicked composition is ", cmp, " sample is ", s def save(self): self.selectfolder(None) lab = str(self.systemsComboBox.currentText()) lab += "_" + self.dataclass.expstr + "_" if self.calctype == 0: lab += "1Dcut_" elif self.calctype == 1: lab += "2Dcut_" pngname = lambda sn: os.path.join(self.folderpath, lab + "_" + sn + ".png") epsname = lambda sn: os.path.join(self.folderpath, lab + "_" + sn + ".eps") for fig, saven in zip( [self.plotw_quat.fig, self.plotw_tern.fig, self.echem30_select.plotw.fig, self.echem30_all.plotw.fig], ["tetr", "projection", "stackedselect", "stackedall"], ): fig.savefig(pngname(saven)) fig.savefig(epsname(saven)) s = "\n".join([` i ` for i in self.smp[self.selectinds]])
compvert2 = numpy.array([0.125, .125, .6, .15]) compvert0 = numpy.array([.2, .2, 0., .6]) compvert1 = numpy.array([1., 0., 0., 0]) critdist = .04 withintriangle = True q.scatter(comps, c=comps[:, 3]) q.label(ha='center', va='center', fontsize=16) q.set_projection(azim=-17, elev=-6) inds, distfromplane, xyparr, xyp_verts, intriangle = q2.filterbydistancefromplane( comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=False, returnall=True) indsnot = q2.filterbydistancefromplane(comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=True) print len(inds), ' points' q2.scatter(comps[inds], c=comps[inds, 3]) q2.scatter(comps[indsnot], c='grey', marker='.', s=5) q2.line(compvert0, compvert1)
cols=stpq.rgb_comp(comps30) stpq.plotbycolor(comps30, cols, marker='o', markersize=3, alpha=1) stpq.set_projection(azim=view_azim, elev=view_elev) pylab.savefig(os.path.join(savefolder, 'QuatPointsAll.png')) pylab.savefig(os.path.join(savefolder, 'QuatPointsAll.eps')) pylab.figure() #axq=pylab.subplot(111) stpqp=QuaternaryPlot(111, ellabels=ellabels) selectinds, distfromplane, xyparr, xyp_verts,intriangle=stpqp.filterbydistancefromplane(comps, compvertsp[0], compvertsp[1], compvertsp[2], critdistp, withintriangle=betweenbool, invlogic=invertbool, returnall=True) xyparr=xyparr[selectinds] cols=stpqp.rgb_comp(comps[selectinds]) stpqp.plotbycolor(comps[selectinds], cols, marker='o', markersize=3, alpha=1) stpqp.line(compvertsp[0], compvertsp[1], lw=2) stpqp.line(compvertsp[2], compvertsp[1], lw=2) stpqp.line(compvertsp[0], compvertsp[2], lw=2) #stpqp.scatter(comps[selectinds], pointsize stpqp.set_projection(azim=view_azim, elev=view_elev) stpqp.label(fontsize=20)