Changeset 345
- Timestamp:
- Aug 18, 2011 8:54:16 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.BAT
r328 r345 1 @echo ========================================================== 2 @echo This file starts GSAS-II 3 @echo = Run this from the directory where GSAS-II is installed = 4 @echo ========================================================== 1 @echo ======================================================================== 2 @echo General Structure Analysis System-II 3 @echo by Robert B. Von Dreele, Argonne National Laboratory(C), 2010 4 @echo This product includes software developed by the UChicago Argonne, LLC, 5 @echo as Operator of Argonne National Laboratory.' 6 @echo ======================================================================== 5 7 @ 6 @REM Get this script's directory; make sure that the path ends 8 @REM Get this script's directory; make sure that the path ends 7 9 @REM with a single backslash 8 10 @set gsasloc=%~dp0\* -
trunk/GSASII.py
r342 r345 1351 1351 try: 1352 1352 if dlg.ShowModal() == wx.ID_OK: 1353 Id = 0 1353 1354 self.PatternTree.DeleteChildren(self.root) 1354 1355 if self.HKL: self.HKL = [] … … 1356 1357 self.G2plotNB.clear() 1357 1358 G2IO.ProjFileOpen(self) 1359 item, cookie = self.PatternTree.GetFirstChild(self.root) 1360 while item and not Id: 1361 name = self.PatternTree.GetItemText(item) 1362 if name[:4] in ['PWDR','HKLF']: 1363 Id = item 1364 item, cookie = self.PatternTree.GetNextChild(self.root, cookie) 1365 if Id: 1366 self.PatternTree.SelectItem(Id) 1358 1367 finally: 1359 1368 dlg.Destroy() -
trunk/GSASIIimage.py
r298 r345 180 180 ValSig = zip(names,fmt,vals,sig) 181 181 CalibPrint(ValSig) 182 if len(rings) > 1:182 try: 183 183 print 'Trial refinement of wavelength - not used for calibration' 184 184 p0 = result[0] … … 189 189 ValSig = zip(names,fmt,resultW[0],sig*np.sqrt(np.diag(resultW[1]))) 190 190 CalibPrint(ValSig) 191 return result[0],resultW[0][-1] 192 else: 191 return result[0],resultW[0][-1] 192 except ValueError: 193 print 'Bad wavelength refinement - no result' 193 194 return result[0],wave 194 195 … … 458 459 radius = dist*ttth 459 460 elcent,phi,radii = ellipse 460 radii[1] = dist*stth*ctth*cosB/(cosB**2-stth**2) 461 radii[0] = math.sqrt(radii[1]*radius*cosB) 462 zdis,cosB = calcZdisCosB(radius,tth,radii) 463 zsinp = zdis*sind(phi) 464 zcosp = zdis*cosd(phi) 465 cent = data['center'] 466 elcent = [cent[0]+zsinp,cent[1]-zcosp] 461 if i: 462 radii[1] = dist*stth*ctth*cosB/(cosB**2-stth**2) 463 radii[0] = math.sqrt(radii[1]*radius*cosB) 464 zdis,cosB = calcZdisCosB(radius,tth,radii) 465 zsinp = zdis*sind(phi) 466 zcosp = zdis*cosd(phi) 467 cent = data['center'] 468 elcent = [cent[0]-zsinp,cent[1]+zcosp] 469 ellipse = (elcent,phi,radii) 467 470 ratio = radii[1]/radii[0] 468 471 Ring,delt = makeRing(dsp,ellipse,pixLimit,cutoff,scalex,scaley,self.ImageZ) … … 549 552 data['tilt'] = result[4] 550 553 N = len(data['ellipses']) 551 data['ellipses'] = [] #clear away individual ellipse fits554 # data['ellipses'] = [] #clear away individual ellipse fits 552 555 for H in HKL[:N]: 553 556 ellipse = GetEllipse(H[3],data) -
trunk/GSASIIphsGUI.py
r342 r345 320 320 except ValueError: 321 321 pass 322 pawlVal.SetValue("%. 2f"%(generalData['Pawley dmin'])) #reset in case of error322 pawlVal.SetValue("%.3f"%(generalData['Pawley dmin'])) #reset in case of error 323 323 324 324 cellGUIlist = [[['m3','m3m'],4,zip([" Unit cell: a = "," Vol = "],["%.5f","%.3f"],[True,False],[0,0])], … … 455 455 pawlSizer = wx.BoxSizer(wx.HORIZONTAL) 456 456 pawlSizer.Add(wx.StaticText(dataDisplay,label=' Pawley dmin: '),0,wx.ALIGN_CENTER_VERTICAL) 457 pawlVal = wx.TextCtrl(dataDisplay,value='%. 2f'%(generalData['Pawley dmin']),style=wx.TE_PROCESS_ENTER)457 pawlVal = wx.TextCtrl(dataDisplay,value='%.3f'%(generalData['Pawley dmin']),style=wx.TE_PROCESS_ENTER) 458 458 pawlVal.Bind(wx.EVT_TEXT_ENTER,OnPawleyVal) 459 459 pawlVal.Bind(wx.EVT_KILL_FOCUS,OnPawleyVal) -
trunk/GSASIIpwd.py
r343 r345 410 410 np.seterr(divide='ignore') 411 411 412 # Voigt function = convolution (norm,cauchy) 413 414 class voigt_gen(st.rv_continuous): 415 ''' 416 Voigt function 417 Parameters 418 ----------------------------------------- 419 ''' 420 def _pdf(self,x,s,g): 421 z = np.empty([2,len(x)]) 422 z[0] = st.norm.pdf(x,scale=s) 423 z[1] = st.cauchy.pdf(x,scale=g) 424 Z = fft(z) 425 return fftshift(ifft(Z.prod(axis=0))).real 426 # def _cdf(self, x): 427 # def _ppf(self, q): 428 # def _sf(self, x): 429 # def _isf(self, q): 430 # def _stats(self): 431 # def _entropy(self): 432 433 voigt = voigt_gen(name='voigt',shapes='ts,g') 434 435 # Finger-Cox_Jephcoat D(2phi,2th) function for S/L = H/L 412 # Normal distribution 413 414 # loc = mu, scale = std 415 _norm_pdf_C = 1./math.sqrt(2*math.pi) 416 class norm_gen(st.rv_continuous): 417 418 def pdf(self,x,*args,**kwds): 419 loc,scale=kwds['loc'],kwds['scale'] 420 x = (x-loc)/scale 421 return np.exp(-x**2/2.0) * _norm_pdf_C / scale 422 423 norm = norm_gen(name='norm',longname='A normal',extradoc=""" 424 425 Normal distribution 426 427 The location (loc) keyword specifies the mean. 428 The scale (scale) keyword specifies the standard deviation. 429 430 normal.pdf(x) = exp(-x**2/2)/sqrt(2*pi) 431 """) 432 433 ## Cauchy 434 435 # median = loc 436 437 class cauchy_gen(st.rv_continuous): 438 439 def pdf(self,x,*args,**kwds): 440 loc,scale=kwds['loc'],kwds['scale'] 441 x = (x-loc)/scale 442 return 1.0/np.pi/(1.0+x*x) / scale 443 444 cauchy = cauchy_gen(name='cauchy',longname='Cauchy',extradoc=""" 445 446 Cauchy distribution 447 448 cauchy.pdf(x) = 1/(pi*(1+x**2)) 449 450 This is the t distribution with one degree of freedom. 451 """) 452 453 454 #GSASII peak fitting routine: Finger, Cox & Jephcoat model 455 436 456 437 457 class fcjde_gen(st.rv_continuous): … … 457 477 def _pdf(self,x,t,s,dx): 458 478 T = dx*x+t 459 ax = npcosd(T)**2 479 ax2 = abs(npcosd(T)) 480 ax = ax2**2 460 481 bx = npcosd(t)**2 461 482 bx = np.where(ax>bx,bx,ax) 462 fx = np.where(ax>bx,(np.sqrt(bx/(ax-bx))-1./s)/ np.sqrt(ax),0.0)483 fx = np.where(ax>bx,(np.sqrt(bx/(ax-bx))-1./s)/ax2,0.0) 463 484 fx = np.where(fx > 0.,fx,0.0) 464 485 return fx 465 # def _cdf(self, x): 466 # def _ppf(self, q): 467 # def _sf(self, x): 468 # def _isf(self, q): 469 # def _stats(self): 470 # def _entropy(self): 486 487 def pdf(self,x,*args,**kwds): 488 loc=kwds['loc'] 489 return self._pdf(x-loc,*args) 471 490 472 491 fcjde = fcjde_gen(name='fcjde',shapes='t,s,dx') … … 485 504 return yb 486 505 487 def calcPeakFFT(x,fxns,widths,pos,args): 488 dx = x[1]-x[0] 489 z = np.empty([len(fxns),len(x)]) 490 for i,(fxn,width,arg) in enumerate(zip(fxns,widths,args)): 491 z[i] = fxn.pdf(x,loc=pos,scale=width,*arg)*dx 492 Z = fft(z) 493 if len(fxns)%2: 494 return ifft(Z.prod(axis=0)).real 495 else: 496 return fftshift(ifft(Z.prod(axis=0))).real 497 498 def getFCJVoigt(pos,intens,sig,gam,shl,xdata): 499 506 def getWidths(pos,sig,gam,shl): 507 widths = [np.sqrt(sig)/100.,gam/200.] 508 fwhm = 2.355*widths[0]+2.*widths[1] 509 fmin = 10.*(fwhm+shl*abs(npcosd(pos))) 510 fmax = 15.0*fwhm 511 if pos > 90: 512 fmin,fmax = [fmax,fmin] 513 return widths,fmin,fmax 514 515 def getFCJVoigt(pos,intens,sig,gam,shl,xdata): 500 516 DX = xdata[1]-xdata[0] 501 517 widths,fmin,fmax = getWidths(pos,sig,gam,shl) 502 x = np.linspace(pos-fmin,pos+fmin,1024) 503 if pos > 90: 504 fmin,fmax = [fmax,fmin] 518 x = np.linspace(pos-fmin,pos+fmin,256) 505 519 dx = x[1]-x[0] 506 arg = [pos,shl/10.,dx,] 507 Df = fcjde.pdf(x,*arg,loc=pos,scale=1.0) 508 if len(np.nonzero(Df)[0])>5: 509 fxns = [st.norm,st.cauchy,fcjde] 510 args = [[],[],arg] 520 Norm = norm.pdf(x,loc=pos,scale=widths[0]) 521 Cauchy = cauchy.pdf(x,loc=pos,scale=widths[1]) 522 arg = [pos,shl/57.2958,dx,] 523 FCJ = fcjde.pdf(x,*arg,loc=pos) 524 if len(np.nonzero(FCJ)[0])>5: 525 z = np.column_stack([Norm,Cauchy,FCJ]).T 526 Z = fft(z) 527 Df = ifft(Z.prod(axis=0)).real 511 528 else: 512 fxns = [st.norm,st.cauchy]513 args = [[],[]]514 Df = calcPeakFFT(x,fxns,widths,pos,args)529 z = np.column_stack([Norm,Cauchy]).T 530 Z = fft(z) 531 Df = fftshift(ifft(Z.prod(axis=0))).real 515 532 Df /= np.sum(Df) 516 533 Df = si.interp1d(x,Df,bounds_error=False,fill_value=0.0) 517 534 return intens*Df(xdata)*DX/dx 518 535 519 536 def getPeakProfile(parmDict,xdata,varyList,bakType): 520 537 521 538 yb = getBackground('',parmDict,bakType,xdata) 522 539 yc = np.zeros_like(yb) 540 dx = xdata[1]-xdata[0] 523 541 U = parmDict['U'] 524 542 V = parmDict['V'] … … 526 544 X = parmDict['X'] 527 545 Y = parmDict['Y'] 528 shl = max(parmDict['SH/L'],0.00 1)546 shl = max(parmDict['SH/L'],0.0005) 529 547 Ka2 = False 530 548 if 'Lam1' in parmDict.keys(): 531 549 Ka2 = True 532 lamRatio = parmDict['Lam2']/parmDict['Lam1']550 lamRatio = 360*(parmDict['Lam2']-parmDict['Lam1'])/(np.pi*parmDict['Lam1']) 533 551 kRatio = parmDict['I(L2)/I(L1)'] 534 552 iPeak = 0 … … 548 566 else: 549 567 gam = X/cosd(pos/2.0)+Y*tand(pos/2.0) 550 gam = max(gam,0.0 1) #avoid neg gamma568 gam = max(gam,0.001) #avoid neg gamma 551 569 Wd,fmin,fmax = getWidths(pos,sig,gam,shl) 552 if pos > 90:553 fmin,fmax = [fmax,fmin]554 570 iBeg = np.searchsorted(xdata,pos-fmin) 555 iFin = np.searchsorted(xdata,pos+fmax) 571 lenX = len(xdata) 572 if not iBeg: 573 iFin = np.searchsorted(xdata,pos+fmin) 574 elif iBeg == lenX: 575 iFin = iBeg 576 else: 577 iFin = min(lenX,iBeg+int((fmin+fmax)/dx)) 556 578 if not iBeg+iFin: #peak below low limit 557 579 iPeak += 1 … … 561 583 yc[iBeg:iFin] += getFCJVoigt(pos,intens,sig,gam,shl,xdata[iBeg:iFin]) 562 584 if Ka2: 563 pos2 = 2.0*asind(lamRatio*sind(pos/2.0)) 564 Wd,fmin,fmax = getWidths(pos2,sig,gam,shl) 565 if pos > 90: 566 fmin,fmax = [fmax,fmin] 567 iBeg = np.searchsorted(xdata,pos2-fmin) 568 iFin = np.searchsorted(xdata,pos2+fmax) 569 yc[iBeg:iFin] += getFCJVoigt(pos2,intens*kRatio,sig,gam,shl,xdata[iBeg:iFin]) 585 pos2 = pos+lamRatio*tand(pos/2.0) # + 360/pi * Dlam/lam * tan(th) 586 kdelt = int((pos2-pos)/dx) 587 iBeg = min(lenX,iBeg+kdelt) 588 iFin = min(lenX,iFin+kdelt) 589 if iBeg-iFin: 590 yc[iBeg:iFin] += getFCJVoigt(pos2,intens*kRatio,sig,gam,shl,xdata[iBeg:iFin]) 570 591 iPeak += 1 571 592 except KeyError: #no more peaks to process 572 593 return yb+yc 573 574 def getWidths(pos,sig,gam,shl): 575 if shl: 576 widths = [np.sqrt(sig)/100.,gam/200.,.1] 577 else: 578 widths = [np.sqrt(sig)/100.,gam/200.] 579 fwhm = 2.355*widths[0]+2.*widths[1] 580 fmin = 10.*(fwhm+shl*abs(npcosd(pos))) 581 fmax = 15.0*fwhm 582 return widths,fmin,fmax 583 594 584 595 def Dict2Values(parmdict, varylist): 585 596 '''Use before call to leastsq to setup list of values for the parameters … … 635 646 insVary.append(insNames[i]) 636 647 instDict = dict(zip(insNames,insVals)) 637 instDict['X'] = max(instDict['X'],0. 1)638 instDict['Y'] = max(instDict['Y'],0. 1)639 instDict['SH/L'] = max(instDict['SH/L'],0.00 1)648 instDict['X'] = max(instDict['X'],0.01) 649 instDict['Y'] = max(instDict['Y'],0.01) 650 instDict['SH/L'] = max(instDict['SH/L'],0.0001) 640 651 return dataType,instDict,insVary 641 652 … … 735 746 return M 736 747 737 Ftol = 0.0 1748 Ftol = 0.0001 738 749 if oneCycle: 739 750 Ftol = 1.0 … … 759 770 dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) 760 771 try: 761 result = so.leastsq(errPeakProfile,values,full_output=True, ftol=Ftol,772 result = so.leastsq(errPeakProfile,values,full_output=True, #ftol=Ftol, 762 773 args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType,dlg)) 763 774 finally: -
trunk/GSASIIpwdGUI.py
r344 r345 84 84 OnPeakFit('LSQ',oneCycle=True) 85 85 86 def OnBGFSPeakFit(event): 87 OnPeakFit('BFGS') 88 86 def OnClearPeaks(event): 87 dlg = wx.MessageDialog(self,'Delete all peaks?','Clear peak list',wx.OK|wx.CANCEL) 88 try: 89 if dlg.ShowModal() == wx.ID_OK: 90 peaks = [] 91 finally: 92 dlg.Destroy() 93 UpdatePeakGrid(self,peaks) 94 G2plt.PlotPatterns(self) 95 89 96 def OnPeakFit(FitPgm,oneCycle=False): 90 97 SaveState() … … 138 145 for key in T: X.append(D[key]) 139 146 data = X 140 G2plt.PlotPatterns(self)141 147 142 148 def setBackgroundColors(): … … 148 154 else: 149 155 self.dataDisplay.SetCellBackgroundColour(r,c,wx.WHITE) 150 151 def RefineSelect(event): 152 data = self.PatternTree.GetItemPyData(self.PickId) 153 r,c = event.GetRow(),event.GetCol() 154 if r < 0 and self.dataDisplay.GetColLabelValue(c) == 'refine': 155 self.dataDisplay.SelectCol(c,False) 156 157 def OnRefine(event): 158 r,c = event.GetRow(),event.GetCol() 159 if self.dataDisplay.GetColLabelValue(c) == 'refine': 160 if self.PeakTable.GetValue(r,c): 161 data[r][c] = False 162 else: 163 data[r][c] = True 164 print r,c,data[r][c] 165 166 167 def RowSelect(event): 168 r,c = event.GetRow(),event.GetCol() 169 if r < 0 and c < 0: 170 if self.dataDisplay.IsSelection(): 171 self.dataDisplay.ClearSelection() 172 elif c < 0: #only row clicks 173 if event.ControlDown(): 174 if r in self.dataDisplay.GetSelectedRows(): 175 self.dataDisplay.DeselectRow(r) 176 else: 177 self.dataDisplay.SelectRow(r,True) 178 elif event.ShiftDown(): 179 for row in range(r+1): 180 self.dataDisplay.SelectRow(row,True) 181 else: 182 self.dataDisplay.ClearSelection() 183 self.dataDisplay.SelectRow(r,True) 184 185 156 186 157 def KeyEditPeakGrid(event): 187 158 rowList = self.dataDisplay.GetSelectedRows() … … 241 212 self.Bind(wx.EVT_MENU, OnLSQPeakFit, id=G2gd.wxID_LSQPEAKFIT) 242 213 self.Bind(wx.EVT_MENU, OnOneCycle, id=G2gd.wxID_LSQONECYCLE) 243 # self.Bind(wx.EVT_MENU, OnBGFSPeakFit, id=G2gd.wxID_BFGSPEAKFIT)214 self.Bind(wx.EVT_MENU, OnClearPeaks, id=G2gd.wxID_CLEARPEAKS) 244 215 self.Bind(wx.EVT_MENU, OnResetSigGam, id=G2gd.wxID_RESETSIGGAM) 245 216 self.dataFrame.PeakFit.Enable(False) … … 271 242 self.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshPeakGrid) 272 243 self.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid) 273 self.dataDisplay.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, RowSelect)274 self.dataDisplay.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, RefineSelect)275 self.dataDisplay.Bind(wg.EVT_GRID_CELL_RIGHT_CLICK,OnRefine)276 244 self.dataDisplay.SetMargins(0,0) 277 245 self.dataDisplay.AutoSizeColumns(False) … … 413 381 UpdateInstrumentGrid(self,data) 414 382 383 def OnWaveChange(event): 384 if 'Lam' in insVal: 385 data[0] = data[0][:1]+tuple(waves['CuKa'])+(.5,)+data[0][2:] 386 data[1] = data[1][:1]+waves['CuKa']+[.5,]+data[1][2:] 387 data[2] = data[2][:1]+[0,0,0,]+data[2][2:] 388 data[3] = data[3][:1]+['Lam1','Lam2','I(L2)/I(L1)',]+data[3][2:] 389 else: 390 data[0] = data[0][:2]+data[0][4:] 391 data[1] = data[1][:2]+data[1][4:] 392 data[2] = data[2][:2]+data[2][4:] 393 data[3] = data[3][:1]+['Lam',]+data[3][4:] 394 UpdateInstrumentGrid(self,data) 395 415 396 def OnNewType(event): 416 397 insVal['Type'] = typePick.GetValue() … … 424 405 data = updateData(insVal,insRef) 425 406 UpdateInstrumentGrid(self,data) 426 427 407 428 408 def OnRatValue(event): 429 409 try: … … 461 441 try: 462 442 value = float(Obj.GetValue()) 463 if value < 0:464 raise ValueError465 443 except ValueError: 466 444 value = insVal[item] … … 487 465 if not self.dataFrame.GetStatusBar(): 488 466 Status = self.dataFrame.CreateStatusBar() 489 self.Bind(wx.EVT_MENU, OnReset, id=G2gd.wxID_INSTPRMRESET) 467 self.Bind(wx.EVT_MENU, OnReset,id=G2gd.wxID_INSTPRMRESET) 468 self.Bind(wx.EVT_MENU,OnWaveChange,id=G2gd.wxID_CHANGEWAVETYPE) 490 469 typePick = wx.ComboBox(self.dataDisplay,value=insVal['Type'], 491 470 choices=['PXC','PNC','PNT'],style=wx.CB_READONLY|wx.CB_DROPDOWN) … … 753 732 key = event.GetKeyCode() 754 733 for col in colList: 755 if self.IndexPeaksTable.Get TypeName(0,col) == wg.GRID_VALUE_BOOL:734 if self.IndexPeaksTable.GetColLabelValue(col) in ['use','refine']: 756 735 if key == 89: #'Y' 757 736 for row in range(self.IndexPeaksTable.GetNumberRows()): data[row][col]=True … … 1291 1270 for i in range(len(refList)): rowLabels.append(str(i+1)) 1292 1271 colLabels = ['H','K','L','mul','d','pos','sig','gam','Fosq','Fcsq',] 1293 Types = 4*[wg.GRID_VALUE_LONG,]+ 6*[wg.GRID_VALUE_FLOAT+':10,4',]1272 Types = 4*[wg.GRID_VALUE_LONG,]+4*[wg.GRID_VALUE_FLOAT+':10,4',]+2*[wg.GRID_VALUE_FLOAT+':10,2',] 1294 1273 self.PeakTable = G2gd.Table(refList,rowLabels=rowLabels,colLabels=colLabels,types=Types) 1295 1274 self.dataFrame.SetLabel('Reflection List for '+self.RefList) -
trunk/GSASIIstruct.py
r342 r345 300 300 if SGLaue in ['-1','2/m','mmm']: 301 301 return #no Pawley symmetry required constraints 302 for varyI in pawleyVary:302 for i,varyI in enumerate(pawleyVary): 303 303 refI = int(varyI.split(':')[-1]) 304 304 ih,ik,il = PawleyRef[refI][:3] 305 for varyJ in pawleyVary[ :refI]:305 for varyJ in pawleyVary[0:i]: 306 306 refJ = int(varyJ.split(':')[-1]) 307 307 jh,jk,jl = PawleyRef[refJ][:3] … … 491 491 cell[1:7] = G2lat.A2cell(A) 492 492 cell[7] = G2lat.calc_V(A) 493 print ' New unit cell: a = %.5f'%(cell[1]),' b =%.5f'%(cell[2]), \494 ' c = %.5f'%(cell[3]),' alpha =%.3f'%(cell[4]),' beta =%.3f'%(cell[5]), \495 ' gamma = %.3f'%(cell[6]),' volume =%.3f'%(cell[7])493 print ' New unit cell: a = %.5f'%(cell[1]),' b = %.5f'%(cell[2]), \ 494 ' c = %.5f'%(cell[3]),' alpha = %.3f'%(cell[4]),' beta = %.3f'%(cell[5]), \ 495 ' gamma = %.3f'%(cell[6]),' volume = %.3f'%(cell[7]) 496 496 if 'Pawley' in Phase['General']['Type']: 497 497 pawleyRef = Phase['Pawley ref'] … … 708 708 pfx = str(pId)+':'+str(hId)+':' 709 709 710 # Add this stuff for Rietveld refinement!!!! 711 # for item in ['Scale','Extinction']: 712 # hapDict[pfx+item] = hapData[item][0] 713 # if hapData[item][1]: 714 # hapVary.append(pfx+item) 715 # controlDict[pfx+'poType'] = hapData['Pref.Ori.'][0] 716 # if hapData['Pref.Ori.'][0] == 'MD': 717 # hapDict[pfx+'MD'] = hapData['Pref.Ori.'][1] 718 # controlDict[pfx+'MDAxis'] = hapData['Pref.Ori.'][3] 719 # if hapData['Pref.Ori.'][2]: 720 # hapVary.append(pfx+'MD') 721 # else: #'SH' spherical harmonics 722 # for item in hapData['Pref.Ori.'][5]: 723 # hapDict[pfx+item] = hapData['Pref.Ori.'][5][item] 724 # if hapData['Pref.Ori.'][2]: 725 # hapVary.append(pfx+item) 726 # print '\n Phase fraction : %10.4f'%(hapData['Scale'][0]) 727 # print ' Extinction coeff: %10.4f'%(hapData['Extinction'][0]) 710 PhFrExtPOSig = {} 711 for item in ['Scale','Extinction']: 712 hapData[item][0] = parmDict[pfx+item] 713 if hapData[item][1]: 714 PhFrExtPOSig[item] = sigDict[pfx+item] 715 if hapData['Pref.Ori.'][0] == 'MD': 716 hapData['Pref.Ori.'][1] = parmDict[pfx+'MD'] 717 if hapData['Pref.Ori.'][2]: 718 PhFrExtPOSig[item] = sigDict[pfx+item] 719 else: #'SH' spherical harmonics 720 for item in hapData['Pref.Ori.'][5]: 721 hapData['Pref.Ori.'][5][item] = parmDict[pfx+item] 722 if hapData['Pref.Ori.'][2]: 723 PhFrExtPOSig[item] = sigDict[pfx+item] 724 # print '\n Phase fraction : %10.4f, sig %10.4f'%(hapData['Scale'][0],PhFrExtPOSig['Scale']) 725 # print ' Extinction coeff: %10.4f, sig %10.4f'%(hapData['Extinction'][0],PhFrExtPOSig['Extinction']) 728 726 # if hapData['Pref.Ori.'][0] == 'MD': 729 727 # Ax = hapData['Pref.Ori.'][3] … … 774 772 if flag: 775 773 insVary.append(insName) 776 instDict[pfx+'X'] = max(instDict[pfx+'X'],0. 1)777 instDict[pfx+'Y'] = max(instDict[pfx+'Y'],0. 1)778 instDict[pfx+'SH/L'] = max(instDict[pfx+'SH/L'],0.00 1)774 instDict[pfx+'X'] = max(instDict[pfx+'X'],0.01) 775 instDict[pfx+'Y'] = max(instDict[pfx+'Y'],0.01) 776 instDict[pfx+'SH/L'] = max(instDict[pfx+'SH/L'],0.0005) 779 777 return dataType,instDict,insVary 780 778 … … 1106 1104 for i,pwr in enumerate(pwrs): 1107 1105 sum += parmDict[phfx+'Mustrain:'+str(i)]*refl[0]**pwr[0]*refl[1]**pwr[1]*refl[2]**pwr[2] 1108 gam += 0.018*refl[4]**2*tand(refl[5]/2.)*sum 1109 1110 return gam 1111 1112 1106 gam += 0.018*refl[4]**2*tand(refl[5]/2.)*sum 1107 return gam 1108 1109 def GetIntensityCorr(refl,phfx,hfx,calcControls,parmDict): 1110 Icorr = parmDict[phfx+'Scale']*parmDict[hfx+'Scale']*refl[3] #scale*multiplicity 1111 Icorr *= G2pwd.Polarization(parmDict[hfx+'Polariz.'],refl[5],parmDict[hfx+'Azimuth']) 1112 1113 return Icorr 1114 1115 def GetReflPos(refl,wave,G,hfx,calcControls,parmDict): 1116 h,k,l = refl[:3] 1117 dsq = 1./G2lat.calc_rDsq2(np.array([h,k,l]),G) 1118 d = np.sqrt(dsq) 1119 pos = 2.0*asind(wave/(2.0*d))+parmDict[hfx+'Zero'] 1120 const = 9.e-2/(np.pi*parmDict[hfx+'Gonio. radius']) #shifts in microns 1121 if 'Bragg' in calcControls[hfx+'instType']: 1122 pos -= const*(4.*parmDict[hfx+'Shift']*cosd(pos/2.0)+ \ 1123 1.e-7*parmDict[hfx+'Transparency']*sind(pos)) #trans(=1/mueff) in Angstroms 1124 else: #Debye-Scherrer - simple but maybe not right 1125 pos -= const*(parmDict[hfx+'DisplaceX']*cosd(pos)+parmDict[hfx+'DisplaceY']*sind(pos)) 1126 return pos 1127 1128 def GetReflSIgGam(refl,wave,G,hfx,phfx,calcControls,parmDict,sizeEllipse): 1129 U = parmDict[hfx+'U'] 1130 V = parmDict[hfx+'V'] 1131 W = parmDict[hfx+'W'] 1132 X = parmDict[hfx+'X'] 1133 Y = parmDict[hfx+'Y'] 1134 tanPos = tand(refl[5]/2.0) 1135 sig = U*tanPos**2+V*tanPos+W #save peak sigma 1136 gam = X/cosd(refl[5]/2.0)+Y*tanPos+GetSampleGam(refl,wave,G,phfx,calcControls,parmDict,sizeEllipse) #save peak gamma 1137 return sig,gam 1138 1113 1139 hId = Histogram['hId'] 1114 1140 hfx = ':%d:'%(hId) … … 1118 1144 1119 1145 if 'C' in calcControls[hfx+'histType']: 1120 U = parmDict[hfx+'U'] 1121 V = parmDict[hfx+'V'] 1122 W = parmDict[hfx+'W'] 1123 X = parmDict[hfx+'X'] 1124 Y = parmDict[hfx+'Y'] 1125 shl = max(parmDict[hfx+'SH/L'],0.001) 1126 Zero = parmDict[hfx+'Zero'] 1127 pola = parmDict[hfx+'Polariz.'] 1146 shl = max(parmDict[hfx+'SH/L'],0.0005) 1128 1147 Ka2 = False 1129 1148 if hfx+'Lam1' in parmDict.keys(): … … 1150 1169 for refl in refList: 1151 1170 if 'C' in calcControls[hfx+'histType']: 1152 h,k,l,m = refl[:4] 1153 dsq = 1./G2lat.calc_rDsq2(np.array([h,k,l]),G) 1154 d = np.sqrt(dsq) 1155 pos = 2.0*asind(wave/(2.0*d))+Zero 1156 const = 9.e-2/(np.pi*parmDict[hfx+'Gonio. radius']) #shifts in microns 1157 if 'Bragg' in calcControls[hfx+'instType']: 1158 pos -= const*(4.*parmDict[hfx+'Shift']*cosd(pos/2.0)+ \ 1159 1.e-7*parmDict[hfx+'Transparency']*sind(pos)) #trans(=1/mueff) in Angstroms 1160 else: #Debye-Scherrer - simple but maybe not right 1161 pos -= const*(parmDict[hfx+'DisplaceX']*cosd(pos)+parmDict[hfx+'DisplaceY']*sind(pos)) 1162 refl[5] = pos 1163 tanPos = tand(pos/2.0) 1164 refl[6] = U*tanPos**2+V*tanPos+W #save peak sigma 1165 refl[7] = X/cosd(pos/2.0)+Y*tanPos+GetSampleGam(refl,wave,G,phfx,calcControls,parmDict,sizeEllipse) #save peak gamma 1171 h,k,l = refl[:3] 1172 refl[5] = GetReflPos(refl,wave,G,hfx,calcControls,parmDict) #corrected reflection position 1173 refl[6:8] = GetReflSIgGam(refl,wave,G,hfx,phfx,calcControls,parmDict,sizeEllipse) #peak sig & gam 1174 Icorr = GetIntensityCorr(refl,phfx,hfx,calcControls,parmDict) 1166 1175 if 'Pawley' in Phase['General']['Type']: 1167 1176 try: 1168 refl[8] = parmDict[ hfx+'Scale']*m*parmDict[pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])]1177 refl[8] = parmDict[pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])] 1169 1178 except KeyError: 1170 1179 print ' ***Error %d,%d,%d missing from Pawley reflection list ***'%(h,k,l) … … 1172 1181 else: 1173 1182 raise ValueError #wants strctrfacr calc here 1174 Wd,fmin,fmax = G2pwd.getWidths(pos,refl[6],refl[7],shl) 1175 if pos > 90: 1176 fmin,fmax = [fmax,fmin] 1177 iBeg = np.searchsorted(x,pos-fmin) 1178 iFin = np.searchsorted(x,pos+fmax) 1183 Wd,fmin,fmax = G2pwd.getWidths(refl[5],refl[6],refl[7],shl) 1184 iBeg = np.searchsorted(x,refl[5]-fmin) 1185 iFin = np.searchsorted(x,refl[5]+fmax) 1179 1186 if not iBeg+iFin: #peak below low limit - skip peak 1180 1187 continue 1181 1188 elif not iBeg-iFin: #peak above high limit - done 1182 1189 return yc,yb 1183 yc[iBeg:iFin] += G2pwd.getFCJVoigt( pos,refl[8],refl[6],refl[7],shl,x[iBeg:iFin]) #>90% of time spent here1190 yc[iBeg:iFin] += G2pwd.getFCJVoigt(refl[5],Icorr*refl[8],refl[6],refl[7],shl,x[iBeg:iFin]) #>90% of time spent here 1184 1191 if Ka2: 1185 pos2 = pos+lamRatio*tand(pos/2.0) # + 360/pi * Dlam/lam * tan(th)1192 pos2 = refl[5]+lamRatio*tand(refl[5]/2.0) # + 360/pi * Dlam/lam * tan(th) 1186 1193 Wd,fmin,fmax = G2pwd.getWidths(pos2,refl[6],refl[7],shl) 1187 if pos > 90:1188 fmin,fmax = [fmax,fmin]1189 1194 iBeg = np.searchsorted(x,pos2-fmin) 1190 1195 iFin = np.searchsorted(x,pos2+fmax) 1191 yc[iBeg:iFin] += G2pwd.getFCJVoigt(pos2, refl[8]*kRatio,refl[6],refl[7],shl,x[iBeg:iFin]) #and here1196 yc[iBeg:iFin] += G2pwd.getFCJVoigt(pos2,Icorr*refl[8]*kRatio,refl[6],refl[7],shl,x[iBeg:iFin]) #and here 1192 1197 else: 1193 1198 raise ValueError … … 1227 1232 Histogram['sumwYd'] = np.sum(np.sqrt(w[xB:xF])*(yd[xB:xF])) 1228 1233 M = np.concatenate((M,np.sqrt(w[xB:xF])*(yd[xB:xF]))) 1229 # print 'sum M^2,y,yb,yc',np.sum(M**2),np.sum(y[xB:xF]),np.sum(yb[xB:xF]),np.sum(yc[xB:xF])1230 1234 Histograms['sumwYo'] = sumwYo 1231 1235 Histograms['Nobs'] = Nobs … … 1277 1281 result = so.leastsq(errRefine,values,full_output=True, #factor=1.,epsfcn=0.00001,ftol=0.0001, 1278 1282 args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg)) 1279 print len(result)1280 1283 finally: 1281 1284 dlg.Destroy()
Note: See TracChangeset
for help on using the changeset viewer.