# Changeset 655

Ignore:
Timestamp:
Jun 25, 2012 3:57:48 PM (10 years ago)
Message:

implement single peak fits for background

Location:
trunk
Files:
4 edited

Unmodified
Removed
• ## trunk/GSASII.py

 r643 parmDict.update(histDict) for parm in parmDict: if parm.split(':')[-1] in ['Azimuth','Gonio. radius','Lam1','Lam2','Omega','Chi','Phi']: if parm.split(':')[-1] in ['Azimuth','Gonio. radius','Lam1','Lam2', 'Omega','Chi','Phi','nDebye','nPeaks']: parmDict[parm] = [parmDict[parm],' '] elif parm.split(':')[-2] in ['Ax','Ay','Az','SHmodel','SHord']:
• ## trunk/GSASIImath.py

 r654 result = so.leastsq(calcPhase,DX,full_output=True,args=(DH,Dphi)) #    for item in zip(DH,Dphi,result[2]['fvec']): #        print item[0],'%.4f %.4f'%(item[1],item[2]) for item in zip(DH,Dphi,result[2]['fvec']): print item[0],'%.4f %.4f'%(item[1],item[2]) chisq = np.sum(result[2]['fvec']**2) DX = np.array(np.fix(-result[0]*steps),dtype='i')
• ## trunk/GSASIIpwd.py

 r650 iD += 1 except KeyError: break break iD = 0 while True: try: pkP = parmDict[pfx+'BkPkpos:'+str(iD)] pkI = parmDict[pfx+'BkPkint:'+str(iD)] pkS = parmDict[pfx+'BkPksig:'+str(iD)] pkG = parmDict[pfx+'BkPkgam:'+str(iD)] shl = 0.002 Wd,fmin,fmax = getWidths(pkP,pkS,pkG,shl) iBeg = np.searchsorted(xdata,pkP-fmin) iFin = np.searchsorted(xdata,pkP+fmax) yb[iBeg:iFin] += pkI*getFCJVoigt3(pkP,pkS,pkG,shl,xdata[iBeg:iFin]) iD += 1 except KeyError: break return yb dydb = np.zeros(shape=(nBak,len(xdata))) dyddb = np.zeros(shape=(3*parmDict[pfx+'nDebye'],len(xdata))) dydpk = np.zeros(shape=(4*parmDict[pfx+'nPeaks'],len(xdata))) dx = xdata[1]-xdata[0] if bakType in ['chebyschev','cosine']: cqr = np.cos(q*dbR) temp = np.exp(-dbU*q**2) dyddb[3*iD] = ff*sqr*temp dyddb[3*iD+1] = ff*dbA*temp*(cqr-sqr)/dbR dyddb[3*iD+2] = -ff*dbA*sqr*temp*q**2 dyddb[3*iD] = 100.*dx*ff*sqr*temp dyddb[3*iD+1] = 100.*dx*ff*dbA*temp*(cqr-sqr)/dbR dyddb[3*iD+2] = -100.*dx*ff*dbA*sqr*temp*q**2 iD += 1 except KeyError: break return dydb,dyddb iD = 0 while True: try: pkP = parmDict[pfx+'BkPkpos:'+str(iD)] pkI = parmDict[pfx+'BkPkint:'+str(iD)] pkS = parmDict[pfx+'BkPksig:'+str(iD)] pkG = parmDict[pfx+'BkPkgam:'+str(iD)] shl = 0.002 Wd,fmin,fmax = getWidths(pkP,pkS,pkG,shl) iBeg = np.searchsorted(xdata,pkP-fmin) iFin = np.searchsorted(xdata,pkP+fmax) Df,dFdp,dFds,dFdg,dFdsh = getdFCJVoigt3(pkP,pkS,pkG,shl,xdata[iBeg:iFin]) dydpk[4*iD][iBeg:iFin] += 100.*dx*pkI*dFdp dydpk[4*iD+1][iBeg:iFin] += 100.*dx*Df dydpk[4*iD+2][iBeg:iFin] += 100.*dx*pkI*dFds dydpk[4*iD+3][iBeg:iFin] += 100.*dx*pkI*dFdg iD += 1 except KeyError: break return dydb,dyddb,dydpk #use old fortran routine # needs to return np.array([dMdx1,dMdx2,...]) in same order as varylist = backVary,insVary,peakVary order dMdv = np.zeros(shape=(len(varyList),len(xdata))) dMdb,dMddb = getBackgroundDerv('',parmDict,bakType,xdata) dMdb,dMddb,dMdpk = getBackgroundDerv('',parmDict,bakType,xdata) if 'Back:0' in varyList:            #background derivs are in front if present dMdv[0:len(dMdb)] = dMdb ip = names.index(parm) dMdv[varyList.index(name)] = dMddb[3*int(id)+ip] names = ['BkPkpos','BkPkint','BkPksig','BkPkgam'] for name in varyList: if 'BkPk' in name: parm,id = name.split(':') ip = names.index(parm) dMdv[varyList.index(name)] = dMdpk[4*int(id)+ip] dx = xdata[1]-xdata[0] U = parmDict['U'] backVary += debyeVary backDict['nPeaks'] = Debye['nPeaks'] peaksDict = {} peaksList = []
• ## trunk/GSASIIstruct.py

 r650 def GetBackgroundParms(hId,Background): Back = Background[0] Debye = Background[1] DebyePeaks = Background[1] bakType,bakFlag = Back[:2] backVals = Back[3:] if bakFlag: backVary = backNames backDict[':'+str(hId)+':nDebye'] = Debye['nDebye'] backDict[':'+str(hId)+':nDebye'] = DebyePeaks['nDebye'] backDict[':'+str(hId)+':nPeaks'] = DebyePeaks['nPeaks'] debyeDict = {} debyeList = [] for i in range(Debye['nDebye']): for i in range(DebyePeaks['nDebye']): debyeNames = [':'+str(hId)+':DebyeA:'+str(i),':'+str(hId)+':DebyeR:'+str(i),':'+str(hId)+':DebyeU:'+str(i)] debyeDict.update(dict(zip(debyeNames,Debye['debyeTerms'][i][::2]))) debyeList += zip(debyeNames,Debye['debyeTerms'][i][1::2]) debyeDict.update(dict(zip(debyeNames,DebyePeaks['debyeTerms'][i][::2]))) debyeList += zip(debyeNames,DebyePeaks['debyeTerms'][i][1::2]) debyeVary = [] for item in debyeList: debyeVary.append(item[0]) backDict.update(debyeDict) backVary += debyeVary backVary += debyeVary peakDict = {} peakList = [] for i in range(DebyePeaks['nPeaks']): peakNames = [':'+str(hId)+':BkPkpos:'+str(i),':'+str(hId)+ \ ':BkPkint:'+str(i),':'+str(hId)+':BkPksig:'+str(i),':'+str(hId)+':BkPkgam:'+str(i)] peakDict.update(dict(zip(peakNames,DebyePeaks['peaksList'][i][::2]))) peakList += zip(peakNames,DebyePeaks['peaksList'][i][1::2]) peakVary = [] for item in peakList: if item[1]: peakVary.append(item[0]) backDict.update(peakDict) backVary += peakVary return bakType,backDict,backVary def PrintBackground(Background): Back = Background[0] Debye = Background[1] DebyePeaks = Background[1] print '\n Background function: ',Back[0],' Refine?',bool(Back[1]) line = ' Coefficients: ' line += '\n'+15*' ' print line if Debye['nDebye']: if DebyePeaks['nDebye']: print '\n Debye diffuse scattering coefficients' parms = ['DebyeA','DebyeR','DebyeU'] line = ' names :' line = ' names :  ' for parm in parms: line += '%16s'%(parm) line += '%8s refine?'%(parm) print line for j,term in enumerate(Debye['debyeTerms']): for i in range(3): line += '%10.4g %5s'%(term[2*i],bool(term[2*i+1])) print line if DebyePeaks['nPeaks']: print '\n Single peak coefficients' parms =    ['BkPkpos','BkPkint','BkPksig','BkPkgam'] line = ' names :  ' for parm in parms: line += '%8s refine?'%(parm) print line for j,term in enumerate(DebyePeaks['peaksList']): line = ' peak'+'%2d'%(j)+':' for i in range(4): line += '%10.3f %5s'%(term[2*i],bool(term[2*i+1])) print line def SetBackgroundParms(pfx,Background,parmDict,sigDict): Back = Background[0] Debye = Background[1] DebyePeaks = Background[1] lenBack = len(Back[3:]) backSig = [0 for i in range(lenBack+3*Debye['nDebye'])] backSig = [0 for i in range(lenBack+3*DebyePeaks['nDebye']+4*DebyePeaks['nPeaks'])] for i in range(lenBack): Back[3+i] = parmDict[pfx+'Back:'+str(i)] if pfx+'Back:'+str(i) in sigDict: backSig[i] = sigDict[pfx+'Back:'+str(i)] if Debye['nDebye']: for i in range(Debye['nDebye']): if DebyePeaks['nDebye']: for i in range(DebyePeaks['nDebye']): names = [pfx+'DebyeA:'+str(i),pfx+'DebyeR:'+str(i),pfx+'DebyeU:'+str(i)] for j,name in enumerate(names): Debye['debyeTerms'][i][2*j] = parmDict[name] DebyePeaks['debyeTerms'][i][2*j] = parmDict[name] if name in sigDict: backSig[lenBack+3*i+j] = sigDict[name] if DebyePeaks['nPeaks']: for i in range(DebyePeaks['nPeaks']): names = [pfx+'BkPkpos:'+str(i),pfx+'BkPkint:'+str(i), pfx+'BkPksig:'+str(i),pfx+'BkPkgam:'+str(i)] for j,name in enumerate(names): DebyePeaks['peaksList'][i][2*j] = parmDict[name] if name in sigDict: backSig[lenBack+3*DebyePeaks['nDebye']+4*i+j] = sigDict[name] return backSig def PrintBackgroundSig(Background,backSig): Back = Background[0] Debye = Background[1] DebyePeaks = Background[1] lenBack = len(Back[3:]) valstr = ' value : ' print valstr print sigstr if Debye['nDebye']: if DebyePeaks['nDebye']: ifAny = False ptfmt = "%12.5f" if ifAny: print '\n Debye diffuse scattering coefficients' print names print ptstr print sigstr if DebyePeaks['nPeaks']: ifAny = False ptfmt = "%14.3f" names =  ' names :' ptstr =  ' values:' sigstr = ' esds  :' for item in sigDict: if 'BkPk' in item: ifAny = True names += '%14s'%(item) ptstr += ptfmt%(parmDict[item]) sigstr += ptfmt%(sigDict[item]) if ifAny: print '\n Single peak coefficients' print names print ptstr bakType = calcControls[hfx+'bakType'] dMdv = np.zeros(shape=(len(varylist),len(x))) dMdb,dMddb = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,x) dMdb,dMddb,dMdpk = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,x) if hfx+'Back:0' in varylist: # for now assume that Back:x vars to not appear in constraints bBpos =varylist.index(hfx+'Back:0') ip = names.index(parm) dMdv[varylist.index(name)] = dMddb[3*id+ip] names = [hfx+'BkPkpos',hfx+'BkPkint',hfx+'BkPksig',hfx+'BkPkgam'] for name in varylist: if 'BkPk' in name: id = int(name.split(':')[-1]) parm = name[:int(name.rindex(':'))] ip = names.index(parm) dMdv[varylist.index(name)] = dMdpk[4*id+ip] if 'C' in calcControls[hfx+'histType']: dx = x[1]-x[0]
Note: See TracChangeset for help on using the changeset viewer.