startup/42-ESM_monochromator.py
def move_to(self,photon_energy,grating='800',branch='A',EPU='57',LP='LH', c='constant',shutter='close'):
        '''
        Sets the monochromator and undulator to the correct values for the given photon energy

        This function reads the definition .csv file and writes the information to data_dict in order to
        be used in the future motion.
        PARAMETERS
        ----------

        photon_energy : float
            The photon energy value to be set.

        grating : str
            The lines per mm of the grating to use, can be '300', '600', '800' or '1200'.

        branch : str
            The beamline branch which is to be used, can be 'A' (default) or 'B'.

        EPU : str
            The undulator to use, can be '57' (default, high energy) or '105'(low energy).

        c : str, optional
            This is an optional call to define if the c value should be calculated or if the pre-defined
            dictionary should be used.

        shutter : str, optional
            This string is used to to optionally have the shutter remain open during the move.

        '''

        # check that the requested value is within the range of both the EPU and the grating.
        if (self.Range[grating][0]> photon_energy) or (self.Range[grating][1]< photon_energy):
            raise RuntimeError('photon energy out of range for grating,'+
                               'use Eph.Range to determine the correct grating and EPU')
        elif not EPU==None:
            if (self.Range['EPU'+EPU][0]> photon_energy) or (self.Range['EPU'+EPU][1]< photon_energy):
                raise RuntimeError('photon energy out of range for EPU,'+
                                   'use Eph.Range to determine the correct grating and EPU')

        #shut the front end shutter prior to moving.
        # DAMA (mrakitin): commenting it out on 06/02/2018
        # since TwoButtonShutter does not behave well. Have to revisit it.
        # if shutter is 'close':
        #     yield from mv(shutter_FOE, 'Close')

        #Set the offsets and translations for the requested locations.
        yield from self.change_offsets(grating, branch)
        yield from mv(PGM.Grating_Trans, self.Grt_Translation[grating] )

        #Determine the number of steps and make the step arrays to use when moving the photon energy.
        n_steps=int(max(round( abs(self.PGM_angles(photon_energy,grating,EPU=EPU)['gamma']-
                               PGM.Mirror_Pitch.position)/1  ),
                    round( abs(self.PGM_angles(photon_energy,grating,EPU=EPU)['beta']-
                        PGM.Grating_Pitch.position)/2  )))
        if n_steps == 0: n_steps = 1 # if the number of steps is 0 set it to 1


        # divide the range of motion of M2 and the grating into 'n_steps' even steps

        if c=='calc':
            c_val = None
        else:
            c_val= self.c_value[branch][grating]


        if n_steps==1:
            M2_steps=[(self.PGM_angles(photon_energy,grating,EPU=EPU,
                                             c=c_val)['gamma'])]
            GRT_steps=[(self.PGM_angles(photon_energy,grating,EPU=EPU,
                                             c=c_val)['beta'])]
        else:
            M2_steps=np.linspace(PGM.Mirror_Pitch.position,
                             self.PGM_angles(photon_energy,grating,EPU=EPU,
                                             c=c_val)['gamma'], num=n_steps)
            GRT_steps=np.linspace(PGM.Grating_Pitch.position,
                              self.PGM_angles(photon_energy,grating,EPU=EPU,
                                              c=c_val)['beta'], num=n_steps)

        for i in range(n_steps):   # set position of M2 pitch and GRT pitch step by step.
            yield from mv(PGM.Mirror_Pitch, M2_steps[i],    PGM.Grating_Pitch, GRT_steps[i])

        yield from mv(PGM.Focus_Const, self.PGM_angles(photon_energy,grating,EPU=EPU, c=c_val)['c'],
                      PGM.Energy, photon_energy)

        if not EPU==None:
            if LP == 'LH':
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'phase'), 0.0 )
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'gap'), self.Und_e2g(photon_energy,EPU=EPU) )
            elif LP == 'LV':
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'phase'), float(EPU)/2 )
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'gap'), self.Und_e2g_LV(photon_energy,EPU=EPU) )
        # if shutter is 'close':
        #     yield from mv(shutter_FOE, 'Open')

#######################################
# commented temporarily next few lines
#######################################
#        if branch == 'A' and EPU == '105' and (grating == '300' or grating == '600' or grating =='800'):
#            yield from mv(M3.Ry,self.M3_e2a(photon_energy, grt=grating)-0.001)  #trick for minimizing backlash
#            for i in range(10):
#                yield from mv(M3.Ry,self.M3_e2a(photon_energy,grt=grating)+i*0.0001)

        return

        Sets the monochromator and undulator to the correct values for the given photon energy

        This function reads the definition .csv file and writes the information to data_dict in order to
        be used in the future motion.
        PARAMETERS
        ----------

        photon_energy : float
            The photon energy value to be set.

        grating : str
            The lines per mm of the grating to use, can be '300', '600', '800' or '1200'.

        branch : str
            The beamline branch which is to be used, can be 'A' (default) or 'B'.

        EPU : str
            The undulator to use, can be '57' (default, high energy) or '105'(low energy).

        c : str, optional
            This is an optional call to define if the c value should be calculated or if the pre-defined
            dictionary should be used.

        shutter : str, optional
            This string is used to to optionally have the shutter remain open during the move.

        
Sets the monochromator and undulator to the correct values for the given photon energy
This function reads the definition .csv file and writes the information to data_dict in order to
be used in the future motion.
PARAMETERS

photon_energy : float
The photon energy value to be set.



branch : str
The beamline branch which is to be used, can be 'A' (default) or 'B'.

EPU : str
The undulator to use, can be '57' (default, high energy) or '105'(low energy).

c : str, optional
This is an optional call to define if the c value should be calculated or if the pre-defined
dictionary should be used.

shutter : str, optional
This string is used to to optionally have the shutter remain open during the move.
Sets the monochromator and undulator to the correct values for the given photon energy This function reads the definition . csv file and writes the information to data_dict in order to be used in the future motion . PARAMETERS photon_energy : float The photon energy value to be set . branch : str The beamline branch which is to be used can be ' A ' ( default ) or ' B ' . EPU : str The undulator to use can be ' 57 ' ( default high energy ) or ' 105 ' ( low energy ) . c : str optional This is an optional call to define if the c value should be calculated or if the pre - defined dictionary should be used . shutter : str optional This string is used to to optionally have the shutter remain open during the move .
def move_to(self,photon_energy,grating='800',branch='A',EPU='57',LP='LH', c='constant',shutter='close'):
        if (self.Range[grating][0]> photon_energy) or (self.Range[grating][1]< photon_energy):
            raise RuntimeError('photon energy out of range for grating,'+
                               'use Eph.Range to determine the correct grating and EPU')
        elif not EPU==None:
            if (self.Range['EPU'+EPU][0]> photon_energy) or (self.Range['EPU'+EPU][1]< photon_energy):
                raise RuntimeError('photon energy out of range for EPU,'+
                                   'use Eph.Range to determine the correct grating and EPU')
        yield from self.change_offsets(grating, branch)
        yield from mv(PGM.Grating_Trans, self.Grt_Translation[grating] )
        n_steps=int(max(round( abs(self.PGM_angles(photon_energy,grating,EPU=EPU)['gamma']-
                               PGM.Mirror_Pitch.position)/1  ),
                    round( abs(self.PGM_angles(photon_energy,grating,EPU=EPU)['beta']-
                        PGM.Grating_Pitch.position)/2  )))
        if n_steps == 0: n_steps = 1 
        if c=='calc':
            c_val = None
        else:
            c_val= self.c_value[branch][grating]
        if n_steps==1:
            M2_steps=[(self.PGM_angles(photon_energy,grating,EPU=EPU,
                                             c=c_val)['gamma'])]
            GRT_steps=[(self.PGM_angles(photon_energy,grating,EPU=EPU,
                                             c=c_val)['beta'])]
        else:
            M2_steps=np.linspace(PGM.Mirror_Pitch.position,
                             self.PGM_angles(photon_energy,grating,EPU=EPU,
                                             c=c_val)['gamma'], num=n_steps)
            GRT_steps=np.linspace(PGM.Grating_Pitch.position,
                              self.PGM_angles(photon_energy,grating,EPU=EPU,
                                              c=c_val)['beta'], num=n_steps)
        for i in range(n_steps):   
            yield from mv(PGM.Mirror_Pitch, M2_steps[i],    PGM.Grating_Pitch, GRT_steps[i])
        yield from mv(PGM.Focus_Const, self.PGM_angles(photon_energy,grating,EPU=EPU, c=c_val)['c'],
                      PGM.Energy, photon_energy)
        if not EPU==None:
            if LP == 'LH':
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'phase'), 0.0 )
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'gap'), self.Und_e2g(photon_energy,EPU=EPU) )
            elif LP == 'LV':
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'phase'), float(EPU)/2 )
                yield from mv(getattr(ip.user_ns['EPU'+EPU],'gap'), self.Und_e2g_LV(photon_energy,EPU=EPU) )
        return
def move_to ( self , photon_energy , grating = '800' , branch = 'A' , EPU = '57' , LP = 'LH' , c = 'constant' , shutter = 'close' ) : if ( self . Range [ grating ] [ 0 ] > photon_energy ) or ( self . Range [ grating ] [ 1 ] < photon_energy ) : raise RuntimeError ( 'photon energy out of range for grating,' + 'use Eph.Range to determine the correct grating and EPU' ) elif not EPU == None : if ( self . Range [ 'EPU' + EPU ] [ 0 ] > photon_energy ) or ( self . Range [ 'EPU' + EPU ] [ 1 ] < photon_energy ) : raise RuntimeError ( 'photon energy out of range for EPU,' + 'use Eph.Range to determine the correct grating and EPU' ) yield from self . change_offsets ( grating , branch ) yield from mv ( PGM . Grating_Trans , self . Grt_Translation [ grating ] ) n_steps = int ( max ( round ( abs ( self . PGM_angles ( photon_energy , grating , EPU = EPU ) [ 'gamma' ] - PGM . Mirror_Pitch . position ) / 1 ) , round ( abs ( self . PGM_angles ( photon_energy , grating , EPU = EPU ) [ 'beta' ] - PGM . Grating_Pitch . position ) / 2 ) ) ) if n_steps == 0 : n_steps = 1 if c == 'calc' : c_val = None else : c_val = self . c_value [ branch ] [ grating ] if n_steps == 1 : M2_steps = [ ( self . PGM_angles ( photon_energy , grating , EPU = EPU , c = c_val ) [ 'gamma' ] ) ] GRT_steps = [ ( self . PGM_angles ( photon_energy , grating , EPU = EPU , c = c_val ) [ 'beta' ] ) ] else : M2_steps = np . linspace ( PGM . Mirror_Pitch . position , self . PGM_angles ( photon_energy , grating , EPU = EPU , c = c_val ) [ 'gamma' ] , num = n_steps ) GRT_steps = np . linspace ( PGM . Grating_Pitch . position , self . PGM_angles ( photon_energy , grating , EPU = EPU , c = c_val ) [ 'beta' ] , num = n_steps ) for i in range ( n_steps ) : yield from mv ( PGM . Mirror_Pitch , M2_steps [ i ] , PGM . Grating_Pitch , GRT_steps [ i ] ) yield from mv ( PGM . Focus_Const , self . PGM_angles ( photon_energy , grating , EPU = EPU , c = c_val ) [ 'c' ] , PGM . Energy , photon_energy ) if not EPU == None : if LP == 'LH' : yield from mv ( getattr ( ip . user_ns [ 'EPU' + EPU ] , 'phase' ) , 0.0 ) yield from mv ( getattr ( ip . user_ns [ 'EPU' + EPU ] , 'gap' ) , self . Und_e2g ( photon_energy , EPU = EPU ) ) elif LP == 'LV' : yield from mv ( getattr ( ip . user_ns [ 'EPU' + EPU ] , 'phase' ) , float ( EPU ) / 2 ) yield from mv ( getattr ( ip . user_ns [ 'EPU' + EPU ] , 'gap' ) , self . Und_e2g_LV ( photon_energy , EPU = EPU ) ) return
Sets the monochromator and undulator to the correct values for the given photon energy
This function reads the definition .csv file and writes the information to data_dict in order to
be used in the future motion.
Sets the monochromator and undulator to the correct values for the given photon energy This function reads the definition . csv file and writes the information to data_dict in order to be used in the future motion .
'''
        Sets the monochromator and undulator to the correct values for the given photon energy

        This function reads the definition .csv file and writes the information to data_dict in order to
        be used in the future motion.
        PARAMETERS
        ----------

        photon_energy : float
            The photon energy value to be set.

        grating : str
            The lines per mm of the grating to use, can be '300', '600', '800' or '1200'.

        branch : str
            The beamline branch which is to be used, can be 'A' (default) or 'B'.

        EPU : str
            The undulator to use, can be '57' (default, high energy) or '105'(low energy).

        c : str, optional
            This is an optional call to define if the c value should be calculated or if the pre-defined
            dictionary should be used.

        shutter : str, optional
            This string is used to to optionally have the shutter remain open during the move.

        ''' # check that the requested value is within the range of both the EPU and the grating. #shut the front end shutter prior to moving. # DAMA (mrakitin): commenting it out on 06/02/2018 # since TwoButtonShutter does not behave well. Have to revisit it. # if shutter is 'close': #     yield from mv(shutter_FOE, 'Close') #Set the offsets and translations for the requested locations. #Determine the number of steps and make the step arrays to use when moving the photon energy. # if the number of steps is 0 set it to 1 # divide the range of motion of M2 and the grating into 'n_steps' even steps # set position of M2 pitch and GRT pitch step by step. # if shutter is 'close': #     yield from mv(shutter_FOE, 'Open') ####################################### # commented temporarily next few lines ####################################### #        if branch == 'A' and EPU == '105' and (grating == '300' or grating == '600' or grating =='800'): #            yield from mv(M3.Ry,self.M3_e2a(photon_energy, grt=grating)-0.001)  #trick for minimizing backlash #            for i in range(10): #                yield from mv(M3.Ry,self.M3_e2a(photon_energy,grt=grating)+i*0.0001)
self
photon_energy
grating
branch
EPU
LP
c
shutter