Changeset 1185
- Timestamp:
- Jan 8, 2014 3:26:10 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIimage.py
r1184 r1185 192 192 193 193 names = ['dist','det-X','det-Y','tilt','phi','dep','wave'] 194 fmt = ['%12. 2f','%12.2f','%12.2f','%12.2f','%12.2f','%12.3f','%12.5f']194 fmt = ['%12.3f','%12.3f','%12.3f','%12.3f','%12.3f','%12.3f','%12.5f'] 195 195 p0 = [parmDict[key] for key in varyList] 196 196 result = leastsq(ellipseCalcD,p0,args=(rings.T,varyList,parmDict),full_output=True,ftol=1.e-8) … … 198 198 parmDict.update(zip(varyList,result[0])) 199 199 vals = list(result[0]) 200 chi = np.sqrt(np.sum(ellipseCalcD(result[0],rings.T,varyList,parmDict)**2)) 201 sig = list(chi*np.sqrt(np.diag(result[1]))) 200 sig = list(np.sqrt(chisq*np.diag(result[1]))) 202 201 sigList = np.zeros(7) 203 202 for i,name in enumerate(names): … … 207 206 if Print: 208 207 CalibPrint(ValSig) 209 return chi ,chisq208 return chisq 210 209 211 210 def ImageLocalMax(image,w,Xpix,Ypix): … … 636 635 varyList = ['dist','det-X','det-Y','tilt','phi'] 637 636 if len(Ringp) > 10: 638 chip ,chisqp= FitDetector(np.array(Ring0+Ringp),varyList,parmDict,True)637 chip = FitDetector(np.array(Ring0+Ringp),varyList,parmDict,True) 639 638 tiltp = parmDict['tilt'] 640 639 phip = parmDict['phi'] … … 647 646 if len(Ringm) > 10: 648 647 parmDict['tilt'] *= -1 649 chim ,chisqm= FitDetector(np.array(Ring0+Ringm),varyList,parmDict,True)648 chim = FitDetector(np.array(Ring0+Ringm),varyList,parmDict,True) 650 649 tiltm = parmDict['tilt'] 651 650 phim = parmDict['phi'] … … 688 687 rings = np.concatenate((data['rings']),axis=0) 689 688 if i: 690 chi ,chisq = FitDetector(rings,varyList,parmDict,False)689 chisq = FitDetector(rings,varyList,parmDict,False) 691 690 data['distance'] = parmDict['dist'] 692 691 data['center'] = [parmDict['det-X'],parmDict['det-Y']] … … 859 858 scaley = 1000./pixSize[1] 860 859 Ring = np.array(makeRing(ring['Dset'],ellipse,ring['pixLimit'],ring['cutoff'],scalex,scaley,Image)).T #returns x,y,dsp for each point in ring 861 ring['ImxyObs'] = Ring[:2] 862 TA = GetTthAzm(Ring[0],Ring[1],Controls) #convert x,y to tth,azm 863 TA[0] = Controls['wavelength']/(2.*npsind(TA[0]/2.)) #convert 2th to d 864 ring['ImtaObs'] = TA 865 ring['ImtaCalc'] = np.zeros_like(ring['ImtaObs']) 866 Ring[0] = TA[0] 867 Ring[1] = TA[1] 868 return Ring,ring 860 if len(Ring): 861 ring['ImxyObs'] = copy.copy(Ring[:2]) 862 TA = GetTthAzm(Ring[0],Ring[1],Controls) #convert x,y to tth,azm 863 TA[0] = Controls['wavelength']/(2.*npsind(TA[0]/2.)) #convert 2th to d 864 ring['ImtaObs'] = TA 865 ring['ImtaCalc'] = np.zeros_like(ring['ImtaObs']) 866 Ring[0] = TA[0] 867 Ring[1] = TA[1] 868 return Ring,ring 869 else: 870 return [],[] #bad ring; no points found 869 871 870 872 def FitStrSta(Image,StrSta,Controls): … … 875 877 wave = Controls['wavelength'] 876 878 StaControls['distance'] += StrSta['Sample z']*cosd(phi) 877 rings = []878 879 879 880 for ring in StrSta['d-zero']: #get observed x,y,d points for the d-zeros 881 dset = ring['Dset'] 880 882 Ring,R = MakeStrStaRing(ring,Image,StaControls) 881 ring.update(R) 882 if len(rings): 883 rings = np.concatenate((rings,Ring),axis=1) 884 else: 885 rings = np.array(Ring) 886 E = StrSta['strain'] 887 p0 = [E[0][0],E[0][1],E[1][1]] 888 E = FitStrain(rings,p0,wave,phi) 889 StrSta['strain'] = E 883 if len(Ring): 884 ring.update(R) 885 p0 = ring['Emat'] 886 ring['Emat'] = FitStrain(Ring,p0,dset,wave,phi) 890 887 CalcStrSta(StrSta,Controls) 891 888 … … 896 893 E = StrSta['strain'] 897 894 for ring in StrSta['d-zero']: 895 Eij = ring['Emat'] 896 E = [[Eij[0],Eij[1],0],[Eij[1],Eij[2],0],[0,0,0]] 898 897 th,azm = ring['ImtaObs'] 899 898 th0 = np.ones_like(azm)*npasind(wave/(2.*ring['Dset'])) … … 923 922 return -Fij*nptand(th) 924 923 925 def FitStrain(rings,p0, wave,phi):926 'Needs a doc string' 927 def StrainPrint(ValSig ):928 print 'Strain tensor :'924 def FitStrain(rings,p0,dset,wave,phi): 925 'Needs a doc string' 926 def StrainPrint(ValSig,dset): 927 print 'Strain tensor for Dset: %.6f'%(dset) 929 928 ptlbls = 'names :' 930 929 ptstr = 'values:' … … 941 940 print sigstr 942 941 943 def strainCalc(p,xyd, wave,phi):942 def strainCalc(p,xyd,dset,wave,phi): 944 943 E = np.array([[p[0],p[1],0],[p[1],p[2],0],[0,0,0]]) 945 944 dspo,azm,dsp = xyd 946 945 th = npasind(wave/(2.0*dspo)) 947 946 V = 1.+np.sum(np.sum(E*calcFij(90.,phi,azm,th).T/1.e6,axis=2),axis=1) 948 dspc = dsp*V 949 return dspo-dspc 950 951 names = ['e11','e12','e22','e33','e13','e23'] 952 fmt = ['%12.2f','%12.2f','%12.2f','%12.2f','%12.2f','%12.5f'] 953 p1 = [-20000.,0,5000.] 954 result = leastsq(strainCalc,p1,args=(rings,wave,phi),full_output=True) 947 dspc = dset*V 948 return dspo**2-dspc**2 949 950 names = ['e11','e12','e22'] 951 fmt = ['%12.2f','%12.2f','%12.2f'] 952 result = leastsq(strainCalc,p0,args=(rings,dset,wave,phi),full_output=True) 955 953 vals = list(result[0]) 956 chi = np.sqrt(np.sum(strainCalc(result[0],rings,wave,phi)**2))957 sig = list( chi*np.sqrt(np.diag(result[1])))954 chisq = np.sum(result[2]['fvec']**2) 955 sig = list(np.sqrt(chisq*np.diag(result[1]))) 958 956 ValSig = zip(names,fmt,vals,sig) 959 StrainPrint(ValSig )960 return np.array([[vals[0],vals[1],0],[vals[1],vals[2],0],[0,0,0]])961 962 957 StrainPrint(ValSig,dset) 958 return vals 959 960 -
trunk/GSASIIimgGUI.py
r1184 r1185 1322 1322 def OnAppendDzero(event): 1323 1323 data['d-zero'].append({'Dset':1.0,'Dcalc':0.0,'pixLimit':10,'cutoff':10.0, 1324 'ImxyObs':[[],[]],'ImtaObs':[[],[]],'ImtaCalc':[[],[]] })1324 'ImxyObs':[[],[]],'ImtaObs':[[],[]],'ImtaCalc':[[],[]],'Emat':[1.0,1.0,1.0]}) 1325 1325 UpdateStressStrain(G2frame,data) 1326 1326 … … 1371 1371 File = open(filename,'w') 1372 1372 save = {} 1373 keys = ['Type','Sample phi','Sample z' ,'strain']1374 keys2 = ['Dset','Dcalc','pixLimit','cutoff' ]1373 keys = ['Type','Sample phi','Sample z'] 1374 keys2 = ['Dset','Dcalc','pixLimit','cutoff','Emat'] 1375 1375 File.write('{\n\t') 1376 1376 for key in keys: … … 1396 1396 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) 1397 1397 G2img.FitStrSta(G2frame.ImageZ,data,Controls) 1398 print 'Strain fitting finished' 1398 1399 UpdateStressStrain(G2frame,data) 1399 1400 G2plt.PlotExposedImage(G2frame,event=event) … … 1448 1449 Obj = event.GetEventObject() 1449 1450 try: 1450 value = min( 10.0,max(1.0,float(Obj.GetValue())))1451 value = min(20.0,max(0.25,float(Obj.GetValue()))) 1451 1452 except ValueError: 1452 1453 value = 1.0 … … 1454 1455 data['d-zero'][Indx[Obj.GetId()]]['Dset'] = value 1455 1456 Ring,R = G2img.MakeStrStaRing(data['d-zero'][Indx[Obj.GetId()]],G2frame.ImageZ,Controls) 1456 data['d-zero'][Indx[Obj.GetId()]].update(R) 1457 if len(Ring): 1458 data['d-zero'][Indx[Obj.GetId()]].update(R) 1459 else: 1460 G2frame.ErrorDialog('Strain peak selection','WARNING - No points found for this ring selection') 1461 #sort them on d-spacing? 1457 1462 UpdateStressStrain(G2frame,data) 1458 1463 G2plt.PlotExposedImage(G2frame,event=event) … … 1519 1524 delIndx.append(dzeroDelete) 1520 1525 dzeroSizer.Add(dzeroDelete,0,wx.ALIGN_CENTER_VERTICAL) 1526 1527 dzeroSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,label=(' Strain tensor:')), 1528 wx.ALIGN_CENTER_VERTICAL) 1529 names = ['e11','e12','e22'] 1530 for i in range(3): 1531 dzeroSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,label=names[i]),0,wx.ALIGN_CENTER_VERTICAL) 1532 tensorElem = wx.TextCtrl(G2frame.dataDisplay,-1,value='%.2f'%(dzero['Emat'][i]),style=wx.TE_READONLY) 1533 tensorElem.SetBackgroundColour(VERY_LIGHT_GREY) 1534 dzeroSizer.Add(tensorElem,0,wx.ALIGN_CENTER_VERTICAL) 1535 dzeroSizer.Add((5,5),0) 1521 1536 return dzeroSizer 1522 1537 1523 def StrainSizer():1524 1525 def OnTensor(event):1526 Obj = event.GetEventObject()1527 try:1528 value = float(Obj.GetValue())1529 except ValueError:1530 value = 1.01531 i,j = Indx[Obj.GetId()]1532 data['strain'][i][j] = value1533 if i != j:1534 data['strain'][j][i] = value1535 UpdateStressStrain(G2frame,data)1536 G2img.CalcStrSta(data,Controls)1537 G2plt.PlotStrain(G2frame,data,newPlot=False)1538 1539 Indx = {}1540 strainSizer = wx.BoxSizer(wx.VERTICAL)1541 strainSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,label=(' Strain tensor:')),1542 0,wx.ALIGN_CENTER_VERTICAL)1543 tensorSizer = wx.FlexGridSizer(3,6,5,5)1544 names = [[' e11','e12','e13'],[' e21','e22','e23'],[' e31','e32','e33']]1545 for i in range(3):1546 for j in range(3):1547 tensorSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,label=names[i][j]),0,wx.ALIGN_CENTER_VERTICAL)1548 # tensorElem = wx.TextCtrl(G2frame.dataDisplay,-1,value='%.2f'%(data['strain'][i][j]),style=wx.TE_READONLY)1549 # tensorElem.SetBackgroundColour(VERY_LIGHT_GREY)1550 tensorElem = wx.TextCtrl(G2frame.dataDisplay,-1,value='%.2f'%(data['strain'][i][j]),style=wx.TE_PROCESS_ENTER)1551 tensorElem.Bind(wx.EVT_TEXT_ENTER,OnTensor)1552 tensorElem.Bind(wx.EVT_KILL_FOCUS,OnTensor)1553 Indx[tensorElem.GetId()] = [i,j]1554 tensorSizer.Add(tensorElem,0,wx.ALIGN_CENTER_VERTICAL)1555 strainSizer.Add(tensorSizer)1556 return strainSizer1557 1558 1538 if G2frame.dataDisplay: 1559 1539 G2frame.dataDisplay.Destroy() … … 1575 1555 mainSizer.Add((5,10),0) 1576 1556 mainSizer.Add(DzeroSizer()) 1577 mainSizer.Add((5,10),0)1578 mainSizer.Add(StrainSizer())1579 1557 1580 1558 mainSizer.Layout() -
trunk/GSASIIplot.py
r1184 r1185 1264 1264 Page.canvas.SetCursor(wx.CROSS_CURSOR) 1265 1265 try: 1266 G2frame.G2plotNB.status.SetStatusText('d-spacing =%9.5f Azimuth =%9.3f'%( xpos,ypos),1)1266 G2frame.G2plotNB.status.SetStatusText('d-spacing =%9.5f Azimuth =%9.3f'%(ypos,xpos),1) 1267 1267 except TypeError: 1268 1268 G2frame.G2plotNB.status.SetStatusText('Select Strain pattern first',1) … … 1287 1287 G2frame.G2plotNB.status.DestroyChildren() 1288 1288 Plot.set_title('Strain') 1289 Plot.set_ xlabel(r'd-spacing',fontsize=14)1290 Plot.set_ ylabel(r'Azimuth',fontsize=14)1289 Plot.set_ylabel(r'd-spacing',fontsize=14) 1290 Plot.set_xlabel(r'Azimuth',fontsize=14) 1291 1291 colors=['b','g','r','c','m','k'] 1292 1292 for N,item in enumerate(data['d-zero']): 1293 X,Y = np.array(item['ImtaObs'])1293 Y,X = np.array(item['ImtaObs']) #plot azimuth as X & d-spacing as Y 1294 1294 Plot.plot(X,Y,colors[N%6]+'+',picker=False) 1295 X,Y= np.array(item['ImtaCalc'])1295 Y,X = np.array(item['ImtaCalc']) 1296 1296 Plot.plot(X,Y,colors[N%6],picker=False) 1297 1297 if not newPlot: … … 2292 2292 except TypeError: 2293 2293 return 2294 if PickName not in ['Image Controls','Masks' ]:2294 if PickName not in ['Image Controls','Masks','Stress/Strain']: 2295 2295 return 2296 2296 pixelSize = Data['pixelSize'] … … 2365 2365 G2imG.UpdateMasks(G2frame,Masks) 2366 2366 PlotImage(G2frame,newImage=False) 2367 elif PickName == 'Stress/Strain': 2368 Xpos,Ypos = [event.xdata,event.ydata] 2369 if not Xpos or not Ypos or Page.toolbar._active: #got point out of frame or zoom/pan selected 2370 return 2371 dsp = G2img.GetDsp(Xpos,Ypos,Data) 2372 StrSta['d-zero'].append({'Dset':dsp,'Dcalc':0.0,'pixLimit':10,'cutoff':10.0, 2373 'ImxyObs':[[],[]],'ImtaObs':[[],[]],'ImtaCalc':[[],[]],'Emat':[1.0,1.0,1.0]}) 2374 R,r = G2img.MakeStrStaRing(StrSta['d-zero'][-1],G2frame.ImageZ,Data) 2375 if not len(R): 2376 del StrSta['d-zero'][-1] 2377 G2frame.ErrorDialog('Strain peak selection','WARNING - No points found for this ring selection') 2378 G2imG.UpdateStressStrain(G2frame,StrSta) 2379 PlotStrain(G2frame,StrSta) 2380 PlotImage(G2frame,newPlot=False) 2367 2381 else: 2368 2382 Xpos,Ypos = [event.xdata,event.ydata] … … 2587 2601 for ring in Data['rings']: 2588 2602 xring,yring = np.array(ring).T[:2] 2589 Plot.plot(xring,yring,' +',color=colors[N%6])2603 Plot.plot(xring,yring,'.',color=colors[N%6]) 2590 2604 N += 1 2591 2605 for ellipse in Data['ellipses']: #what about hyperbola? … … 2595 2609 Plot.text(cent[0],cent[1],'+',color=col,ha='center',va='center') 2596 2610 if G2frame.PatternTree.GetItemText(G2frame.PickId) in 'Stress/Strain': 2597 print 'plot stress/strain stuff'2598 2611 for N,ring in enumerate(StrSta['d-zero']): 2599 2612 xring,yring = ring['ImxyObs'] 2600 Plot.plot(xring,yring,colors[N%6]+' o')2613 Plot.plot(xring,yring,colors[N%6]+'.') 2601 2614 #masks - mask lines numbered after integration limit lines 2602 2615 spots = Masks['Points']
Note: See TracChangeset
for help on using the changeset viewer.