diff --git a/build/lib/iexcode/instruments/IEX_VPU.py b/build/lib/iexcode/instruments/IEX_VPU.py index 142e4fce0b16166aa70067ec1b9e56d44338fe92..feab47091c7794b56af95953b0a345c2bfb13251 100644 --- a/build/lib/iexcode/instruments/IEX_VPU.py +++ b/build/lib/iexcode/instruments/IEX_VPU.py @@ -8,36 +8,39 @@ from epics import caget, caput from iexcode.instruments.userCalcs import userCalcOut_clear from iexcode.instruments.utilities import dateandtime, print_warning_message, read_dict from iexcode.instruments.VLS_PGM import mono_grating_get -from iexcode.instruments.shutters import main_shutter_open +from iexcode.instruments.shutters import shutter_check IDcal_path="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries" ############################################################################################################## ################################ ID limits and calibration ############################## ############################################################################################################## - -pv = 'ID29:' -pvs={'AccessSecurity':pv+'AccessSecurity.VAL', - 'mode_rbv':pv+'ActualMode', - 'mode_val':pv+'DesiredMode.VAL', - 'check_ready':pv+'feedback.VAL', - 'check_busy':pv+'BusyRecord', - 'busy_reset':pv+'Busy.VAL', - 'main_power':pv+'Main_on_off.VAL', - 'energy_rbv':pv+'Energy.VAL', - 'energy_sp':pv+'EnergySet.VAL', - 'start_ramp':pv+'StartRamp.VAL', - 'energy_eV_rbv':pv+'EnergyRBV', - 'energy_eV_sp':pv+'EnergyScanSet.VAL', - 'scan_eV_rbv':pv+'EnergyScanSeteV', - 'scan_eV_val':pv+'EnergySetRBV', - 'table_dir':pv+'TableDirection', - 'By_q':pv+'ByqRdbk', - 'Bx_q':pv+'BxqRdbk', - 'Vcoil':pv+'ByRdbk.VAL', - 'Hcoil':pv+'BxRdbk.VAL', +def ID_pvs(): + """ + dictionary of ID pvs + """ + pv = 'ID29:' + pvs={'AccessSecurity':pv+'AccessSecurity.VAL', + 'mode_rbv':pv+'ActualMode', + 'mode_val':pv+'DesiredMode.VAL', + 'check_ready':pv+'feedback.VAL', + 'check_busy':pv+'BusyRecord', + 'busy_reset':pv+'Busy.VAL', + 'main_power':pv+'Main_on_off.VAL', + 'energy_rbv':pv+'Energy.VAL', + 'energy_sp':pv+'EnergySet.VAL', + 'start_ramp':pv+'StartRamp.VAL', + 'energy_eV_rbv':pv+'EnergyRBV', + 'energy_eV_sp':pv+'EnergyScanSet.VAL', + 'scan_eV_rbv':pv+'EnergyScanSeteV', + 'scan_eV_val':pv+'EnergySetRBV', + 'table_dir':pv+'TableDirection', + 'By_q':pv+'ByqRdbk', + 'Bx_q':pv+'BxqRdbk', + 'Vcoil':pv+'ByRdbk.VAL', + 'Hcoil':pv+'BxRdbk.VAL', 'QP_ratio':pv+'QuasiRatio.RVAL',} - + return pvs def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1=LCP,2=V,3=H) @@ -54,7 +57,7 @@ def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1= except KeyError: message_string='Not a valid ID mode!'+"\nValid Modes: "+str(ID_mode_list()) print_warning_message(message_string) - ID=caget(pvs['energy_rbv']) + ID=caget(ID_pvs()['energy_rbv']) return round(ID,1) ############################################################################################################## @@ -62,7 +65,7 @@ def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1= ############################################################################################################## -def ID_wait_for_permission(): +def ID_wait_for_permission(verbose=True): """ Monitors the ID permissions and waits for the ID to be in User Mode and then breaks Checks the status every 30 seconds @@ -70,12 +73,13 @@ def ID_wait_for_permission(): Previously: WaitForPermission """ while True: - ID_Access=caget(pvs['AccessSecurity']) + ID_Access=caget(ID_pvs()['AccessSecurity']) if (ID_Access!=0): print("Checking ID permission, please wait..."+dateandtime()) sleep(30) else: - print("ID now in user mode -"+dateandtime()) + if verbose: + print("ID now in user mode -"+dateandtime()) break ############################################################################################################## @@ -88,7 +92,7 @@ def ID_get_all(verbose=False): vals={ "ID_mode":ID_mode_get(verbose=False), "ID_QP_ratio":ID_QP_ratio_get(verbose=False), - "ID_sp":caget(pvs['energy_sp']), + "ID_sp":caget(ID_pvs()['energy_sp']), "ID_rbv":ID_get_eV(verbose=False) } @@ -104,7 +108,7 @@ def ID_energy_range(ID_mode=None): Previously: ID_Range """ if ID_mode == None: - ID_state=caget(pvs['mode_rbv']) + ID_state=caget(ID_pvs()['mode_rbv']) else: ID_state = ID_state_mode(ID_mode) # RCP,LCP, V , H , HN @@ -149,7 +153,7 @@ def ID_state_get(): """ Returns the current ID state """ - ID_state = caget(pvs['mode_rbv']) + ID_state = caget(ID_pvs()['mode_rbv']) return ID_state def ID_mode_get(verbose=True): @@ -167,33 +171,42 @@ def ID_mode_set(ID_mode): """ writes the desired mode to the correct ID pv """ - caput(pvs['mode_val'],ID_mode,wait=True,timeout=18000) # RCP + caput(ID_pvs()['mode_val'],ID_mode,wait=True,timeout=18000) # RCP -def ID_ready(verbose=True): +def ID_ready(verbose=False): """ check both the read and busy pv every 2 seconds Previously: ID_Ready """ while True: - RBV=caget(pvs['energy_rbv']) - checkready=caget(pvs['check_ready']) - checkbusy=caget(pvs['check_busy']) - if (checkready!="Ready") or (RBV < 3.7): + RBV = caget(ID_pvs()['energy_rbv']) + checkready = caget(ID_pvs()['check_ready']) + checkbusy = caget(ID_pvs()['check_busy'],as_string=True) + if (checkready!="Ready"): + print('checkready',checkready) sleep(2) - elif ((checkready=="Ready") and (RBV > 3.7)) and (checkbusy=="Busy"): - caput(pvs['busy_reset'],0) + if checkbusy=="Busy": + sleep(2) + print('checkbusy',checkbusy) + else: + if RBV > 3.7: + #thinks its done but isn't, need to reset busy + caput(ID_pvs()['busy_reset'],0) + sleep(2) + if verbose: + print('resetting ID busy record') else: if verbose: - print("ID Ready") - return True + print("ID Ready") + return True def ID_power_status(): """ gets if the ID power supplies are On or Off """ - ID_OnOff=caget(pvs['main_power']) + ID_OnOff=caget(ID_pvs()['main_power']) if ID_OnOff == 1: return 'Off' elif ID_OnOff == 0: @@ -203,8 +216,8 @@ def ID_off(verbose=True): """ waits for permission then turns on the main coils OFF """ - ID_wait_for_permission() - caput(pvs['main_power'],1,wait=True,timeout=18000) + ID_wait_for_permission(verbose=False) + caput(ID_pvs()['main_power'],1,wait=True,timeout=18000) sleep(5) if verbose: print("ID is now off") @@ -215,12 +228,12 @@ def ID_on(verbose=True): waits for permission then turns on the main coils On """ - ID_wait_for_permission() + ID_wait_for_permission(verbose=False) if verbose: print("Starting ID - "+dateandtime()) - caput(pvs['energy_sp'],3.8) - caput(pvs['main_power'],0,wait=True,timeout=18000) + caput(ID_pvs()['energy_sp'],3.8) + caput(ID_pvs()['main_power'],0,wait=True,timeout=18000) def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True): """ @@ -240,7 +253,7 @@ def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True): ID_mode_set(ID_mode, verbose) #opens the main shutter if ID_ready(): - main_shutter_open() + shutter_check(verbose) if verbose: print('ID is now on, please set your energy') @@ -254,8 +267,8 @@ def ID_switch_mode(ID_mode): Previously Switch_IDMode """ - ID_wait_for_permission() - main_shutter_open() + ID_wait_for_permission(verbose=False) + shutter_check(verbose=False) ID_state = ID_state_get() try: @@ -275,7 +288,7 @@ def ID_get(verbose=False): """ returns the readback value for the """ - ID_RBV = caget(pvs['energy_rbv']) + ID_RBV = caget(ID_pvs()['energy_rbv']) if verbose: print("ID_RBV: ", ID_RBV) return ID_RBV @@ -289,6 +302,20 @@ def ID_get_eV(verbose=False): print("ID_RBV: ", ID_RBV) return ID_RBV +def _ID_write_SP_proc(keV): + ramp_delay=5 + caput(ID_pvs()['energy_sp'],keV,wait=True,timeout=18000) + sleep(ramp_delay) + caput(ID_pvs()['start_ramp'],1,wait=True,timeout=18000) + +def _ID_bw_ok(keV): + ID_SP = caget(ID_pvs()['energy_sp']) + ID_bw = ID_SP * 0.095 + ID_diff = abs(ID_get()-keV) + if ID_diff > ID_bw: + return False + else: + return True def ID_set(keV,verbose=True): """ @@ -296,49 +323,42 @@ def ID_set(keV,verbose=True): Previously: SetID_Raw """ - def _ID_write_SP_proc(keV): - caput(pvs['energy_sp'],keV,wait=True,timeout=18000) - sleep(0.5) - caput(pvs['start_ramp'],1) - - def _ID_bw_ok(keV,verbose=False): - ID_SP = caget(pvs['energy_sp']) - ID_bw = ID_SP * 0.095 - ID_diff = abs(ID_get()-keV) - if ID_diff > ID_bw: - return False - else: - return True + + #check if I'm already there + ID_SP = round(caget(ID_pvs()['energy_sp']),3) + if round(keV,3) == ID_SP: + if verbose: + print("ID already at "+str(ID_SP)) + else: - #checking permissions and opening the main shutter - ID_wait_for_permission() - main_shutter_open() + #checking permissions and opening the main shutter + ID_wait_for_permission(verbose=False) + shutter_check(verbose=False) - #checking if desired is with allowed range, if not printing the nearest allowed value - ID_max,ID_min = ID_energy_range() - if keV < ID_min or keV > ID_max: - message_string="Set point out of BL energy range \nPlease select a different energy." - message_string+="\nClosest allowed value is "+str(min(max(keV,ID_min),ID_max)) - print_warning_message(message_string) - else: - #desired energy is within range - _ID_write_SP_proc(keV) - # ID not at energy - ready = ID_ready(verbose=False) - if ready: - #set the energy - _ID_write_SP_proc(ID_SP/1000) - while not ID_ready(verbose=False): - sleep(20) - #is ID within some bandwidth - if _ID_bw_ok(ID_SP,verbose=verbose): + #checking if desired is with allowed range, if not printing the nearest allowed value + ID_min,ID_max = ID_energy_range() + if keV < ID_min or keV > ID_max: + message_string="Set point out of BL energy range \nPlease select a different energy." + message_string+="\nClosest allowed value is "+str(min(max(keV,ID_min),ID_max)) + print_warning_message(message_string) + else: + #set energy sp and ramp + _ID_write_SP_proc(keV) + + ID_ready(verbose=False) + #run twice to make sure ready (sometime busy is weird and instantaneously give ready) + ID_ready(verbose=False) + + #check if ID within some bandwidth + if _ID_bw_ok(ID_SP): if verbose: - ID_SP = caget(pvs['energy_sp']) + ID_SP = caget(ID_pvs()['energy_sp']) ID_RBV = ID_get() print("ID SET : "+"%.1f" % ID_SP, "eV") print("ID RBV : "+"%.1f" % ID_RBV, "eV") - print(caget(pvs['table_dir'],as_string=True)) + print(caget(ID_pvs()['table_dir'],as_string=True)) else: + print_warning_message("ID not within energy bandwidth") ID_QP_ratio_get(verbose) @@ -363,10 +383,10 @@ def ID_QP_ratio_get(verbose=True): calculate the QP ratio """ - Byq=caget(pvs['By_q']) - Vcoil=caget(pvs['Vcoil']) + Byq=caget(ID_pvs()['By_q']) + Vcoil=caget(ID_pvs()['Vcoil']) ratio_calc=round(Byq/Vcoil,3)*100 - ratio_RBV=caget(pvs['QP_ratio']) + ratio_RBV=caget(ID_pvs()['QP_ratio']) if verbose: print("QP RBV =", ratio_RBV,"%") print("QP calculated ratio =", ratio_calc ,"%") @@ -467,8 +487,8 @@ def ID_scan_pvs(): """ returns the rbv and val for scanning """ - val_pv=pvs['scan_eV_val'] - rbv_pv=pvs['scan_eV_rbv'] + val_pv=ID_pvs()['scan_eV_val'] + rbv_pv=ID_pvs()['scan_eV_rbv'] return rbv_pv, val_pv def ID_scan_fillin(mda,scan_dim,start,stop,step,**kwargs): diff --git a/build/lib/iexcode/instruments/diagnostics.py b/build/lib/iexcode/instruments/diagnostics.py index e062b81e0cd6496867ce78bf16316549ad3c67e7..104d7939540081b5ebd0faf566fa834ab40df6c7 100644 --- a/build/lib/iexcode/instruments/diagnostics.py +++ b/build/lib/iexcode/instruments/diagnostics.py @@ -8,6 +8,61 @@ import iexcode.instruments.cfg as iex ############################################################################################################## ################################ default positions ############################## ############################################################################################################## +def diagnostics_go2(diag_name,preset_name): + pv = _diagnostics_preset_pv(diag_name,preset_name) + caput(pv+'_Trigger.PROC',1) + +def diagnostics_sp_read(diag_name,preset_name): + pv = _diagnostics_preset_pv(diag_name,preset_name) + caget(pv+'_Setpoint.VAL') + +def _diagnostics_sp_write(diag_name,preset_name): + pv = _diagnostics_preset_pv(diag_name,preset_name) + caget(pv+'_Setpoint.VAL') + +def _diagnostics_preset_pv(diag_name,preset_name): + """ + dictionary of the motor pvs for the beamline diagnostics + """ + ioc = '29idb:' + d = _diagnostics_get_presets() + pv=None + + if diag_name.casefold() in (key.casefold() for key in list(d.keys())): + idx = [item.lower() for item in list(d.keys())].index(diag_name.lower()) + diag_name=list(d.keys())[idx] + if preset_name.casefold() in (preset.casefold() for preset in d[diag_name]): + idx = [item.lower() for item in d[diag_name]].index(preset_name.lower()) + preset_name = d[diag_name][idx] + pv = ioc+diag_name+'_'+preset_name + else: + message ='preset_name = '+preset_name+' not a valid name' + message +='\npreset_names:'+str(d[diag_name]) + print_warning_message(message) + + else: + message = 'diag_name = '+diag_name+' not a valid name' + message +='\npreset_names:'+str(list(d.keys())) + print_warning_message(message) + + return pv + +def _diagnostics_get_presets(): + presets={ + 'H-wire':['OUT','Start'], + 'V-wire':['OUT','Start'], + 'H-Diagon':['OUT','Si-2800','ML-400','ML-460'], + 'V-Diagon':['OUT','Si-2800','ML-400','ML-460'], + 'D1A':['OUT','Mesh'], + 'D2B':['OUT','Mesh','YAG'], + 'D3B':['OUT','YAG'], + 'D4C':['OUT','Mesh','YAG'], + 'gas-cell':['OUT','Diode1','Diode2'], + 'D4D':['OUT','Mesh','YAG'], + 'D5D':['OUT','Mesh','YAG'], + } + return presets + ###### We should make pvs in the 29idb ioc to hold these values: def _diagnostics_dict(): diff --git a/build/lib/iexcode/instruments/shutters.py b/build/lib/iexcode/instruments/shutters.py index e30e9f6ad338a8ab4bdc0181f25c515919588d15..0ac7e1143db1c9911a8d2667da4aa0294bf561ca 100644 --- a/build/lib/iexcode/instruments/shutters.py +++ b/build/lib/iexcode/instruments/shutters.py @@ -8,7 +8,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.utilities import dateandtime -def shutter_check(): +def shutter_check(verbose=True): """ Checks main shutter is open, if not opens it" Checks brancg shutter is open, if not opens it" @@ -22,9 +22,11 @@ def shutter_check(): main_shutter_open() sleep(10) else: - print("Shutter is now open" , dateandtime()) + if verbose: + print("Shutter is now open" , dateandtime()) break shutter_open = branch_shutter_status() + if shutter_open == False: branch_shutter_open() diff --git a/build/lib/iexcode/instruments/slits.py b/build/lib/iexcode/instruments/slits.py index f8a3b82764f3ac6fdf28c633e152a464fbde26a0..612bb84098b21a64d6ff265f44a2423ece2b4d26 100644 --- a/build/lib/iexcode/instruments/slits.py +++ b/build/lib/iexcode/instruments/slits.py @@ -68,10 +68,10 @@ def slits_pvs(slit_name): center.append((center_val,center_rbv)) else: for slit_HV in d[slit_name]: - size_val = slit_HV +'size.VAL' - size_rbv = slit_HV +'t2.C' - center_val = slit_HV +'center.VAL' - center_rbv = slit_HV +'t2.D' + size_rbv = slit_HV +'size.VAL' + size_val = slit_HV +'t2.C' + center_rbv = slit_HV +'center.VAL' + center_val = slit_HV +'t2.D' size.append((size_val,size_rbv)) center.append((center_val,center_rbv)) else: @@ -121,8 +121,9 @@ def slits_set(slit_name,size,center,verbose=True,wait=True): synchs the slit motors and the slit table and then sets the center and size slit_name is key in slits_dictionary - size = (H_size, V_size) #inf => all the way open + size = (H_size, V_size) #inf in direction specified => all the way open center = (H_center, V_center) + None=> use current value Previously: SetSlit """ @@ -133,14 +134,22 @@ def slits_set(slit_name,size,center,verbose=True,wait=True): if inf in size: size = _slits_wide_open_dictionary()[slit_name] - + size_pvs,center_pvs = slits_pvs(slit_name) + for i in range(0,len(size_pvs)): + #get pvnames size_rbv, size_val, = size_pvs[i] center_rbv,center_val = center_pvs[i] - if center_rbv != None: - caput(center_val, center[i],wait=wait,timeout=180) + #check if there is a pv + if center_rbv != None: + #check if specified value + if center[i] != None: + caput(center_val, center[i],wait=wait,timeout=180) + #check if there is a pv if size_rbv != None: + #check if specified value + if size[i] != None: caput(size_val, size[i],wait=wait,timeout=180) if verbose: @@ -280,7 +289,7 @@ def slit1A_set(H_size,V_size,verbose=True,**kwargs): Previously: SetSlit1A """ - kwargs.setdefault('center',(0,0)) + kwargs.setdefault('center',(None,None)) slit_name = 'slit1A' size = (H_size,V_size) @@ -304,7 +313,7 @@ def slit2B_set(H_size,V_size,verbose=True,**kwargs): Previously: SetSlit2B """ - kwargs.setdefault('center',(0,0)) + kwargs.setdefault('center',(None,None)) slit_name = "slit2B" size = (H_size,V_size) diff --git a/build/lib/iexcode/instruments/utilities.py b/build/lib/iexcode/instruments/utilities.py index fb052f8e1087624849bcdaf1e13303f4246976ea..7dd7914457230e382dbc9e38b3263ecab5e0f578 100644 --- a/build/lib/iexcode/instruments/utilities.py +++ b/build/lib/iexcode/instruments/utilities.py @@ -115,7 +115,7 @@ def read_dict(filename,**kwargs): if 'path' in kwargs: path = kwargs['path'] else: - path = os.path.join(os.path.dirname(__file__),'IEX_dictionaries') + path = os.path.join(os.path.dirname(os.path.dirname(__file__)),'IEX_dictionaries') fpath = os.path.join(path,filename) with open(fpath) as f: for c,line in enumerate(f.readlines()): diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py index 5aa6707c149a9e611f5ed9d5aa530a8ca96222c9..e61e120d4087786f666ae2d48fe2e1a4633b9752 100644 --- a/build/lib/iexcode/instruments/xrays.py +++ b/build/lib/iexcode/instruments/xrays.py @@ -299,7 +299,7 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True): Previously: SetSlit_BL """ hv_rbv = mono_energy_get() - grt = mono_grating_get + grt = mono_grating_get() # slit were defined for the range: 500 - 2000 hv = max(hv_rbv,500) @@ -312,7 +312,7 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True): V=0.65*c # set to 65% of RR calculation (no longer 80%) => cf 2016_2_summary try: - slit_position = read_dict(FileName='Dict_Slit.txt') + slit_position = read_dict('Dict_Slit.txt') except KeyError: print_warning_message("Unable to read dictionary") return @@ -324,8 +324,9 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True): Size1A=( aperture_fit(hv,1)[0]*c_1A, aperture_fit(hv,1)[1]*c_1A ) Size2B=( aperture_fit(hv,2)[0]*c_2B, round(aperture_fit(hv,2)[1]*c_2B*V,3)) - slit1A_set(Size1A[0],Size1A[1],H1_center,V1_center,verbose) # standard operating - slit1A_set(Size2B[0],Size2B[1],H2_center,V2_center,verbose) + + slit1A_set(Size1A[0],Size1A[1],center=(H1_center,V1_center),verbose=verbose) # standard operating + slit2B_set(Size2B[0],Size2B[1],center=(H2_center,V2_center),verbose=verbose) def mvID(val,QP_ratio=100): @@ -514,40 +515,6 @@ def BL_energy_tables(start_stop_step_lists,**kwargs): return mono_array,ID_array -############################################################################################################## -########################### shutter check ###################### -############################################################################################################## - -def shutter_check(verbose=True): - """ - Opens the shutter in the branch determined from the position of m3r - - Previously: Check_BranchShutter - """ - #main shutter - if main_shutter_status: - if verbose: - print("Main shutter already open") - else: - main_shutter_open() - - #branch shutter - branch = m3r_branch(verbose) - if branch_shutter_status(branch): - if verbose: - print(dateandtime(), +branch+" shutter already open..." ,) - else: - while True: - if branch_shutter_status(branch) == False : - if verbose: - print(dateandtime(), "Opening "+branch+" shutter ..." ,) - branch_shutter_open(branch,verbose=False) - sleep(30) - else: - print(dateandtime(), +branch+" shutter is now open..." ,) - break - - ############################################################################################################## ########################### switch branch ###################### ############################################################################################################## diff --git a/iexcode.egg-info/SOURCES.txt b/iexcode.egg-info/SOURCES.txt index 514373e134e7fa61cd972510592a01d7eedd375e..5f295bd671f74ac49c3b658661a3bb5ab234b1ec 100644 --- a/iexcode.egg-info/SOURCES.txt +++ b/iexcode.egg-info/SOURCES.txt @@ -11,6 +11,20 @@ iexcode.egg-info/SOURCES.txt iexcode.egg-info/dependency_links.txt iexcode.egg-info/requires.txt iexcode.egg-info/top_level.txt +iexcode/IEX_dictionaries/Dict_IDCal.txt +iexcode/IEX_dictionaries/Dict_IDCal_QP70.txt +iexcode/IEX_dictionaries/Dict_M0.txt +iexcode/IEX_dictionaries/Dict_M1.txt +iexcode/IEX_dictionaries/Dict_M3.txt +iexcode/IEX_dictionaries/Dict_Slit.txt +iexcode/IEX_dictionaries/Dict_TempDiode.txt +iexcode/IEX_dictionaries/DiodeResponsivityCurve +iexcode/IEX_dictionaries/DiodeResponsivityCurve_2 +iexcode/IEX_dictionaries/Flux_Curves.txt +iexcode/IEX_dictionaries/Flux_Curves_QP70.txt +iexcode/IEX_dictionaries/M0M1_positions.py +iexcode/IEX_dictionaries/calibrationToFix.txt +iexcode/IEX_dictionaries/mono_parameters.txt iexcode/instruments/AD_utilities.py iexcode/instruments/ARPES.py iexcode/instruments/FMB_mirrors.py diff --git a/iexcode/IEX_dictionaries/Dict_IDCal_QP70.txt b/iexcode/IEX_dictionaries/Dict_IDCal_QP70.txt new file mode 100644 index 0000000000000000000000000000000000000000..8eca1ee8a8f813ed13dae5a2aeeee875ef9f84de --- /dev/null +++ b/iexcode/IEX_dictionaries/Dict_IDCal_QP70.txt @@ -0,0 +1,2 @@ +======= 20220720: +{'HEG': {0: [[600.0, [-3934.5121751152246, 33.06771682164138, -0.09748027014943843, 0.00013134538357912652, -6.6156258423234e-08]], [2200.0, [37.641114276917925, 0.8805247038981882, 0.000177319710501711, -8.681533726733966e-08, 1.637418437746742e-11]], [2475.0, [37283044.37499022, -66946.28212137106, 45.04278902689384, -0.013457675462255252, 1.506533154743431e-06]], [3000.0, [17.45662531316536, 0.9879977565183667, -1.4023065577422464e-05, 4.13598612141151e-08, -1.10678651468184e-11]]], 3: [[600.0, [-327.2776484031912, 4.250523583656505, -0.011420286241297649, 1.7377653116404346e-05, -9.625686600221612e-09]], [2200.0, [115.13378003090979, 0.62518020085401, 0.000493471405264986, -2.541590613504621e-07, 4.7566608931331754e-11]], [2475.0, [67723621.24081981, -121554.95831214589, 81.75236674834781, -0.02441691402082744, 2.7324624578449198e-06]], [3000.0, [282015.3094934323, -421.5392502375951, 0.2368599641813117, -5.886206039411446e-05, 5.4722692634234e-09]]], 2: [[600.0, [-604.5006436697821, 3.0530278050672597, 0.0006285185258970196, -7.876285868395855e-06, 6.618688516815772e-09]], [2200.0, [34.67137980324179, 0.8848938354598829, 0.00017775770898386393, -9.469862981232054e-08, 1.8324158207531115e-11]], [3000.0, [-2860246.725610371, 5647.919349714751, -4.443144683580959, 0.0017419171106990991, -3.403199365489676e-07, 2.651081000072826e-11]]], 1: [[600.0, [-5546.5982856048695, 45.335675108612506, -0.13258153746595475, 0.000176077206850398, -8.750569596947354e-08]], [2200.0, [92.51295555787782, 0.6803805602551622, 0.000465091752020332, -2.401401686918187e-07, 4.423893424043697e-11]], [2475.0, [3449361.27208402, -5801.739949520198, 3.631288689620224, -0.0010005763773733346, 1.0226450881073942e-07]], [3000.0, [3927.9644361329165, 2.1528284786200116, -0.004967658772507909, 2.429386882858212e-06, -3.4831847463365186e-10]]]}, 'MEG': {0: [[600.0, [-3001.937193310452, 21.42281919811338, -0.05227046427223767, 5.905824890998193e-05, -2.4939838147750625e-08]], [2000.0, [313.0968883306113, -0.2938296061789439, 0.001699091022186045, -9.91811118699757e-07, 2.153713696737839e-10]]], 3: [[400.0, [316.61188617261655, -1.0928356160426151, 0.001606873234993028, 1.0630167423682258e-05, -1.7235785616953938e-08]], [600.0, [2151.088181587851, -14.957751114654686, 0.04372332202114167, -5.323639729278192e-05, 2.423772386377759e-08]], [2000.0, [71.32298980283552, 0.68449538511254, 0.0002902770466891661, -1.3380458329376547e-07, 2.74232295907911e-11]]], 2: [[600.0, [-256.95386250879153, 1.742041461292414, 0.0004447575432601805, -3.4622258899824124e-06, 2.763500097429317e-09]], [2000.0, [45.57685538381576, 0.724721099465095, 0.0003123695989474393, -1.839135169295821e-07, 4.415613512235391e-11]]], 1: [[600.0, [-10147.599023252156, 76.83462945874766, -0.21225269846559314, 0.000262824484491281, -1.214906763653339e-07]], [2000.0, [64.74418160981251, 0.7253703579324517, 0.00020677370737382257, -3.1583128363601195e-08, -8.981349903206108e-12]]]}} diff --git a/iexcode/IEX_dictionaries/Dict_M0.txt b/iexcode/IEX_dictionaries/Dict_M0.txt new file mode 100644 index 0000000000000000000000000000000000000000..662b047ee2512002af2b4a69c2cd7b6a17b11176 --- /dev/null +++ b/iexcode/IEX_dictionaries/Dict_M0.txt @@ -0,0 +1,5 @@ +======= 20220913: +{"TX":0,"TY":0, "TZ":0, "RX":0,"RY":0, "RZ":0} + +======= 20220914: +{'TX': 0.301, 'TY': -22.5, 'TZ': 0.301, 'RX': -0.0, 'RY': -0.151, 'RZ': 0.039} diff --git a/iexcode/IEX_dictionaries/Dict_M1.txt b/iexcode/IEX_dictionaries/Dict_M1.txt new file mode 100644 index 0000000000000000000000000000000000000000..95d9b39c8c3b631f3beae3624f9b5bd821604b40 --- /dev/null +++ b/iexcode/IEX_dictionaries/Dict_M1.txt @@ -0,0 +1,8 @@ +======= 20220913: +{"TX":0,"TY":0, "TZ":0, "RX":0,"RY":0, "RZ":0} + +======= 20220914: +{'TX': 1.449, 'TY': -21.5, 'TZ': 1.449, 'RX': -0.0, 'RY': 8.439, 'RZ': 3.47} + +======= 20220914: +{'TX': 1.449, 'TY': -21.5, 'TZ': 1.449, 'RX': -0.0, 'RY': 8.439, 'RZ': 3.47} diff --git a/iexcode/IEX_dictionaries/Dict_M3.txt b/iexcode/IEX_dictionaries/Dict_M3.txt new file mode 100644 index 0000000000000000000000000000000000000000..76eac698dc243569e7507d91b147a4d59964f457 --- /dev/null +++ b/iexcode/IEX_dictionaries/Dict_M3.txt @@ -0,0 +1,2 @@ +======= 20220614: +{"TX":-2.5,"TY":0, "TZ":0, "RX":-13.955,"RY":-16.322, "RZ":-8.5} diff --git a/iexcode/IEX_dictionaries/Dict_Slit.txt b/iexcode/IEX_dictionaries/Dict_Slit.txt index 12ba84e10e0a5536d0f46c66aabe0d9649c9084a..084d24d45838e55877ad98b95ccbd217107a7da2 100644 --- a/iexcode/IEX_dictionaries/Dict_Slit.txt +++ b/iexcode/IEX_dictionaries/Dict_Slit.txt @@ -1,4 +1,3 @@ - ======= 20201231: {'HEG':{'S1H':0,'S1V':0.25,'S2H':0,'S2V':-0.75},'MEG':{'S1H':0.25,'S1V':0.125,'S2H':-0.5,'S2V':0.5}} @@ -133,3 +132,50 @@ ======= 20220329: {'HEG': {'S2V': -0.244, 'S2H': -0.125, 'S1V': 0.0, 'S1H': 0.09}, 'MEG': {'S2V': 0.05, 'S2H': -0.02, 'S1V': -0.05, 'S1H': 0.1}} + +======= 20220405: +{'HEG': {'S2V': -0.015, 'S2H': -0.028, 'S1V': -0.041, 'S1H': 0.107}, 'MEG': {'S2V': 0.05, 'S2H': -0.02, 'S1V': -0.05, 'S1H': 0.1}} + +======= 20220405: +{'HEG': {'S2V': -0.015, 'S2H': -0.028, 'S1V': -0.041, 'S1H': 0.107}, 'MEG': {'S2V': -0.0725, 'S2H': 0.1813, 'S1V': -0.0789, 'S1H': 0.1735}} + +======= 20220412: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.0725, 'S2H': 0.1813, 'S1V': -0.0789, 'S1H': 0.1735}} + +======= 20220412: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': 0.2254, 'S2H': -0.0578, 'S1V': -0.0666, 'S1H': 0.1837}} + +======= 20220419: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.017, 'S2H': -0.1458, 'S1V': -0.02759, 'S1H': 0.198}} + +======= 20220531: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.002, 'S2H': 0.2313, 'S1V': -0.509, 'S1H': 0.1616}} + +======= 20220603: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.0049, 'S2H': 0.0096, 'S1V': -0.0544, 'S1H': 0.1711}} + +======= 20220607: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.0073, 'S2H': 0.1322, 'S1V': -0.0689, 'S1H': 0.139}} + +======= 20220614: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.0169, 'S2H': 0.231, 'S1V': -0.0, 'S1H': 0.1256}} +======= 20220621: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': 0.0028, 'S2H': -0.1809, 'S1V': -0.0472, 'S1H': 0.1476}} + +======= 20220629: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.0065, 'S2H': -0.3358, 'S1V': -0.1502, 'S1H': 0.2736}} + +======= 20220705: +{'HEG': {'S2V': -0.0135, 'S2H': -0.1435, 'S1V': -0.0383, 'S1H': 0.1339}, 'MEG': {'S2V': -0.029, 'S2H': -0.3559, 'S1V': -0.0557, 'S1H': 0.1449}} + +======= 20220705: +{'HEG': {'S2V': -0.5736, 'S2H': -0.312, 'S1V': -0.0121, 'S1H': 0.1182}, 'MEG': {'S2V': -0.029, 'S2H': -0.3559, 'S1V': -0.0557, 'S1H': 0.1449}} + +======= 20220713: +{'HEG': {'S2V': -0.5736, 'S2H': -0.312, 'S1V': -0.0121, 'S1H': 0.1182}, 'MEG': {'S2V': -0.0047, 'S2H': -0.5352, 'S1V': -0.0441, 'S1H': 0.123}} + +======= 20220719: +{'HEG': {'S2V': -0.5736, 'S2H': -0.312, 'S1V': -0.0121, 'S1H': 0.1182}, 'MEG': {'S2V': -0.0271, 'S2H': -0.3154, 'S1V': -0.0604, 'S1H': 0.113}} + +======= 20220726: +{'HEG': {'S2V': -0.5736, 'S2H': -0.312, 'S1V': -0.0121, 'S1H': 0.1182}, 'MEG': {'S2V': -0.0489, 'S2H': -0.5032, 'S1V': -0.0115, 'S1H': 0.2177}} diff --git a/iexcode/IEX_dictionaries/Flux_Curves_QP70.txt b/iexcode/IEX_dictionaries/Flux_Curves_QP70.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ebdc1d63bc5df8a423d0c5dcf2e7d707bd58bfc --- /dev/null +++ b/iexcode/IEX_dictionaries/Flux_Curves_QP70.txt @@ -0,0 +1,42 @@ + +======= 20220720: + +----- flux_x: +{'MEG': {0: [[600.0, array([439.52, 484.53, 536.53, 590.59, 644.02])], [1500.0, array([ 643.3150091 , 698.27638369, 751.92819053, 804.32851937, + 855.85957584, 906.94762404, 957.62883976, 1008.16118875, + 1058.61331684, 1109.08200868, 1159.60303415, 1210.18400879, + 1260.80802369, 1311.41803046, 1361.97140942, 1412.24939421, + 1462.16437202, 1511.52883401, 1560.18223664])]], 3: [[400.0, array([261.2 , 321.01, 372.41, 430.4 ])], [600.0, array([430.4 , 485.99, 538.17, 590.59, 641.97])], [1500.0, array([ 642.33414808, 696.40046444, 749.78523155, 802.70679918, + 855.20268058, 907.36091505, 959.131399 , 1010.50673309, + 1061.73799295, 1112.64806192, 1163.30746953, 1213.72542759, + 1263.91577528, 1313.87611693, 1363.60216817, 1413.0934456 , + 1462.34136595, 1511.30391423, 1560.0098909 ])]], 2: [[600.0, array([484.52, 536.53, 590.58, 644.01])], [1500.0, array([ 643.67872489, 696.39449875, 748.68451943, 800.80899782, + 852.69105756, 904.41720315, 955.93918876, 1007.30454524, + 1058.50731464, 1109.59661276, 1160.54134668, 1211.33241352, + 1261.95763777, 1312.42030824, 1362.61711289, 1412.55398924, + 1462.19394606, 1511.47510981, 1560.37547278])]], 1: [[600.0, array([438.2 , 482.98, 534.78, 583.44, 636. ])], [1500.0, array([ 635.87569328, 688.63387248, 740.7642036 , 792.29704081, + 843.29680358, 893.81787821, 943.94262125, 993.73556398, + 1043.23173691, 1092.47885098, 1141.54069278, 1190.46375301, + 1239.31206379, 1288.13945996, 1336.97448654, 1385.91496532, + 1434.98992597, 1484.23051482, 1533.69987274])]]}} +----- flux_y: +{'MEG': {0: [[600.0, array([1.69158915e+11, 2.08804750e+11, 2.31668324e+11, 3.34882933e+11, + 3.80203782e+11])], [1500.0, array([3.80203782e+11, 4.46868047e+11, 4.99220650e+11, 5.68471098e+11, + 6.19554944e+11, 6.64099063e+11, 6.86700841e+11, 6.94129493e+11, + 6.92912470e+11, 6.76929478e+11, 6.52455412e+11, 6.10130165e+11, + 5.82819364e+11, 5.44097059e+11, 5.00613963e+11, 4.73637865e+11, + 4.42900806e+11, 4.08118044e+11, 3.86443758e+11])]], 3: [[400.0, array([2.07094724e+10, 4.91850743e+10, 6.83548158e+10, 1.00826960e+11])], [600.0, array([1.00826960e+11, 1.31386117e+11, 1.45302751e+11, 1.84401156e+11, + 1.96547991e+11])], [1500.0, array([1.96547991e+11, 2.31426905e+11, 2.66511659e+11, 3.04558624e+11, + 3.43008444e+11, 3.83114487e+11, 4.05307437e+11, 4.16801991e+11, + 4.19203408e+11, 4.14410939e+11, 4.03083879e+11, 3.85122357e+11, + 3.68233195e+11, 3.50341535e+11, 3.27304810e+11, 3.08285915e+11, + 2.90908581e+11, 2.75272734e+11, 2.61154524e+11])]], 2: [[600.0, array([1.29798464e+11, 1.42975699e+11, 1.77491240e+11, 2.05858697e+11])], [1500.0, array([2.05858697e+11, 2.43589523e+11, 2.74930597e+11, 3.13778705e+11, + 3.54132939e+11, 3.83672970e+11, 4.06461475e+11, 4.19266945e+11, + 4.23430826e+11, 4.16245461e+11, 4.07779009e+11, 3.91378629e+11, + 3.69973403e+11, 3.47417563e+11, 3.29959730e+11, 3.09206441e+11, + 2.91825326e+11, 2.78247315e+11, 2.62472215e+11])]], 1: [[600.0, array([1.95443600e+11, 2.37980112e+11, 2.63344561e+11, 3.08919456e+11, + 3.63863197e+11])], [1500.0, array([3.63863197e+11, 4.16045131e+11, 4.66471171e+11, 5.18255780e+11, + 5.78827895e+11, 6.27713326e+11, 6.57194435e+11, 6.76568690e+11, + 6.08682096e+11, 6.74642773e+11, 6.53995264e+11, 6.19850673e+11, + 5.88794730e+11, 5.53449825e+11, 5.12839982e+11, 4.77251214e+11, + 4.42649534e+11, 3.77680200e+11, 3.53648814e+11])]]}} diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py index 142e4fce0b16166aa70067ec1b9e56d44338fe92..feab47091c7794b56af95953b0a345c2bfb13251 100644 --- a/iexcode/instruments/IEX_VPU.py +++ b/iexcode/instruments/IEX_VPU.py @@ -8,36 +8,39 @@ from epics import caget, caput from iexcode.instruments.userCalcs import userCalcOut_clear from iexcode.instruments.utilities import dateandtime, print_warning_message, read_dict from iexcode.instruments.VLS_PGM import mono_grating_get -from iexcode.instruments.shutters import main_shutter_open +from iexcode.instruments.shutters import shutter_check IDcal_path="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries" ############################################################################################################## ################################ ID limits and calibration ############################## ############################################################################################################## - -pv = 'ID29:' -pvs={'AccessSecurity':pv+'AccessSecurity.VAL', - 'mode_rbv':pv+'ActualMode', - 'mode_val':pv+'DesiredMode.VAL', - 'check_ready':pv+'feedback.VAL', - 'check_busy':pv+'BusyRecord', - 'busy_reset':pv+'Busy.VAL', - 'main_power':pv+'Main_on_off.VAL', - 'energy_rbv':pv+'Energy.VAL', - 'energy_sp':pv+'EnergySet.VAL', - 'start_ramp':pv+'StartRamp.VAL', - 'energy_eV_rbv':pv+'EnergyRBV', - 'energy_eV_sp':pv+'EnergyScanSet.VAL', - 'scan_eV_rbv':pv+'EnergyScanSeteV', - 'scan_eV_val':pv+'EnergySetRBV', - 'table_dir':pv+'TableDirection', - 'By_q':pv+'ByqRdbk', - 'Bx_q':pv+'BxqRdbk', - 'Vcoil':pv+'ByRdbk.VAL', - 'Hcoil':pv+'BxRdbk.VAL', +def ID_pvs(): + """ + dictionary of ID pvs + """ + pv = 'ID29:' + pvs={'AccessSecurity':pv+'AccessSecurity.VAL', + 'mode_rbv':pv+'ActualMode', + 'mode_val':pv+'DesiredMode.VAL', + 'check_ready':pv+'feedback.VAL', + 'check_busy':pv+'BusyRecord', + 'busy_reset':pv+'Busy.VAL', + 'main_power':pv+'Main_on_off.VAL', + 'energy_rbv':pv+'Energy.VAL', + 'energy_sp':pv+'EnergySet.VAL', + 'start_ramp':pv+'StartRamp.VAL', + 'energy_eV_rbv':pv+'EnergyRBV', + 'energy_eV_sp':pv+'EnergyScanSet.VAL', + 'scan_eV_rbv':pv+'EnergyScanSeteV', + 'scan_eV_val':pv+'EnergySetRBV', + 'table_dir':pv+'TableDirection', + 'By_q':pv+'ByqRdbk', + 'Bx_q':pv+'BxqRdbk', + 'Vcoil':pv+'ByRdbk.VAL', + 'Hcoil':pv+'BxRdbk.VAL', 'QP_ratio':pv+'QuasiRatio.RVAL',} - + return pvs def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1=LCP,2=V,3=H) @@ -54,7 +57,7 @@ def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1= except KeyError: message_string='Not a valid ID mode!'+"\nValid Modes: "+str(ID_mode_list()) print_warning_message(message_string) - ID=caget(pvs['energy_rbv']) + ID=caget(ID_pvs()['energy_rbv']) return round(ID,1) ############################################################################################################## @@ -62,7 +65,7 @@ def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1= ############################################################################################################## -def ID_wait_for_permission(): +def ID_wait_for_permission(verbose=True): """ Monitors the ID permissions and waits for the ID to be in User Mode and then breaks Checks the status every 30 seconds @@ -70,12 +73,13 @@ def ID_wait_for_permission(): Previously: WaitForPermission """ while True: - ID_Access=caget(pvs['AccessSecurity']) + ID_Access=caget(ID_pvs()['AccessSecurity']) if (ID_Access!=0): print("Checking ID permission, please wait..."+dateandtime()) sleep(30) else: - print("ID now in user mode -"+dateandtime()) + if verbose: + print("ID now in user mode -"+dateandtime()) break ############################################################################################################## @@ -88,7 +92,7 @@ def ID_get_all(verbose=False): vals={ "ID_mode":ID_mode_get(verbose=False), "ID_QP_ratio":ID_QP_ratio_get(verbose=False), - "ID_sp":caget(pvs['energy_sp']), + "ID_sp":caget(ID_pvs()['energy_sp']), "ID_rbv":ID_get_eV(verbose=False) } @@ -104,7 +108,7 @@ def ID_energy_range(ID_mode=None): Previously: ID_Range """ if ID_mode == None: - ID_state=caget(pvs['mode_rbv']) + ID_state=caget(ID_pvs()['mode_rbv']) else: ID_state = ID_state_mode(ID_mode) # RCP,LCP, V , H , HN @@ -149,7 +153,7 @@ def ID_state_get(): """ Returns the current ID state """ - ID_state = caget(pvs['mode_rbv']) + ID_state = caget(ID_pvs()['mode_rbv']) return ID_state def ID_mode_get(verbose=True): @@ -167,33 +171,42 @@ def ID_mode_set(ID_mode): """ writes the desired mode to the correct ID pv """ - caput(pvs['mode_val'],ID_mode,wait=True,timeout=18000) # RCP + caput(ID_pvs()['mode_val'],ID_mode,wait=True,timeout=18000) # RCP -def ID_ready(verbose=True): +def ID_ready(verbose=False): """ check both the read and busy pv every 2 seconds Previously: ID_Ready """ while True: - RBV=caget(pvs['energy_rbv']) - checkready=caget(pvs['check_ready']) - checkbusy=caget(pvs['check_busy']) - if (checkready!="Ready") or (RBV < 3.7): + RBV = caget(ID_pvs()['energy_rbv']) + checkready = caget(ID_pvs()['check_ready']) + checkbusy = caget(ID_pvs()['check_busy'],as_string=True) + if (checkready!="Ready"): + print('checkready',checkready) sleep(2) - elif ((checkready=="Ready") and (RBV > 3.7)) and (checkbusy=="Busy"): - caput(pvs['busy_reset'],0) + if checkbusy=="Busy": + sleep(2) + print('checkbusy',checkbusy) + else: + if RBV > 3.7: + #thinks its done but isn't, need to reset busy + caput(ID_pvs()['busy_reset'],0) + sleep(2) + if verbose: + print('resetting ID busy record') else: if verbose: - print("ID Ready") - return True + print("ID Ready") + return True def ID_power_status(): """ gets if the ID power supplies are On or Off """ - ID_OnOff=caget(pvs['main_power']) + ID_OnOff=caget(ID_pvs()['main_power']) if ID_OnOff == 1: return 'Off' elif ID_OnOff == 0: @@ -203,8 +216,8 @@ def ID_off(verbose=True): """ waits for permission then turns on the main coils OFF """ - ID_wait_for_permission() - caput(pvs['main_power'],1,wait=True,timeout=18000) + ID_wait_for_permission(verbose=False) + caput(ID_pvs()['main_power'],1,wait=True,timeout=18000) sleep(5) if verbose: print("ID is now off") @@ -215,12 +228,12 @@ def ID_on(verbose=True): waits for permission then turns on the main coils On """ - ID_wait_for_permission() + ID_wait_for_permission(verbose=False) if verbose: print("Starting ID - "+dateandtime()) - caput(pvs['energy_sp'],3.8) - caput(pvs['main_power'],0,wait=True,timeout=18000) + caput(ID_pvs()['energy_sp'],3.8) + caput(ID_pvs()['main_power'],0,wait=True,timeout=18000) def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True): """ @@ -240,7 +253,7 @@ def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True): ID_mode_set(ID_mode, verbose) #opens the main shutter if ID_ready(): - main_shutter_open() + shutter_check(verbose) if verbose: print('ID is now on, please set your energy') @@ -254,8 +267,8 @@ def ID_switch_mode(ID_mode): Previously Switch_IDMode """ - ID_wait_for_permission() - main_shutter_open() + ID_wait_for_permission(verbose=False) + shutter_check(verbose=False) ID_state = ID_state_get() try: @@ -275,7 +288,7 @@ def ID_get(verbose=False): """ returns the readback value for the """ - ID_RBV = caget(pvs['energy_rbv']) + ID_RBV = caget(ID_pvs()['energy_rbv']) if verbose: print("ID_RBV: ", ID_RBV) return ID_RBV @@ -289,6 +302,20 @@ def ID_get_eV(verbose=False): print("ID_RBV: ", ID_RBV) return ID_RBV +def _ID_write_SP_proc(keV): + ramp_delay=5 + caput(ID_pvs()['energy_sp'],keV,wait=True,timeout=18000) + sleep(ramp_delay) + caput(ID_pvs()['start_ramp'],1,wait=True,timeout=18000) + +def _ID_bw_ok(keV): + ID_SP = caget(ID_pvs()['energy_sp']) + ID_bw = ID_SP * 0.095 + ID_diff = abs(ID_get()-keV) + if ID_diff > ID_bw: + return False + else: + return True def ID_set(keV,verbose=True): """ @@ -296,49 +323,42 @@ def ID_set(keV,verbose=True): Previously: SetID_Raw """ - def _ID_write_SP_proc(keV): - caput(pvs['energy_sp'],keV,wait=True,timeout=18000) - sleep(0.5) - caput(pvs['start_ramp'],1) - - def _ID_bw_ok(keV,verbose=False): - ID_SP = caget(pvs['energy_sp']) - ID_bw = ID_SP * 0.095 - ID_diff = abs(ID_get()-keV) - if ID_diff > ID_bw: - return False - else: - return True + + #check if I'm already there + ID_SP = round(caget(ID_pvs()['energy_sp']),3) + if round(keV,3) == ID_SP: + if verbose: + print("ID already at "+str(ID_SP)) + else: - #checking permissions and opening the main shutter - ID_wait_for_permission() - main_shutter_open() + #checking permissions and opening the main shutter + ID_wait_for_permission(verbose=False) + shutter_check(verbose=False) - #checking if desired is with allowed range, if not printing the nearest allowed value - ID_max,ID_min = ID_energy_range() - if keV < ID_min or keV > ID_max: - message_string="Set point out of BL energy range \nPlease select a different energy." - message_string+="\nClosest allowed value is "+str(min(max(keV,ID_min),ID_max)) - print_warning_message(message_string) - else: - #desired energy is within range - _ID_write_SP_proc(keV) - # ID not at energy - ready = ID_ready(verbose=False) - if ready: - #set the energy - _ID_write_SP_proc(ID_SP/1000) - while not ID_ready(verbose=False): - sleep(20) - #is ID within some bandwidth - if _ID_bw_ok(ID_SP,verbose=verbose): + #checking if desired is with allowed range, if not printing the nearest allowed value + ID_min,ID_max = ID_energy_range() + if keV < ID_min or keV > ID_max: + message_string="Set point out of BL energy range \nPlease select a different energy." + message_string+="\nClosest allowed value is "+str(min(max(keV,ID_min),ID_max)) + print_warning_message(message_string) + else: + #set energy sp and ramp + _ID_write_SP_proc(keV) + + ID_ready(verbose=False) + #run twice to make sure ready (sometime busy is weird and instantaneously give ready) + ID_ready(verbose=False) + + #check if ID within some bandwidth + if _ID_bw_ok(ID_SP): if verbose: - ID_SP = caget(pvs['energy_sp']) + ID_SP = caget(ID_pvs()['energy_sp']) ID_RBV = ID_get() print("ID SET : "+"%.1f" % ID_SP, "eV") print("ID RBV : "+"%.1f" % ID_RBV, "eV") - print(caget(pvs['table_dir'],as_string=True)) + print(caget(ID_pvs()['table_dir'],as_string=True)) else: + print_warning_message("ID not within energy bandwidth") ID_QP_ratio_get(verbose) @@ -363,10 +383,10 @@ def ID_QP_ratio_get(verbose=True): calculate the QP ratio """ - Byq=caget(pvs['By_q']) - Vcoil=caget(pvs['Vcoil']) + Byq=caget(ID_pvs()['By_q']) + Vcoil=caget(ID_pvs()['Vcoil']) ratio_calc=round(Byq/Vcoil,3)*100 - ratio_RBV=caget(pvs['QP_ratio']) + ratio_RBV=caget(ID_pvs()['QP_ratio']) if verbose: print("QP RBV =", ratio_RBV,"%") print("QP calculated ratio =", ratio_calc ,"%") @@ -467,8 +487,8 @@ def ID_scan_pvs(): """ returns the rbv and val for scanning """ - val_pv=pvs['scan_eV_val'] - rbv_pv=pvs['scan_eV_rbv'] + val_pv=ID_pvs()['scan_eV_val'] + rbv_pv=ID_pvs()['scan_eV_rbv'] return rbv_pv, val_pv def ID_scan_fillin(mda,scan_dim,start,stop,step,**kwargs): diff --git a/iexcode/instruments/diagnostics.py b/iexcode/instruments/diagnostics.py index e062b81e0cd6496867ce78bf16316549ad3c67e7..104d7939540081b5ebd0faf566fa834ab40df6c7 100644 --- a/iexcode/instruments/diagnostics.py +++ b/iexcode/instruments/diagnostics.py @@ -8,6 +8,61 @@ import iexcode.instruments.cfg as iex ############################################################################################################## ################################ default positions ############################## ############################################################################################################## +def diagnostics_go2(diag_name,preset_name): + pv = _diagnostics_preset_pv(diag_name,preset_name) + caput(pv+'_Trigger.PROC',1) + +def diagnostics_sp_read(diag_name,preset_name): + pv = _diagnostics_preset_pv(diag_name,preset_name) + caget(pv+'_Setpoint.VAL') + +def _diagnostics_sp_write(diag_name,preset_name): + pv = _diagnostics_preset_pv(diag_name,preset_name) + caget(pv+'_Setpoint.VAL') + +def _diagnostics_preset_pv(diag_name,preset_name): + """ + dictionary of the motor pvs for the beamline diagnostics + """ + ioc = '29idb:' + d = _diagnostics_get_presets() + pv=None + + if diag_name.casefold() in (key.casefold() for key in list(d.keys())): + idx = [item.lower() for item in list(d.keys())].index(diag_name.lower()) + diag_name=list(d.keys())[idx] + if preset_name.casefold() in (preset.casefold() for preset in d[diag_name]): + idx = [item.lower() for item in d[diag_name]].index(preset_name.lower()) + preset_name = d[diag_name][idx] + pv = ioc+diag_name+'_'+preset_name + else: + message ='preset_name = '+preset_name+' not a valid name' + message +='\npreset_names:'+str(d[diag_name]) + print_warning_message(message) + + else: + message = 'diag_name = '+diag_name+' not a valid name' + message +='\npreset_names:'+str(list(d.keys())) + print_warning_message(message) + + return pv + +def _diagnostics_get_presets(): + presets={ + 'H-wire':['OUT','Start'], + 'V-wire':['OUT','Start'], + 'H-Diagon':['OUT','Si-2800','ML-400','ML-460'], + 'V-Diagon':['OUT','Si-2800','ML-400','ML-460'], + 'D1A':['OUT','Mesh'], + 'D2B':['OUT','Mesh','YAG'], + 'D3B':['OUT','YAG'], + 'D4C':['OUT','Mesh','YAG'], + 'gas-cell':['OUT','Diode1','Diode2'], + 'D4D':['OUT','Mesh','YAG'], + 'D5D':['OUT','Mesh','YAG'], + } + return presets + ###### We should make pvs in the 29idb ioc to hold these values: def _diagnostics_dict(): diff --git a/iexcode/instruments/shutters.py b/iexcode/instruments/shutters.py index e30e9f6ad338a8ab4bdc0181f25c515919588d15..0ac7e1143db1c9911a8d2667da4aa0294bf561ca 100644 --- a/iexcode/instruments/shutters.py +++ b/iexcode/instruments/shutters.py @@ -8,7 +8,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.utilities import dateandtime -def shutter_check(): +def shutter_check(verbose=True): """ Checks main shutter is open, if not opens it" Checks brancg shutter is open, if not opens it" @@ -22,9 +22,11 @@ def shutter_check(): main_shutter_open() sleep(10) else: - print("Shutter is now open" , dateandtime()) + if verbose: + print("Shutter is now open" , dateandtime()) break shutter_open = branch_shutter_status() + if shutter_open == False: branch_shutter_open() diff --git a/iexcode/instruments/slits.py b/iexcode/instruments/slits.py index f8a3b82764f3ac6fdf28c633e152a464fbde26a0..612bb84098b21a64d6ff265f44a2423ece2b4d26 100644 --- a/iexcode/instruments/slits.py +++ b/iexcode/instruments/slits.py @@ -68,10 +68,10 @@ def slits_pvs(slit_name): center.append((center_val,center_rbv)) else: for slit_HV in d[slit_name]: - size_val = slit_HV +'size.VAL' - size_rbv = slit_HV +'t2.C' - center_val = slit_HV +'center.VAL' - center_rbv = slit_HV +'t2.D' + size_rbv = slit_HV +'size.VAL' + size_val = slit_HV +'t2.C' + center_rbv = slit_HV +'center.VAL' + center_val = slit_HV +'t2.D' size.append((size_val,size_rbv)) center.append((center_val,center_rbv)) else: @@ -121,8 +121,9 @@ def slits_set(slit_name,size,center,verbose=True,wait=True): synchs the slit motors and the slit table and then sets the center and size slit_name is key in slits_dictionary - size = (H_size, V_size) #inf => all the way open + size = (H_size, V_size) #inf in direction specified => all the way open center = (H_center, V_center) + None=> use current value Previously: SetSlit """ @@ -133,14 +134,22 @@ def slits_set(slit_name,size,center,verbose=True,wait=True): if inf in size: size = _slits_wide_open_dictionary()[slit_name] - + size_pvs,center_pvs = slits_pvs(slit_name) + for i in range(0,len(size_pvs)): + #get pvnames size_rbv, size_val, = size_pvs[i] center_rbv,center_val = center_pvs[i] - if center_rbv != None: - caput(center_val, center[i],wait=wait,timeout=180) + #check if there is a pv + if center_rbv != None: + #check if specified value + if center[i] != None: + caput(center_val, center[i],wait=wait,timeout=180) + #check if there is a pv if size_rbv != None: + #check if specified value + if size[i] != None: caput(size_val, size[i],wait=wait,timeout=180) if verbose: @@ -280,7 +289,7 @@ def slit1A_set(H_size,V_size,verbose=True,**kwargs): Previously: SetSlit1A """ - kwargs.setdefault('center',(0,0)) + kwargs.setdefault('center',(None,None)) slit_name = 'slit1A' size = (H_size,V_size) @@ -304,7 +313,7 @@ def slit2B_set(H_size,V_size,verbose=True,**kwargs): Previously: SetSlit2B """ - kwargs.setdefault('center',(0,0)) + kwargs.setdefault('center',(None,None)) slit_name = "slit2B" size = (H_size,V_size) diff --git a/iexcode/instruments/utilities.py b/iexcode/instruments/utilities.py index fb052f8e1087624849bcdaf1e13303f4246976ea..7dd7914457230e382dbc9e38b3263ecab5e0f578 100644 --- a/iexcode/instruments/utilities.py +++ b/iexcode/instruments/utilities.py @@ -115,7 +115,7 @@ def read_dict(filename,**kwargs): if 'path' in kwargs: path = kwargs['path'] else: - path = os.path.join(os.path.dirname(__file__),'IEX_dictionaries') + path = os.path.join(os.path.dirname(os.path.dirname(__file__)),'IEX_dictionaries') fpath = os.path.join(path,filename) with open(fpath) as f: for c,line in enumerate(f.readlines()): diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py index 5aa6707c149a9e611f5ed9d5aa530a8ca96222c9..e61e120d4087786f666ae2d48fe2e1a4633b9752 100644 --- a/iexcode/instruments/xrays.py +++ b/iexcode/instruments/xrays.py @@ -299,7 +299,7 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True): Previously: SetSlit_BL """ hv_rbv = mono_energy_get() - grt = mono_grating_get + grt = mono_grating_get() # slit were defined for the range: 500 - 2000 hv = max(hv_rbv,500) @@ -312,7 +312,7 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True): V=0.65*c # set to 65% of RR calculation (no longer 80%) => cf 2016_2_summary try: - slit_position = read_dict(FileName='Dict_Slit.txt') + slit_position = read_dict('Dict_Slit.txt') except KeyError: print_warning_message("Unable to read dictionary") return @@ -324,8 +324,9 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True): Size1A=( aperture_fit(hv,1)[0]*c_1A, aperture_fit(hv,1)[1]*c_1A ) Size2B=( aperture_fit(hv,2)[0]*c_2B, round(aperture_fit(hv,2)[1]*c_2B*V,3)) - slit1A_set(Size1A[0],Size1A[1],H1_center,V1_center,verbose) # standard operating - slit1A_set(Size2B[0],Size2B[1],H2_center,V2_center,verbose) + + slit1A_set(Size1A[0],Size1A[1],center=(H1_center,V1_center),verbose=verbose) # standard operating + slit2B_set(Size2B[0],Size2B[1],center=(H2_center,V2_center),verbose=verbose) def mvID(val,QP_ratio=100): @@ -514,40 +515,6 @@ def BL_energy_tables(start_stop_step_lists,**kwargs): return mono_array,ID_array -############################################################################################################## -########################### shutter check ###################### -############################################################################################################## - -def shutter_check(verbose=True): - """ - Opens the shutter in the branch determined from the position of m3r - - Previously: Check_BranchShutter - """ - #main shutter - if main_shutter_status: - if verbose: - print("Main shutter already open") - else: - main_shutter_open() - - #branch shutter - branch = m3r_branch(verbose) - if branch_shutter_status(branch): - if verbose: - print(dateandtime(), +branch+" shutter already open..." ,) - else: - while True: - if branch_shutter_status(branch) == False : - if verbose: - print(dateandtime(), "Opening "+branch+" shutter ..." ,) - branch_shutter_open(branch,verbose=False) - sleep(30) - else: - print(dateandtime(), +branch+" shutter is now open..." ,) - break - - ############################################################################################################## ########################### switch branch ###################### ############################################################################################################## diff --git a/setup.py b/setup.py index aa9e5e58aec60526ea8e6bb2f2998d4fe81b14af..b2ab9407bce84c8e19ea76c4b54dea747788f570 100755 --- a/setup.py +++ b/setup.py @@ -20,6 +20,6 @@ setup( install_requires=install_requires, scripts=[], dependency_links=[], - package_data={'': []} + package_data={'': ['IEX_dictionaries/*']} )