Changeset 2411
- Timestamp:
- Aug 8, 2016 5:09:05 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r2403 r2411 103 103 104 104 [ wxID_STRSTACOPY, wxID_STRSTAFIT, wxID_STRSTASAVE, wxID_STRSTALOAD,wxID_STRSTSAMPLE, 105 wxID_APPENDDZERO,wxID_STRSTAALLFIT,wxID_UPDATEDZERO, 106 ] = [wx.NewId() for item in range( 8)]105 wxID_APPENDDZERO,wxID_STRSTAALLFIT,wxID_UPDATEDZERO,wxID_STRSTAPLOT, 106 ] = [wx.NewId() for item in range(9)] 107 107 108 108 [ wxID_BACKCOPY,wxID_LIMITCOPY, wxID_SAMPLECOPY, wxID_SAMPLECOPYSOME, wxID_BACKFLAGCOPY, wxID_SAMPLEFLAGCOPY, … … 1814 1814 self.StrStaEdit.Append(help='Fit stress/strain data', 1815 1815 id=wxID_STRSTAFIT, kind=wx.ITEM_NORMAL,text='Fit stress/strain') 1816 self.StrStaEdit.Append(help='Plot intensity distribution', 1817 id=wxID_STRSTAPLOT, kind=wx.ITEM_NORMAL,text='Plot intensity distribution') 1816 1818 self.StrStaEdit.Append(help='Update d-zero from ave d-zero', 1817 1819 id=wxID_UPDATEDZERO, kind=wx.ITEM_NORMAL,text='Update d-zero') … … 4125 4127 data = G2frame.PatternTree.GetItemPyData( 4126 4128 GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) 4127 G2frame.ImageZ = G2imG.GetImageZ(G2frame,data )4129 G2frame.ImageZ = G2imG.GetImageZ(G2frame,data,newRange=False) 4128 4130 strsta = G2frame.PatternTree.GetItemPyData(item) 4129 G2plt.PlotImage(G2frame,newPlot=True)4130 4131 G2plt.PlotStrain(G2frame,strsta,newPlot=True) 4132 G2plt.PlotImage(G2frame,newPlot=False) 4131 4133 G2imG.UpdateStressStrain(G2frame,strsta) 4132 4134 elif G2frame.PatternTree.GetItemText(item) == 'PDF Controls': -
trunk/GSASIIimage.py
r2348 r2411 21 21 import numpy.linalg as nl 22 22 import numpy.ma as ma 23 import numpy.fft as fft 24 import scipy.signal as signal 23 25 import polymask as pm 24 26 from scipy.optimize import leastsq … … 216 218 xpix = int(Xpix) #get reference corner of pixel chosen 217 219 ypix = int(Ypix) 218 if (w < xpix < sizex-w) and (w < ypix < sizey-w) and image[ypix,xpix]: 219 Z = image[ypix-w:ypix+w,xpix-w:xpix+w] 220 Zmax = np.argmax(Z) 221 Zmin = np.argmin(Z) 220 if not w: 221 ZMax = np.sum(image[ypix-1:ypix+1,xpix-1:xpix+1]) 222 return xpix,ypix,ZMax,0.0001 223 if (w2 < xpix < sizex-w2) and (w2 < ypix < sizey-w2) and image[ypix,xpix]: 224 ZMax = image[ypix-w:ypix+w,xpix-w:xpix+w] 225 Zmax = np.argmax(ZMax) 226 ZMin = image[ypix-w2:ypix+w2,xpix-w2:xpix+w2] 227 Zmin = np.argmin(ZMin) 222 228 xpix += Zmax%w2-w 223 229 ypix += Zmax/w2-w 224 return xpix,ypix,np.ravel(Z )[Zmax],max(0.0001,np.ravel(Z)[Zmin]) #avoid neg/zero minimum230 return xpix,ypix,np.ravel(ZMax)[Zmax],max(0.0001,np.ravel(ZMin)[Zmin]) #avoid neg/zero minimum 225 231 else: 226 232 return 0,0,0,0 … … 243 249 ring = [] 244 250 C = int(ellipseC()) #ring circumference 251 azm = [] 245 252 for i in range(0,C,1): #step around ring in 1mm increments 246 253 a = 360.*i/C … … 257 264 if [X,Y,dsp] not in ring: #no duplicates! 258 265 ring.append([X,Y,dsp]) 266 azm.append(a) 259 267 if len(ring) < 10: 260 268 ring = [] 261 return ring 269 azm = [] 270 return ring,azm 262 271 263 272 def GetEllipse2(tth,dxy,dist,cent,tilt,phi): … … 554 563 break 555 564 ellipse = GetEllipse(dsp,data) 556 Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,ma.array(G2frame.ImageZ,mask=tam)) 565 Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,ma.array(G2frame.ImageZ,mask=tam))[0] 557 566 if Ring: 558 567 if iH >= skip: … … 623 632 #setup 360 points on that ring for "good" fit 624 633 data['ellipses'].append(ellipse[:]+('g',)) 625 Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ) 634 Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)[0] 626 635 if Ring: 627 636 ellipse = FitEllipse(Ring) 628 Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ) #do again637 Ring = makeRing(1.0,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)[0] #do again 629 638 ellipse = FitEllipse(Ring) 630 639 else: … … 670 679 tth = npatan2d(radii[0],dist) 671 680 data['wavelength'] = wave = 2.0*dsp*sind(tth/2.0) 672 Ring0 = makeRing(dsp,ellipse,3,cutoff,scalex,scaley,G2frame.ImageZ) 681 Ring0 = makeRing(dsp,ellipse,3,cutoff,scalex,scaley,G2frame.ImageZ)[0] 673 682 ttth = nptand(tth) 674 683 stth = npsind(tth) … … 706 715 ellipsep = GetEllipse2(tth,0.,dist,centp,tilt,phi) 707 716 print fmt%('plus ellipse :',ellipsep[0][0],ellipsep[0][1],ellipsep[1],ellipsep[2][0],ellipsep[2][1]) 708 Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,G2frame.ImageZ) 717 Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,G2frame.ImageZ)[0] 709 718 parmDict = {'dist':dist,'det-X':centp[0],'det-Y':centp[1], 710 719 'tilt':tilt,'phi':phi,'wave':wave,'dep':0.0} … … 720 729 ellipsem = GetEllipse2(tth,0.,dist,centm,-tilt,phi) 721 730 print fmt%('minus ellipse:',ellipsem[0][0],ellipsem[0][1],ellipsem[1],ellipsem[2][0],ellipsem[2][1]) 722 Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,G2frame.ImageZ) 731 Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,G2frame.ImageZ)[0] 723 732 if len(Ringm) > 10: 724 733 parmDict['tilt'] *= -1 … … 760 769 data['ellipses'].append(copy.deepcopy(ellipse+('g',))) 761 770 if debug: print fmt%('predicted ellipse:',elcent[0],elcent[1],phi,radii[0],radii[1]) 762 Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ) 771 Ring = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,G2frame.ImageZ)[0] 763 772 if Ring: 764 773 data['rings'].append(np.array(Ring)) … … 979 988 scalex = 1000./pixSize[0] 980 989 scaley = 1000./pixSize[1] 981 Ring = np.array(makeRing(ring['Dset'],ellipse,ring['pixLimit'],ring['cutoff'],scalex,scaley,Image) ).T #returns x,y,dsp for each point in ring990 Ring = np.array(makeRing(ring['Dset'],ellipse,ring['pixLimit'],ring['cutoff'],scalex,scaley,Image)[0]).T #returns x,y,dsp for each point in ring 982 991 if len(Ring): 983 992 ring['ImxyObs'] = copy.copy(Ring[:2]) … … 1001 1010 phi = StrSta['Sample phi'] 1002 1011 wave = Controls['wavelength'] 1012 pixelSize = Controls['pixelSize'] 1013 scalex = 1000./pixelSize[0] 1014 scaley = 1000./pixelSize[1] 1003 1015 StaType = StrSta['Type'] 1004 1016 StaControls['distance'] += StrSta['Sample z']*cosd(phi) … … 1013 1025 ring['Emat'] = val 1014 1026 ring['Esig'] = esd 1027 ellipse = FitEllipse(R['ImxyObs'].T) 1028 ringxy,ringazm = makeRing(ring['Dcalc'],ellipse,0,0.,scalex,scaley,Image) 1029 ringint = np.array([float(Image[int(y*scaley),int(x*scalex)]) for x,y in np.array(ringxy)[:,:2]]) 1030 ringint /= np.mean(ringint) 1031 ring['Ivar'] = np.var(ringint) 1032 print 'Variance in normalized ring intensity: %.3f'%(ring['Ivar']) 1015 1033 CalcStrSta(StrSta,Controls) 1034 1035 def IntStrSta(Image,StrSta,Controls): 1036 StaControls = copy.deepcopy(Controls) 1037 pixelSize = Controls['pixelSize'] 1038 scalex = 1000./pixelSize[0] 1039 scaley = 1000./pixelSize[1] 1040 phi = StrSta['Sample phi'] 1041 StaControls['distance'] += StrSta['Sample z']*cosd(phi) 1042 RingsAI = [] 1043 for ring in StrSta['d-zero']: #get observed x,y,d points for the d-zeros 1044 Ring,R = MakeStrStaRing(ring,Image,StaControls) 1045 if len(Ring): 1046 ellipse = FitEllipse(R['ImxyObs'].T) 1047 ringxy,ringazm = makeRing(ring['Dcalc'],ellipse,0,0.,scalex,scaley,Image) 1048 ringint = np.array([float(Image[int(y*scaley),int(x*scalex)]) for x,y in np.array(ringxy)[:,:2]]) 1049 ringint /= np.mean(ringint) 1050 print 'variance:',ring['Dcalc'],np.var(ringint) 1051 RingsAI.append(np.array(zip(ringazm,ringint)).T) 1052 # GSASIIpath.IPyBreak() 1053 return RingsAI 1016 1054 1017 1055 def CalcStrSta(StrSta,Controls): -
trunk/GSASIIimgGUI.py
r2348 r2411 51 51 ################################################################################ 52 52 53 def GetImageZ(G2frame,data ):53 def GetImageZ(G2frame,data,newRange=True): 54 54 '''Gets image & applies dark, background & flat background corrections 55 55 :param wx.Frame G2frame: main GSAS-II frame … … 100 100 sumImg -= int(data.get('Flat Bkg',0)) 101 101 Imax = np.max(sumImg) 102 data['range'] = [(0,Imax),[0,Imax]] 102 if newRange: 103 data['range'] = [(0,Imax),[0,Imax]] 103 104 return sumImg 104 105 … … 1448 1449 littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Lower/Upper thresholds '),0,WACV) 1449 1450 lowerThreshold = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=thresh[1],key=0, 1450 1451 min=thresh[0][0],OnLeave=Replot,typeHint=int) 1451 1452 littleSizer.Add(lowerThreshold,0,WACV) 1452 1453 upperThreshold = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=thresh[1],key=1, 1453 1454 max=thresh[0][1],OnLeave=Replot,typeHint=int) 1454 1455 littleSizer.Add(upperThreshold,0,WACV) 1455 1456 mainSizer.Add(littleSizer,0,) … … 1471 1472 spotText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg) 1472 1473 spotDiameter = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=Spots[i],key=2, 1473 1474 max=100.,OnLeave=Replot,nDig=[8,2]) 1474 1475 littleSizer.Add(spotDiameter,0,WACV) 1475 1476 spotDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?', 1476 locationcode='Delete+Points+'+str(i), 1477 handler=onDeleteMask) 1477 locationcode='Delete+Points+'+str(i),handler=onDeleteMask) 1478 1478 littleSizer.Add(spotDelete,0,WACV) 1479 1479 mainSizer.Add(littleSizer,0,) … … 1494 1494 littleSizer.Add(ringText,0,WACV) 1495 1495 ringThick = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=Rings[i],key=1, 1496 1496 min=0.001,max=1.,OnLeave=Replot,nDig=[8,3]) 1497 1497 littleSizer.Add(ringThick,0,WACV) 1498 1498 ringDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?', 1499 locationcode='Delete+Rings+'+str(i), 1500 handler=onDeleteMask) 1499 locationcode='Delete+Rings+'+str(i),handler=onDeleteMask) 1501 1500 littleSizer.Add(ringDelete,0,WACV) 1502 1501 mainSizer.Add(littleSizer,0,) … … 1524 1523 littleSizer.Add(azmText,0,WACV) 1525 1524 arcThick = G2G.ValidatedTxtCtrl(G2frame.dataDisplay,loc=Arcs[i],key=2, 1526 1525 min=0.001,max=20.,OnLeave=Replot,nDig=[8,3]) 1527 1526 littleSizer.Add(arcThick,0,WACV) 1528 1527 arcDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?', 1529 locationcode='Delete+Arcs+'+str(i), 1530 handler=onDeleteMask) 1528 locationcode='Delete+Arcs+'+str(i),handler=onDeleteMask) 1531 1529 littleSizer.Add(arcDelete,0,WACV) 1532 1530 mainSizer.Add(littleSizer,0,) … … 1545 1543 littleSizer.Add(polyText,0,WACV) 1546 1544 polyDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?', 1547 locationcode='Delete+Polygons+'+str(i), 1548 handler=onDeleteMask) 1545 locationcode='Delete+Polygons+'+str(i),handler=onDeleteMask) 1549 1546 littleSizer.Add(polyDelete,0,WACV) 1550 1547 mainSizer.Add(littleSizer,0,) … … 1561 1558 littleSizer.Add(frameText,0,WACV) 1562 1559 frameDelete = G2G.G2LoggedButton(G2frame.dataDisplay,label='delete?', 1563 locationcode='Delete+Frame', 1564 handler=onDeleteFrame) 1560 locationcode='Delete+Frame',handler=onDeleteFrame) 1565 1561 littleSizer.Add(frameDelete,0,WACV) 1566 1562 mainSizer.Add(littleSizer,0,) … … 1742 1738 UpdateStressStrain(G2frame,data) 1743 1739 1740 def OnPlotStrSta(event): 1741 Controls = G2frame.PatternTree.GetItemPyData( 1742 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) 1743 RingInt = G2img.IntStrSta(G2frame.ImageZ,data,Controls) 1744 Names = ['d=%.3f'%(ring['Dcalc']) for ring in data['d-zero']] 1745 G2plt.PlotExposedImage(G2frame,event=event) 1746 G2frame.G2plotNB.Delete('Ring Intensities') 1747 G2plt.PlotXY(G2frame,RingInt,labelX='Azimuth', 1748 labelY='Intensity',newPlot=True,Title='Ring Intensities', 1749 names=Names,lines=True) 1750 1744 1751 def OnFitStrSta(event): 1745 1752 Controls = G2frame.PatternTree.GetItemPyData( … … 1792 1799 variables += item['Emat'] 1793 1800 sig += item['Esig'] 1794 varylist = ['%d %s%s'%(i,';',Name) for Name in varyNames]1801 varylist = ['%d;%s'%(i,Name) for Name in varyNames] 1795 1802 varyList += varylist 1796 1803 parmDict.update(dict(zip(varylist,item['Emat']))) 1797 parmDict['%d:Dcalc'%(i)] = item['Dcalc'] 1804 parmDict['%d;Dcalc'%(i)] = item['Dcalc'] 1805 parmDict['%d;Ivar'%(i)] = item['Ivar'] 1806 variables.append(item['Ivar']) 1807 varyList.append('%d;Ivar'%(i)) 1808 sig.append(0.) 1798 1809 SeqResult[name] = {'variables':variables,'varyList':varyList,'sig':sig,'Rvals':[], 1799 1810 'covMatrix':np.eye(len(variables)),'title':name,'parmDict':parmDict} … … 1972 1983 G2frame.dataFrame.Bind(wx.EVT_MENU, OnUpdateDzero, id=G2gd.wxID_UPDATEDZERO) 1973 1984 G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitStrSta, id=G2gd.wxID_STRSTAFIT) 1985 G2frame.dataFrame.Bind(wx.EVT_MENU, OnPlotStrSta, id=G2gd.wxID_STRSTAPLOT) 1974 1986 G2frame.dataFrame.Bind(wx.EVT_MENU, OnFitAllStrSta, id=G2gd.wxID_STRSTAALLFIT) 1975 1987 G2frame.dataFrame.Bind(wx.EVT_MENU, OnCopyStrSta, id=G2gd.wxID_STRSTACOPY) -
trunk/GSASIIplot.py
r2401 r2411 2438 2438 def PlotXY(G2frame,XY,XY2=None,labelX=None,labelY=None,newPlot=False, 2439 2439 Title='',lines=False,names=[],names2=[]): 2440 '''simple plot of xy data , used for diagnostic purposes2440 '''simple plot of xy data 2441 2441 ''' 2442 2442 def OnKeyPress(event): … … 2457 2457 #GSASIIpath.IPyBreak() 2458 2458 return 2459 wx.CallAfter(PlotXY,G2frame,XY,XY2,labelX,labelY,False,Title, False,names)2459 wx.CallAfter(PlotXY,G2frame,XY,XY2,labelX,labelY,False,Title,lines,names) 2460 2460 2461 2461 def OnMotion(event): … … 2487 2487 Page.Offset = [0,0] 2488 2488 2489 if XY2 and len(XY2) > 1:2489 if lines: 2490 2490 Page.Choice = (' key press','l: offset left','r: offset right','d: offset down', 2491 2491 'u: offset up','o: reset offset',) … … 2513 2513 Ymax = max(Ymax,max(Y)) 2514 2514 if lines: 2515 dX = Page.Offset[0]*(ixy+1)*Xmax/500. 2516 dY = Page.Offset[1]*(ixy+1)*Ymax/100. 2515 2517 if len(names): 2516 Plot.plot(X ,Y,colors[ixy%6],picker=False,label=names[ixy])2518 Plot.plot(X+dX,Y+dY,colors[ixy%6],picker=False,label=names[ixy]) 2517 2519 else: 2518 Plot.plot(X ,Y,colors[ixy%6],picker=False)2520 Plot.plot(X+dX,Y+dY,colors[ixy%6],picker=False) 2519 2521 else: 2520 2522 Plot.plot(X,Y,colors[ixy%6]+'+',picker=False) … … 2545 2547 2546 2548 def PlotXYZ(G2frame,XY,Z,labelX=None,labelY=None,newPlot=False,Title=''): 2547 '''simple contour plot of xyz data , used for diagnostic purposes2549 '''simple contour plot of xyz data 2548 2550 ''' 2549 2551 def OnKeyPress(event):
Note: See TracChangeset
for help on using the changeset viewer.