def getPeakProfile(parmDict, xdata, varyList, bakType): yb = getBackground('', parmDict, bakType, xdata) yc = np.zeros_like(yb) cw = np.diff(xdata) cw = np.append(cw, cw[-1]) #if 'C' in dataType: U = parmDict['U'] V = parmDict['V'] W = parmDict['W'] X = parmDict['X'] Y = parmDict['Y'] #shl = max(parmDict['SH/L'],0.002) shl = 0.002 Ka2 = False if 'Lam1' in parmDict.keys(): Ka2 = True lamRatio = 360 * (parmDict['Lam2'] - parmDict['Lam1']) / (np.pi * parmDict['Lam1']) kRatio = parmDict['I(L2)/I(L1)'] iPeak = 0 while True: try: pos = parmDict['pos' + str(iPeak)] theta = (pos - parmDict['Zero']) / 2.0 intens = parmDict['int' + str(iPeak)] sigName = 'sig' + str(iPeak) if sigName in varyList: sig = parmDict[sigName] else: sig = U * tand(theta)**2 + V * tand(theta) + W sig = max(sig, 0.001) #avoid neg sigma gamName = 'gam' + str(iPeak) if gamName in varyList: gam = parmDict[gamName] else: gam = X / cosd(theta) + Y * tand(theta) gam = max(gam, 0.001) #avoid neg gamma Wd, fmin, fmax = gsas.getWidthsCW(pos, sig, gam, shl) iBeg = np.searchsorted(xdata, pos - fmin) iFin = np.searchsorted(xdata, pos + fmin) if not iBeg + iFin: #peak below low limit iPeak += 1 continue elif not iBeg - iFin: #peak above high limit return yb + yc yc[iBeg:iFin] += intens * gsas.getFCJVoigt3( pos, sig, gam, shl, xdata[iBeg:iFin]) if Ka2: pos2 = pos + lamRatio * tand( pos / 2.0) # + 360/pi * Dlam/lam * tan(th) iBeg = np.searchsorted(xdata, pos2 - fmin) iFin = np.searchsorted(xdata, pos2 + fmin) if iBeg - iFin: yc[iBeg:iFin] += intens * kRatio * gsas.getFCJVoigt3( pos2, sig, gam, shl, xdata[iBeg:iFin]) iPeak += 1 except KeyError: #no more peaks to process return yb + yc
def getPeakProfile(parmDict,xdata,varyList,bakType): yb = getBackground('',parmDict,bakType,xdata) yc = np.zeros_like(yb) cw = np.diff(xdata) cw = np.append(cw,cw[-1]) #if 'C' in dataType: U = parmDict['U'] V = parmDict['V'] W = parmDict['W'] X = parmDict['X'] Y = parmDict['Y'] #shl = max(parmDict['SH/L'],0.002) shl=0.002 Ka2 = False if 'Lam1' in parmDict.keys(): Ka2 = True lamRatio = 360*(parmDict['Lam2']-parmDict['Lam1'])/(np.pi*parmDict['Lam1']) kRatio = parmDict['I(L2)/I(L1)'] iPeak = 0 while True: try: pos = parmDict['pos'+str(iPeak)] theta = (pos-parmDict['Zero'])/2.0 intens = parmDict['int'+str(iPeak)] sigName = 'sig'+str(iPeak) if sigName in varyList: sig = parmDict[sigName] else: sig = U*tand(theta)**2+V*tand(theta)+W sig = max(sig,0.001) #avoid neg sigma gamName = 'gam'+str(iPeak) if gamName in varyList: gam = parmDict[gamName] else: gam = X/cosd(theta)+Y*tand(theta) gam = max(gam,0.001) #avoid neg gamma Wd,fmin,fmax = gsas.getWidthsCW(pos,sig,gam,shl) iBeg = np.searchsorted(xdata,pos-fmin) iFin = np.searchsorted(xdata,pos+fmin) if not iBeg+iFin: #peak below low limit iPeak += 1 continue elif not iBeg-iFin: #peak above high limit return yb+yc yc[iBeg:iFin] += intens*gsas.getFCJVoigt3(pos,sig,gam,shl,xdata[iBeg:iFin]) if Ka2: pos2 = pos+lamRatio*tand(pos/2.0) # + 360/pi * Dlam/lam * tan(th) iBeg = np.searchsorted(xdata,pos2-fmin) iFin = np.searchsorted(xdata,pos2+fmin) if iBeg-iFin: yc[iBeg:iFin] += intens*kRatio*gsas.getFCJVoigt3(pos2,sig,gam,shl,xdata[iBeg:iFin]) iPeak += 1 except KeyError: #no more peaks to process return yb+yc
def getPeakProfileDerv(parmDict,xdata,varyList,bakType): # 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 = getBackgroundDerv('',parmDict,bakType,xdata) if 'Back:0' in varyList: #background derivs are in front if present dMdv[0:len(dMdb)] = dMdb cw = np.diff(xdata) cw = np.append(cw,cw[-1]) U = parmDict['U'] V = parmDict['V'] W = parmDict['W'] X = parmDict['X'] Y = parmDict['Y'] # shl = max(parmDict['SH/L'], 0.002) shl=0.002 Ka2 = False iPeak = 0 while True: try: pos = parmDict['pos' + str(iPeak)] theta = (pos - parmDict['Zero']) / 2.0 intens = parmDict['int' + str(iPeak)] sigName = 'sig' + str(iPeak) tanth = tand(theta) costh = cosd(theta) if sigName in varyList: sig = parmDict[sigName] else: sig = U * tanth ** 2 + V * tanth + W dsdU = tanth ** 2 dsdV = tanth dsdW = 1.0 sig = max(sig, 0.001) # avoid neg sigma gamName = 'gam' + str(iPeak) if gamName in varyList: gam = parmDict[gamName] else: gam = X / costh + Y * tanth dgdX = 1.0 / costh dgdY = tanth gam = max(gam, 0.001) # avoid neg gamma Wd, fmin, fmax = gsas.getWidthsCW(pos, sig, gam, shl) iBeg = np.searchsorted(xdata, pos - fmin) iFin = np.searchsorted(xdata, pos + fmin) if not iBeg + iFin: # peak below low limit iPeak += 1 continue elif not iBeg - iFin: # peak above high limit break dMdpk = np.zeros(shape=(6, len(xdata))) dMdipk = gsas.getdFCJVoigt3(pos, sig, gam, shl, xdata[iBeg:iFin]) for i in range(1, 5): dMdpk[i][iBeg:iFin] += 100.*cw[iBeg:iFin] * intens * dMdipk[i] dMdpk[0][iBeg:iFin] += 100.*cw[iBeg:iFin] * dMdipk[0] dervDict = {'int':dMdpk[0], 'pos':dMdpk[1], 'sig':dMdpk[2], 'gam':dMdpk[3], 'shl':dMdpk[4]} for parmName in ['pos', 'int', 'sig', 'gam']: try: idx = varyList.index(parmName + str(iPeak)) dMdv[idx] = dervDict[parmName] except ValueError: pass if 'U' in varyList: dMdv[varyList.index('U')] += dsdU * dervDict['sig'] if 'V' in varyList: dMdv[varyList.index('V')] += dsdV * dervDict['sig'] if 'W' in varyList: dMdv[varyList.index('W')] += dsdW * dervDict['sig'] if 'X' in varyList: dMdv[varyList.index('X')] += dgdX * dervDict['gam'] if 'Y' in varyList: dMdv[varyList.index('Y')] += dgdY * dervDict['gam'] if 'SH/L' in varyList: dMdv[varyList.index('SH/L')] += dervDict['shl'] # problem here if 'I(L2)/I(L1)' in varyList: dMdv[varyList.index('I(L2)/I(L1)')] += dervDict['L1/L2'] iPeak += 1 except KeyError: # no more peaks to process break return dMdv
def getPeakProfileDerv(parmDict, xdata, varyList, bakType): # 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 = getBackgroundDerv('', parmDict, bakType, xdata) if 'Back:0' in varyList: #background derivs are in front if present dMdv[0:len(dMdb)] = dMdb cw = np.diff(xdata) cw = np.append(cw, cw[-1]) U = parmDict['U'] V = parmDict['V'] W = parmDict['W'] X = parmDict['X'] Y = parmDict['Y'] # shl = max(parmDict['SH/L'], 0.002) shl = 0.002 Ka2 = False iPeak = 0 while True: try: pos = parmDict['pos' + str(iPeak)] theta = (pos - parmDict['Zero']) / 2.0 intens = parmDict['int' + str(iPeak)] sigName = 'sig' + str(iPeak) tanth = tand(theta) costh = cosd(theta) if sigName in varyList: sig = parmDict[sigName] else: sig = U * tanth**2 + V * tanth + W dsdU = tanth**2 dsdV = tanth dsdW = 1.0 sig = max(sig, 0.001) # avoid neg sigma gamName = 'gam' + str(iPeak) if gamName in varyList: gam = parmDict[gamName] else: gam = X / costh + Y * tanth dgdX = 1.0 / costh dgdY = tanth gam = max(gam, 0.001) # avoid neg gamma Wd, fmin, fmax = gsas.getWidthsCW(pos, sig, gam, shl) iBeg = np.searchsorted(xdata, pos - fmin) iFin = np.searchsorted(xdata, pos + fmin) if not iBeg + iFin: # peak below low limit iPeak += 1 continue elif not iBeg - iFin: # peak above high limit break dMdpk = np.zeros(shape=(6, len(xdata))) dMdipk = gsas.getdFCJVoigt3(pos, sig, gam, shl, xdata[iBeg:iFin]) for i in range(1, 5): dMdpk[i][ iBeg:iFin] += 100. * cw[iBeg:iFin] * intens * dMdipk[i] dMdpk[0][iBeg:iFin] += 100. * cw[iBeg:iFin] * dMdipk[0] dervDict = { 'int': dMdpk[0], 'pos': dMdpk[1], 'sig': dMdpk[2], 'gam': dMdpk[3], 'shl': dMdpk[4] } for parmName in ['pos', 'int', 'sig', 'gam']: try: idx = varyList.index(parmName + str(iPeak)) dMdv[idx] = dervDict[parmName] except ValueError: pass if 'U' in varyList: dMdv[varyList.index('U')] += dsdU * dervDict['sig'] if 'V' in varyList: dMdv[varyList.index('V')] += dsdV * dervDict['sig'] if 'W' in varyList: dMdv[varyList.index('W')] += dsdW * dervDict['sig'] if 'X' in varyList: dMdv[varyList.index('X')] += dgdX * dervDict['gam'] if 'Y' in varyList: dMdv[varyList.index('Y')] += dgdY * dervDict['gam'] if 'SH/L' in varyList: dMdv[varyList.index('SH/L')] += dervDict['shl'] # problem here if 'I(L2)/I(L1)' in varyList: dMdv[varyList.index('I(L2)/I(L1)')] += dervDict['L1/L2'] iPeak += 1 except KeyError: # no more peaks to process break return dMdv