Changeset 1184
- Timestamp:
- Jan 7, 2014 3:45:30 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r1183 r1184 3755 3755 G2imG.UpdateStressStrain(G2frame,data) 3756 3756 G2plt.PlotImage(G2frame) 3757 G2plt.PlotStrain(G2frame,data,newPlot=True) 3757 3758 elif G2frame.PatternTree.GetItemText(item) == 'HKL Plot Controls': 3758 3759 G2frame.PickId = item -
trunk/GSASIIimage.py
r1180 r1184 236 236 amb = radii[1]-radii[0] 237 237 return np.pi*apb*(1+3*(amb/apb)**2/(10+np.sqrt(4-3*(amb/apb)**2))) 238 238 239 cent,phi,radii = ellipse 239 cphi = cosd(phi )240 sphi = sind(phi )240 cphi = cosd(phi-90.) #convert to major axis rotation 241 sphi = sind(phi-90.) 241 242 ring = [] 242 sumI = 0 243 amin = 0 244 amax = 360 245 C = int(ellipseC()) 246 for i in range(0,C,1): 243 C = int(ellipseC()) #ring circumference 244 for i in range(0,C,1): #step around ring in 1mm increments 247 245 a = 360.*i/C 248 x = radii[ 0]*cosd(a)249 y = radii[ 1]*sind(a)246 x = radii[1]*cosd(a) #major axis 247 y = radii[0]*sind(a) 250 248 X = (cphi*x-sphi*y+cent[0])*scalex #convert mm to pixels 251 249 Y = (sphi*x+cphi*y+cent[1])*scaley 252 250 X,Y,I,J = ImageLocalMax(image,pix,X,Y) 253 251 if I and J and I/J > reject: 254 sumI += I/J255 252 X += .5 #set to center of pixel 256 253 Y += .5 257 X /= scalex #convert to mm254 X /= scalex #convert back to mm 258 255 Y /= scaley 259 amin = min(amin,a) 260 amax = max(amax,a) 261 if [X,Y,dsp] not in ring: 256 if [X,Y,dsp] not in ring: #no duplicates! 262 257 ring.append([X,Y,dsp]) 263 if len(ring) < 10: #want more than 10 deg258 if len(ring) < 10: 264 259 ring = [] 265 260 return ring … … 393 388 azm = (npatan2d(dy,dx)+azmthoff+720.)%360. 394 389 G = D/data['distance']**2 #for geometric correction = 1/cos(2theta)^2 if tilt=0. 395 return tth,azm,G,dsp390 return np.array([tth,azm,G,dsp]) 396 391 397 392 def GetTth(x,y,data): … … 404 399 405 400 def GetTthAzmD(x,y,data): 406 '''Give 2-theta, azimuth & geometric correctionvalues for detector x,y position;401 '''Give 2-theta, azimuth & d-spacing values for detector x,y position; 407 402 calibration info in data 408 403 ''' … … 858 853 return H0,H1,H2 859 854 860 def FitStrSta(Image,StrSta,Controls,Masks): 855 def MakeStrStaRing(ring,Image,Controls): 856 ellipse = GetEllipse(ring['Dset'],Controls) 857 pixSize = Controls['pixelSize'] 858 scalex = 1000./pixSize[0] 859 scaley = 1000./pixSize[1] 860 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 869 870 def FitStrSta(Image,StrSta,Controls): 861 871 'Needs a doc string' 862 872 … … 865 875 wave = Controls['wavelength'] 866 876 StaControls['distance'] += StrSta['Sample z']*cosd(phi) 867 pixSize = StaControls['pixelSize']868 scalex = 1000./pixSize[0]869 scaley = 1000./pixSize[1]870 877 rings = [] 871 878 872 879 for ring in StrSta['d-zero']: #get observed x,y,d points for the d-zeros 873 ellipse = GetEllipse(ring['Dset'],StaControls) 874 Ring = np.array(makeRing(ring['Dset'],ellipse,ring['pixLimit'],ring['cutoff'],scalex,scaley,Image)).T 875 ring['ImxyObs'] = np.array(Ring[:2]) #need to apply masks to this to eliminate bad points 876 ring['ImtaObs'] = GetTthAzm(Ring[0],Ring[1],StaControls) #convert x,y to tth,azm 877 ring['ImtaCalc'] = np.zeros_like(ring['ImtaObs']) 878 Ring[0] /= 2. #convert to theta 880 Ring,R = MakeStrStaRing(ring,Image,StaControls) 881 ring.update(R) 879 882 if len(rings): 880 883 rings = np.concatenate((rings,Ring),axis=1) 881 884 else: 882 rings = np.array(Ring) 885 rings = np.array(Ring) 883 886 E = StrSta['strain'] 884 p0 = [E[0][0],E[1][1],E[2][2],E[0][1],E[0][2],E[1][2]] 885 E,dth = FitStrain(rings,p0,wave,phi) 887 p0 = [E[0][0],E[0][1],E[1][1]] 888 E = FitStrain(rings,p0,wave,phi) 889 StrSta['strain'] = E 890 CalcStrSta(StrSta,Controls) 891 892 def CalcStrSta(StrSta,Controls): 893 894 wave = Controls['wavelength'] 895 phi = StrSta['Sample phi'] 896 E = StrSta['strain'] 886 897 for ring in StrSta['d-zero']: 887 898 th,azm = ring['ImtaObs'] 888 th0 = npasind(wave/(2.*ring['Dset'])) 889 V = np.sum(np.sum(E*calcFij(90.,phi,azm,th0).T,axis=2),axis=1) 890 dth = 180.*V/(np.pi*10e6) #in degrees & microstrain units 891 ring['ImtaCalc'] = np.array([(th0-dth)/2,azm]) 892 StrSta['strain'] = E 899 th0 = np.ones_like(azm)*npasind(wave/(2.*ring['Dset'])) 900 V = 1.+np.sum(np.sum(E*calcFij(90.,phi,azm,th0).T/1.e6,axis=2),axis=1) 901 ring['ImtaCalc'] = np.array([V*ring['Dset'],azm]) 893 902 894 903 def calcFij(omg,phi,azm,th): … … 933 942 934 943 def strainCalc(p,xyd,wave,phi): 935 # E = np.array([[p[0],p[3],p[4]],[p[3],p[1],p[5]],[p[4],p[5],p[2]]]) 936 E = np.array([[p[0],0,0],[0,p[1],0],[0,0,0]]) 937 th,azm,dsp = xyd 938 th0 = npasind(wave/(2.*dsp)) 939 V = np.sum(np.sum(E*calcFij(90.,phi,azm,th).T,axis=2),axis=1) 940 dth = 180.*V/(np.pi*10e6) #in degrees & microstrain units 941 th0 += dth 942 return th-th0 943 944 names = ['e11','e22','e33','e12','e13','e23'] 944 E = np.array([[p[0],p[1],0],[p[1],p[2],0],[0,0,0]]) 945 dspo,azm,dsp = xyd 946 th = npasind(wave/(2.0*dspo)) 947 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'] 945 952 fmt = ['%12.2f','%12.2f','%12.2f','%12.2f','%12.2f','%12.5f'] 946 p1 = [ 1,-1]953 p1 = [-20000.,0,5000.] 947 954 result = leastsq(strainCalc,p1,args=(rings,wave,phi),full_output=True) 948 955 vals = list(result[0]) … … 951 958 ValSig = zip(names,fmt,vals,sig) 952 959 StrainPrint(ValSig) 953 # return np.array([[vals[0],vals[3],vals[4]],[vals[3],vals[1],vals[5]],[vals[4],vals[5],vals[2]]]) 954 return np.array([[vals[0],0,0],[0,vals[1],0],[0,0,0]]),result[2]['fvec'] 955 956 960 return np.array([[vals[0],vals[1],0],[vals[1],vals[2],0],[0,0,0]]) 961 962 -
trunk/GSASIIimgGUI.py
r1180 r1184 1321 1321 1322 1322 def OnAppendDzero(event): 1323 data['d-zero'].append({'Dset':1.0,'Dcalc':0.0,'pixLimit':10,'cutoff':10.0,'ImxyObs':[[],[]],'ImxyCalc':[[],[]]}) 1323 data['d-zero'].append({'Dset':1.0,'Dcalc':0.0,'pixLimit':10,'cutoff':10.0, 1324 'ImxyObs':[[],[]],'ImtaObs':[[],[]],'ImtaCalc':[[],[]]}) 1324 1325 UpdateStressStrain(G2frame,data) 1325 1326 … … 1383 1384 for key in keys2: 1384 1385 File.write("'"+key+"':"+':'+str(data2[key])+',') 1385 File.write("'ImxyObs':[[],[]],'Im xycalc':[[],[]]},\n")1386 File.write("'ImxyObs':[[],[]],'ImtaObs':[[],[]],'Imtacalc':[[],[]]},\n") 1386 1387 File.write('\t]\n}') 1387 1388 File.close() … … 1394 1395 Controls = G2frame.PatternTree.GetItemPyData( 1395 1396 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) 1396 G2img.FitStrSta(G2frame.ImageZ,data,Controls ,Masks)1397 G2img.FitStrSta(G2frame.ImageZ,data,Controls) 1397 1398 UpdateStressStrain(G2frame,data) 1398 1399 G2plt.PlotExposedImage(G2frame,event=event) 1399 G2plt.PlotStrain(G2frame,data,newPlot=False ,type='Strain')1400 G2plt.PlotStrain(G2frame,data,newPlot=False) 1400 1401 1401 1402 def SamSizer(): … … 1452 1453 Obj.SetValue("%.5f"%(value)) 1453 1454 data['d-zero'][Indx[Obj.GetId()]]['Dset'] = value 1455 Ring,R = G2img.MakeStrStaRing(data['d-zero'][Indx[Obj.GetId()]],G2frame.ImageZ,Controls) 1456 data['d-zero'][Indx[Obj.GetId()]].update(R) 1457 UpdateStressStrain(G2frame,data) 1458 G2plt.PlotExposedImage(G2frame,event=event) 1459 G2plt.PlotStrain(G2frame,data,newPlot=False) 1454 1460 1455 1461 def OnDeleteDzero(event): … … 1457 1463 del(data['d-zero'][delIndx.index(Obj)]) 1458 1464 UpdateStressStrain(G2frame,data) 1465 G2plt.PlotExposedImage(G2frame,event=event) 1466 G2plt.PlotStrain(G2frame,data,newPlot=False) 1459 1467 1460 1468 def OnCutOff(event): … … 1466 1474 Obj.SetValue("%.1f"%(value)) 1467 1475 data['d-zero'][Indx[Obj.GetId()]]['cutoff'] = value 1476 G2plt.PlotExposedImage(G2frame,event=event) 1477 G2plt.PlotStrain(G2frame,data,newPlot=False) 1468 1478 1469 1479 def OnPixLimit(event): 1470 1480 Obj = event.GetEventObject() 1471 1481 data['d-zero'][Indx[Obj.GetId()]]['pixLimit'] = int(Obj.GetValue()) 1482 G2plt.PlotExposedImage(G2frame,event=event) 1483 G2plt.PlotStrain(G2frame,data,newPlot=False) 1472 1484 1473 1485 Indx = {} … … 1511 1523 def StrainSizer(): 1512 1524 1525 def OnTensor(event): 1526 Obj = event.GetEventObject() 1527 try: 1528 value = float(Obj.GetValue()) 1529 except ValueError: 1530 value = 1.0 1531 i,j = Indx[Obj.GetId()] 1532 data['strain'][i][j] = value 1533 if i != j: 1534 data['strain'][j][i] = value 1535 UpdateStressStrain(G2frame,data) 1536 G2img.CalcStrSta(data,Controls) 1537 G2plt.PlotStrain(G2frame,data,newPlot=False) 1538 1539 Indx = {} 1513 1540 strainSizer = wx.BoxSizer(wx.VERTICAL) 1514 1541 strainSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,label=(' Strain tensor:')), … … 1519 1546 for j in range(3): 1520 1547 tensorSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,label=names[i][j]),0,wx.ALIGN_CENTER_VERTICAL) 1521 tensorElem = wx.TextCtrl(G2frame.dataDisplay,-1,value='%.2f'%(data['strain'][i][j]),style=wx.TE_READONLY) 1522 tensorElem.SetBackgroundColour(VERY_LIGHT_GREY) 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] 1523 1554 tensorSizer.Add(tensorElem,0,wx.ALIGN_CENTER_VERTICAL) 1524 1555 strainSizer.Add(tensorSizer) … … 1527 1558 if G2frame.dataDisplay: 1528 1559 G2frame.dataDisplay.Destroy() 1560 Controls = G2frame.PatternTree.GetItemPyData( 1561 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')) 1529 1562 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.StrStaMenu) 1530 1563 G2frame.dataFrame.Bind(wx.EVT_MENU, OnAppendDzero, id=G2gd.wxID_APPENDDZERO) -
trunk/GSASIIplot.py
r1180 r1184 1255 1255 ################################################################################ 1256 1256 1257 def PlotStrain(G2frame,data,newPlot=False ,type=''):1257 def PlotStrain(G2frame,data,newPlot=False): 1258 1258 '''plot of strain data, used for diagnostic purposes 1259 1259 ''' … … 1264 1264 Page.canvas.SetCursor(wx.CROSS_CURSOR) 1265 1265 try: 1266 G2frame.G2plotNB.status.SetStatusText(' X =%9.3f %s =%9.3f'%(xpos,type,ypos),1)1266 G2frame.G2plotNB.status.SetStatusText('d-spacing =%9.5f Azimuth =%9.3f'%(xpos,ypos),1) 1267 1267 except TypeError: 1268 G2frame.G2plotNB.status.SetStatusText('Select '+type+'pattern first',1)1268 G2frame.G2plotNB.status.SetStatusText('Select Strain pattern first',1) 1269 1269 1270 1270 try: 1271 plotNum = G2frame.G2plotNB.plotList.index( type)1271 plotNum = G2frame.G2plotNB.plotList.index('Strain') 1272 1272 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 1273 1273 if not newPlot: … … 1278 1278 except ValueError: 1279 1279 newPlot = True 1280 Plot = G2frame.G2plotNB.addMpl( type).gca()1281 plotNum = G2frame.G2plotNB.plotList.index( type)1280 Plot = G2frame.G2plotNB.addMpl('Strain').gca() 1281 plotNum = G2frame.G2plotNB.plotList.index('Strain') 1282 1282 Page = G2frame.G2plotNB.nb.GetPage(plotNum) 1283 1283 Page.canvas.mpl_connect('motion_notify_event', OnMotion) … … 1286 1286 Page.SetFocus() 1287 1287 G2frame.G2plotNB.status.DestroyChildren() 1288 Plot.set_title( type)1289 Plot.set_xlabel(r' $\mathsf{2\theta}$',fontsize=14)1288 Plot.set_title('Strain') 1289 Plot.set_xlabel(r'd-spacing',fontsize=14) 1290 1290 Plot.set_ylabel(r'Azimuth',fontsize=14) 1291 1291 colors=['b','g','r','c','m','k'] … … 2598 2598 for N,ring in enumerate(StrSta['d-zero']): 2599 2599 xring,yring = ring['ImxyObs'] 2600 Plot.plot(xring,yring,colors[N%6]+'+') 2601 for xring,yring in np.array(ring['ImxyCalc']).T: 2602 Plot.add_artist(Polygon(ring['ImxyCalc'].T,ec='b',fc='none')) 2603 Plot.plot(xring,yring) 2600 Plot.plot(xring,yring,colors[N%6]+'o') 2604 2601 #masks - mask lines numbered after integration limit lines 2605 2602 spots = Masks['Points']
Note: See TracChangeset
for help on using the changeset viewer.