Changeset 118
 Timestamp:
 Jul 16, 2010 10:21:45 AM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIplot.py
r108 r118 230 230 PlotPatterns(self) 231 231 else: #picked a limit line 232 self.itemPicked = pick 232 self.itemPicked = pick 233 233 234 234 def OnPlotKeyPress(event): … … 553 553 Page.canvas.draw() 554 554 555 def PlotExposedImage(self,newPlot=False ):555 def PlotExposedImage(self,newPlot=False,event=None): 556 556 plotNo = self.G2plotNB.nb.GetSelection() 557 557 if self.G2plotNB.nb.GetPageText(plotNo) == '2D Powder Image': 558 PlotImage(self,newPlot )558 PlotImage(self,newPlot,event) 559 559 elif self.G2plotNB.nb.GetPageText(plotNo) == '2D Integration': 560 PlotIntegration(self,newPlot )561 562 def PlotImage(self,newPlot=False ):560 PlotIntegration(self,newPlot,event) 561 562 def PlotImage(self,newPlot=False,event=None): 563 563 from matplotlib.patches import Ellipse,Arc,Circle,Polygon 564 564 import numpy.ma as ma … … 665 665 scalex = 1000./pixelSize[0] 666 666 scaley = 1000./pixelSize[1] 667 print self.itemPicked668 667 if self.itemPicked is None and PickName == 'Image Controls': 669 668 size = len(self.ImageZ) … … 780 779 Page.canvas.mpl_connect('pick_event', OnImPick) 781 780 Page.canvas.mpl_connect('button_release_event', OnImRelease) 782 Page.SetFocus() 781 if not event: #event from GUI TextCtrl  don't want focus to change to plot!!! 782 Page.SetFocus() 783 783 Plot.set_title(self.PatternTree.GetItemText(self.Image)[4:]) 784 784 size,imagefile = self.PatternTree.GetItemPyData(self.Image) … … 808 808 #do threshold mask  "real" mask  others are just bondaries 809 809 Zlim = Masks['Thresholds'][1] 810 MA = ma.masked_greater(ma.masked_less(self.ImageZ,Zlim[0]),Zlim[1]) 811 MaskA = ma.getmaskarray(MA) 812 A = G2img.ImageCompress(MA,imScale) 813 AM = G2img.ImageCompress(MaskA,imScale) 810 wx.BeginBusyCursor() 811 try: 812 MA = ma.masked_greater(ma.masked_less(self.ImageZ,Zlim[0]),Zlim[1]) 813 MaskA = ma.getmaskarray(MA) 814 A = G2img.ImageCompress(MA,imScale) 815 AM = G2img.ImageCompress(MaskA,imScale) 816 817 ImgM = Plot.imshow(AM,aspect='equal',cmap='Reds', 818 interpolation='nearest',vmin=0,vmax=2,extent=[0,Xmax,Xmax,0]) 819 Img = Plot.imshow(A,aspect='equal',cmap=acolor, 820 interpolation='nearest',vmin=Imin,vmax=Imax,extent=[0,Xmax,Xmax,0]) 814 821 815 ImgM = Plot.imshow(AM,aspect='equal',cmap='Reds', 816 interpolation='nearest',vmin=0,vmax=2,extent=[0,Xmax,Xmax,0]) 817 Img = Plot.imshow(A,aspect='equal',cmap=acolor, 818 interpolation='nearest',vmin=Imin,vmax=Imax,extent=[0,Xmax,Xmax,0]) 819 820 Plot.plot(xcent,ycent,'x') 821 if Data['showLines']: 822 LRAzim = Data['LRazimuth'] #NB: integers 823 IOtth = Data['IOtth'] 824 wave = Data['wavelength'] 825 dspI = wave/(2.0*sind(IOtth[0]/2.0)) 826 ellI = G2img.GetEllipse(dspI,Data) #=False if dsp didn't yield an ellipse (ugh! a parabola or a hyperbola) 827 dspO = wave/(2.0*sind(IOtth[1]/2.0)) 828 ellO = G2img.GetEllipse(dspO,Data) #Ditto & more likely for outer ellipse 829 if Data['fullIntegrate']: 830 Azm = np.array(range(0,361)) 822 Plot.plot(xcent,ycent,'x') 823 if Data['showLines']: 824 LRAzim = Data['LRazimuth'] #NB: integers 825 IOtth = Data['IOtth'] 826 wave = Data['wavelength'] 827 dspI = wave/(2.0*sind(IOtth[0]/2.0)) 828 ellI = G2img.GetEllipse(dspI,Data) #=False if dsp didn't yield an ellipse (ugh! a parabola or a hyperbola) 829 dspO = wave/(2.0*sind(IOtth[1]/2.0)) 830 ellO = G2img.GetEllipse(dspO,Data) #Ditto & more likely for outer ellipse 831 if Data['fullIntegrate']: 832 Azm = np.array(range(0,361)) 833 else: 834 Azm = np.array(range(LRAzim[0],LRAzim[1]+1)) 835 if ellI: 836 xyI = [] 837 for azm in Azm: 838 xyI.append(G2img.GetDetectorXY(dspI,azm,Data)) 839 xyI = np.array(xyI) 840 arcxI,arcyI = xyI.T 841 Plot.plot(arcxI,arcyI,picker=3) 842 if ellO: 843 xyO = [] 844 for azm in Azm: 845 xyO.append(G2img.GetDetectorXY(dspO,azm,Data)) 846 xyO = np.array(xyO) 847 arcxO,arcyO = xyO.T 848 Plot.plot(arcxO,arcyO,picker=3) 849 if ellO and ellI and not Data['fullIntegrate']: 850 Plot.plot([arcxI[0],arcxO[0]],[arcyI[0],arcyO[0]],picker=3) 851 Plot.plot([arcxI[1],arcxO[1]],[arcyI[1],arcyO[1]],picker=3) 852 for xring,yring in Data['ring']: 853 Plot.plot(xring,yring,'r+',picker=3) 854 if Data['setRings']: 855 rings = np.concatenate((Data['rings']),axis=0) 856 for xring,yring,dsp in rings: 857 Plot.plot(xring,yring,'r+') 858 for ellipse in Data['ellipses']: 859 cent,phi,[width,height],col = ellipse 860 Plot.add_artist(Ellipse([cent[0],cent[1]],2*width,2*height,phi,ec=col,fc='none')) 861 Plot.text(cent[0],cent[1],'+',color=col,ha='center',va='center') 862 #masks  mask lines numbered after integration limit lines 863 spots = Masks['Points'] 864 rings = Masks['Rings'] 865 arcs = Masks['Arcs'] 866 polygons = Masks['Polygons'] 867 for x,y,d in spots: 868 Plot.add_artist(Circle((x,y),radius=d/2,fc='none',ec='r',picker=3)) 869 self.ringList = [] 870 for iring,(tth,thick) in enumerate(rings): 871 wave = Data['wavelength'] 872 x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data))),2) 873 x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tththick/2.,wave),Data))),2) 874 self.ringList.append([Plot.plot(x1,y1,'r',picker=3),iring,'o']) 875 self.ringList.append([Plot.plot(x2,y2,'r',picker=3),iring,'i']) 876 self.arcList = [] 877 for iarc,(tth,azm,thick) in enumerate(arcs): 878 wave = Data['wavelength'] 879 x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data),azm)),2) 880 x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(max(0.01,tththick/2.),wave),Data),azm)),2) 881 self.arcList.append([Plot.plot(x1,y1,'r',picker=3),iarc,'o']) 882 self.arcList.append([Plot.plot(x2,y2,'r',picker=3),iarc,'i']) 883 self.arcList.append([Plot.plot([x1[0],x2[0]],[y1[0],y2[0]],'r',picker=3),iarc,'l']) 884 self.arcList.append([Plot.plot([x1[1],x2[1]],[y1[1],y2[1]],'r',picker=3),iarc,'u']) 885 self.polyList = [] 886 for ipoly,polygon in enumerate(polygons): 887 x,y = np.hsplit(np.array(polygon),2) 888 self.polyList.append([Plot.plot(x,y,'r',picker=3),ipoly]) 889 colorBar = Page.figure.colorbar(Img) 890 Plot.set_xlim(xlim) 891 Plot.set_ylim(ylim) 892 if not newPlot: 893 Page.toolbar.push_current() 894 Plot.set_xlim(xylim[0]) 895 Plot.set_ylim(xylim[1]) 896 xylim = [] 897 Page.toolbar.push_current() 898 Page.toolbar.draw() 831 899 else: 832 Azm = np.array(range(LRAzim[0],LRAzim[1]+1)) 833 if ellI: 834 xyI = [] 835 for azm in Azm: 836 xyI.append(G2img.GetDetectorXY(dspI,azm,Data)) 837 xyI = np.array(xyI) 838 arcxI,arcyI = xyI.T 839 Plot.plot(arcxI,arcyI,picker=3) 840 if ellO: 841 xyO = [] 842 for azm in Azm: 843 xyO.append(G2img.GetDetectorXY(dspO,azm,Data)) 844 xyO = np.array(xyO) 845 arcxO,arcyO = xyO.T 846 Plot.plot(arcxO,arcyO,picker=3) 847 if ellO and ellI and not Data['fullIntegrate']: 848 Plot.plot([arcxI[0],arcxO[0]],[arcyI[0],arcyO[0]],picker=3) 849 Plot.plot([arcxI[1],arcxO[1]],[arcyI[1],arcyO[1]],picker=3) 850 for xring,yring in Data['ring']: 851 Plot.plot(xring,yring,'r+',picker=3) 852 if Data['setRings']: 853 rings = np.concatenate((Data['rings']),axis=0) 854 for xring,yring,dsp in rings: 855 Plot.plot(xring,yring,'r+') 856 for ellipse in Data['ellipses']: 857 cent,phi,[width,height],col = ellipse 858 Plot.add_artist(Ellipse([cent[0],cent[1]],2*width,2*height,phi,ec=col,fc='none')) 859 Plot.text(cent[0],cent[1],'+',color=col,ha='center',va='center') 860 #masks  mask lines numbered after integration limit lines 861 spots = Masks['Points'] 862 rings = Masks['Rings'] 863 arcs = Masks['Arcs'] 864 polygons = Masks['Polygons'] 865 for x,y,d in spots: 866 Plot.add_artist(Circle((x,y),radius=d/2,fc='none',ec='r',picker=3)) 867 self.ringList = [] 868 for iring,(tth,thick) in enumerate(rings): 869 wave = Data['wavelength'] 870 x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data))),2) 871 x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tththick/2.,wave),Data))),2) 872 self.ringList.append([Plot.plot(x1,y1,'r',picker=3),iring,'o']) 873 self.ringList.append([Plot.plot(x2,y2,'r',picker=3),iring,'i']) 874 self.arcList = [] 875 for iarc,(tth,azm,thick) in enumerate(arcs): 876 wave = Data['wavelength'] 877 x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data),azm)),2) 878 x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(max(0.01,tththick/2.),wave),Data),azm)),2) 879 self.arcList.append([Plot.plot(x1,y1,'r',picker=3),iarc,'o']) 880 self.arcList.append([Plot.plot(x2,y2,'r',picker=3),iarc,'i']) 881 self.arcList.append([Plot.plot([x1[0],x2[0]],[y1[0],y2[0]],'r',picker=3),iarc,'l']) 882 self.arcList.append([Plot.plot([x1[1],x2[1]],[y1[1],y2[1]],'r',picker=3),iarc,'u']) 883 self.polyList = [] 884 for ipoly,polygon in enumerate(polygons): 885 x,y = np.hsplit(np.array(polygon),2) 886 self.polyList.append([Plot.plot(x,y,'r',picker=3),ipoly]) 887 colorBar = Page.figure.colorbar(Img) 888 Plot.set_xlim(xlim) 889 Plot.set_ylim(ylim) 890 if not newPlot: 891 Page.toolbar.push_current() 892 Plot.set_xlim(xylim[0]) 893 Plot.set_ylim(xylim[1]) 894 xylim = [] 895 Page.toolbar.push_current() 896 Page.toolbar.draw() 897 else: 898 Page.canvas.draw() 899 900 def PlotIntegration(self,newPlot=False): 900 Page.canvas.draw() 901 finally: 902 wx.EndBusyCursor() 903 904 def PlotIntegration(self,newPlot=False,event=None): 901 905 902 906 def OnMotion(event): … … 925 929 Page.views = False 926 930 view = False 927 Page.SetFocus() 931 if not event: 932 Page.SetFocus() 928 933 929 934 Data = self.PatternTree.GetItemPyData(
Note: See TracChangeset
for help on using the changeset viewer.