# Changeset 264

Ignore:
Timestamp:
Mar 31, 2011 4:41:13 PM (11 years ago)
Message:

begin implementation of pdf generation - work in progress
modify image to have azimuth=0 as vertical "up"
add textctrls for max and min image intensity
fix to some lattice parameter defaults for some Laue groups

Location:
trunk
Files:
10 edited

Unmodified
Removed

• ## trunk/GSASIIElem.py

 r230 import sys import os.path import  wx.lib.colourselect as wscs import wx.lib.colourselect as wscs import GSASIIpath import numpy as np t = -fb*SQ return np.sum(fa*np.exp(t))+FormFac['fc'] def ComptonFac(ComptonCoeff,SQ): """compute Compton scattering factor @param ComptonCoeff: list [Z, a1:a5, b1:b5] @param SQ: (sin-theta/lambda)**2 @return: comp: compton scattering factor """ ca = np.array(ComptonCoeff[1:6]) cb = np.array(ComptonCoeff[6:11]) t = -cb*SQ return ComptonCoeff[0]-np.sum(ca*np.exp(t)) def FPcalc(Orbs, KEv): "Makes periodic table widget for picking element - caller maintains element list" Elem=None def _init_ctrls(self, prnt): def _init_ctrls(self, prnt,oneOnly): wx.Dialog.__init__(self, id=-1, name='PickElement', parent=prnt, pos=wx.DefaultPosition, i=0 for E in ET.ElTable: if oneOnly: color=E[4] else: color=E[6] PickElement.ElButton(self,name=E[0], #            pos=wx.Point(E[1]*40+25,E[2]*24+24),tip=E[3],color=E[4]) pos=wx.Point(E[1]*40+25,E[2]*24+24),tip=E[3],color=E[6]) pos=wx.Point(E[1]*40+25,E[2]*24+24),tip=E[3],color=color,oneOnly=oneOnly) i+=1 def __init__(self, parent): self._init_ctrls(parent) def ElButton(self, name, pos, tip, color): def __init__(self, parent,oneOnly=False): self._init_ctrls(parent,oneOnly) def ElButton(self, name, pos, tip, color, oneOnly): Black = wx.Colour(0,0,0) El = wx.ComboBox(choices=name, parent=self, pos=pos, size=wx.Size(40,23), style=wx.CB_READONLY, value=name[0]) if oneOnly: El = wscs.ColourSelect(label=name[0], parent=self,colour=color, pos=pos, size=wx.Size(40,23), style=wx.RAISED_BORDER) #            El.SetLabel(name) El.Bind(wx.EVT_BUTTON, self.OnElButton) else: El = wx.ComboBox(choices=name, parent=self, pos=pos, size=wx.Size(40,23), style=wx.CB_READONLY, value=name[0]) El.Bind(wx.EVT_COMBOBOX,self.OnElButton) El.SetBackgroundColour(color) El.SetToolTipString(tip) El.Bind(wx.EVT_COMBOBOX, self.OnElButton) def OnElButton(self, event): El = event.GetEventObject().GetLabel() self.Elem = (El) self.Elem = El self.EndModal(wx.ID_OK)

• ## trunk/GSASIIimage.py

 r263 B = np.array(-(x**2+y**2)) bb,err = fel.fellipse(len(x),x,y,1.E-7) #    print nl.lstsq(M.T,B)[0] #    print bb return err,makeParmsEllipse(bb) ring = [] if azm: aR = azm[0],azm[1],1 aR = azm[0]-90,azm[1]-90,1 if azm[1]-azm[0] > 180: aR[2] = 2 tth = npatand(np.sqrt(dx**2+dy**2-Z**2)/(dist-Z)) dsp = wave/(2.*npsind(tth/2.)) azm = npatan2d(dy,dx)+azmthoff azm = npatan2d(dx,-dy)+azmthoff return tth,azm,dsp data['center'] = copy.copy(ellipse[0])           #not right!! (but useful for now) data['ellipses'].append(ellipse[:]+('r',)) G2plt.PlotImage(self,newImage=False) G2plt.PlotImage(self,newImage=True) #setup for calibration else: ellipse = newellipse #                if abs((radii[1]/radii[0]-ratio)/ratio) > 0.1: #                    print 'Bad fit for ring # %i. Try reducing Pixel search range'%(i) #                    return False zdis,cosB = calcZdisCosB(radius,tth,radii) Tilt = acosd(cosB)          # 0 <= tilt <= 90 tiltSum += numZ*abs(Tilt) if not np.all(checkEllipse(Zsum,distSum,xSum,ySum,dist,data['center'][0],data['center'][1])): print 'Bad ellipse. Try reducing Pixel search range' print 'Bad fit for ring # %i. Try reducing Pixel search range'%(i) cent = data['center'] print ('for ring # %2i @ d-space %.4f: dist %.3f rotate %6.2f tilt %6.2f Xcent %.3f Ycent %.3f Npts %d' %(i,dsp,dist,phi,Tilt,cent[0],cent[1],numZ)) %(i,dsp,dist,phi-90.,Tilt,cent[0],cent[1],numZ)) data['ellipses'].append(copy.deepcopy(ellipse+('r',))) else:
• ## trunk/GSASIIimgGUI.py

 r261 cutOff.SetValue("%.1f"%(data['cutoff']))          #reset in case of error def OnMaxVal(event): try: value = min(data['range'][0][1],int(maxVal.GetValue())) if value < data['range'][1][0]+1: raise ValueError data['range'][1][1] = value except ValueError: pass maxVal.SetValue('%.0f'%(data['range'][1][1])) DeltOne = data['range'][1][1]-max(0.0,data['range'][0][0]) sqrtDeltOne = math.sqrt(DeltOne) maxSel.SetValue(int(100*sqrtDeltOne/sqrtDeltZero)) minSel.SetValue(int(100*(data['range'][1][0]/DeltOne))) G2plt.PlotExposedImage(self,event=event) def OnMinVal(event): try: value = int(minVal.GetValue()) if value > data['range'][1][1]-1: raise ValueError data['range'][1][0] = value except ValueError: pass minVal.SetValue('%.0f'%(data['range'][1][0])) minSel.SetValue(int(100*(data['range'][1][0]-max(0.0,data['range'][0][0]))/DeltOne)) G2plt.PlotExposedImage(self,event=event) def OnMaxSlider(event): sqrtDeltZero = math.sqrt(data['range'][0][1]) DeltOne = max(1.0,data['range'][1][1]-data['range'][1][0]) minSel.SetValue(int(100*(data['range'][1][0]/DeltOne))) maxVal.SetValue('%.0f'%(data['range'][1][1])) G2plt.PlotExposedImage(self,event=event) imin = int(minSel.GetValue())*DeltOne/100. data['range'][1][0] = max(0.0,min(data['range'][1][1]-1,imin)) minVal.SetValue('%.0f'%(data['range'][1][0])) G2plt.PlotExposedImage(self,event=event) def OnLRazim(event): Lazm = int(self.Lazim.GetValue()) Razm = int(self.Razim.GetValue()) Lazm = min(180,int(self.Lazim.GetValue())) Razm = max(-180,int(self.Razim.GetValue())) data['LRazimuth'] = [Lazm,Razm] G2plt.PlotExposedImage(self,event=event) def OnClearCalib(event): def OnCalibrate(event): self.dataFrame.ImageEdit.Enable(id=G2gd.wxID_IMCLEARCALIB,enable=True) data['setRings'] = False setRings.SetValue(data['setRings']) self.dataFrame.GetStatusBar().SetStatusText('Select > 4 points on 1st used ring; LB to pick, RB on point to delete else RB to finish') self.ifGetRing = True G2plt.PlotIntegration(self,newPlot=True) G2IO.SaveIntegration(self,self.PickId,data) self.MakePDF.Enable(True) def OnIntegrateAll(event): mainSizer.Add((5,5),0) maxSizer = wx.FlexGridSizer(2,2,0,5) maxSizer = wx.FlexGridSizer(2,3,0,5) maxSizer.AddGrowableCol(1,1) maxSizer.SetFlexibleDirection(wx.HORIZONTAL) value=int(100*sqrtDeltOne/sqrtDeltZero)) maxSizer.Add(maxSel,1,wx.EXPAND) maxSel.Bind(wx.EVT_SLIDER, OnMaxSlider) maxSel.Bind(wx.EVT_SLIDER, OnMaxSlider) maxVal = wx.TextCtrl(parent=self.dataDisplay,value='%.0f'%(data['range'][1][1])) maxVal.Bind(wx.EVT_TEXT_ENTER,OnMaxVal) maxVal.Bind(wx.EVT_KILL_FOCUS,OnMaxVal) maxSizer.Add(maxVal,0,wx.ALIGN_CENTER_VERTICAL) maxSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Min intensity'),0, wx.ALIGN_CENTER_VERTICAL) maxSizer.Add(minSel,1,wx.EXPAND) minSel.Bind(wx.EVT_SLIDER, OnMinSlider) minVal = wx.TextCtrl(parent=self.dataDisplay,value='%.0f'%(data['range'][1][0])) minVal.Bind(wx.EVT_TEXT_ENTER,OnMinVal) minVal.Bind(wx.EVT_KILL_FOCUS,OnMinVal) maxSizer.Add(minVal,0,wx.ALIGN_CENTER_VERTICAL) mainSizer.Add(maxSizer,0,wx.ALIGN_LEFT|wx.EXPAND) dataSizer.Add(wx.StaticText(parent=self.dataDisplay,label=' Tilt rotation'),0, wx.ALIGN_CENTER_VERTICAL) rotSel = wx.TextCtrl(parent=self.dataDisplay,value=("%9.3f"%(data['rotation'])),style=wx.TE_READONLY) rotSel = wx.TextCtrl(parent=self.dataDisplay,value=("%9.3f"%(data['rotation']-90.)),style=wx.TE_READONLY) rotSel.SetBackgroundColour(VERY_LIGHT_GREY) dataSizer.Add(rotSel,0,wx.ALIGN_CENTER_VERTICAL)
• ## trunk/GSASIIlattice.py

 r230 else: return [0,0,0] def CellAbsorption(ElList,Volume): # ElList = dictionary of element contents including mu muT = 0 for El in ElList: muT += ElList[El]['mu']*ElList[El]['FormulaNo'] return muT/Volume def qRebin(x,y,nQbins): #Rebin data from x to qx #   input: #   X - array of q-values in increasing order #   y - array of intensities for the x array #   nQbins - number of q-bins desired #   returns: #   qx - array of q-values #   qy - array of rebinned intensities dQ = (x[-1]-x[0])/nQbins dQ2 = dQ/2. Qmin = x[0] yf = y[0] frac = 0.0 jch = 0 kch = 0 qy = [] for i in range(nQbins): Q = Qmin+dQ*i rom = Q rop = rom+dQ sdq = (1.-frac)*dQ qy.append(1-frac)*yf*dQ #      DELQ = (XT(NCHANS)-XT(1))/FLOAT(MCHANS) #      DELQ2 = DELQ/2.0 #      QMIN = XT(1) #      JCH = 1 #      KCH = 0 #      YF = YT(1) #      FRAC = 0.0 #      DQ = XT(2)-QMIN #      DO ICH = 1,MCHANS #        Q = QMIN+DELQ*FLOAT(ICH-1) !Front end interpolation #        ROM = Q #        ROP = ROM+DELQ #        SDQ = (1.0-FRAC)*DQ #        RY(ICH) = (1.0-FRAC)*YF*DQ !Sum intervening channels #        DO WHILE ( ROP.GT.XT(KCH+1) .AND. KCH.NE.NCHANS-1 ) #          KCH = MIN(KCH+1,NCHANS-1) #        END DO #        DO LCH=JCH+1,KCH #          DQ = XT(LCH+1)-XT(LCH) #          SDQ = SDQ+DQ #          RY(ICH) = RY(ICH)+DQ*YT(LCH) #        END DO !Tail end interpolation #        XF = XT(MAX(1,KCH)) #        YF = YT(MAX(1,KCH)) #        DQ = XT(KCH+1)-XF #        DY = YT(KCH+1)-YF #        FRAC = (ROP-XF)/DQ #        SDQ = SDQ+DQ*FRAC #        RY(ICH) = RY(ICH)+YF*FRAC*DQ !Reset lower limit #        JCH = KCH #        RY(ICH) = RY(ICH)/SDQ #      END DO #      RETURN #      END #Permutations and Combinations
• ## trunk/GSASIIpeak.py

 r243 #GSASII peak fitting module #GSASII powder calculation module ########### SVN repository information ################### # \$Date\$ plist.append(p) return plist def Transmission(Geometry,Abs,Diam): #Calculate sample transmission #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate' #   Abs: absorption coeff in cm-1 #   Diam: sample thickness/diameter in mm if 'Cylinder' in Geometry:      #Lobanov & Alte da Veiga for 2-theta = 0; beam fully illuminates sample MuR = Abs*Diam/5.0 if MuR <= 3.0: T0 = 16/(3.*math.pi) T1 = -0.045780 T2 = -0.02489 T3 = 0.003045 T = -T0*MuR-T1*MuR**2-T2*MuR**3-T3*MuR**4 if T < -20.: return 2.06e-9 else: return math.exp(T) else: T1 = 1.433902 T2 = 0.013869+0.337894 T3 = 1.933433+1.163198 T4 = 0.044365-0.04259 T = (T1-T4)/(1.0+T2*(MuR-3.0))**T3+T4 return T/100. def Absorb(Geometry,Abs,Diam,Tth,Phi=0,Psi=0): #Calculate sample absorption #   Geometry: one of 'Cylinder','Bragg-Brentano','Tilting Flat Plate in transmission','Fixed flat plate' #   Abs: absorption coeff in cm-1 #   Diam: sample thickness/diameter in mm #   Tth: 2-theta scattering angle - can be numpy array #   Phi: flat plate tilt angle - future #   Psi: flat plate tilt axis - future MuR = Abs*Diam/5.0 Sth2 = npsind(Tth/2.0)**2 Cth2 = 1.-Sth2 if 'Cylinder' in Geometry:      #Lobanov & Alte da Veiga for 2-theta = 0; beam fully illuminates sample if MuR < 3.0: T0 = 16.0/(3*np.pi) T1 = (25.99978-0.01911*Sth2**0.25)*np.exp(-0.024551*Sth2)+ \ 0.109561*np.sqrt(Sth2)-26.04556 T2 = -0.02489-0.39499*Sth2+1.219077*Sth2**1.5- \ 1.31268*Sth2**2+0.871081*Sth2**2.5-0.2327*Sth2**3 T3 = 0.003045+0.018167*Sth2-0.03305*Sth2**2 Trns = -T0*MuR-T1*MuR**2-T2*MuR**3-T3*MuR**4 return np.exp(Trns) else: T1 = 1.433902+11.07504*Sth2-8.77629*Sth2*Sth2+ \ 10.02088*Sth2**3-3.36778*Sth2**4 T2 = (0.013869-0.01249*Sth2)*np.exp(3.27094*Sth2)+ \ (0.337894+13.77317*Sth2)/(1.0+11.53544*Sth2)**1.555039 T3 = 1.933433/(1.0+23.12967*Sth2)**1.686715- \ 0.13576*np.sqrt(Sth2)+1.163198 T4 = 0.044365-0.04259/(1.0+0.41051*Sth2)**148.4202 Trns = (T1-T4)/(1.0+T2*(MuR-3.0))**T3+T4 return Trns/100. elif 'Bragg' in Geometry: return 1.0 elif 'Fixed' in Geometry: #assumes sample plane is perpendicular to incident beam # and only defined for 2theta < 90 T1 = np.exp(-MuR) T2 = np.exp(-MuR/(1.-2.*Sth2)) Tb = -2.*Abs*Sth2 return (T1-T2)/Tb elif 'Tilting' in Geometry: #assumes symmetric tilt so sample plane is parallel to diffraction vector cth = npcosd(Tth/2.0) return (Diam/cth)*np.exp(-MuR/cth) def Polarization(Pola,Azm,Tth): #   Calculate x-ray polarization correction #   Pola: polarization coefficient e.g 1.0 fully polarized, 0.5 unpolarized #   Azm: azimuthal angle e.g. 0.0 in plane of polarization(?) #   Tth: 2-theta scattering angle - can be numpy array pass def ValEsd(value,esd=0,nTZ=False):                  #NOT complete - don't use data = [x,y,w,yc,yb,yd] return True,smin,Rwp,runtime,GoOn def ComputePDF(data,xydata): for key in data: print key,data[key] #subtract backgrounds - if any xydata['Sample corrected'] = xydata['Sample'] if 'Sample Bkg.' in xydata: xydata['Sample corrected'][1][1] -= (xydata['Sample Bkg.'][1][1]+ data['Sample Bkg.']['Add'])*data['Sample Bkg.']['Mult'] if 'Container' in xydata: xydata['Sample corrected'][1][1] -= (xydata['Container'][1][1]+ data['Container']['Add'])*data['Container']['Mult'] if 'Container Bkg.' in xydata: xydata['Sample corrected'][1][1] += (xydata['Container Bkg.'][1][1]+ data['Container Bkg.']['Add'])*data['Container Bkg.']['Mult'] return xydata['Sample corrected'],[]
• ## trunk/GSASIIphsGUI.py

 r242 Obj.SetValue("%.5f"%(cell[4])) elif laue in ['3','3m1','31m','6/m','6/mmm','4/m','4/mmm']: cell[4] = cell[5] = 90. cell[6] = 120. if ObjId == 0: cell[1] = cell[2] = value elif laue in ['mmm']: cell[ObjId+1] = value cell[4] = cell[5] = cell[6] = 90. Obj.SetValue("%.5f"%(cell[ObjId+1])) elif laue in ['2/m'+'a']: cell[5] = cell[6] = 90. if ObjId != 3: cell[ObjId+1] = value Obj.SetValue("%.3f"%(cell[4])) elif laue in ['2/m'+'b']: cell[4] = cell[6] = 90. if ObjId != 3: cell[ObjId+1] = value Obj.SetValue("%.3f"%(cell[5])) elif laue in ['2/m'+'c']: cell[5] = cell[6] = 90. if ObjId != 3: cell[ObjId+1] = value
• ## trunk/GSASIIplot.py

 r261 Page.canvas.draw() self.Pwdr = True def PlotSofQ(self,newPlot=False): superMinusOne = unichr(0xaf)+unichr(0xb9) def OnPlotKeyPress(event): newPlot = False if event.key == 'u': if self.Contour: self.Cmax = min(1.0,self.Cmax*1.2) elif self.Offset < 100.: self.Offset += 1. elif event.key == 'd': if self.Contour: self.Cmax = max(0.0,self.Cmax*0.8) elif self.Offset > 0.: self.Offset -= 1. elif event.key == 'c': newPlot = True if self.Contour: self.Contour = False else: self.Contour = True self.SinglePlot = False self.Offset = 0 elif event.key == 's': if self.Contour: choice = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] dlg = wx.SingleChoiceDialog(self,'Select','Color scheme',choice) if dlg.ShowModal() == wx.ID_OK: sel = dlg.GetSelection() self.ContourColor = choice[sel] else: self.ContourColor = 'Paired' dlg.Destroy() else: if self.SinglePlot: self.SinglePlot = False else: self.SinglePlot = True elif event.key == 'i':                  #for smoothing contour plot choice = ['nearest','bilinear','bicubic','spline16','spline36','hanning', 'hamming','hermite','kaiser','quadric','catrom','gaussian','bessel', 'mitchell','sinc','lanczos'] dlg = wx.SingleChoiceDialog(self,'Select','Interpolation',choice) if dlg.ShowModal() == wx.ID_OK: sel = dlg.GetSelection() self.Interpolate = choice[sel] else: self.Interpolate = 'nearest' dlg.Destroy() PlotSofQ(self,newPlot=newPlot) def OnKeyBox(event): if self.G2plotNB.nb.GetSelection() == self.G2plotNB.plotList.index('S(Q)'): event.key = cb.GetValue()[0] cb.SetValue(' key press') OnPlotKeyPress(event) def OnMotion(event): xpos = event.xdata if xpos:                                        #avoid out of frame mouse position ypos = event.ydata Page.canvas.SetCursor(wx.CROSS_CURSOR) try: if self.Contour: self.G2plotNB.status.SetStatusText('Q =%9.3fA pattern ID =%5d'%(xpos,int(ypos)),1) else: self.G2plotNB.status.SetStatusText('Q =%9.3fA S(q) =%9.1f'%(xpos,ypos),1) except TypeError: self.G2plotNB.status.SetStatusText('Select S(Q) pattern first',1) xylim = [] try: plotNum = self.G2plotNB.plotList.index('S(Q)') Page = self.G2plotNB.nb.GetPage(plotNum) if not newPlot: Plot = Page.figure.gca()          #get previous S(Q) plot & get limits xylim = Plot.get_xlim(),Plot.get_ylim() Page.figure.clf() Plot = Page.figure.gca() except ValueError,error: newPlot = True self.Cmax = 1.0 Plot = self.G2plotNB.addMpl('S(Q)').gca() plotNum = self.G2plotNB.plotList.index('S(Q)') Page = self.G2plotNB.nb.GetPage(plotNum) Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) Page.canvas.mpl_connect('motion_notify_event', OnMotion) Page.SetFocus() self.G2plotNB.status.DestroyChildren() if self.Contour: Choice = (' key press','d: lower contour max','u: raise contour max', 'i: interpolation method','s: color scheme','c: contour off') else: Choice = (' key press','d: offset down','u: offset up', 'c: contour on','s: toggle single plot','+: no selection') cb = wx.ComboBox(self.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY, choices=Choice) cb.Bind(wx.EVT_COMBOBOX, OnKeyBox) cb.SetValue(' key press') PatternId = self.PatternId PickId = self.PickId Plot.set_title('S(Q)') Plot.set_xlabel(r'\$Q,\AA\$'+superMinusOne,fontsize=14) Plot.set_ylabel(r'S(Q)',fontsize=14) colors=['b','g','r','c','m','k'] name = self.PatternTree.GetItemText(PatternId)[4:] G2gd.GetPatternTreeItemId(self,PatternId, 'Instrument Parameters') Pattern = [] if self.SinglePlot: name = 'S(Q)'+self.PatternTree.GetItemText(PatternId)[4:] Id = G2gd.GetPatternTreeItemId(self,PatternId,name) if Pattern: Pattern = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,Id,name)) Pattern.append(name) PlotList = [Pattern,] else: PlotList = [] item, cookie = self.PatternTree.GetFirstChild(self.root) while item: if 'PDF' in self.PatternTree.GetItemText(item): name = 'S(Q)'+self.PatternTree.GetItemText(item)[4:] print name Id = G2gd.GetPatternTreeItemId(self,item,name) Pattern = self.PatternTree.GetItemPyData(Id) if Pattern: Pattern.append(name) PlotList.append(Pattern) item, cookie = self.PatternTree.GetNextChild(self.root, cookie) Ymax = 1.0 lenX = 0 for Pattern in PlotList: xye = Pattern[1] Ymax = max(Ymax,max(xye[1])) offset = self.Offset*Ymax/100.0 if self.Contour: ContourZ = [] ContourY = [] Nseq = 0 for N,Pattern in enumerate(PlotList): xye = np.array(Pattern[1]) if PickId: ifpicked = Pattern[2] == self.PatternTree.GetItemText(PatternId) X = xye[0] if not lenX: lenX = len(X) Y = xye[1]+offset*N if self.Contour: if lenX == len(X): ContourY.append(N) ContourZ.append(Y) ContourX = X Nseq += 1 Plot.set_ylabel('Data sequence',fontsize=12) else: if ifpicked: Plot.plot(X,Y,colors[N%6]+'+',picker=3.,clip_on=False) Page.canvas.SetToolTipString('') else: Plot.plot(X,Y,colors[N%6],picker=False) if self.Contour: acolor = mpl.cm.get_cmap(self.ContourColor) Img = Plot.imshow(ContourZ,cmap=acolor,vmin=0,vmax=Ymax*self.Cmax,interpolation=self.Interpolate, extent=[ContourX[0],ContourX[-1],ContourY[0],ContourY[-1]],aspect='auto',origin='lower') Page.figure.colorbar(Img) if not newPlot: Page.toolbar.push_current() Plot.set_xlim(xylim[0]) Plot.set_ylim(xylim[1]) xylim = [] Page.toolbar.push_current() Page.toolbar.draw() else: Page.canvas.draw() def PlotGofR(self,newPlot=False): def OnPlotKeyPress(event): newPlot = False if event.key == 'u': if self.Contour: self.Cmax = min(1.0,self.Cmax*1.2) elif self.Offset < 100.: self.Offset += 1. elif event.key == 'd': if self.Contour: self.Cmax = max(0.0,self.Cmax*0.8) elif self.Offset > 0.: self.Offset -= 1. elif event.key == 'c': newPlot = True if self.Contour: self.Contour = False else: self.Contour = True self.SinglePlot = False self.Offset = 0 elif event.key == 's': if self.Contour: choice = [m for m in mpl.cm.datad.keys() if not m.endswith("_r")] dlg = wx.SingleChoiceDialog(self,'Select','Color scheme',choice) if dlg.ShowModal() == wx.ID_OK: sel = dlg.GetSelection() self.ContourColor = choice[sel] else: self.ContourColor = 'Paired' dlg.Destroy() else: if self.SinglePlot: self.SinglePlot = False else: self.SinglePlot = True elif event.key == 'i':                  #for smoothing contour plot choice = ['nearest','bilinear','bicubic','spline16','spline36','hanning', 'hamming','hermite','kaiser','quadric','catrom','gaussian','bessel', 'mitchell','sinc','lanczos'] dlg = wx.SingleChoiceDialog(self,'Select','Interpolation',choice) if dlg.ShowModal() == wx.ID_OK: sel = dlg.GetSelection() self.Interpolate = choice[sel] else: self.Interpolate = 'nearest' dlg.Destroy() PlotGofR(self,newPlot=newPlot) def OnKeyBox(event): if self.G2plotNB.nb.GetSelection() == self.G2plotNB.plotList.index('G(R)'): event.key = cb.GetValue()[0] cb.SetValue(' key press') OnPlotKeyPress(event) def OnMotion(event): xpos = event.xdata if xpos:                                        #avoid out of frame mouse position ypos = event.ydata Page.canvas.SetCursor(wx.CROSS_CURSOR) try: if self.Contour: self.G2plotNB.status.SetStatusText('r =%9.3fA pattern ID =%5d'%(xpos,int(ypos)),1) else: self.G2plotNB.status.SetStatusText('r =%9.3fA G(r) =%9.1f'%(xpos,ypos),1) except TypeError: self.G2plotNB.status.SetStatusText('Select G(R) pattern first',1) xylim = [] try: plotNum = self.G2plotNB.plotList.index('G(r)') Page = self.G2plotNB.nb.GetPage(plotNum) if not newPlot: Plot = Page.figure.gca()          #get previous G(R) plot & get limits xylim = Plot.get_xlim(),Plot.get_ylim() Page.figure.clf() Plot = Page.figure.gca() except ValueError,error: newPlot = True self.Cmax = 1.0 Plot = self.G2plotNB.addMpl('G(r)').gca() plotNum = self.G2plotNB.plotList.index('G(r)') Page = self.G2plotNB.nb.GetPage(plotNum) Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) Page.canvas.mpl_connect('motion_notify_event', OnMotion) Page.SetFocus() self.G2plotNB.status.DestroyChildren() if self.Contour: Choice = (' key press','d: lower contour max','u: raise contour max', 'i: interpolation method','s: color scheme','c: contour off') else: Choice = (' key press','d: offset down','u: offset up', 'c: contour on','s: toggle single plot','+: no selection') cb = wx.ComboBox(self.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY, choices=Choice) cb.Bind(wx.EVT_COMBOBOX, OnKeyBox) cb.SetValue(' key press') PatternId = self.PatternId Pattern = [] if self.SinglePlot: Pattern = self.PatternTree.GetItemPyData(PatternId) Pattern.append(self.PatternTree.GetItemText(PatternId)) PlotList = [Pattern,] else: PlotList = [] item, cookie = self.PatternTree.GetFirstChild(self.root) while item: if 'PDF' in self.PatternTree.GetItemText(item): Pattern = self.PatternTree.GetItemPyData(item) PlotList.append(Pattern) item, cookie = self.PatternTree.GetNextChild(self.root, cookie) Plot.set_title('G(r)') Plot.set_xlabel(r'\$r,\AA\$',fontsize=14) Plot.set_ylabel(r'G(r)',fontsize=14) PatternId = self.PatternId Page.canvas.draw() def PlotPowderLines(self): Dsp = lambda tth,wave: wave/(2.*sind(tth/2.)) global Data,Masks newImage = True colors=['b','g','r','c','m','k'] Data = self.PatternTree.GetItemPyData( xyI = [] for azm in Azm: xyI.append(G2img.GetDetectorXY(dspI,azm,Data)) xyI.append(G2img.GetDetectorXY(dspI,azm-90.,Data)) xyI = np.array(xyI) arcxI,arcyI = xyI.T xyO = [] for azm in Azm: xyO.append(G2img.GetDetectorXY(dspO,azm,Data)) xyO.append(G2img.GetDetectorXY(dspO,azm-90.,Data)) xyO = np.array(xyO) arcxO,arcyO = xyO.T