diff --git a/build/lib/iexcode/instruments/AD_utilities.py b/build/lib/iexcode/instruments/AD_utilities.py index dde214f254b2fc7d5441fa50814a9ebd2f5a8a38..cbe60f3ee47135bbcc4875ba9ae578ebf5139c1e 100644 --- a/build/lib/iexcode/instruments/AD_utilities.py +++ b/build/lib/iexcode/instruments/AD_utilities.py @@ -56,7 +56,15 @@ def AD_EnableStats(ADplugin): caput(ADplugin+"ComputeStatistics","Yes") caput(ADplugin+"ComputeCentroid","Yes") - +def AD_last_filename(ADplugin,verbose=True): + """ + returns the full path for the last saved image + """ + fpath = caget(ADplugin+"FullFileName_RBV",as_string=True) + if verbose: + print(ADplugin," => ",fpath) + return fpath + def AD_SaveFileSetup(ADplugin,**kwargs): """ ADplugin = "29id_ps1:TIFF1:" which IOC and which filesaving plugin diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py index ad8520546027f66b8f8505028761c9ebe115fc1c..ca7dc1133fc173608eae53d0f2e686be47b5f83e 100644 --- a/build/lib/iexcode/instruments/ARPES.py +++ b/build/lib/iexcode/instruments/ARPES.py @@ -5,7 +5,7 @@ from epics import caget,caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config -from iexcode.instruments.cameras import _enable_endstation_cameras +from iexcode.instruments.IEX_cameras import _enable_endstation_cameras from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv from iexcode.instruments.Logfile import Logfile diff --git a/build/lib/iexcode/instruments/Kappa.py b/build/lib/iexcode/instruments/Kappa.py index 86a4a841af608eb0a9cedfbf4e6f16f6aac2a2bb..972b016731285a82c26825b812a03bd9b6488efe 100644 --- a/build/lib/iexcode/instruments/Kappa.py +++ b/build/lib/iexcode/instruments/Kappa.py @@ -7,7 +7,7 @@ from epics import caget, caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config -from iexcode.instruments.cameras import _enable_endstation_cameras +from iexcode.instruments.IEX_cameras import _enable_endstation_cameras from iexcode.instruments.staff import staff_detector_dictionary from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda diff --git a/build/lib/iexcode/instruments/Motors.py b/build/lib/iexcode/instruments/Motors.py index 5e7756b15fce0ec439ffa87ad051f1ca99152664..35d863936b25b8853221d24a6bd91ff098a4f37c 100644 --- a/build/lib/iexcode/instruments/Motors.py +++ b/build/lib/iexcode/instruments/Motors.py @@ -214,20 +214,26 @@ class Motors: kwargs.setdefault('outer_scan_dim',2) kwargs.setdefault('snake',False) kwargs.setdefault('execute',True) + kwargs.setdefault('debug',False) + #for kappa only kwargs.setdefault('cts',0.1) kwargs.setdefault('mpa',False) - from iexcode.instruments.IEX_BL_config import BL - rbv_pv,val_pv,sgm_pv,pv = self._motor_dictionary[inner_loop_list[0]] + inner_loop_list.pop(0) inner_loop_list.insert(0,rbv_pv) inner_loop_list.insert(0,val_pv) rbv_pv,val_pv,sgm_pv,pv = self._motor_dictionary[outer_loop_list[0]] + outer_loop_list.pop(0) outer_loop_list.insert(0,rbv_pv) outer_loop_list.insert(0,val_pv) + if kwargs['debug']: + print('inner_loop_list = ',inner_loop_list) + print('outer_loop_list = ',outer_loop_list) + if kwargs["mode"] == "relative": current_value1 = caget(inner_loop_list[1]) inner_loop_list[2]=round(current_value1+inner_loop_list[2],3) @@ -237,9 +243,8 @@ class Motors: outer_loop_list[2]=round(current_value1+outer_loop_list[2],3) outer_loop_list[3]=round(current_value1+outer_loop_list[3],3) - scaler_cts(kwargs['cts'],verbose=True,**kwargs) - iex.BL.mda.fillin_2D(inner_loop_list,outer_loop_list, - outer_scan_dim=kwargs['outer_scan_dim'],**kwargs) + scaler_cts(kwargs['cts'],verbose=True) + iex.BL.mda.fillin_2D(inner_loop_list,outer_loop_list,**kwargs) if kwargs['execute']: iex.BL.mda.go(**kwargs) diff --git a/build/lib/iexcode/instruments/VLS_PGM.py b/build/lib/iexcode/instruments/VLS_PGM.py index 4a40674b807b46f8211d99ea5cc563832cf9c509..8446e1bf6909eb67b546b6b91387715c9fbd9479 100644 --- a/build/lib/iexcode/instruments/VLS_PGM.py +++ b/build/lib/iexcode/instruments/VLS_PGM.py @@ -14,24 +14,24 @@ from iexcode.instruments.utilities import print_warning_message,read_dict ############################################################################################################## ################################ mono ############################## ############################################################################################################## -def _mono_grating_names(): +def mono_grating_names(): """ List of grating names """ ext = ['C', 'D', 'E', 'F', 'G', 'H', 'I', "J", "K", "L" ] GRT_names = ["MEG_Imp","HEG","MEG","Dummy", "not used", "not used", "not used","not used","not used","not used"] - GRT_names=GRT_names[0:2] # only use the first 3 slots + GRT_names=GRT_names[0:3] # only use the first 3 slots return GRT_names -def _mono_mirror_names(): +def mono_mirror_names(): """ List of grating names """ ext = ['C', 'D', 'E', 'F', 'G', 'H', 'I', "J", "K", "L" ] MIR_names = ["Au", "Silicon", "Carbon","not used","not used","not used","not used","not used","not used","not used"] - MIR_names=MIR_names[0:2] # only use the first 3 slots + MIR_names=MIR_names[0:3] # only use the first 3 slots return MIR_names def _mono_extensions(): @@ -51,7 +51,7 @@ def mono_energy_range(GRT=None): if GRT == 'HEG': hv_min=120 hv_max=2200 - elif GRT == 'MEG': + else: hv_min=120 hv_max=3000 return hv_min,hv_max @@ -64,14 +64,14 @@ def mono_get_all(verbose=False): """ d = mono_get_all_extended(verbose=False) vals = { - 'hv':d['ENERGY_MON'], - 'hv_sp':d['ENERGY_SP'], - 'grating':d['GRT'], - 'mirror':d['MIR'], + 'hv':d['energy'], + 'hv_sp':d['energy_sp'], + 'grating':d['grt'], + 'mirror':d['mir'], } if verbose: - print(" hv: "+"%.2f" % vals['hv'], "eV, hv_sp: " % vals['hv_sp']) - print(" grating : "+vals['grating']," mirror : "+vals['mirror']) + print(" hv: "+"%.2f" % vals['hv'], "eV, hv_sp: "+"% .2f" % vals['hv_sp']) + print(" grating : "+vals['grating'],", mirror : "+vals['mirror']) return vals def _mono_grating_num(): @@ -97,26 +97,48 @@ def _mono_pvs(grt_num=None,mir_num=None): 'energy':"29idmono:ENERGY_MON", 'energy_sp':"29idmono:ENERGY_SP", 'grt_density':"29idmono:GRT_DENSITY", - 'grt_offset':'29idmonoGRT:P_OFFSETS.'+ext['grt_num'], - 'grt_b2':'29idmonoGRT:B2_CALC.'+ext['grt_num'], - 'grt_pos':'29idmonoGRT:X_DEF_POS.'+ext['grt_num'], - 'grt_LD':'29idmonoGRT:TYPE_CALC.'+ext['grt_num'], - 'grt_tun0':'29idmonoGRT:TUN0_CALC.'+ext['grt_num'], - 'grt_tun1':'29idmonoGRT:TUN1_CALC.'+ext['grt_num'], - 'grt_tun2':'29idmonoGRT:TUN2_CALC.'+ext['grt_num'], - 'grt_tun3':'29idmonoGRT:TUN3_CALC.'+ext['grt_num'], + 'grt_offset':'29idmonoGRT:P_OFFSETS.'+ext[grt_num], + 'grt_b2':'29idmonoGRT:B2_CALC.'+ext[grt_num], + 'grt_pos':'29idmonoGRT:X_DEF_POS.'+ext[grt_num], + 'grt_LD':'29idmonoGRT:TYPE_CALC.'+ext[grt_num], + 'grt_tun0':'29idmonoGRT:TUN0_CALC.'+ext[grt_num], + 'grt_tun1':'29idmonoGRT:TUN1_CALC.'+ext[grt_num], + 'grt_tun2':'29idmonoGRT:TUN2_CALC.'+ext[grt_num], + 'grt_tun3':'29idmonoGRT:TUN3_CALC.'+ext[grt_num], 'grt_type_sp':"29idmonoGRT_TYPE_SP", - 'grt_move':"29idb:'gr:move", + 'grt_type_move':"29idmonoGRT:X_DCPL_CALC.PROC", + 'mir_type_sp':"29idmonoMIR_TYPE_SP", + 'mir_type_move':"29idmonoMIR:X_DCPL_CALC.PROC", + 'mono_pitch_state':'29idmono:ERDY_STS', + 'grt_P_sp':"29idmonoGRT:P_SP", 'grt_P_status':"29idmonoGRT:P_AXIS_STS", + 'grt_P_stop':"29idmonoGRT:P.STOP", + 'grt_P_kill':"29idmonoGRT:P_KILL_CMD.PROC", + 'grt_P_enable':"29idmonoGRT:P_ENA_CMD.PROC", + 'mir_P_sp':"29idmonoMIR:P_SP", 'mir_P_status':"29idmonoMIR:P_AXIS_STS", + 'mir_P_stop':"29idmonoMIR:P.STOP", + 'mir_P_kill':"29idmonoMIR:P_KILL_CMD.PROC", + 'mir_P_enable':"29idmonoMIR:P_ENA_CMD.PROC", + 'grt_X_sp':"29idmonoGRT:X_SP", 'grt_X_status':"29idmonoGRT:X_AXIS_STS", + 'grt_X_stop':"29idmonoGRT:X.STOP", + 'grt_X_kill':"29idmonoGRT:X_KILL_CMD.PROC", + 'grt_X_enable':"29idmonoGRT:X_ENA_CMD.PROC", + 'mir_X_sp':"29idmonoMIR:X_SP", 'mir_X_status':"29idmonoMIR:X_AXIS_STS", - 'mir_offset':'29idmonoMIR:P_OFFSETS.'+ext['mir_num'], - 'mir_pos':'29idmonoMIR:X_DEF_POS.'+ext['mir_num'], + 'mir_X_stop':"29idmonoMIR:X.STOP", + 'mir_X_kill':"29idmonoMIR:X_KILL_CMD.PROC", + 'mir_X_enable':"29idmonoMIR:X_ENA_CMD.PROC", + 'mir_offset':'29idmonoMIR:P_OFFSETS.'+ext[mir_num], + 'mir_pos':'29idmonoMIR:X_DEF_POS.'+ext[mir_num], + 'mono_stop':"29idmono:STOP_CMD.PROC", 'cff':'29idmono:CC_MON', 'arm':'29idmono:PARAMETER.G' + } + return d def mono_get_all_extended(verbose=False): """ @@ -127,22 +149,22 @@ def mono_get_all_extended(verbose=False): """ grt_num = _mono_grating_num() mir_num = _mono_mirror_num() - grt_names = _mono_grating_names() - mir_names = _mono_mirror_names() + grt_names = mono_grating_names() + mir_names = mono_mirror_names() ext=_mono_extensions() - pvs = _mono_pvs(grt_num=None,mir_num=None) + pvs = _mono_pvs() vals={ 'grt_num':grt_num, 'mir_num':mir_num, - 'grt':grt_names[grt_num], - 'mir':mir_names[mir_num], + 'grt':grt_names[grt_num-1], + 'mir':mir_names[mir_num-1], 'energy':caget(pvs['energy']), 'energy_sp':caget(pvs['energy_sp']), - 'grt_density':caget(pvs['energy_sp']), + 'grt_density':caget(pvs['grt_density']), 'grt_offset':caget(pvs['grt_offset']), - 'grt_b2':caget(pvs['grt_offset']), + 'grt_b2':caget(pvs['grt_b2']), 'grt_pos':caget(pvs['grt_pos']), 'grt_LD':caget(pvs['grt_LD']), 'grt_tun0':caget(pvs['grt_tun0']), @@ -155,13 +177,13 @@ def mono_get_all_extended(verbose=False): 'mir_X_status':caget(pvs['mir_X_status']), 'mir_offset':caget(pvs['mir_offset']), 'mir_pos':caget(pvs['mir_pos']), - 'CFF':caget('29idmono:CC_MON'), + 'cff':caget('29idmono:CC_MON'), 'arm':caget('29idmono:PARAMETER.G') } if verbose: for key in vals.keys(): - print(key,vals[key]) + print(key," = ",vals[key]) return vals @@ -171,6 +193,12 @@ def mono_grating_get(): """ return mono_get_all_extended()['grt'] +def mono_mirror_get(): + """ + returns the grating density and the string name for the grating + """ + return mono_get_all_extended()['mir'] + def mono_energy_get(): """ returns the grating density and the string name for the grating @@ -197,14 +225,14 @@ def mono_energy_set(hv_eV,verbose=True): mono_status = mono_status_get() while True: - if mono_status() > 1: + if mono_status > 1: mono_resest_pitch() caput(pv,hv_eV,wait=True,timeout=60) time.sleep(2.5) else: break if verbose: - print("Mono set to",str(hv_eV),"eV") + print("Mono set to",str(round(hv_eV,3)),"eV") def mono_scan_pvs(): """ @@ -223,37 +251,69 @@ def mono_status_get(): Previously Mono_Status """ - pvs = _mono_pvs()['energy'] - mir_P_status = caget(pvs['mir_P_status']) - grt_P_status = caget(pvs['grt_P_status']) - mir_X_status = caget(pvs['mir_P_status']) - grt_X_status = caget(pvs['grt_P_status']) + pvs = _mono_pvs() + mir_P_status = int(caget(pvs['mir_P_status'])) + grt_P_status = int(caget(pvs['grt_P_status'])) + mir_X_status = int(caget(pvs['mir_P_status'])) + grt_X_status = int(caget(pvs['grt_P_status'])) mirror_status = mir_P_status * mir_X_status grating_status = grt_P_status * grt_X_status return mirror_status*grating_status - -def mono_grating_translate(grating,verbose=True): +def mono_grating_change(grating_name,verbose=True): """ Translate between the different grating positions + list grating_name: mono_grating_names() - Warning: this does not close the shutters use XX + Warning: this does not close the shutters use xrays:mirror Previously: Move_GRT """ - current_grating=mono_grating_get() + _mono_optic_change('grating',grating_name, verbose) + +def mono_mirror_change(mirror_name,verbose=True): + """ + Translate between the different mirror positions + list mirror_name: mono_mirror_names() + + Warning: this does not close the shutters + + """ + _mono_optic_change('mirror',mirror_name, verbose) + +def _mono_optic_change(optic,name, verbose=True): + """ + optic = 'mirror','grating' + """ + hv_eV = mono_energy_get() try: - grating_state = _mono_grating_names().index(grating) - + if optic == 'grating': + num = mono_grating_names().index(name)+1 + elif optic == 'mirror': + num = mono_mirror_names().index(name)+1 except: - print_warning_message(grating+' not a valid grating') + print_warning_message(name+' not a valid '+optic) + return + + pvs = _mono_pvs () + if optic == 'grating': + type_get = mono_grating_get() + type_sp = pvs['grt_type_sp'] + type_move = pvs['grt_type_move'] + elif optic == 'mirror': + type_get = mono_mirror_get() + type_sp = pvs['mir_type_sp'] + type_move = pvs['mir_type_move'] + else: + print('Error: optic = ',optic,' not a valid choice') + return - if current_grating != grating: - pvs=_mono_pvs() - caput(pvs['grt_type_sp'],grating_state,wait=True,timeout=18000) - caput(pvs['grt_move'],1,wait=True,timeout=18000) + if type_get != name: + caput(type_sp,num,wait=True,timeout=18000) + caput(type_move,1,wait=True,timeout=18000) + while True: if mono_status_get() > 1: time.sleep(5) @@ -263,20 +323,20 @@ def mono_grating_translate(grating,verbose=True): else: if verbose: - print("grating is already "+grating) + print(optic+" is already "+name) if verbose: - print("Mono Grating:",grating) - + print("Mono "+optic+":",name) def mono_resest_pitch(): """ resets the MIR and GRT pitch interlocks after a following error or limit Previoulsy part of SetMono """ - caput("29idmonoMIR:P.STOP",1) + pv=_mono_pvs() + caput(pv['grt_P_stop'],1) time.sleep(1) - caput("29idmonoGRT:P.STOP",1) + caput(pv['mir_P_stop'],1) time.sleep(1) print('Mono pitch was reset') @@ -286,12 +346,14 @@ def mono_kill(): Previously: Kill_Mono """ - caput("29idmonoMIR:P_KILL_CMD.PROC",1) - caput("29idmonoGRT:P_KILL_CMD.PROC",1) -# caput("29idmonoGRT:X_KILL_CMD.PROC",1) + pv=_mono_pvs() + caput(pv['grt_P_kill'],1) + caput(pv['mir_P_kill'],1) + caput(pv['grt_X_kill'],1) + caput(pv['mir_X_kill'],1) time.sleep(5) - caput("29idmono:STOP_CMD.PROC",1) -# caput("29idmonoGRT:X_HOME_CMD.PROC",1) + mono_stop() + def mono_stop(): @@ -300,7 +362,8 @@ def mono_stop(): Previously: Stop_Mono """ - caput("29idmono:STOP_CMD.PROC",1) + pv=_mono_pvs() + caput(pv['mono_stop'],1) time.sleep(5) def mono_enable(): @@ -309,10 +372,11 @@ def mono_enable(): Previously: Enable_Mono """ - caput("29idmonoGRT:X_ENA_CMD.PROC",1) - caput("29idmonoGRT:P_ENA_CMD.PROC",1) - caput("29idmonoMIR:X_ENA_CMD.PROC",1) - caput("29idmonoMIR:P_ENA_CMD.PROC",1) + pv=_mono_pvs() + caput(pv['grt_P_enable'],1) + caput(pv['mir_P_enable'],1) + caput(pv['grt_X_enable'],1) + caput(pv['mir_X_enable'],1) def mono_limits_reset(): """ @@ -321,50 +385,29 @@ def mono_limits_reset(): Previously: Reset_Mono_Limits """ - # caput("29idmono_GRT_TYPE_SP.ONST", 'MEG_PA') - # caput("29idmono_GRT_TYPE_SP.TWST", 'HEG_JY') - # caput("29idmono_GRT_TYPE_SP.THST", 'MEG_JY') - caput("29idmono:ENERGY_SP.DRVL",200) - caput("29idmono:ENERGY_SP.LOW",200) - caput("29idmono:ENERGY_SP.LOLO",200) - caput("29idmono:ENERGY_SP.LOPR",200) + + pv=_mono_pvs()['energy_sp'] + caput(pv+".DRVL",200) + caput(pv+".LOW",200) + caput(pv+".LOLO",200) + caput(pv+".LOPR",200) print("Mono limits have been reset.") -def mono_cff_print(): - """ - print the cff tuning parameters and arm for the current grating - - Previously: Get_CFF - """ - d = mono_get_all_extended - cff = d['cff'] - tun0 = d['grt_tun0'] - tun1 = d['grt_tun1'] - tun2 = d['grt_tun2'] - tun3 = d['grt_tun3'] - arm = d['arm'] - print(" cff : "+"%.4f" % cff , " exit arm: "+"%.1f" % arm,"mm") - print(" tun0 : "+"%.4e" % tun0 , " tun1: "+"%.4e" % tun1) - print(" tun2 : "+"%.4e" % tun2 , " tun3: "+"%.4e" % tun3) def mono_parameters_pv(grt_num=None,mir_num=None): """ returns dictionary with mono_parameter for current grating/mirror """ - if grt_num is None: - grt_num = _mono_grating_num()() - if mir_num is None: - mir_num = _mono_mirror_num()() - - ext = _mono_extensions() + pvs=_mono_pvs(grt_num,mir_num) + d={ - 'mir_offset':"29idmonoMIR:P_OFFSETS."+ext[mir_num], - 'mir_pos':"29idmonoMIR:X_DEF_POS."+ext[mir_num], - 'grt_offset':"29idmonoGRT:P_OFFSETS."+ext[grt_num], - 'grt_pos':"29idmonoGRT:X_DEF_POS."+ext[grt_num], - 'grt_density':"29idmonoGRT:TYPE_CALC."+ext[grt_num], - 'grt_b2':"29idmonoGRT:B2_CALC."+ext[grt_num] + 'mir_offset':pvs['mir_offset'], + 'mir_pos':pvs['mir_pos'], + 'grt_offset':pvs['grt_offset'], + 'grt_pos':pvs['grt_pos'], + 'grt_density':pvs['grt_density'], + 'grt_b2':pvs['grt_b2'] } return d @@ -376,8 +419,8 @@ def mono_parameters_get(): Previously: Mono_Parameters_Get """ date=time.strftime("%Y%m%d",time.localtime()) - mirList = _mono_mirror_names() - grtList = _mono_grating_names() + mirList = mono_mirror_names() + grtList = mono_grating_names() pvList = _mono_extensions() #MIR @@ -466,7 +509,7 @@ def mono_temperature_interlock(): -def mono_scan_fillin(hv_start,hv_stop,hv_step,**kwargs): +def mono_scan(hv_start,hv_stop,hv_step,**kwargs): """ fills in the scanRecord for scanning the mono @@ -486,7 +529,7 @@ def mono_scan_fillin(hv_start,hv_stop,hv_step,**kwargs): iex.BL.mda.positioner_after_scan("STAY") -def mono_scan_fillin_table(hv_array,**kwargs): +def mono_scan_table(hv_array,**kwargs): """ fills in the scanRecord for scanning the mono @@ -518,16 +561,16 @@ def mono_scan_after(**kwargs): ############################################################################################################## ################################ aligmnent and commissioning ############################## ############################################################################################################## -def mono_motor_move(motor,value): +def mono_motor_move(motor,value,wait=True,timeout=18000): """ for pitch motor => MIR:P or GRT:P for translation motor => MIR:X or GRT:X Previously: Move_FMBMono """ - val_pv,rbv_pv = mono_motor_scan_pvs() + val_pv,rbv_pv = mono_motor_scan_pvs(motor) caput(val_pv+".PREC",3) - caput(val_pv,value,wait=True,timeout=18000) + caput(val_pv,value,wait=wait,timeout=timeout) def mono_motor_scan_pvs(motor): """ @@ -537,7 +580,7 @@ def mono_motor_scan_pvs(motor): rbv_pv = "29idmono"+motor+"_MON" return val_pv,rbv_pv -def mono_motor_scan_fillin(motor,start,stop,step,**kwargs): +def mono_motor_scan(motor,start,stop,step,**kwargs): """ for pitch motor => MIR:P or GRT:P for translation motor => MIR:X or GRT:X @@ -556,12 +599,8 @@ def mono_zero_order(angle): Previously: Mono_zero """ - angle=angle*1.0 - caput("29idmonoMIR:P_POS_SP",angle,wait=True,timeout=18000) - caput("29idmonoMIR:P_MOVE_CMD.PROC",1,wait=True,timeout=18000) - caput("29idmonoGRT:P_POS_SP",angle,wait=True,timeout=18000) - caput("29idmonoGRT:P_MOVE_CMD.PROC",1,wait=True,timeout=18000) - print("Mono set to zero order: MIR_pitch = "+str(angle)+", GRT_pitch = "+str(angle)) + mono_angles_set(angle,angle) + print("Mono set to zero order:") def mono_angles_set(alpha,beta): #JM modified to monitor the ready, moving sequentialy ended up in crash sometimes """ @@ -571,14 +610,16 @@ def mono_angles_set(alpha,beta): #JM modified to monitor the ready, moving seque """ alpha=alpha*1.0 beta=beta*1.0 - #Putting Setpoints Go - caput("29idmonoGRT:P_SP",alpha) - caput("29idmonoMIR:P_SP",beta) - ready=0 - while ready != 1: - time.sleep(0.1) - ready=caget('29idmono:ERDY_STS') - print("Mono set to zero order: MIR_pitch = "+str(alpha)+", GRT_pitch = "+str(beta)) + pvs = _mono_pvs() + + #don't wait during move so they move in parallel (less likely to crash) + caput(pvs['mir_P_sp'],alpha) + caput(pvs['grt_P_sp'],beta) + time.sleep(0.5) #need sleep before things start moving + + while caget(pvs['mono_pitch_state']) != 1: + time.sleep(0.5) + print("MIR_pitch = "+str(alpha)+", GRT_pitch = "+str(beta)) def mono_pink_beam(): """ @@ -587,17 +628,10 @@ def mono_pink_beam(): Previously: Mono_pinkbeam """ - caput("29idmonoMIR:P_POS_SP",0,0) - caput("29idmonoMIR:P_MOVE_CMD.PROC",0) - time.sleep(3) - caput("29idmonoGRT:P_POS_SP",0.0) - caput("29idmonoGRT:P_MOVE_CMD.PROC",0) - time.sleep(3) - caput("29idmonoMIR:X_POS_SP",-52) - caput("29idmonoMIR:X_MOVE_CMD.PROC",0) - time.sleep(3) - caput("29idmonoGRT:X_POS_SP",210) - caput("29idmonoGRT:X_MOVE_CMD.PROC",0,wait=True,timeout=18000) + mono_angles_set(0,0) + pvs=_mono_pvs() + mono_motor_move('MIR:X',-52,wait=False) + mono_motor_move('GRT:X',210,wait=True) def mono_CC(): """ @@ -612,16 +646,24 @@ def mono_CC(): caput("29idmono:ENERGY_SP", 440) +def mono_grating_offset_get(grt_num=None): + pvs=_mono_pvs(grt_num,None) + return caget(pvs['grt_offset']) + def mono_grating_offset_set(val,grt_num=None): """ sets the grating offset for the grating Previously: Mono_Set_GRT0 """ - pvs=_mono_pvs(grt_num,None) + pvs=_mono_pvs(None,None) caput(pvs['grt_offset'],val) mono_get_all_extended(verbose=True) +def mono_mirror_offset_get(mir_num=None): + pvs=_mono_pvs(None,mir_num) + return caget(pvs['mir_offset']) + def mono_mirror_offset_set(val,mir_num=None): """ sets the mirror offset for the grating @@ -663,6 +705,9 @@ def mono_grating_mirror_offsets_set(mirror_offset): mono_energy_set(energy_sp) mono_get_all_extended(verbose=True) +def mono_grating_b2_get(grt_num=None): + pvs = _mono_pvs(grt_num,None) + return caget(pvs['grt_b2']) def mono_grating_b2_set(val,grt_num=None): """ @@ -677,6 +722,24 @@ def mono_grating_b2_set(val,grt_num=None): mono_energy_set(hv) mono_get_all_extended(verbose=True) +def mono_cff_get(): + """ + print the cff tuning parameters and arm for the current grating + + Previously: Get_CFF + """ + d = mono_get_all_extended() + cff = d['cff'] + tun0 = d['grt_tun0'] + tun1 = d['grt_tun1'] + tun2 = d['grt_tun2'] + tun3 = d['grt_tun3'] + arm = d['arm'] + print(" cff : "+"%.4f" % cff , " exit arm: "+"%.1f" % arm,"mm") + print(" tun0 : "+"%.4e" % tun0 , " tun1: "+"%.4e" % tun1) + print(" tun2 : "+"%.4e" % tun2 , " tun3: "+"%.4e" % tun3) + + def mono_cff_set(val,tune_num): """ sets the tuning parameters for the cff calculation @@ -709,6 +772,10 @@ def mono_cff_set(val,tune_num): print('Pitch grating, mirror: ',current_vals['grt_pitch'],current_vals['mir_pitch']) print('Differences : ',grt_dif,mir_dif) +def mono_arm_get(): + pvs = _mono_pvs() + return caget(pvs(['arm'])) + def mono_arm_set(distance_mm): """ sets the exit arm for the grating @@ -725,7 +792,8 @@ def mono_arm_set(distance_mm): print ('Pitch grating, mirror: ',grt_pitch,mir_pitch) #set the exit arm - caput("29idmono:PARAMETER.G",distance_mm) + + caput(pvs(['arm']),distance_mm) time.sleep(1) #set then energy diff --git a/build/lib/iexcode/instruments/scanRecord.py b/build/lib/iexcode/instruments/scanRecord.py index 2fc7d396b6bc9a886699195dbb43da3a976527af..11f724da53606fee474d5298cd044328b5ee0f91 100644 --- a/build/lib/iexcode/instruments/scanRecord.py +++ b/build/lib/iexcode/instruments/scanRecord.py @@ -467,12 +467,16 @@ class ScanRecord: kwargs.setdefault("positioner_num",1) kwargs.setdefault('detector_settling_time',default_detector_settling_time) kwargs.setdefault('positioner_settling_time',default_positioner_settling_time) + kwargs.setdefault('debug',False) self.progress(kwargs['scan_dim']) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) posNum = kwargs['positioner_num'] + if kwargs['debug']: + print('fillin: ',val_pv,rbv_pv,start,stop,steps_points) + caput(scan_pv+".P"+str(posNum)+"PV",val_pv) caput(scan_pv+".R"+str(posNum)+"PV",rbv_pv) caput(scan_pv+".P"+str(posNum)+"SP",start*1.0) @@ -828,7 +832,7 @@ class ScanRecord: ############################################################################################################## ############################# 2D scans typewriter/snake scans ############################## ############################################################################################################## - def fillin_2D(self,inner_loop_list,outer_loop_list,outer_scan_dim=2,**kwargs): + def fillin_2D(self,inner_loop_list,outer_loop_list,**kwargs): """ Fills in a the Scan Record for a 2D scan (Mesh), InnerMotorList=[val_pv1,rbv_pv1,start1,stop1,step1] #scanDIM=1 @@ -841,13 +845,16 @@ class ScanRecord: snake: coming soon """ kwargs.setdefault("snake",False) + kwargs.setdefault("outer_scan_dim",2) + + outer_scan_dim = kwargs['outer_scan_dim'] #fillin inner loop kwargs.update({'scan_dim':outer_scan_dim-1}) self.fillin(inner_loop_list[0],inner_loop_list[1],inner_loop_list[2],inner_loop_list[3],inner_loop_list[4],**kwargs) #fillin outer loop kwargs.update({'scan_dim':outer_scan_dim}) - self.fillin(outer_loop_list[0],outer_loop_list[1],outer_loop_list[2],outer_loop_list[3],outer_loop_list[1],**kwargs) + self.fillin(outer_loop_list[0],outer_loop_list[1],outer_loop_list[2],outer_loop_list[3],outer_loop_list[4],**kwargs) diff --git a/build/lib/iexcode/instruments/slits.py b/build/lib/iexcode/instruments/slits.py index 42448064d4693a4a3902a348579651c12c21805a..77dc9aa22d585d942636a2cd77166284841ba283 100644 --- a/build/lib/iexcode/instruments/slits.py +++ b/build/lib/iexcode/instruments/slits.py @@ -28,7 +28,7 @@ def _slits_dictionary(): return d def slit_name_list(): - d=_slits_dictionary + d=_slits_dictionary() for key in d.keys(): print(key) diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py index 0dd844574642d4f26a294ea1e7a15a4821ba0e73..f6c1bebdb453e0ea30c283c5e682a1d1b289c6c7 100644 --- a/build/lib/iexcode/instruments/xrays.py +++ b/build/lib/iexcode/instruments/xrays.py @@ -361,7 +361,7 @@ def getE(): """ return energy_get() -def grating(grating): +def grating(grating_name): """ used to switch between gratings grating = 'HEG' / 'MEG' @@ -377,13 +377,13 @@ def grating(grating): shutter_open = main_shutter_status() main_shutter_close() print("Switching grating, please wait...") - mono_grating_translate(grating,quiet=True) + mono_grating_change(grating_name,verbose=False) apertures_set() if shutter_open: main_shutter_open() - print(dateandtime()," grating: "+grating) + print(dateandtime()) else: print("grating: "+grating) @@ -391,8 +391,9 @@ def grating_get(): """ returns the current grating """ - grt = mono_grating_get() - return grt + grating_name = mono_grating_get() + return grating_name + def polarization(ID_mode): """ diff --git a/iexcode.egg-info/SOURCES.txt b/iexcode.egg-info/SOURCES.txt index 96e4bca3e9f806b8d9fd2868636f03c0b70768f7..2b4744d96b861d3c672b3cd32c70f034c2ae84ea 100644 --- a/iexcode.egg-info/SOURCES.txt +++ b/iexcode.egg-info/SOURCES.txt @@ -16,6 +16,7 @@ iexcode/instruments/ARPES.py iexcode/instruments/FMB_mirrors.py iexcode/instruments/IEX_BL_config.py iexcode/instruments/IEX_VPU.py +iexcode/instruments/IEX_cameras.py iexcode/instruments/Kappa.py iexcode/instruments/Kappa_det.py iexcode/instruments/Lakeshore_335.py @@ -26,7 +27,6 @@ iexcode/instruments/Scienta.py iexcode/instruments/VLS_PGM.py iexcode/instruments/__init__.py iexcode/instruments/bakeout.py -iexcode/instruments/cameras.py iexcode/instruments/cfg.py iexcode/instruments/conversions_constants.py iexcode/instruments/current_amplifiers.py @@ -57,6 +57,7 @@ iexcode/macros/BL_shutdown.py iexcode/macros/ID_energy_calibration.py iexcode/macros/Kappa_optimization.py iexcode/macros/__init__.py +iexcode/macros/cam_macros.py iexcode/macros/commissioning.py iexcode/macros/quick_plot.py iexcode/macros/start_of_the_week.py diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index ad8520546027f66b8f8505028761c9ebe115fc1c..ca7dc1133fc173608eae53d0f2e686be47b5f83e 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -5,7 +5,7 @@ from epics import caget,caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config -from iexcode.instruments.cameras import _enable_endstation_cameras +from iexcode.instruments.IEX_cameras import _enable_endstation_cameras from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv from iexcode.instruments.Logfile import Logfile diff --git a/iexcode/instruments/IEX_cameras.py b/iexcode/instruments/IEX_cameras.py new file mode 100644 index 0000000000000000000000000000000000000000..63e822095d2e5ebd53be2e354c95be53f4f82087 --- /dev/null +++ b/iexcode/instruments/IEX_cameras.py @@ -0,0 +1,58 @@ +import time +from epics import caget,caput,PV + +import iexcode.instruments.cfg as iex +from iexcode.instruments.AD_utilities import * + +############################################################################################################## +############################## Camera PV dictionary ############################## +############################################################################################################## + +def cam_pv_dictionary(): + """ + dictionary of pv names for the beamline cameras + """ + d={ + 1:"29id_ps1:", + 2:"29id_ps2:", + 3:"29id_ps3:", + 4:"29id_ps4:", + 5:"29idarv5:", + 6:"29id_ps6:", + 7:"29id_ps7:", + } + return d + +############################################################################################################## +############################## Endstation Cameras ############################## +############################################################################################################## + +def _enable_endstation_cameras(unused_off=True): + """ + Turns on cameras related to a given endstation if they are connected + unused_off=True turns off other cameras + + """ + endstation=iex.BL.endstation_name + + #For new endstation modify here: + cam_dict={'ARPES':[0,1,2],'Kappa':[3,4,6]} # index of cam_list + + d=cam_pv_dictionary() + for num in d.keys(): + pv=d[num]+"cam1:Acquire" + #camera in list + if num in cam_dict[endstation]: + #two connected to deal with network traffic + PV(pv).connected + time.sleep(0.1) + if PV(pv).connected: + caput(pv,'Acquire') + else: + print(d[num]+" ioc in not running") + #camera not in list + else: + if unused_off: + if PV(pv).connected: + caput(pv,'Done') + diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py index 86a4a841af608eb0a9cedfbf4e6f16f6aac2a2bb..972b016731285a82c26825b812a03bd9b6488efe 100644 --- a/iexcode/instruments/Kappa.py +++ b/iexcode/instruments/Kappa.py @@ -7,7 +7,7 @@ from epics import caget, caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config -from iexcode.instruments.cameras import _enable_endstation_cameras +from iexcode.instruments.IEX_cameras import _enable_endstation_cameras from iexcode.instruments.staff import staff_detector_dictionary from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda diff --git a/iexcode/instruments/Motors.py b/iexcode/instruments/Motors.py index 5e7756b15fce0ec439ffa87ad051f1ca99152664..35d863936b25b8853221d24a6bd91ff098a4f37c 100644 --- a/iexcode/instruments/Motors.py +++ b/iexcode/instruments/Motors.py @@ -214,20 +214,26 @@ class Motors: kwargs.setdefault('outer_scan_dim',2) kwargs.setdefault('snake',False) kwargs.setdefault('execute',True) + kwargs.setdefault('debug',False) + #for kappa only kwargs.setdefault('cts',0.1) kwargs.setdefault('mpa',False) - from iexcode.instruments.IEX_BL_config import BL - rbv_pv,val_pv,sgm_pv,pv = self._motor_dictionary[inner_loop_list[0]] + inner_loop_list.pop(0) inner_loop_list.insert(0,rbv_pv) inner_loop_list.insert(0,val_pv) rbv_pv,val_pv,sgm_pv,pv = self._motor_dictionary[outer_loop_list[0]] + outer_loop_list.pop(0) outer_loop_list.insert(0,rbv_pv) outer_loop_list.insert(0,val_pv) + if kwargs['debug']: + print('inner_loop_list = ',inner_loop_list) + print('outer_loop_list = ',outer_loop_list) + if kwargs["mode"] == "relative": current_value1 = caget(inner_loop_list[1]) inner_loop_list[2]=round(current_value1+inner_loop_list[2],3) @@ -237,9 +243,8 @@ class Motors: outer_loop_list[2]=round(current_value1+outer_loop_list[2],3) outer_loop_list[3]=round(current_value1+outer_loop_list[3],3) - scaler_cts(kwargs['cts'],verbose=True,**kwargs) - iex.BL.mda.fillin_2D(inner_loop_list,outer_loop_list, - outer_scan_dim=kwargs['outer_scan_dim'],**kwargs) + scaler_cts(kwargs['cts'],verbose=True) + iex.BL.mda.fillin_2D(inner_loop_list,outer_loop_list,**kwargs) if kwargs['execute']: iex.BL.mda.go(**kwargs) diff --git a/iexcode/instruments/VLS_PGM.py b/iexcode/instruments/VLS_PGM.py index 4a40674b807b46f8211d99ea5cc563832cf9c509..8446e1bf6909eb67b546b6b91387715c9fbd9479 100644 --- a/iexcode/instruments/VLS_PGM.py +++ b/iexcode/instruments/VLS_PGM.py @@ -14,24 +14,24 @@ from iexcode.instruments.utilities import print_warning_message,read_dict ############################################################################################################## ################################ mono ############################## ############################################################################################################## -def _mono_grating_names(): +def mono_grating_names(): """ List of grating names """ ext = ['C', 'D', 'E', 'F', 'G', 'H', 'I', "J", "K", "L" ] GRT_names = ["MEG_Imp","HEG","MEG","Dummy", "not used", "not used", "not used","not used","not used","not used"] - GRT_names=GRT_names[0:2] # only use the first 3 slots + GRT_names=GRT_names[0:3] # only use the first 3 slots return GRT_names -def _mono_mirror_names(): +def mono_mirror_names(): """ List of grating names """ ext = ['C', 'D', 'E', 'F', 'G', 'H', 'I', "J", "K", "L" ] MIR_names = ["Au", "Silicon", "Carbon","not used","not used","not used","not used","not used","not used","not used"] - MIR_names=MIR_names[0:2] # only use the first 3 slots + MIR_names=MIR_names[0:3] # only use the first 3 slots return MIR_names def _mono_extensions(): @@ -51,7 +51,7 @@ def mono_energy_range(GRT=None): if GRT == 'HEG': hv_min=120 hv_max=2200 - elif GRT == 'MEG': + else: hv_min=120 hv_max=3000 return hv_min,hv_max @@ -64,14 +64,14 @@ def mono_get_all(verbose=False): """ d = mono_get_all_extended(verbose=False) vals = { - 'hv':d['ENERGY_MON'], - 'hv_sp':d['ENERGY_SP'], - 'grating':d['GRT'], - 'mirror':d['MIR'], + 'hv':d['energy'], + 'hv_sp':d['energy_sp'], + 'grating':d['grt'], + 'mirror':d['mir'], } if verbose: - print(" hv: "+"%.2f" % vals['hv'], "eV, hv_sp: " % vals['hv_sp']) - print(" grating : "+vals['grating']," mirror : "+vals['mirror']) + print(" hv: "+"%.2f" % vals['hv'], "eV, hv_sp: "+"% .2f" % vals['hv_sp']) + print(" grating : "+vals['grating'],", mirror : "+vals['mirror']) return vals def _mono_grating_num(): @@ -97,26 +97,48 @@ def _mono_pvs(grt_num=None,mir_num=None): 'energy':"29idmono:ENERGY_MON", 'energy_sp':"29idmono:ENERGY_SP", 'grt_density':"29idmono:GRT_DENSITY", - 'grt_offset':'29idmonoGRT:P_OFFSETS.'+ext['grt_num'], - 'grt_b2':'29idmonoGRT:B2_CALC.'+ext['grt_num'], - 'grt_pos':'29idmonoGRT:X_DEF_POS.'+ext['grt_num'], - 'grt_LD':'29idmonoGRT:TYPE_CALC.'+ext['grt_num'], - 'grt_tun0':'29idmonoGRT:TUN0_CALC.'+ext['grt_num'], - 'grt_tun1':'29idmonoGRT:TUN1_CALC.'+ext['grt_num'], - 'grt_tun2':'29idmonoGRT:TUN2_CALC.'+ext['grt_num'], - 'grt_tun3':'29idmonoGRT:TUN3_CALC.'+ext['grt_num'], + 'grt_offset':'29idmonoGRT:P_OFFSETS.'+ext[grt_num], + 'grt_b2':'29idmonoGRT:B2_CALC.'+ext[grt_num], + 'grt_pos':'29idmonoGRT:X_DEF_POS.'+ext[grt_num], + 'grt_LD':'29idmonoGRT:TYPE_CALC.'+ext[grt_num], + 'grt_tun0':'29idmonoGRT:TUN0_CALC.'+ext[grt_num], + 'grt_tun1':'29idmonoGRT:TUN1_CALC.'+ext[grt_num], + 'grt_tun2':'29idmonoGRT:TUN2_CALC.'+ext[grt_num], + 'grt_tun3':'29idmonoGRT:TUN3_CALC.'+ext[grt_num], 'grt_type_sp':"29idmonoGRT_TYPE_SP", - 'grt_move':"29idb:'gr:move", + 'grt_type_move':"29idmonoGRT:X_DCPL_CALC.PROC", + 'mir_type_sp':"29idmonoMIR_TYPE_SP", + 'mir_type_move':"29idmonoMIR:X_DCPL_CALC.PROC", + 'mono_pitch_state':'29idmono:ERDY_STS', + 'grt_P_sp':"29idmonoGRT:P_SP", 'grt_P_status':"29idmonoGRT:P_AXIS_STS", + 'grt_P_stop':"29idmonoGRT:P.STOP", + 'grt_P_kill':"29idmonoGRT:P_KILL_CMD.PROC", + 'grt_P_enable':"29idmonoGRT:P_ENA_CMD.PROC", + 'mir_P_sp':"29idmonoMIR:P_SP", 'mir_P_status':"29idmonoMIR:P_AXIS_STS", + 'mir_P_stop':"29idmonoMIR:P.STOP", + 'mir_P_kill':"29idmonoMIR:P_KILL_CMD.PROC", + 'mir_P_enable':"29idmonoMIR:P_ENA_CMD.PROC", + 'grt_X_sp':"29idmonoGRT:X_SP", 'grt_X_status':"29idmonoGRT:X_AXIS_STS", + 'grt_X_stop':"29idmonoGRT:X.STOP", + 'grt_X_kill':"29idmonoGRT:X_KILL_CMD.PROC", + 'grt_X_enable':"29idmonoGRT:X_ENA_CMD.PROC", + 'mir_X_sp':"29idmonoMIR:X_SP", 'mir_X_status':"29idmonoMIR:X_AXIS_STS", - 'mir_offset':'29idmonoMIR:P_OFFSETS.'+ext['mir_num'], - 'mir_pos':'29idmonoMIR:X_DEF_POS.'+ext['mir_num'], + 'mir_X_stop':"29idmonoMIR:X.STOP", + 'mir_X_kill':"29idmonoMIR:X_KILL_CMD.PROC", + 'mir_X_enable':"29idmonoMIR:X_ENA_CMD.PROC", + 'mir_offset':'29idmonoMIR:P_OFFSETS.'+ext[mir_num], + 'mir_pos':'29idmonoMIR:X_DEF_POS.'+ext[mir_num], + 'mono_stop':"29idmono:STOP_CMD.PROC", 'cff':'29idmono:CC_MON', 'arm':'29idmono:PARAMETER.G' + } + return d def mono_get_all_extended(verbose=False): """ @@ -127,22 +149,22 @@ def mono_get_all_extended(verbose=False): """ grt_num = _mono_grating_num() mir_num = _mono_mirror_num() - grt_names = _mono_grating_names() - mir_names = _mono_mirror_names() + grt_names = mono_grating_names() + mir_names = mono_mirror_names() ext=_mono_extensions() - pvs = _mono_pvs(grt_num=None,mir_num=None) + pvs = _mono_pvs() vals={ 'grt_num':grt_num, 'mir_num':mir_num, - 'grt':grt_names[grt_num], - 'mir':mir_names[mir_num], + 'grt':grt_names[grt_num-1], + 'mir':mir_names[mir_num-1], 'energy':caget(pvs['energy']), 'energy_sp':caget(pvs['energy_sp']), - 'grt_density':caget(pvs['energy_sp']), + 'grt_density':caget(pvs['grt_density']), 'grt_offset':caget(pvs['grt_offset']), - 'grt_b2':caget(pvs['grt_offset']), + 'grt_b2':caget(pvs['grt_b2']), 'grt_pos':caget(pvs['grt_pos']), 'grt_LD':caget(pvs['grt_LD']), 'grt_tun0':caget(pvs['grt_tun0']), @@ -155,13 +177,13 @@ def mono_get_all_extended(verbose=False): 'mir_X_status':caget(pvs['mir_X_status']), 'mir_offset':caget(pvs['mir_offset']), 'mir_pos':caget(pvs['mir_pos']), - 'CFF':caget('29idmono:CC_MON'), + 'cff':caget('29idmono:CC_MON'), 'arm':caget('29idmono:PARAMETER.G') } if verbose: for key in vals.keys(): - print(key,vals[key]) + print(key," = ",vals[key]) return vals @@ -171,6 +193,12 @@ def mono_grating_get(): """ return mono_get_all_extended()['grt'] +def mono_mirror_get(): + """ + returns the grating density and the string name for the grating + """ + return mono_get_all_extended()['mir'] + def mono_energy_get(): """ returns the grating density and the string name for the grating @@ -197,14 +225,14 @@ def mono_energy_set(hv_eV,verbose=True): mono_status = mono_status_get() while True: - if mono_status() > 1: + if mono_status > 1: mono_resest_pitch() caput(pv,hv_eV,wait=True,timeout=60) time.sleep(2.5) else: break if verbose: - print("Mono set to",str(hv_eV),"eV") + print("Mono set to",str(round(hv_eV,3)),"eV") def mono_scan_pvs(): """ @@ -223,37 +251,69 @@ def mono_status_get(): Previously Mono_Status """ - pvs = _mono_pvs()['energy'] - mir_P_status = caget(pvs['mir_P_status']) - grt_P_status = caget(pvs['grt_P_status']) - mir_X_status = caget(pvs['mir_P_status']) - grt_X_status = caget(pvs['grt_P_status']) + pvs = _mono_pvs() + mir_P_status = int(caget(pvs['mir_P_status'])) + grt_P_status = int(caget(pvs['grt_P_status'])) + mir_X_status = int(caget(pvs['mir_P_status'])) + grt_X_status = int(caget(pvs['grt_P_status'])) mirror_status = mir_P_status * mir_X_status grating_status = grt_P_status * grt_X_status return mirror_status*grating_status - -def mono_grating_translate(grating,verbose=True): +def mono_grating_change(grating_name,verbose=True): """ Translate between the different grating positions + list grating_name: mono_grating_names() - Warning: this does not close the shutters use XX + Warning: this does not close the shutters use xrays:mirror Previously: Move_GRT """ - current_grating=mono_grating_get() + _mono_optic_change('grating',grating_name, verbose) + +def mono_mirror_change(mirror_name,verbose=True): + """ + Translate between the different mirror positions + list mirror_name: mono_mirror_names() + + Warning: this does not close the shutters + + """ + _mono_optic_change('mirror',mirror_name, verbose) + +def _mono_optic_change(optic,name, verbose=True): + """ + optic = 'mirror','grating' + """ + hv_eV = mono_energy_get() try: - grating_state = _mono_grating_names().index(grating) - + if optic == 'grating': + num = mono_grating_names().index(name)+1 + elif optic == 'mirror': + num = mono_mirror_names().index(name)+1 except: - print_warning_message(grating+' not a valid grating') + print_warning_message(name+' not a valid '+optic) + return + + pvs = _mono_pvs () + if optic == 'grating': + type_get = mono_grating_get() + type_sp = pvs['grt_type_sp'] + type_move = pvs['grt_type_move'] + elif optic == 'mirror': + type_get = mono_mirror_get() + type_sp = pvs['mir_type_sp'] + type_move = pvs['mir_type_move'] + else: + print('Error: optic = ',optic,' not a valid choice') + return - if current_grating != grating: - pvs=_mono_pvs() - caput(pvs['grt_type_sp'],grating_state,wait=True,timeout=18000) - caput(pvs['grt_move'],1,wait=True,timeout=18000) + if type_get != name: + caput(type_sp,num,wait=True,timeout=18000) + caput(type_move,1,wait=True,timeout=18000) + while True: if mono_status_get() > 1: time.sleep(5) @@ -263,20 +323,20 @@ def mono_grating_translate(grating,verbose=True): else: if verbose: - print("grating is already "+grating) + print(optic+" is already "+name) if verbose: - print("Mono Grating:",grating) - + print("Mono "+optic+":",name) def mono_resest_pitch(): """ resets the MIR and GRT pitch interlocks after a following error or limit Previoulsy part of SetMono """ - caput("29idmonoMIR:P.STOP",1) + pv=_mono_pvs() + caput(pv['grt_P_stop'],1) time.sleep(1) - caput("29idmonoGRT:P.STOP",1) + caput(pv['mir_P_stop'],1) time.sleep(1) print('Mono pitch was reset') @@ -286,12 +346,14 @@ def mono_kill(): Previously: Kill_Mono """ - caput("29idmonoMIR:P_KILL_CMD.PROC",1) - caput("29idmonoGRT:P_KILL_CMD.PROC",1) -# caput("29idmonoGRT:X_KILL_CMD.PROC",1) + pv=_mono_pvs() + caput(pv['grt_P_kill'],1) + caput(pv['mir_P_kill'],1) + caput(pv['grt_X_kill'],1) + caput(pv['mir_X_kill'],1) time.sleep(5) - caput("29idmono:STOP_CMD.PROC",1) -# caput("29idmonoGRT:X_HOME_CMD.PROC",1) + mono_stop() + def mono_stop(): @@ -300,7 +362,8 @@ def mono_stop(): Previously: Stop_Mono """ - caput("29idmono:STOP_CMD.PROC",1) + pv=_mono_pvs() + caput(pv['mono_stop'],1) time.sleep(5) def mono_enable(): @@ -309,10 +372,11 @@ def mono_enable(): Previously: Enable_Mono """ - caput("29idmonoGRT:X_ENA_CMD.PROC",1) - caput("29idmonoGRT:P_ENA_CMD.PROC",1) - caput("29idmonoMIR:X_ENA_CMD.PROC",1) - caput("29idmonoMIR:P_ENA_CMD.PROC",1) + pv=_mono_pvs() + caput(pv['grt_P_enable'],1) + caput(pv['mir_P_enable'],1) + caput(pv['grt_X_enable'],1) + caput(pv['mir_X_enable'],1) def mono_limits_reset(): """ @@ -321,50 +385,29 @@ def mono_limits_reset(): Previously: Reset_Mono_Limits """ - # caput("29idmono_GRT_TYPE_SP.ONST", 'MEG_PA') - # caput("29idmono_GRT_TYPE_SP.TWST", 'HEG_JY') - # caput("29idmono_GRT_TYPE_SP.THST", 'MEG_JY') - caput("29idmono:ENERGY_SP.DRVL",200) - caput("29idmono:ENERGY_SP.LOW",200) - caput("29idmono:ENERGY_SP.LOLO",200) - caput("29idmono:ENERGY_SP.LOPR",200) + + pv=_mono_pvs()['energy_sp'] + caput(pv+".DRVL",200) + caput(pv+".LOW",200) + caput(pv+".LOLO",200) + caput(pv+".LOPR",200) print("Mono limits have been reset.") -def mono_cff_print(): - """ - print the cff tuning parameters and arm for the current grating - - Previously: Get_CFF - """ - d = mono_get_all_extended - cff = d['cff'] - tun0 = d['grt_tun0'] - tun1 = d['grt_tun1'] - tun2 = d['grt_tun2'] - tun3 = d['grt_tun3'] - arm = d['arm'] - print(" cff : "+"%.4f" % cff , " exit arm: "+"%.1f" % arm,"mm") - print(" tun0 : "+"%.4e" % tun0 , " tun1: "+"%.4e" % tun1) - print(" tun2 : "+"%.4e" % tun2 , " tun3: "+"%.4e" % tun3) def mono_parameters_pv(grt_num=None,mir_num=None): """ returns dictionary with mono_parameter for current grating/mirror """ - if grt_num is None: - grt_num = _mono_grating_num()() - if mir_num is None: - mir_num = _mono_mirror_num()() - - ext = _mono_extensions() + pvs=_mono_pvs(grt_num,mir_num) + d={ - 'mir_offset':"29idmonoMIR:P_OFFSETS."+ext[mir_num], - 'mir_pos':"29idmonoMIR:X_DEF_POS."+ext[mir_num], - 'grt_offset':"29idmonoGRT:P_OFFSETS."+ext[grt_num], - 'grt_pos':"29idmonoGRT:X_DEF_POS."+ext[grt_num], - 'grt_density':"29idmonoGRT:TYPE_CALC."+ext[grt_num], - 'grt_b2':"29idmonoGRT:B2_CALC."+ext[grt_num] + 'mir_offset':pvs['mir_offset'], + 'mir_pos':pvs['mir_pos'], + 'grt_offset':pvs['grt_offset'], + 'grt_pos':pvs['grt_pos'], + 'grt_density':pvs['grt_density'], + 'grt_b2':pvs['grt_b2'] } return d @@ -376,8 +419,8 @@ def mono_parameters_get(): Previously: Mono_Parameters_Get """ date=time.strftime("%Y%m%d",time.localtime()) - mirList = _mono_mirror_names() - grtList = _mono_grating_names() + mirList = mono_mirror_names() + grtList = mono_grating_names() pvList = _mono_extensions() #MIR @@ -466,7 +509,7 @@ def mono_temperature_interlock(): -def mono_scan_fillin(hv_start,hv_stop,hv_step,**kwargs): +def mono_scan(hv_start,hv_stop,hv_step,**kwargs): """ fills in the scanRecord for scanning the mono @@ -486,7 +529,7 @@ def mono_scan_fillin(hv_start,hv_stop,hv_step,**kwargs): iex.BL.mda.positioner_after_scan("STAY") -def mono_scan_fillin_table(hv_array,**kwargs): +def mono_scan_table(hv_array,**kwargs): """ fills in the scanRecord for scanning the mono @@ -518,16 +561,16 @@ def mono_scan_after(**kwargs): ############################################################################################################## ################################ aligmnent and commissioning ############################## ############################################################################################################## -def mono_motor_move(motor,value): +def mono_motor_move(motor,value,wait=True,timeout=18000): """ for pitch motor => MIR:P or GRT:P for translation motor => MIR:X or GRT:X Previously: Move_FMBMono """ - val_pv,rbv_pv = mono_motor_scan_pvs() + val_pv,rbv_pv = mono_motor_scan_pvs(motor) caput(val_pv+".PREC",3) - caput(val_pv,value,wait=True,timeout=18000) + caput(val_pv,value,wait=wait,timeout=timeout) def mono_motor_scan_pvs(motor): """ @@ -537,7 +580,7 @@ def mono_motor_scan_pvs(motor): rbv_pv = "29idmono"+motor+"_MON" return val_pv,rbv_pv -def mono_motor_scan_fillin(motor,start,stop,step,**kwargs): +def mono_motor_scan(motor,start,stop,step,**kwargs): """ for pitch motor => MIR:P or GRT:P for translation motor => MIR:X or GRT:X @@ -556,12 +599,8 @@ def mono_zero_order(angle): Previously: Mono_zero """ - angle=angle*1.0 - caput("29idmonoMIR:P_POS_SP",angle,wait=True,timeout=18000) - caput("29idmonoMIR:P_MOVE_CMD.PROC",1,wait=True,timeout=18000) - caput("29idmonoGRT:P_POS_SP",angle,wait=True,timeout=18000) - caput("29idmonoGRT:P_MOVE_CMD.PROC",1,wait=True,timeout=18000) - print("Mono set to zero order: MIR_pitch = "+str(angle)+", GRT_pitch = "+str(angle)) + mono_angles_set(angle,angle) + print("Mono set to zero order:") def mono_angles_set(alpha,beta): #JM modified to monitor the ready, moving sequentialy ended up in crash sometimes """ @@ -571,14 +610,16 @@ def mono_angles_set(alpha,beta): #JM modified to monitor the ready, moving seque """ alpha=alpha*1.0 beta=beta*1.0 - #Putting Setpoints Go - caput("29idmonoGRT:P_SP",alpha) - caput("29idmonoMIR:P_SP",beta) - ready=0 - while ready != 1: - time.sleep(0.1) - ready=caget('29idmono:ERDY_STS') - print("Mono set to zero order: MIR_pitch = "+str(alpha)+", GRT_pitch = "+str(beta)) + pvs = _mono_pvs() + + #don't wait during move so they move in parallel (less likely to crash) + caput(pvs['mir_P_sp'],alpha) + caput(pvs['grt_P_sp'],beta) + time.sleep(0.5) #need sleep before things start moving + + while caget(pvs['mono_pitch_state']) != 1: + time.sleep(0.5) + print("MIR_pitch = "+str(alpha)+", GRT_pitch = "+str(beta)) def mono_pink_beam(): """ @@ -587,17 +628,10 @@ def mono_pink_beam(): Previously: Mono_pinkbeam """ - caput("29idmonoMIR:P_POS_SP",0,0) - caput("29idmonoMIR:P_MOVE_CMD.PROC",0) - time.sleep(3) - caput("29idmonoGRT:P_POS_SP",0.0) - caput("29idmonoGRT:P_MOVE_CMD.PROC",0) - time.sleep(3) - caput("29idmonoMIR:X_POS_SP",-52) - caput("29idmonoMIR:X_MOVE_CMD.PROC",0) - time.sleep(3) - caput("29idmonoGRT:X_POS_SP",210) - caput("29idmonoGRT:X_MOVE_CMD.PROC",0,wait=True,timeout=18000) + mono_angles_set(0,0) + pvs=_mono_pvs() + mono_motor_move('MIR:X',-52,wait=False) + mono_motor_move('GRT:X',210,wait=True) def mono_CC(): """ @@ -612,16 +646,24 @@ def mono_CC(): caput("29idmono:ENERGY_SP", 440) +def mono_grating_offset_get(grt_num=None): + pvs=_mono_pvs(grt_num,None) + return caget(pvs['grt_offset']) + def mono_grating_offset_set(val,grt_num=None): """ sets the grating offset for the grating Previously: Mono_Set_GRT0 """ - pvs=_mono_pvs(grt_num,None) + pvs=_mono_pvs(None,None) caput(pvs['grt_offset'],val) mono_get_all_extended(verbose=True) +def mono_mirror_offset_get(mir_num=None): + pvs=_mono_pvs(None,mir_num) + return caget(pvs['mir_offset']) + def mono_mirror_offset_set(val,mir_num=None): """ sets the mirror offset for the grating @@ -663,6 +705,9 @@ def mono_grating_mirror_offsets_set(mirror_offset): mono_energy_set(energy_sp) mono_get_all_extended(verbose=True) +def mono_grating_b2_get(grt_num=None): + pvs = _mono_pvs(grt_num,None) + return caget(pvs['grt_b2']) def mono_grating_b2_set(val,grt_num=None): """ @@ -677,6 +722,24 @@ def mono_grating_b2_set(val,grt_num=None): mono_energy_set(hv) mono_get_all_extended(verbose=True) +def mono_cff_get(): + """ + print the cff tuning parameters and arm for the current grating + + Previously: Get_CFF + """ + d = mono_get_all_extended() + cff = d['cff'] + tun0 = d['grt_tun0'] + tun1 = d['grt_tun1'] + tun2 = d['grt_tun2'] + tun3 = d['grt_tun3'] + arm = d['arm'] + print(" cff : "+"%.4f" % cff , " exit arm: "+"%.1f" % arm,"mm") + print(" tun0 : "+"%.4e" % tun0 , " tun1: "+"%.4e" % tun1) + print(" tun2 : "+"%.4e" % tun2 , " tun3: "+"%.4e" % tun3) + + def mono_cff_set(val,tune_num): """ sets the tuning parameters for the cff calculation @@ -709,6 +772,10 @@ def mono_cff_set(val,tune_num): print('Pitch grating, mirror: ',current_vals['grt_pitch'],current_vals['mir_pitch']) print('Differences : ',grt_dif,mir_dif) +def mono_arm_get(): + pvs = _mono_pvs() + return caget(pvs(['arm'])) + def mono_arm_set(distance_mm): """ sets the exit arm for the grating @@ -725,7 +792,8 @@ def mono_arm_set(distance_mm): print ('Pitch grating, mirror: ',grt_pitch,mir_pitch) #set the exit arm - caput("29idmono:PARAMETER.G",distance_mm) + + caput(pvs(['arm']),distance_mm) time.sleep(1) #set then energy diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py index 2fc7d396b6bc9a886699195dbb43da3a976527af..11f724da53606fee474d5298cd044328b5ee0f91 100644 --- a/iexcode/instruments/scanRecord.py +++ b/iexcode/instruments/scanRecord.py @@ -467,12 +467,16 @@ class ScanRecord: kwargs.setdefault("positioner_num",1) kwargs.setdefault('detector_settling_time',default_detector_settling_time) kwargs.setdefault('positioner_settling_time',default_positioner_settling_time) + kwargs.setdefault('debug',False) self.progress(kwargs['scan_dim']) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) posNum = kwargs['positioner_num'] + if kwargs['debug']: + print('fillin: ',val_pv,rbv_pv,start,stop,steps_points) + caput(scan_pv+".P"+str(posNum)+"PV",val_pv) caput(scan_pv+".R"+str(posNum)+"PV",rbv_pv) caput(scan_pv+".P"+str(posNum)+"SP",start*1.0) @@ -828,7 +832,7 @@ class ScanRecord: ############################################################################################################## ############################# 2D scans typewriter/snake scans ############################## ############################################################################################################## - def fillin_2D(self,inner_loop_list,outer_loop_list,outer_scan_dim=2,**kwargs): + def fillin_2D(self,inner_loop_list,outer_loop_list,**kwargs): """ Fills in a the Scan Record for a 2D scan (Mesh), InnerMotorList=[val_pv1,rbv_pv1,start1,stop1,step1] #scanDIM=1 @@ -841,13 +845,16 @@ class ScanRecord: snake: coming soon """ kwargs.setdefault("snake",False) + kwargs.setdefault("outer_scan_dim",2) + + outer_scan_dim = kwargs['outer_scan_dim'] #fillin inner loop kwargs.update({'scan_dim':outer_scan_dim-1}) self.fillin(inner_loop_list[0],inner_loop_list[1],inner_loop_list[2],inner_loop_list[3],inner_loop_list[4],**kwargs) #fillin outer loop kwargs.update({'scan_dim':outer_scan_dim}) - self.fillin(outer_loop_list[0],outer_loop_list[1],outer_loop_list[2],outer_loop_list[3],outer_loop_list[1],**kwargs) + self.fillin(outer_loop_list[0],outer_loop_list[1],outer_loop_list[2],outer_loop_list[3],outer_loop_list[4],**kwargs) diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py index 0dd844574642d4f26a294ea1e7a15a4821ba0e73..f6c1bebdb453e0ea30c283c5e682a1d1b289c6c7 100644 --- a/iexcode/instruments/xrays.py +++ b/iexcode/instruments/xrays.py @@ -361,7 +361,7 @@ def getE(): """ return energy_get() -def grating(grating): +def grating(grating_name): """ used to switch between gratings grating = 'HEG' / 'MEG' @@ -377,13 +377,13 @@ def grating(grating): shutter_open = main_shutter_status() main_shutter_close() print("Switching grating, please wait...") - mono_grating_translate(grating,quiet=True) + mono_grating_change(grating_name,verbose=False) apertures_set() if shutter_open: main_shutter_open() - print(dateandtime()," grating: "+grating) + print(dateandtime()) else: print("grating: "+grating) @@ -391,8 +391,9 @@ def grating_get(): """ returns the current grating """ - grt = mono_grating_get() - return grt + grating_name = mono_grating_get() + return grating_name + def polarization(ID_mode): """ diff --git a/iexcode/macros/cameras.py b/iexcode/macros/cam_macros.py similarity index 57% rename from iexcode/macros/cameras.py rename to iexcode/macros/cam_macros.py index 877769bd7ca6fb6bbb4a0f974039657d9c2950c1..5bb7727a534f4ccea9e838570eaf0d8b3b7e974f 100644 --- a/iexcode/macros/cameras.py +++ b/iexcode/macros/cam_macros.py @@ -4,60 +4,9 @@ from epics import caget,caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.AD_utilities import * +from iexcode.instruments.IEX_cameras import cam_pv_dictionary from iexcode.macros.quick_plot import * -############################################################################################################## -############################## Camera PV dictionary ############################## -############################################################################################################## - -def _pv_dictionary(): - """ - dictionary of pv names for the beamline cameras - """ - d={ - 1:"29id_ps1:", - 2:"29id_ps2:", - 3:"29id_ps3:", - 4:"29id_ps4:", - 5:"29idarv5:", - 6:"29id_ps6:", - 7:"29id_ps7:", - } - return d - -############################################################################################################## -############################## Endstation Cameras ############################## -############################################################################################################## - -def _enable_endstation_cameras(unused_off=True): - """ - Turns on cameras related to a given endstation if they are connected - unused_off=True turns off other cameras - - """ - endstation=iex.BL.endstation_name - - #For new endstation modify here: - cam_dict={'ARPES':[0,1,2],'Kappa':[3,4,6]} # index of cam_list - - d=_pv_dictionary() - for num in d.keys(): - pv=d[num]+"cam1:Acquire" - #camera in list - if num in cam_dict[endstation]: - #two connected to deal with network traffic - PV(pv).connected - time.sleep(0.1) - if PV(pv).connected: - caput(pv,'Acquire') - else: - print(d[num]+" ioc in not running") - #camera not in list - else: - if unused_off: - if PV(pv).connected: - caput(pv,'Done') - ############################################################################################################## ############################## Camera Snapping an image ############################## @@ -74,7 +23,7 @@ def cam_snap(cam_num,ADtype='TIFF',**kwargs): False => leave saving enabled and camera in single acquision """ - ADplugin = _pv_dictionary()[cam_num]+ADtype+"1:" + ADplugin = cam_pv_dictionary()[cam_num]+ADtype+"1:" AD_snap(ADplugin,**kwargs) @@ -97,7 +46,7 @@ def cam_scan_setup(cam_num,ADtype='TIFF',**kwargs): FileTemplate="%s%s_%4.4d."+dtype; format for filename first %s = filepath, second %s = prefix prefix = dtype by default """ - ADplugin = _pv_dictionary()[cam_num]+ADtype+"1:" + ADplugin = cam_pv_dictionary()[cam_num]+ADtype+"1:" ADplugin_ScanSetup(ADplugin,iex.BL.mda, **kwargs) def cam_live(cam_num): @@ -106,14 +55,14 @@ def cam_live(cam_num): a.k.a free run """ - ADplugin = _pv_dictionary()[cam_num] + ADplugin = cam_pv_dictionary()[cam_num] AD_FreeRun(ADplugin) def cam_done(cam_num,**kwargs): """ stops camera acquisition (not will stop after current acquisition) """ - ADplugin = _pv_dictionary()[cam_num] + ADplugin = cam_pv_dictionary()[cam_num] AD_Done(ADplugin,**kwargs) def cam_save_setup(cam_num,ADtype='TIFF',**kwargs): @@ -122,14 +71,14 @@ def cam_save_setup(cam_num,ADtype='TIFF',**kwargs): **kwargs prefix: beginning of filename """ - ADplugin = _pv_dictionary()[cam_num]+ADtype+"1:" + ADplugin = cam_pv_dictionary()[cam_num]+ADtype+"1:" AD_SaveFileSetup(ADplugin,**kwargs) def cam_last_filepath(cam_num,ADtype='TIFF',verbose=True): """ returns the full path for the last saved image """ - ADplugin = _pv_dictionary()[cam_num]+ADtype+"1:" + ADplugin = cam_pv_dictionary()[cam_num]+ADtype+"1:" fpath = AD_last_filename(ADplugin) return fpath diff --git a/iexcode/macros/quick_plot.py b/iexcode/macros/quick_plot.py index 407c7c239efd093412849a05dd49bac6c477c004..80b46d352d621245f9f89c525fa26daa9985e9e8 100755 --- a/iexcode/macros/quick_plot.py +++ b/iexcode/macros/quick_plot.py @@ -18,6 +18,7 @@ from netCDF4 import Dataset from epics import caget from iexplot.mda import readMDA,scanDim import iexcode.instruments.cfg as iex +from iexcode.instruments.scanRecord import last_mda from iexcode.instruments.current_amplifiers import current2flux #print("EPICS package and dependent functions are not installed") @@ -1506,15 +1507,15 @@ def fit_hkl(mydata,n,pos,det,FWHM,fct='gauss',xrange=None,title='',marker='x',gr return center -def fit_d4(n=iex.BL.mda.lastFileNum()): +def fit_d4(n=last_mda()): d4=fit_mda(n,34,0.1,'gauss',title='mda_'+str(n).zfill(4)) return round(d4,3) -def fit_d3(n=iex.BL.mda.lastFileNum()): +def fit_d3(n=last_mda()): d3=fit_mda(n,33,3,'gauss',title='mda_'+str(n).zfill(4)) return round(d3,3) -def fit_z(n=iex.BL.mda.lastFileNum(),d=33): +def fit_z(n=last_mda(),d=33): z=fit_mda(n,d,500,'erf',title='mda_'+str(n).zfill(4)) return round(z,0)