Changeset 5264
- Timestamp:
- Apr 16, 2022 8:54:53 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIdataGUI.py
r5262 r5264 7941 7941 G2frame.GPXtree.SetItemPyData(item,data) 7942 7942 #end patch 7943 #if GSASIIpath.GetConfigValue('debug'):7944 #import importlib as imp7945 #imp.reload(G2pdG)7946 #print('reloading G2pdG')7943 if GSASIIpath.GetConfigValue('debug'): 7944 import importlib as imp 7945 imp.reload(G2pdG) 7946 print('reloading G2pdG') 7947 7947 G2pdG.UpdatePeakGrid(G2frame,data) 7948 7948 G2plt.PlotPatterns(G2frame) -
trunk/GSASIIpath.py
r5135 r5264 1073 1073 except (AttributeError,TypeError): # happens on building docs 1074 1074 return 1075 if path2GSAS2 not in sys.path: 1076 sys.path.insert(0,path2GSAS2) # make sure current path is used 1075 1077 binpath = None 1076 1078 binprfx = GetBinaryPrefix() -
trunk/GSASIIplot.py
r5262 r5264 2025 2025 PlotPatterns(G2frame,newPlot,plotType) 2026 2026 2027 def plotVline(Page,Plot,Lines,Parms,pos,color,pick): 2028 if Page.plotStyle['qPlot']: 2029 Lines.append(Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,pos),color=color, 2030 picker=pick,pickradius=2.)) 2031 elif Page.plotStyle['dPlot']: 2032 Lines.append(Plot.axvline(G2lat.Pos2dsp(Parms,pos),color=color, 2033 picker=pick,pickradius=2.)) 2034 else: 2035 Lines.append(Plot.axvline(pos,color=color, 2036 picker=pick,pickradius=2.)) 2037 2027 2038 def PlotPatterns(G2frame,newPlot=False,plotType='PWDR',data=None, 2028 2039 extraKeys=[],refineMode=False): … … 3036 3047 return '_'+string 3037 3048 3038 #### beginning PlotPatterns execution3049 ###### beginning PlotPatterns execution 3039 3050 global exclLines,Page 3040 3051 global DifLine # BHT: probably does not need to be global … … 3715 3726 else: 3716 3727 Ni = N 3717 if Page.plotStyle['qPlot']: 3718 Lines.append(Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,item[0]),color='b', 3719 picker=True,pickradius=2.)) 3720 elif Page.plotStyle['dPlot']: 3721 Lines.append(Plot.axvline(G2lat.Pos2dsp(Parms,item[0]),color='b', 3722 picker=True,pickradius=2.)) 3723 else: 3724 Lines.append(Plot.axvline(item[0],color='b', 3725 picker=True,pickradius=2.)) 3728 plotVline(Page,Plot,Lines,Parms,item[0],'b',True) 3726 3729 if Ni == N+1: 3727 3730 Lines[-1].set_lw(Lines[-1].get_lw()+1) 3731 data['LaueFringe'] = data.get('LaueFringe',{}) 3732 for pos in data['LaueFringe'].get('satellites',[]): 3733 plotVline(Page,Plot,Lines,Parms,pos,'k',False) 3728 3734 if G2frame.GPXtree.GetItemText(PickId) == 'Limits': 3729 3735 tip = 'On data point: Lower limit - L MB; Upper limit - R MB. On limit: MB down to move' -
trunk/GSASIIpwd.py
r5261 r5264 4 4 *GSASIIpwd: Powder calculations module* 5 5 ============================================== 6 7 This version hacked to provide Laue Fringe fitting. 6 8 7 9 ''' … … 50 52 print ('pydiffax is not available for this platform') 51 53 import GSASIIfiles as G2fil 52 54 import LaueFringe as LF 53 55 54 56 # trig functions in degrees … … 1407 1409 yb = getBackground('',parmDict,bakType,dataType,xdata,fixback)[0] 1408 1410 yc = np.zeros_like(yb) 1409 if 'C' in dataType: 1411 if parmDict.get('LaueFringe',False): 1412 if 'Lam1' in parmDict.keys(): 1413 lam = parmDict['Lam1'] 1414 lam2 = parmDict['Lam2'] 1415 Ka2 = True 1416 lamRatio = 360*(lam2-lam)/(np.pi*lam) 1417 kRatio = parmDict['I(L2)/I(L1)'] 1418 else: 1419 lam = parmDict['Lam'] 1420 Ka2 = False 1421 shol = 0 1422 # loop over peaks 1423 iPeak = -1 1424 cells = parmDict['ncell'] 1425 while True: 1426 iPeak += 1 1427 try: 1428 pos = parmDict['pos'+str(iPeak)] 1429 #tth = (pos-parmDict['Zero']) 1430 intens = parmDict['int'+str(iPeak)] 1431 damp = parmDict['damp'+str(iPeak)] 1432 asym = parmDict['asym'+str(iPeak)] 1433 sig = parmDict['sig'+str(iPeak)] 1434 gam = parmDict['gam'+str(iPeak)] 1435 fmin = 4 # for now make peaks 4 degrees wide 1436 fmin = min(0.9*abs(xdata[-1] - xdata[0]),fmin) # unless the data range is smaller 1437 iBeg = np.searchsorted(xdata,pos-fmin/2) 1438 iFin = np.searchsorted(xdata,pos+fmin/2) 1439 if not iBeg+iFin: # skip peak below low limit 1440 continue 1441 elif not iBeg-iFin: # got peak above high limit (peaks sorted, so we can stop) 1442 break 1443 LF.LaueFringePeakCalc(xdata,yc,lam,pos,intens,damp,asym,sig,gam,shol,cells,fmin) 1444 if Ka2: 1445 pos2 = pos+lamRatio*tand(pos/2.0) # + 360/pi * Dlam/lam * tan(th) 1446 iBeg = np.searchsorted(xdata,pos2-fmin) 1447 iFin = np.searchsorted(xdata,pos2+fmin) 1448 if iBeg-iFin: 1449 LF.LaueFringePeakCalc(xdata,yc,lam2,pos2,intens*kRatio,damp,asym,sig,gam,shol,cells,fmin) 1450 except KeyError: #no more peaks to process 1451 return yb+yc 1452 elif 'C' in dataType: 1410 1453 shl = max(parmDict['SH/L'],0.002) 1411 1454 Ka2 = False … … 1603 1646 ip = names.index(parm) 1604 1647 dMdv[varyList.index(name)] = dMdpk[4*int(Id)+ip] 1648 if parmDict.get('LaueFringe',False): 1649 for i,name in enumerate(varyList): 1650 if not np.all(dMdv[i] == 0): continue 1651 deltaParmDict = parmDict.copy() 1652 delta = max(parmDict[name]/1e5,0.001) 1653 deltaParmDict[name] += delta 1654 intArrP = getPeakProfile(dataType,deltaParmDict,xdata,fixback,varyList,bakType) 1655 deltaParmDict[name] -= 2*delta 1656 intArrM = getPeakProfile(dataType,deltaParmDict,xdata,fixback,varyList,bakType) 1657 dMdv[i] = 0.5 * (intArrP - intArrM) / delta 1658 return dMdv 1605 1659 if 'C' in dataType: 1606 1660 shl = max(parmDict['SH/L'],0.002) … … 2091 2145 2092 2146 :param str FitPgm: type of fit to perform. At present this is ignored. 2147 :param str FitPgm: type of fit to perform. 2148 This should be 'LSQ' for a standard least-squares fit 2149 with pseudo-Voigt peaks or 'LaueFringe' for on-specular thin-film fitting. 2093 2150 :param list Peaks: a list of peaks. Each peak entry is a list with paired values: 2094 2151 The number of pairs depends on the data type (see :func:`getHeaderInfo`). … … 2374 2431 return M 2375 2432 2376 #---- beginning of DoPeakFit --------------------------------------------- -2433 #---- beginning of DoPeakFit --------------------------------------------- 2377 2434 if controls: 2378 2435 Ftol = controls['min dM/M'] … … 2384 2441 if fixback is None: 2385 2442 fixback = np.zeros_like(y) 2386 yc *= 0.#set calcd ones to zero2387 yb *= 0.2388 yd *= 0.2443 yc.fill(0.) #set calcd ones to zero 2444 yb.fill(0.) 2445 yd.fill(0.) 2389 2446 xBeg = np.searchsorted(x,Limits[0]) 2390 2447 xFin = np.searchsorted(x,Limits[1])+1 … … 2409 2466 raise Exception('Instrumental profile terms cannot be varied '+ 2410 2467 'after setPeakInstPrmMode(False) is used') 2468 fitFunc = errPeakProfile 2469 dervFunc = devPeakProfile 2470 parmDict['LaueFringe'] = False 2471 if FitPgm == 'LaueFringe': 2472 #====================================================================== 2473 print('Debug: reload LaueFringe') # TODO: remove me 2474 import imp 2475 imp.reload(LF) 2476 # TODO: remove ^^^^ 2477 #====================================================================== 2478 for v in ('U','V','W','X','Y','Z','alpha','alpha-0','alpha-1', 2479 'beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q',): 2480 if v in varyList: 2481 raise Exception('Instrumental profile terms cannot be varied '+ 2482 'in Laue Fringe fits') 2483 parmDict['LaueFringe'] = True 2484 #fitFunc = LF.errLaueFit 2485 #dervFunc = None 2486 elif 'analytic' not in controls.get('deriv type',''): 2487 dervFunc = None 2488 2411 2489 while not noFit: 2412 2490 begin = time.time() … … 2414 2492 Rvals = {} 2415 2493 badVary = [] 2416 result = so.leastsq( errPeakProfile,values,Dfun=devPeakProfile,full_output=True,ftol=Ftol,col_deriv=True,2494 result = so.leastsq(fitFunc,values,Dfun=dervFunc,full_output=True,ftol=Ftol,col_deriv=True, 2417 2495 args=(x[xBeg:xFin],y[xBeg:xFin],fixback[xBeg:xFin],wtFactor*w[xBeg:xFin],dataType,parmDict,varyList,bakType,dlg)) 2418 2496 ncyc = int(result[2]['nfev']/2) … … 2446 2524 if dlg: dlg.Destroy() 2447 2525 yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin],fixback[xBeg:xFin])[0] 2526 # if FitPgm == 'LaueFringe': 2527 # yc[xBeg:xFin] = LF.getLauePeakProfile(dataType,parmDict,x[xBeg:xFin],fixback[xBeg:xFin],varyList,bakType) 2528 # else: 2529 # yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],fixback[xBeg:xFin],varyList,bakType) 2448 2530 yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],fixback[xBeg:xFin],varyList,bakType) 2449 2531 yd[xBeg:xFin] = y[xBeg:xFin]-yc[xBeg:xFin] -
trunk/GSASIIpwdGUI.py
r5256 r5264 835 835 G2frame.OnFileSaveas(event) 836 836 FitPgm = 'LSQ' 837 #if data.get('FitPgm',0) == 1:838 #FitPgm = 'LaueFringe'837 if data.get('FitPgm',0) == 1: 838 FitPgm = 'LaueFringe' 839 839 wx.CallAfter(OnPeakFit,FitPgm) 840 840 … … 845 845 reflGrid.DisableCellEditControl() 846 846 FitPgm = 'LSQ' 847 #if data.get('FitPgm',0) == 1:848 #FitPgm = 'LaueFringe'847 if data.get('FitPgm',0) == 1: 848 FitPgm = 'LaueFringe' 849 849 wx.CallAfter(OnPeakFit,FitPgm,oneCycle=True) 850 850 … … 952 952 wtFactor = Pattern[0]['wtFactor'] 953 953 bxye = GetFileBackground(G2frame,data,background,scale=False) 954 peaks['LaueFringe'] = peaks.get('LaueFringe',{}) 955 peaks['LaueFringe']['satellites'] = [] 956 overallInfo = [] 957 import LaueFringe as LF 958 lines = peaks['LaueFringe'].get('Show') 959 if 'Laue' in FitPgm: 960 overallInfo = [{'ncell':peaks['LaueFringe']['ncell']}] # add overall info 961 if lines: 962 for i in peaks['peaks']: 963 pks = list(range(-lines,0)) + list(range(1,lines+1)) 964 peaks['LaueFringe']['satellites'].extend( 965 LF.LaueSatellite(i[0],peaks['LaueFringe']['ncell'],pks)) 966 #====================================================================== 967 print('Debug: reload G2pwd') # TODO: remove me 968 import imp 969 imp.reload(G2pwd) 970 imp.reload(G2plt) 971 # TODO: remove ^^^^ 972 #====================================================================== 954 973 if noFit: 955 results = G2pwd.DoPeakFit(FitPgm,peaks['peaks'] ,background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,noFit=True)974 results = G2pwd.DoPeakFit(FitPgm,peaks['peaks']+overallInfo,background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,noFit=True) 956 975 G2plt.PlotPatterns(G2frame,plotType='PWDR') 957 976 return … … 959 978 parent=G2frame, 960 979 style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) 961 results = G2pwd.DoPeakFit(FitPgm,peaks['peaks'] ,background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,dlg)980 results = G2pwd.DoPeakFit(FitPgm,peaks['peaks']+overallInfo,background,limits,inst,inst2,data,bxye,[],oneCycle,controls,wtFactor,dlg) 962 981 peaks['sigDict'] = results[0] 963 982 text = 'Peak fit: Rwp=%.2f%% Nobs= %d Nparm= %d Npeaks= %d'%(results[3]['Rwp'],results[1][2]['fjac'].shape[1],len(results[0]),len(peaks['peaks'])) … … 1118 1137 'Redraw the peak listings after the mode changes' 1119 1138 wx.CallAfter(UpdatePeakGrid,G2frame,data) 1139 wx.CallLater(100,RefreshPeakGrid,None) 1120 1140 1121 1141 def RefreshPeakGrid(event): 1122 1142 'recompute & plot the peaks any time a value in the table is edited' 1123 1143 FitPgm = 'LSQ' 1124 #if data.get('FitPgm',0) == 1:1125 #FitPgm = 'LaueFringe'1144 if data.get('FitPgm',0) == 1: 1145 FitPgm = 'LaueFringe' 1126 1146 OnPeakFit(FitPgm,noFit=True) 1127 1147 … … 1135 1155 #### beginning of UpdatePeakGrid 1136 1156 #====================================================================== 1137 #data['FitPgm'] = data.get('FitPgm',0)1157 data['FitPgm'] = data.get('FitPgm',0) 1138 1158 G2frame.GetStatusBar().SetStatusText('Global refine: select refine column & press Y or N',1) 1139 1159 G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.PeakMenu) … … 1214 1234 mainSizer.Add(topSizer,0,wx.EXPAND) 1215 1235 G2G.HorizontalLine(mainSizer,G2frame.dataWindow) 1216 # if 'C' in Inst['Type'][0]: 1217 # topSizer = wx.BoxSizer(wx.HORIZONTAL) 1218 # topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Fitting mode: '),0,WACV) 1219 # pkType = G2G.G2ChoiceButton(G2frame.dataWindow,('Powder diffraction','Laue fringes'), 1220 # indLoc=data,indKey='FitPgm', 1221 # onChoice=updateMe) 1222 # topSizer.Add(pkType) 1223 # mainSizer.Add(topSizer) 1236 if 'C' in Inst['Type'][0]: 1237 topSizer = wx.BoxSizer(wx.HORIZONTAL) 1238 topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Fitting mode: '),0,WACV) 1239 pkType = G2G.G2ChoiceButton(G2frame.dataWindow,('Powder diffraction','Laue fringes'), 1240 indLoc=data,indKey='FitPgm', 1241 onChoice=updateMe) 1242 topSizer.Add(pkType,0,WACV) 1243 if data['FitPgm']: 1244 topSizer.Add((15,-1)) 1245 if 'LaueFringe' not in data: 1246 data['LaueFringe'] = {'ncell':20} 1247 elif 'ncell' not in data['LaueFringe']: 1248 data['LaueFringe']['ncell'] = 20 1249 siz = G2G.G2SpinWidget(G2frame.dataWindow,data['LaueFringe'] ,'ncell', 1250 'Laue ncell', 1251 onChange=RefreshPeakGrid,onChangeArgs=[None]) 1252 topSizer.Add(siz,0,WACV) 1253 data['LaueFringe']['Show'] = data['LaueFringe'].get('Show',0) 1254 #ch = G2G.G2CheckBox(G2frame.dataWindow,' Show',data['LaueFringe'],'Show', 1255 # OnChange=RefreshPeakGrid) 1256 topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' Show '),0,WACV) 1257 ch = G2G.EnumSelector(G2frame.dataWindow,data['LaueFringe'],'Show', 1258 ['None','1','2','3','4','5','6'],list(range(7)), 1259 OnChange=RefreshPeakGrid) 1260 topSizer.Add(ch,0,WACV) 1261 topSizer.Add(wx.StaticText(G2frame.dataWindow,label=' satellites'),0,WACV) 1262 mainSizer.Add(topSizer) 1224 1263 mainSizer.Add(reflGrid,0,wx.ALL,10) 1225 1264 G2frame.dataWindow.SetSizer(mainSizer) 1226 1265 G2frame.dataWindow.SetDataSize() 1227 1266 RefreshPeakGrid(None) 1267 1228 1268 ################################################################################ 1229 1269 ##### Background -
trunk/GSASIIstrIO.py
r5232 r5264 3385 3385 pFile.write(' Performed LeBail extraction for phase %s in histogram %s\n'%(phase,histogram)) 3386 3386 elif 'E' not in Inst['Type'][0]: 3387 if pfx+'Scale' in PhFrExtPOSig:3388 var = pfx + 'WgtFrac'3387 var = pfx + 'WgtFrac' 3388 if pfx+'Scale' in PhFrExtPOSig or var in sigDict: 3389 3389 wtFr = parmDict.get(var,0) 3390 3390 sigwtFr = sigDict.get(var,0) 3391 3391 pFile.write(' Phase fraction : %10.5g, sig %10.5g Weight fraction : %8.5f, sig %10.5f\n'% 3392 (hapData['Scale'][0],PhFrExtPOSig [pfx+'Scale'],wtFr,sigwtFr))3392 (hapData['Scale'][0],PhFrExtPOSig.get(pfx+'Scale',0),wtFr,sigwtFr)) 3393 3393 if pfx+'Extinction' in PhFrExtPOSig: 3394 3394 pFile.write(' Extinction coeff: %10.4f, sig %10.4f\n'%(hapData['Extinction'][0],PhFrExtPOSig[pfx+'Extinction']))
Note: See TracChangeset
for help on using the changeset viewer.