Exemple #1
0
def findbeamasa(asa,beampos=None,oriidx=None):
    """Finds the beam position of an ASA measurement.
    
    Inputs:
        asa: ASA dictionary (with the fields 'pixels' and 'position') or a list of them.
        beampos: if None (default): a figure is presented for user interaction.
            Otherwise it should be a floating point value, the beam position.
        oriidx: if *asa* is not a list, this is ignored. Otherwise this is the
            index in the list according to which the primary beam position is to
            be determined. Special values are None (determine beam position
            one-by-one), or 'avg' (to determine the beam position one-by-one and
            average them).
    """
    if type(asa)!=type([]) and type(asa)!=type(tuple()):
        asa=[asa]
        oriidx=None
    if beampos is not None: #we already have a beam position, set oriidx to None to skip beam finding.
        oriidx=None
    if type(oriidx)==type(1): #find the peak position acccording to the oriidx-th measurement
        pylab.clf()
        beampos=guitools.findpeak(asa[oriidx]['pixels'],asa[oriidx]['position'],
            prompt='Select the beam area and press ENTER or an empty area to cancel.')
    elif oriidx=='avg': # find all beam positions and average
        bps=np.zeros(len(asa))
        for i in range(len(asa)):
            pylab.clf()
            bps[i]=guitools.findpeak(asa[i]['pixel'],asa[i]['position'],
                prompt='Select the beam area and press ENTER or an empty area to cancel.')
        beampos=bps.mean()
    for a in asa:
        # If we are here, two cases are possible:
        #    1) we already have a beampos value
        #    2) beampos is None and oriidx is None.
        if beampos is not None: #1
            beampos1=beampos 
        else: #2
            pylab.clf()
            beampos1=guitools.findpeak(a['pixels'],a['position'],
                prompt='Select the beam area and press ENTER or an empty area to cancel.')
        a['params']['BeamPos']=beampos1
    return
Exemple #2
0
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
Exemple #3
0
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