Пример #1
0
    def inner(acc, **kwargs):
        """Get counts on a set of channels"""
        local_kwargs = {}
        if "frames" in kwargs:
            local_kwargs["frames"] = kwargs["frames"] + g.get_frames()
        if "uamps" in kwargs:
            local_kwargs["uamps"] = kwargs["uamps"] + g.get_frames()
        g.resume()
        g.waitfor(**local_kwargs)
        g.pause()

        # Ensure that get_spectrum actually returns a value
        spec = None
        while spec is None:
            spec = g.get_spectrum(1, g.get_period())
        base = sum(g.get_spectrum(1, period=g.get_period())["signal"]) * 100.0
        pols = [Average(0, base) for _ in spectra_list]
        for idx, spectra in enumerate(spectra_list):
            for channel in spectra:
                # Ensure that get_spectrum actually returns a value
                spec = None
                while spec is None:
                    spec = g.get_spectrum(channel, g.get_period())
                temp = sum(spec["signal"])
                pols[idx] += Average(temp * 100.0, 0.0)
        if len(pols) == 1:
            return acc, pols[0]
        return acc, MonoidList(pols)
Пример #2
0
    def inner_pol(**kwargs):
        """
        Get a single polarisation measurement
        """
        slices = [
            slice(222, 666),
            slice(222, 370),
            slice(370, 518),
            slice(518, 666)
        ]

        i = g.get_period()

        g.change(period=i + 1)
        flipper1(1)
        g.waitfor_move()
        gfrm = g.get_frames()
        g.resume()
        g.waitfor(frames=gfrm + kwargs["frames"])
        g.pause()

        flipper1(0)
        g.change(period=i + 2)
        gfrm = g.get_frames()
        g.resume()
        g.waitfor(frames=gfrm + kwargs["frames"])
        g.pause()

        pols = [Polarisation.zero() for _ in slices]
        for channel in spectra:
            mon1 = g.get_spectrum(1, i + 1)
            spec1 = g.get_spectrum(channel, i + 1)
            mon2 = g.get_spectrum(1, i + 2)
            spec2 = g.get_spectrum(channel, i + 2)
            for idx, slc in enumerate(slices):
                ups = Average(
                    np.sum(spec1["signal"][slc]) * 100.0,
                    np.sum(mon1["signal"]) * 100.0)
                down = Average(
                    np.sum(spec2["signal"][slc]) * 100.0,
                    np.sum(mon2["signal"]) * 100.0)
                pols[idx] += Polarisation(ups, down)
        return MonoidList(pols)
Пример #3
0
def scan_axis(axis,startval,endval,npoints,frms,rtitle,usem4=0):
    lm.setuplarmor_nrscanning()

    gen.change(title=rtitle)
    gen.change(nperiods=npoints)
    
    gen.begin(paused=1)
    # setup the scan arrays and figure
    xval=np.zeros(npoints)
    yval=np.zeros(npoints)
    eval=np.zeros(npoints)

    stepsize=(endval-startval)/float(npoints-1)
    for i in range(npoints):
        xval[i]=(startval+i*stepsize)

    mpl.ion()
    fig1=mpl.figure(1)
    mpl.clf()
    ax = mpl.subplot(111)
    #ax.set_xlim((0,4))
    ax.set_xlabel(axis)
    ax.set_ylabel('Normalised Neutron counts')
    # reasonable x-Axis, necessary to get the full window from the first datapoint
    scanrange = np.absolute(endval - startval)
    mpl.xlim((startval-scanrange*0.05, endval+scanrange*0.05))
    mpl.draw()
    mpl.pause(0.001)
    
    for i in range(npoints):
        gen.change(period=i+1)
        cset_str(axis,xval[i])
        gen.waitfor(seconds=1)
        gen.waitfor_move()
        gfrm=gen.get_frames()
        gen.resume()
        gen.waitfor(frames=gfrm+frms)
        gen.pause()
        a1=gen.get_spectrum(1,i+1)
        msig=sum(a1['signal'])*100.0
        mesig=(math.sqrt(msig))
        print "msig="+str(msig)+" mesig="+str(mesig)
        # get the interesting monitor
        if usem4 < 1:
            a1=gen.get_spectrum(11,i+1)
            sig=sum(a1['signal'])*100.0
            a1=gen.get_spectrum(12,i+1)
            sig+=sum(a1['signal'])*100.0
            esig=math.sqrt(sig)
        else:
            a1=gen.get_spectrum(4,i+1)
            sig=sum(a1['signal'])*100.0
            esig=math.sqrt(sig)
        print "sig="+str(sig)+" esig="+str(esig)
        yval[i]=(sig/msig)
        eval[i]=(math.sqrt((sig/(msig*msig))+(sig*sig/(msig*msig*msig))))
        print "yval="+str(yval[i])+" esig="+str(eval[i])
        ax.errorbar(xval[i], yval[i], eval[i], fmt = 'ko')
        fig1.canvas.draw()
        mpl.pause(0.001)
        f.open('u:/users/Larmor/lastscan.csv','w')
        s=str(xval[i])+','+str(yval[i])+','+str(eval[i])+'\n'
        f.write(s)
        f.close()
    gen.abort()
    #f.open('u:/users/Larmor/lastscan.csv','w')
    #for i in range(npoints):
    #    s=str(xval[i])+','+str(yval[i])+','+str(eval[i])+'\n'
    #    f.write(s)
    #f.close()
    '''
Пример #4
0
def scan_axis_mantid(axis,startval,endval,npoints,frms,rtitle,usem4=0):
    lm.setuplarmor_nrscanning()

    gen.change(title=rtitle)
    gen.change(nperiods=npoints)
    
    gen.begin(paused=1)
    # setup the scan arrays and figure
    xval=np.zeros(npoints)
    yval=np.zeros(npoints)
    eval=np.zeros(npoints)

    stepsize=(endval-startval)/float(npoints-1)
    for i in range(npoints):
        xval[i]=(startval+i*stepsize)

    gui_cmd(mpl.ion)
    fig1=gui_cmd(mpl.figure,1)
    gui_cmd(mpl.clf)
    ax=gui_cmd(mpl.subplot,111)
    #ax.set_xlim((0,4))
    gui_cmd(ax.set_xlabel,axis)
    gui_cmd(ax.set_ylabel,'Normalised Neutron counts')
    # reasonable x-Axis, necessary to get the full window from the first datapoint
    scanrange = np.absolute(endval - startval)
    gui_cmd(mpl.xlim,(startval-scanrange*0.05, endval+scanrange*0.05))
    gui_cmd(mpl.draw)
    gui_cmd(mpl.pause,0.001)
    
    for i in range(npoints):
        gen.change(period=i+1)
        cset_str(axis,xval[i])
        sleep(15)
        #gen.waitfor_move()
        
        gfrm=gen.get_frames()
        gen.resume()
        gen.waitfor(frames=gfrm+frms)
        gen.pause()
        a1=gen.get_spectrum(1,i+1)
        msig=sum(a1['signal'])*100.0
        mesig=(math.sqrt(msig))
        print "msig="+str(msig)+" mesig="+str(mesig)
        # get the interesting monitor
        if usem4 < 1:
            a1=gen.get_spectrum(11,i+1)
            sig=sum(a1['signal'])*100.0
            a1=gen.get_spectrum(12,i+1)
            sig+=sum(a1['signal'])*100.0
            esig=math.sqrt(sig)
        else:
            a1=gen.get_spectrum(4,i+1)
            sig=sum(a1['signal'])*100.0
            esig=math.sqrt(sig)
        print "sig="+str(sig)+" esig="+str(esig)
        yval[i]=(sig/msig)
        eval[i]=(math.sqrt((sig/(msig*msig))+(sig*sig/(msig*msig*msig))))
        print "yval="+str(yval[i])+" esig="+str(eval[i])
        gui_cmd(ax.errorbar,xval[i], yval[i], eval[i], fmt = 'ko')
        gui_cmd(fig1.canvas.draw)
        gui_cmd(mpl.pause,0.001)
    
    gen.abort()
Пример #5
0
def scan_axis(axis, startval, endval, npoints, frms, rtitle, usem4=0):
    lm.setuplarmor_nrscanning()

    gen.change(title=rtitle)
    gen.change(nperiods=npoints)

    gen.begin(paused=1)
    # setup the scan arrays and figure
    xval = np.zeros(npoints)
    yval = np.zeros(npoints)
    eval = np.zeros(npoints)

    stepsize = (endval - startval) / float(npoints - 1)
    for i in range(npoints):
        xval[i] = (startval + i * stepsize)

    mpl.ion()
    fig1 = mpl.figure(1)
    mpl.clf()
    ax = mpl.subplot(111)
    #ax.set_xlim((0,4))
    ax.set_xlabel(axis)
    ax.set_ylabel('Normalised Neutron counts')
    # reasonable x-Axis, necessary to get the full window from the first datapoint
    scanrange = np.absolute(endval - startval)
    mpl.xlim((startval - scanrange * 0.05, endval + scanrange * 0.05))
    mpl.draw()
    mpl.pause(0.001)

    for i in range(npoints):
        gen.change(period=i + 1)
        cset_str(axis, xval[i])
        gen.waitfor(seconds=1)
        gen.waitfor_move()
        gfrm = gen.get_frames()
        gen.resume()
        gen.waitfor(frames=gfrm + frms)
        gen.pause()
        a1 = gen.get_spectrum(1, i + 1)
        msig = sum(a1['signal']) * 100.0
        mesig = (math.sqrt(msig))
        print "msig=" + str(msig) + " mesig=" + str(mesig)
        # get the interesting monitor
        if usem4 < 1:
            a1 = gen.get_spectrum(11, i + 1)
            sig = sum(a1['signal']) * 100.0
            a1 = gen.get_spectrum(12, i + 1)
            sig += sum(a1['signal']) * 100.0
            esig = math.sqrt(sig)
        else:
            a1 = gen.get_spectrum(4, i + 1)
            sig = sum(a1['signal']) * 100.0
            esig = math.sqrt(sig)
        print "sig=" + str(sig) + " esig=" + str(esig)
        yval[i] = (sig / msig)
        eval[i] = (math.sqrt((sig / (msig * msig)) + (sig * sig /
                                                      (msig * msig * msig))))
        print "yval=" + str(yval[i]) + " esig=" + str(eval[i])
        ax.errorbar(xval[i], yval[i], eval[i], fmt='ko')
        fig1.canvas.draw()
        mpl.pause(0.001)
        f.open('u:/users/Larmor/lastscan.csv', 'w')
        s = str(xval[i]) + ',' + str(yval[i]) + ',' + str(eval[i]) + '\n'
        f.write(s)
        f.close()
    gen.abort()
    #f.open('u:/users/Larmor/lastscan.csv','w')
    #for i in range(npoints):
    #    s=str(xval[i])+','+str(yval[i])+','+str(eval[i])+'\n'
    #    f.write(s)
    #f.close()
    '''
Пример #6
0
def scan_axis_mantid(axis, startval, endval, npoints, frms, rtitle, usem4=0):
    lm.setuplarmor_nrscanning()

    gen.change(title=rtitle)
    gen.change(nperiods=npoints)

    gen.begin(paused=1)
    # setup the scan arrays and figure
    xval = np.zeros(npoints)
    yval = np.zeros(npoints)
    eval = np.zeros(npoints)

    stepsize = (endval - startval) / float(npoints - 1)
    for i in range(npoints):
        xval[i] = (startval + i * stepsize)

    gui_cmd(mpl.ion)
    fig1 = gui_cmd(mpl.figure, 1)
    gui_cmd(mpl.clf)
    ax = gui_cmd(mpl.subplot, 111)
    #ax.set_xlim((0,4))
    gui_cmd(ax.set_xlabel, axis)
    gui_cmd(ax.set_ylabel, 'Normalised Neutron counts')
    # reasonable x-Axis, necessary to get the full window from the first datapoint
    scanrange = np.absolute(endval - startval)
    gui_cmd(mpl.xlim, (startval - scanrange * 0.05, endval + scanrange * 0.05))
    gui_cmd(mpl.draw)
    gui_cmd(mpl.pause, 0.001)

    for i in range(npoints):
        gen.change(period=i + 1)
        cset_str(axis, xval[i])
        sleep(15)
        #gen.waitfor_move()

        gfrm = gen.get_frames()
        gen.resume()
        gen.waitfor(frames=gfrm + frms)
        gen.pause()
        a1 = gen.get_spectrum(1, i + 1)
        msig = sum(a1['signal']) * 100.0
        mesig = (math.sqrt(msig))
        print "msig=" + str(msig) + " mesig=" + str(mesig)
        # get the interesting monitor
        if usem4 < 1:
            a1 = gen.get_spectrum(11, i + 1)
            sig = sum(a1['signal']) * 100.0
            a1 = gen.get_spectrum(12, i + 1)
            sig += sum(a1['signal']) * 100.0
            esig = math.sqrt(sig)
        else:
            a1 = gen.get_spectrum(4, i + 1)
            sig = sum(a1['signal']) * 100.0
            esig = math.sqrt(sig)
        print "sig=" + str(sig) + " esig=" + str(esig)
        yval[i] = (sig / msig)
        eval[i] = (math.sqrt((sig / (msig * msig)) + (sig * sig /
                                                      (msig * msig * msig))))
        print "yval=" + str(yval[i]) + " esig=" + str(eval[i])
        gui_cmd(ax.errorbar, xval[i], yval[i], eval[i], fmt='ko')
        gui_cmd(fig1.canvas.draw)
        gui_cmd(mpl.pause, 0.001)

    gen.abort()