Пример #1
0
def genEtmpByE(filename,
               Estart=8.0,
               Eend=9.0,
               harmonicVal=3,
               cgap=4.0,
               numpt=51,
               filedir='/nfs/xf05id1/energyScanConfig/'):
    '''
    provide the start & end positions for energy
    file will be saved to the indicated file directory and file name
    '''

    print(filedir)
    out = open(filedir + filename + '.text', 'w')

    Bstart, C2X, Ustart = SRXenergy.EtoAll(Estart, harmonic=harmonicVal)
    Bend, C2X, Uend = SRXenergy.EtoAll(Eend, harmonic=harmonicVal)

    Ugap = numpy.linspace(Ustart, Uend, num=numpt)
    Bragg = numpy.linspace(Bstart, Bend, num=numpt)
    for i in xrange(0, numpt):
        #        str="%(a)6.4f %(b)6.3f %(c)6.3f\n"%{"a":Bragg[i], "b":Ugap[i], "c":cgap}
        str = "%(a)6.4f %(b)6.4f %(c)6.3f\n" % {
            "a": Bragg[i],
            "b": Ugap[i],
            "c": cgap
        }

        out.write(str)
    out.close()
Пример #2
0
def genEbyEwC2X(filename,
                Estart=8.0,
                Eend=9.0,
                harmonicVal=3,
                XoffsetVal=25.2709,
                Estep=.001,
                numEpts=None,
                display=False,
                filedir='/nfs/xf05id1/energyScanConfig/'):
    '''
    provide the start & end positions for energy in keV, correct c2x for each step using values calculated by SRXenergy.EtoAll
    user can specify either Estep or numEpts; if numEpts is specified, Estep will be ignored; if numEpts is not specified, Estep will be used (default = 1 eV)
    when display is True, bragg, ugap and c2x values will be printed for each energy point; default = False
    filename needs to be string type
    file will be saved to the indicated file directory and file name
    '''

    print(filedir)
    out = open(filedir + filename + '.text', 'w')

    print('start E:')
    Bstart, C2X, Ustart = SRXenergy.EtoAll(Estart,
                                           harmonic=harmonicVal,
                                           Xoffset=XoffsetVal)
    print('end E:')
    Bend, C2X, Uend = SRXenergy.EtoAll(Eend,
                                       harmonic=harmonicVal,
                                       Xoffset=XoffsetVal)

    #    Ugap=numpy.linspace(Ustart, Uend,num=numpt)
    #    Bragg=numpy.linspace(Bstart, Bend, num=numpt)

    if numEpts == None:
        nume = int((Eend - Estart) / Estep + 1)  #number of energy points
    else:
        nume = numEpts
    print(nume)
    pt = 1
    elist = []
    for e in numpy.linspace(Estart, Eend, num=nume):
        elist.append(e)
        if display:
            print('Energy point number:', pt)
        braggtar, c2xtar, ugaptar = SRXenergy.EtoAll(e,
                                                     harmonic=harmonicVal,
                                                     Xoffset=XoffsetVal,
                                                     show=display)
        #        str="%(a)6.4f %(b)6.3f %(c)6.3f\n"%{"a":Bragg[i], "b":Ugap[i], "c":cgap}
        str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
            "bragg": braggtar,
            "ugap": ugaptar,
            "c2x": c2xtar
        }
        out.write(str)
        pt = pt + 1
    print('energy points:', elist)
    print('total energy number of point:', nume)
    print('energy step size:', (elist[1] - elist[0]) * 1000, 'eV; ',
          (elist[1] - elist[0]), 'keV')
    out.close()
Пример #3
0
def xrfxanescheck(x3dir=srxdatadir.dfx3filedir, fileprefix=None, roil=0, roih=4095, filenum=0, ptlist=[0, -1]):
   
    x=range(0,4096)
    x3file = h5py.File(x3dir+fileprefix+'_'+str(filenum)+'.hdf5', 'r')      
    mcadata = x3file['/entry/instrument/detector/data']
    bragg = x3file['/entry/instrument/NDAttributes/BraggAngle']
        
    fileshape=mcadata.shape
    print(fileshape)
    
    #ch1mcapt = numpy.sum(numpy.array(mcadata[:,:,0,:]), axis=0)
    #ch2mcapt = numpy.sum(numpy.array(mcadata[:,:,1,:]), axis=0)
    #ch3mcapt = numpy.sum(numpy.array(mcadata[:,:,2,:]), axis=0)
    
    allchmca = numpy.sum(numpy.array(mcadata), axis=2) #sum three different elements,  1 axis   
    
    for pt in ptlist:       
        ptallchmca=allchmca[pt,:,:]   
        ptallchmca=numpy.squeeze(ptallchmca)                                                  
        p=plt.plot(x[roil:roih],ptallchmca[roil:roih], label=str(SRXenergy.BraggtoE(bragg[pt])))
 
    plt.xlabel('channel number')    

    plt.ylabel('fluorescence signal - sum of 3 channels roi (a.u.)')
    plt.legend(loc=1)
    plt.show(p)
Пример #4
0
def genEtmpByErange(filename,
                    E0=8.0,
                    E1=8.1,
                    E2=8.2,
                    E3=8.3,
                    harmonicVal=3,
                    cgap=4.0,
                    numpt1=51,
                    numpt2=10,
                    numpt3=50,
                    filedir='/nfs/xf05id1/energyScanConfig/'):
    '''
    provide the start & end positions for energy
    four different energy ranges, set different number of points
    E0-E1:numpt1, E1-E2:numpt2, E2-E3:numpt3, 
    file will be saved to the indicated file directory and file name
    '''

    print(filedir)
    out = open(filedir + filename + '.text', 'w')

    #first range
    Bstart, C2X, Ustart = SRXenergy.EtoAll(E0, harmonic=harmonicVal)
    Bend, C2X, Uend = SRXenergy.EtoAll(E1, harmonic=harmonicVal)

    Ugap = numpy.linspace(Ustart, Uend, num=numpt1)
    Bragg = numpy.linspace(Bstart, Bend, num=numpt1)
    for i in xrange(0, numpt1):
        str = "%(a)6.4f %(b)6.4f %(c)6.3f\n" % {
            "a": Bragg[i],
            "b": Ugap[i],
            "c": cgap
        }
        out.write(str)

    #second range
    Bstart, C2X, Ustart = SRXenergy.EtoAll(E1, harmonic=harmonicVal)
    Bend, C2X, Uend = SRXenergy.EtoAll(E2, harmonic=harmonicVal)

    Ugap = numpy.linspace(Ustart, Uend, num=numpt2)
    Bragg = numpy.linspace(Bstart, Bend, num=numpt2)
    for i in xrange(1, numpt2):
        str = "%(a)6.4f %(b)6.4f %(c)6.3f\n" % {
            "a": Bragg[i],
            "b": Ugap[i],
            "c": cgap
        }
        out.write(str)

    #third range
    Bstart, C2X, Ustart = SRXenergy.EtoAll(E2, harmonic=harmonicVal)
    Bend, C2X, Uend = SRXenergy.EtoAll(E3, harmonic=harmonicVal)

    Ugap = numpy.linspace(Ustart, Uend, num=numpt3)
    Bragg = numpy.linspace(Bstart, Bend, num=numpt3)
    for i in xrange(1, numpt3):
        str = "%(a)6.4f %(b)6.4f %(c)6.3f\n" % {
            "a": Bragg[i],
            "b": Ugap[i],
            "c": cgap
        }
        out.write(str)

    out.close()


#def getE

#def getBragg( )
Пример #5
0
    #use for bpm option    
    foilDic={'Cu':25.0, 'Se': 0.0, 'Fe':25.0, 'Ti':25}
    
    centroidX={}
    centroidY={}
    
    theoryBragg=[]
    dx=[]
    dy=[]

    
    C2Xval=caget('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.VAL')
    C1Rval=caget('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.VAL')
    
    
    dBragg=SRXenergy.whdBragg()
    
    for element in elementList:
        centroidXSample=[]
        centroidYSample=[]

        print element
        E=energyDic[element]
        print 'Edge:', E
          
        BraggRBV, C2X, ugap=SRXenergy.EtoAll(E)
        SRXpmenergy.move(E, XoffsetIN=26.0)
 
        if usecamera == True:
            caput(expotimePV, expotime[element]) 
            while ctmax.get() <= 200:
    #expotime={'Cu':0.1, 'Fe':0.2, 'Se':0.2, 'Cr': 0.3}  #150 mA, 20151007, end-station

    #use for bpm option
    foilDic = {'Cu': 25.0, 'Se': 0.0, 'Fe': 25.0, 'Ti': 25}

    centroidX = {}
    centroidY = {}

    theoryBragg = []
    dx = []
    dy = []

    C2Xval = caget('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.VAL')
    C1Rval = caget('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.VAL')

    dBragg = SRXenergy.whdBragg()

    for element in elementList:
        centroidXSample = []
        centroidYSample = []

        print element
        E = energyDic[element]
        print 'Edge:', E

        BraggRBV, C2X, ugap = SRXenergy.EtoAll(E,
                                               harmonic=harmonicDic[element])

        #print BraggRBV
        #print ugap
        #print C2X, '\n'
Пример #7
0
def moveE(Energy,
          harmonicIN=3,
          c2xIN=None,
          c1rIN=None,
          simulate=True,
          XoffsetIn=None):

    braggVAL = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.VAL')
    braggRBV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.RBV')

    c1rVAL = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.VAL')
    c1rRBV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.RBV')

    c2xVAL = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.VAL')
    c2xRBV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.RBV')

    ugapVAL = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Inp:Pos')
    ugapRBV = PV('SR:C5-ID:G1{IVU21:1-LEnc}Gap')
    ugapGO = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Sw:Go')

    xoffsetflag = False

    #    braggRBV.add_callback(cbfbragg)
    #    print('here1')
    #    braggRBV.run_callbacks()
    #    print('here2')
    #
    #    c1rRBV.add_callback(cbfc1r)
    #    c1rRBV.run_callbacks()
    #
    #    c2xRBV.add_callback(cbfc2x)
    #    c2xRBV.run_callbacks()
    #
    #    ugapRBV.add_callback(cbfugap)
    #    ugapRBV.run_callbacks()

    #setup the traget positions for all motors
    if XoffsetIn == None:
        braggTAR, c2x, ugapTAR = SRXenergy.EtoAll(Energy,
                                                  harmonic=harmonicIN,
                                                  show=False)
    else:
        xoffsetflag = True
        braggTAR, c2x, ugapTAR = SRXenergy.EtoAll(Energy,
                                                  harmonic=harmonicIN,
                                                  show=False,
                                                  Xoffset=XoffsetIn)

#if user doesn't specify c2x and c1r, use the current values

    if c1rIN == None:
        c1rTAR = c1rRBV.get()
    elif c1rIN == 'linear':
        c1rTAR = c1ri + (Energy - Ei) / (Ef - Ei) * (c1rf - c1ri)
    else:
        c1rTAR = c1rIN

    ###need to move this section
    if xoffsetflag == True:
        print('here2!')
        c2xTAR = c2x
    elif c2xIN == None:
        c2xTAR = c2xRBV.get()
    elif c1rIN == 'linear':
        c1rTAR = c2xi + (Energy - Ei) / (Ef - Ei) * (c2xf - c2xi)
    else:
        c2xTAR = c2xIN

    #moving the motors
    print('current positions:')
    print(' Energy:', str(SRXenergy.BraggtoE(braggRBV.get(), show=False)),
          'keV')
    print(' HDCM Bragg:', str(braggRBV.get()))
    print(' undulator gap:', str(ugapRBV.get()))
    print(' HDCM 1st crystal roll:', str(c1rRBV.get()))
    print(' HDCM 2nd crystal gap:', str(c2xRBV.get()))

    print('moving the motors to:')
    print(' Energy:', str(Energy))
    print(' HDCM Bragg:', str(braggTAR))
    print(' undulator gap:', str(ugapTAR))
    print(' HDCM 1st crystal roll:', str(c1rTAR))
    print(' HDCM 2nd crystal gap:', str(c2xTAR))

    if simulate == False:

        c1rVAL.put(c1rTAR, wait=True)
        c2xVAL.put(c2xTAR, wait=True)
        braggVAL.put(braggTAR, wait=True)

        ugapVAL.put(ugapTAR, wait=True)
        ugapGO.put(0)
        time.sleep(5)

        print('done moving the motors, current positions:')
        print(' Energy:', str(SRXenergy.BraggtoE(braggRBV.get(), show=False)),
              'keV')
        print(' HDCM Bragg:', str(braggRBV.get()))
        print(' undulator gap:', str(ugapRBV.get()))
        print(' HDCM 1st crystal roll:', str(c1rRBV.get()))
        print(' HDCM 2nd crystal gap:', str(c2xRBV.get()))

    else:
        print('simulating, not moving the motors.')
Пример #8
0
def move(Energy,
         harmonicIN=None,
         XoffsetIN=SRXenergy.XoffsetCurrent,
         c2xIN=None,
         c1rIN=None,
         simulate=False,
         show=True):
    '''
    user input energy, move undulator gap, c1x and HDCM bragg
    Note:
        The default is choosing the highest harmonic and adjust c2x using the default Xoffset (taken from SRXenergy.XoffsetCurrent).
        It'd give error message if the energy is out of our range.
        It checks if the c1r, c2x and bragg are done moving, and if the u-gap break is on.    
    
    input:
        Energy: user defined energy as the target, in a unit of keV
        
    key words:
        harmonicIN: default is 'None'. program will choose the highest harmonic achievable for that energy range (recommended)
                    user can provide an alternative harmonic value if desired.
        XoffsetIN: default is taken from SRXenergy.XoffsetCurrent. This will determined the c2x target when moving energy (recommended). 
                   user can provide a user-defined value
        c2xIN: defualt is None. If user specify a value for c2xIN, this value will be used as a fixed c2x value, and XoffsetIN will be ignored.  
               if c2xIN == None and XoffsetIN == None, current c2x value will be used.
        c1rIN: default is None. If user doesn't specify c1r, use current c1r value (recommended)
        simulate: deault is False, meaning that the motors will move. If it is set to False, the motors will not move and users can check the calculation.       
    
    '''

    #dbd_bragg=0.001
    #dbd_c1r=0.001
    #dbd_c2x=0.001
    dbd_ugap = 0.001

    Energy = float(Energy)

    braggVAL = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.VAL')
    braggRBV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.RBV')
    braggMOV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.MOVN')

    c1rVAL = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.VAL')
    c1rRBV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.RBV')
    c1rMOV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:R1}Mtr.MOVN')

    c2xVAL = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.VAL')
    c2xRBV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.RBV')
    c2xMOV = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.MOVN')

    ugapVAL = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Inp:Pos')
    ugapRBV = PV('SR:C5-ID:G1{IVU21:1-LEnc}Gap')
    ugapGO = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Sw:Go')
    ugapbrkON = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Rb:Brk')

    #xoffsetflag = False

    #    braggRBV.add_callback(cbfbragg)
    #    print('here1')
    #    braggRBV.run_callbacks()
    #    print('here2')
    #
    #    c1rRBV.add_callback(cbfc1r)
    #    c1rRBV.run_callbacks()
    #
    #    c2xRBV.add_callback(cbfc2x)
    #    c2xRBV.run_callbacks()
    #
    #    ugapRBV.add_callback(cbfugap)
    #    ugapRBV.run_callbacks()

    #calculate the right harmonic for undulator gap
    harmonictest = 3
    if harmonicIN == None:
        #choose the right harmonic
        braggcal, c2xcal, ugapcal = SRXenergy.EtoAll(Energy,
                                                     harmonic=harmonictest,
                                                     show=False)
        if ugapcal <= 6.4:
            print(
                'The energy you entered is too low. Minimum energy = 4.4 keV')
            sys.exit()
        while ugapcal >= 6.4:
            harmonictest = harmonictest + 2
            #print(harmonictest)
            braggcal, c2xcal, ugapcal = SRXenergy.EtoAll(Energy,
                                                         harmonic=harmonictest,
                                                         show=False)
            #print(ugapcal)
        harmonicIN = harmonictest - 2
        if harmonicIN > 17:
            print(
                'The energy you entered is too high. Maximum energy = 25.0 keV'
            )
            sys.exit()
        print('using harmonic: ' + str(harmonicIN))

    #setup the traget positions for all motors
    if XoffsetIN == None:
        braggTAR, c2x, ugapTAR = SRXenergy.EtoAll(Energy,
                                                  harmonic=harmonicIN,
                                                  show=False)
    else:
        braggTAR, c2x, ugapTAR = SRXenergy.EtoAll(Energy,
                                                  harmonic=harmonicIN,
                                                  show=False,
                                                  Xoffset=XoffsetIN)

#if user doesn't specify c1r, use current c1r value
    if c1rIN == None:
        c1rTAR = c1rRBV.get()
#    elif c1rIN == 'linear':
#        c1rTAR=c1ri+(Energy-Ei)/(Ef-Ei)*(c1rf-c1ri)
    else:
        c1rTAR = c1rIN

    if c2xIN != None:
        c2xTAR = c2xIN
    elif XoffsetIN != None:
        c2xTAR = c2x
    else:
        print('Both XoffsetIN and c2xIN are "None". use current c2x value.')
        c2xTAR = c2xRBV.get()

    #moving the motors
    if show == True:
        print('current positions:')
        print(' Energy:', str(SRXenergy.BraggtoE(braggRBV.get(), show=False)),
              'keV')
        print(' HDCM Bragg:', str(braggRBV.get()))
        print(' undulator gap:', str(ugapRBV.get()))
        print(' HDCM 1st crystal roll:', str(c1rRBV.get()))
        print(' HDCM 2nd crystal gap:', str(c2xRBV.get()))

        print('moving the motors to:')
        print(' Energy:', str(Energy))
        print(' HDCM Bragg:', str(braggTAR))
        print(' undulator gap:', str(ugapTAR))
        print(' HDCM 1st crystal roll:', str(c1rTAR))
        print(' HDCM 2nd crystal gap:', str(c2xTAR))

    if simulate == False:

        c1rVAL.put(c1rTAR, wait=True)
        c2xVAL.put(c2xTAR, wait=True)
        ugapVAL.put(ugapTAR, wait=True)
        ugapGO.put(0)
        braggVAL.put(braggTAR, wait=True)
        time.sleep(1)

        #while (c1rRBV.get()-c1rVAL.get()) > dbd_c1r:
        if c1rMOV.get() == 1:
            print('waiting for c1r.')
        while c1rMOV.get() == 1:
            time.sleep(1)
        print('c1r in place')

        #while (c2xRBV.get()-c2xVAL.get()) > dbd_c2x:
        if c2xMOV.get() == 1:
            print('waiting for c2x.')
        while c2xMOV.get() == 1:
            time.sleep(1)
        print('c2x in place')

        #while (braggRBV.get()-braggVAL.get()) > dbd_bragg:
        if braggMOV.get() == 1:
            print('waiting for bragg.')
        while braggMOV.get() == 1:
            time.sleep(1)
        print('bragg in place')

        #while (ugapVAL.get()-ugapRBV.get()) > dbd_ugap:
        if ugapbrkON.get() == 0:
            print('waiting for ugap.')
        while ugapbrkON.get() == 0:
            time.sleep(1)
        if ugapRBV.get() - ugapVAL.get() <= dbd_ugap:
            print('ugap in place')
        else:
            print(
                'ugap position cannot be reached. Possible taper error. Check to see if ugap Correction Function is disabled'
            )

        print('done moving the motors, current positions:')
        print(' Energy:', str(SRXenergy.BraggtoE(braggRBV.get(), show=False)),
              'keV')
        print(' HDCM Bragg:', str(braggRBV.get()))
        print(' undulator gap:', str(ugapRBV.get()))
        print(' HDCM 1st crystal roll:', str(c1rRBV.get()))
        print(' HDCM 2nd crystal gap:', str(c2xRBV.get()))

    else:
        if show == True:
            print('simulating, not moving the motors.')
        return harmonicIN
Пример #9
0
def genE(
        filename='econfigtest',
        Estart=8.0,
        Eend=9.0,
        harmonicVal=None,
        XoffsetVal=SRXenergy.XoffsetCurrent,
        Estep=.001,
        numEpts=None,
        display=False,
        showelist=False,
        correctC2X=True,
        c2xfix=None,
        nosave=False,
        detuneugap=None,  #future capability
        filedir='/nfs/xf05id1/energyScanConfig/'):
    '''
    previously called: genEbyEwC2X
    provide the start & end positions for energy in keV, correct c2x for each step using values calculated by SRXenergy.EtoAll
    user can specify either Estep or numEpts; if numEpts is specified, Estep will be ignored; if numEpts is not specified, Estep will be used (default = 1 eV)
    when display is True, bragg, ugap and c2x values will be printed for each energy point; default = False
    filename needs to be string type
    file will be saved to the indicated file directory and file name
    
    updated:
        default harmonic will be calculated automatically based on the input energy range
        it'll use the maximum harmonic (smallest u-gap) possible.
        user can still define harmonic if desired.    
    
    [example]
    import escript
    edge=13.035    
    escript.genE(filename='20151024test3', Estart=edge-0.5, Eend=edge+0.5, harmonicVal=7, numEpts=20)
    #OR
    escript.genE(filename='20151024test3', Estart=edge-0.5, Eend=edge+0.5, harmonicVal=7, Estep=0.01)
    '''

    if harmonicVal == None:
        harmonicVal = SRXpmenergy.move(Eend, simulate=True, show=False)

    if nosave == False:
        out = open(filedir + filename + '.text', 'w')

    print('start E:')
    Bstart, C2X, Ustart = SRXenergy.EtoAll(Estart,
                                           harmonic=harmonicVal,
                                           Xoffset=XoffsetVal)
    print('end E:')
    Bend, C2X, Uend = SRXenergy.EtoAll(Eend,
                                       harmonic=harmonicVal,
                                       Xoffset=XoffsetVal)

    if numEpts == None:
        nume = int(round((Eend - Estart) / Estep +
                         1))  #number of energy points
    else:
        nume = numEpts
    #print(nume)
    pt = 0
    elist = []
    estep = []
    c2xnow = c2xRBV.get()

    for e in numpy.linspace(Estart, Eend, num=nume):
        pt = pt + 1
        elist.append(e)
        if display:
            print('Energy point number:', pt)
        braggtar, c2xtar, ugaptar = SRXenergy.EtoAll(e,
                                                     harmonic=harmonicVal,
                                                     Xoffset=XoffsetVal,
                                                     show=display)

        if correctC2X == True:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xtar
            }
        elif c2xfix == None:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xnow
            }
        else:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xfix
            }
        if pt >= 2:
            estep.append(elist[pt - 1] - elist[pt - 2])

        if nosave == False:
            out.write(str)
    est = numpy.average(numpy.array(estep))

    if showelist:
        print('energy points:', elist)

    print('total energy number of point:', nume)
    print('energy step size:', est * 1000, 'eV; ', est, 'keV')
    if nosave == False:
        print('--config=\'' + filedir + filename + '.text\'')
        out.close()
    else:
        print('nosave = True, file is not saved')
Пример #10
0
def genErange(filename='econfigtest',
              edge=8.50,
              E0=-0.1,
              E1=-0.05,
              E2=+0.05,
              E3=+0.25,
              harmonicVal=None,
              XoffsetVal=SRXenergy.XoffsetCurrent,
              numEpt1=None,
              numEpt2=None,
              numEpt3=None,
              Estep1=.002,
              Estep2=.001,
              Estep3=0.005,
              correctC2X=True,
              c2xfix=None,
              nosave=False,
              display=False,
              showelist=False,
              filedir='/nfs/xf05id1/energyScanConfig/'):
    '''
    provide the start & end positions for energy
    four different energy ranges, set different number of points
    E0-E1:numpt1, E1-E2:numpt2, E2-E3:numpt3, 
    file will be saved to the indicated file directory and file name
    correct c2x, see genE for the syntax

    updated:
        default harmonic will be calculated automatically based on the input energy range
        it'll use the maximum harmonic (smallest u-gap) possible.
        user can still define harmonic if desired.
    
    [example]
     #using default values: E0=-0.1, E1=-0.05, E2 =+0.05, E3 = +0.25, Estep1=.002, Estep2 = .001, Estep3 = 0.005
     escript.genErange('20151024_Pb_02', edge=13.035, harmonicVal=7)

     #OR specify energy and stepsize
     esscript.Erange('20151024_Pb_03', edge=13.035, E0=-0.2, E1=-0.1, E2 =+0.1, E3 = +0.5, harmonicVal = 7,  Estep1=.005, Estep2 = .002, Estep3 = 0.01)    
    
    '''

    if harmonicVal == None:
        #        Eend = edge+E3
        #        harmonicVal = SRXpmenergy.move(Eend, simulate=True, show=False)
        Estart = edge + E0
        harmonicVal = SRXpmenergy.move(Estart, simulate=True, show=False)

    if nosave == False:
        out = open(filedir + filename + '.text', 'w')

    pt = 0
    elist = []
    c2xnow = c2xRBV.get()

    print('E0:')
    Bstart, C2X, Ustart = SRXenergy.EtoAll(edge + E0, harmonic=harmonicVal)
    print('E1:')
    Bend, C2X, Uend = SRXenergy.EtoAll(edge + E1, harmonic=harmonicVal)

    #first range
    if numEpt1 == None:
        nume = int(round((E1 - E0) / Estep1 + 1))  #number of energy points
    else:
        nume = numEpt1
    #print(nume)
    estep = []

    for e in numpy.linspace(edge + E0, edge + E1, num=nume):
        pt = pt + 1
        elist.append(e)
        if display:
            print('Energy point number:', pt)
        braggtar, c2xtar, ugaptar = SRXenergy.EtoAll(e,
                                                     harmonic=harmonicVal,
                                                     Xoffset=XoffsetVal,
                                                     show=display)
        if correctC2X == True:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xtar
            }
        elif c2xfix == None:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xnow
            }
        else:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xfix
            }
        if pt >= 2:
            estep.append(elist[pt - 1] - elist[pt - 2])
            #print(estep)
        if nosave == False:
            out.write(str)
    est1 = numpy.average(numpy.array(estep))
    #print(len(estep))

    #second range

    print('E1:')
    Bstart, C2X, Ustart = SRXenergy.EtoAll(edge + E1, harmonic=harmonicVal)
    print('E2:')
    Bend, C2X, Uend = SRXenergy.EtoAll(edge + E2, harmonic=harmonicVal)

    if numEpt2 == None:
        nume = int(round((E2 - E1) / Estep2 + 1))  #number of energy points
    else:
        nume = numEpt2
    #print(nume)
    estep = []
    for e in numpy.linspace(edge + E1 + Estep2, edge + E2, num=nume - 1):
        pt = pt + 1
        elist.append(e)
        if display:
            print('Energy point number:', pt)
        braggtar, c2xtar, ugaptar = SRXenergy.EtoAll(e,
                                                     harmonic=harmonicVal,
                                                     Xoffset=XoffsetVal,
                                                     show=display)
        if correctC2X == True:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xtar
            }
        elif c2xfix == None:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xnow
            }
        else:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xfix
            }
        estep.append(elist[pt - 1] - elist[pt - 2])
        #print(estep)
        out.write(str)
    est2 = numpy.average(numpy.array(estep))
    #print(len(estep))

    #third range
    print('E2:')
    Bstart, C2X, Ustart = SRXenergy.EtoAll(edge + E2, harmonic=harmonicVal)
    print('E3:')
    Bend, C2X, Uend = SRXenergy.EtoAll(edge + E3, harmonic=harmonicVal)

    if numEpt3 == None:
        nume = int(round((E3 - E2) / Estep3 + 1))  #number of energy points
    else:
        nume = numEpt3
    #print(nume)

    estep = []
    for e in numpy.linspace(edge + E2 + Estep3, edge + E3, num=nume - 1):
        pt = pt + 1
        elist.append(e)
        if display:
            print('Energy point number:', pt)
        braggtar, c2xtar, ugaptar = SRXenergy.EtoAll(e,
                                                     harmonic=harmonicVal,
                                                     Xoffset=XoffsetVal,
                                                     show=display)
        if correctC2X == True:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xtar
            }
        elif c2xfix == None:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xnow
            }
        else:
            str = "%(bragg)6.4f %(ugap)6.4f %(c2x)6.3f\n" % {
                "bragg": braggtar,
                "ugap": ugaptar,
                "c2x": c2xfix
            }
        estep.append(elist[pt - 1] - elist[pt - 2])
        #print(estep)
        out.write(str)
    est3 = numpy.average(numpy.array(estep))
    #print(len(estep))

    if showelist:
        print('energy points:', elist)
    print('total energy number of point:', len(elist))
    print('energy step size 1:', est1 * 1000, 'eV; ', est1, 'keV')
    print('energy step size 2:', est2 * 1000, 'eV; ', est2, 'keV')
    print('energy step size 3:', est3 * 1000, 'eV; ', est3, 'keV')

    if nosave == False:
        print('--config=\'' + filedir + filename + '.text\'')
        out.close()
    else:
        print('nosave = True, file is not saved')
Пример #11
0
    i0array = numpy.abs(i0array - offset)

    econfigFile = econfigFileList[filect]
    filect = filect + 1

    #####load Energy Axis###############
    energyAxis = []
    numenergypt = 0
    with open(econfigFile, 'r') as feconf:
        while True:
            line = feconf.readline()
            if not line: break
            numenergypt = numenergypt + 1
            lineList = line.split(" ")
            bragg = float(lineList[0])
            energyAxis.append(SRXenergy.BraggtoE(bragg, show=False))
            #print energyAxis

    ch1sum = numpy.zeros((4096))
    ch2sum = numpy.zeros((4096))
    ch3sum = numpy.zeros((4096))

    #xenergy = srxmcaEnergyCal.srxmcaenergy()

    print filedir + fileprefix + str(filenum) + '.hdf5'
    infile = h5py.File(filedir + fileprefix + str(filenum) + '.hdf5', 'r')
    name = filedir + fileprefix + str(filenum) + '.hdf5'
    print name
    print len(infile)

    x = range(0, 4096)