def agstcalib(xdata,ydata,peaks,peakmode='Lorentz',wavelength=1.54,d=48.68,returnq=True): """Find q-range from AgSt (or AgBeh) measurements. Inputs: xdata: vector of abscissa values (typically pixel numbers) ydata: vector of scattering data (counts) peaks: list of the orders of peaks (ie. [1,2,3]) peakmode: what type of function should be fitted on the peak. Possible values: 'Lorentz' and 'Gauss' wavelength: wavelength of the X-ray radiation. Default is Cu Kalpha, 1.54 Angstroems d: the periodicity of the sample (default: 48.68 A for silver stearate) returnq: returns only the q-range if True. If False, returns the pixelsize/dist and beamcenter values Output: If returnq is true then the q-scale in a vector which is of the same size as xdata. If returnq is false, then a,b,aerr,berr where a is pixelsize/dist, b is the beam center coordinate in pixels and aerr and berr are their errors, respectively Notes: A graphical window will be popped up len(peaks)-times, each prompting the user to zoom on the n-th peak. After the last peak was selected, the function returns. """ pcoord=[] for p in peaks: tmp=guitools.findpeak(xdata,ydata,('Zoom to peak %d and press ENTER' % p),peakmode,scaling='log') pcoord.append(tmp) pcoord=np.array(pcoord) n=np.array(peaks) a=(n*wavelength)/(2*d) x=2*a*np.sqrt(1-a**2)/(1-2*a**2) LperH,xcent,LperHerr,xcenterr=fitting.linfit(x,pcoord) print 'pixelsize/dist:',1/LperH,'+/-',LperHerr/LperH**2 print 'beam position:',xcent,'+/-',xcenterr if returnq: return calcqrangefrom1D(xdata,xcent,LperH,1,wavelength) else: return 1/LperH,xcent,LperHerr/LperH**2,xcenterr
def tripcalib(xdata,ydata,peakmode='Lorentz',wavelength=1.54,qvals=2*np.pi*np.array([0.21739,0.25641,0.27027]),returnq=True): """Find q-range from Tripalmitine measurements. Inputs: xdata: vector of abscissa values (typically pixel numbers) ydata: vector of scattering data (counts) peakmode: what type of function should be fitted on the peak. Possible values: 'Lorentz' and 'Gauss' wavelength: wavelength of the X-ray radiation. Default is Cu Kalpha, 1.54 Angstroems qvals: a list of q-values corresponding to peaks. The default values are for Tripalmitine returnq: True if the q-range is to be returned. False if the fit parameters are requested instead of the q-range Output: The q-scale in a vector which is of the same size as xdata, if returnq was True. Otherwise a,b,aerr,berr where q=a*x+b and x is the pixel number Notes: A graphical window will be popped up len(qvals)-times, each prompting the user to zoom on the n-th peak. After the last peak was selected, the q-range will be returned. """ pcoord=[] peaks=range(len(qvals)) for p in peaks: tmp=guitools.findpeak(xdata,ydata, ('Zoom to peak %d (q = %f) and press ENTER' % (p,qvals[p])), peakmode,scaling='lin') pcoord.append(tmp) pcoord=np.array(pcoord) a,b,aerr,berr=fitting.linfit(pcoord,qvals) if returnq: return a*xdata+b else: return a,b,aerr,berr