diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py index 70b4ea4ae1947e9492d476b0fa5cb6ea64b9bae5..ba46b7430a5cdb360ea9a65791f156cbd4765c82 100644 --- a/build/lib/iexcode/instruments/ARPES.py +++ b/build/lib/iexcode/instruments/ARPES.py @@ -11,14 +11,14 @@ 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 from iexcode.instruments.staff import staff_detector_dictionary -from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all, xrays_log_dictionary +from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all, xrays_log_dictionary from iexcode.instruments.conversions_constants import * from iexcode.instruments.utilities import * from iexcode.instruments.userCalcs import * from iexcode.instruments.Motors import Motors -from iexcode.instruments.current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence +from iexcode.instruments.SRS_current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence from iexcode.instruments.valves import branch_valve_close from iexcode.instruments.shutters import branch_shutter_close @@ -147,7 +147,7 @@ def _ARPES_detector_dictionary(): #add detectors related to beamline if iex.BL.xrays: - det_dict.update(_xrays_detector_dictionary()) + det_dict.update(xrays_detector_dictionary()) return det_dict diff --git a/build/lib/iexcode/instruments/Kappa.py b/build/lib/iexcode/instruments/Kappa.py index 7c3ca56b35d1da10ea0fe0ee6c2ff2be5cb6e77a..cb565d1633d08e3922fbd990af567de242f27d5d 100644 --- a/build/lib/iexcode/instruments/Kappa.py +++ b/build/lib/iexcode/instruments/Kappa.py @@ -12,15 +12,15 @@ 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 from iexcode.instruments.staff import staff_detector_dictionary -from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all +from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all from iexcode.instruments.conversions_constants import * from iexcode.instruments.utilities import * from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs from iexcode.instruments.Motors import Motors -from iexcode.instruments.current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence -from iexcode.instruments.current_amplifiers import SRS +from iexcode.instruments.SRS_current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence +from iexcode.instruments.SRS_current_amplifiers import SRS from iexcode.instruments.valves import branch_valve_close from iexcode.instruments.shutters import branch_shutter_close @@ -185,7 +185,7 @@ def _kappa_detector_dictionary(**kwargs): #add detectors related to beamline if iex.BL.xrays: - det_dict.update(_xrays_detector_dictionary()) + det_dict.update(xrays_detector_dictionary()) return det_dict diff --git a/build/lib/iexcode/instruments/diagnostics.py b/build/lib/iexcode/instruments/diagnostics.py index d021dc45f4cb4e471fc0b356c32014d204a20db1..93705290fa35267786c94df0a14361ca4289dd8a 100644 --- a/build/lib/iexcode/instruments/diagnostics.py +++ b/build/lib/iexcode/instruments/diagnostics.py @@ -3,7 +3,7 @@ from numpy import nan from epics import caput, caget import iexcode.instruments.cfg as iex -from iexcode.instruments.current_amplifiers import Keithley,SRS +from iexcode.instruments.SRS_current_amplifiers import Keithley,SRS from iexcode.instruments.utilities import print_warning_message ############################################################################################################## ################################ default positions ############################## diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py index 6eb545e43108965e99ecb9ea4c0d00da7115d42e..5d57f2d078d82647a80cb9218ea7393dba9844a8 100644 --- a/build/lib/iexcode/instruments/xrays.py +++ b/build/lib/iexcode/instruments/xrays.py @@ -9,7 +9,7 @@ from time import sleep from epics import caget,caput import iexcode.instruments.cfg as iex -from iexcode.instruments.current_amplifiers import ca_average, ca_detector_list +from iexcode.instruments.SRS_current_amplifiers import ca_average, ca_detector_list from iexcode.instruments.diagnostics import * from iexcode.instruments.FMB_mirrors import FMB_mirror_get from iexcode.instruments.IEX_VPU import * diff --git a/build/lib/iexcode/macros/__init__.py b/build/lib/iexcode/macros/__init__.py index e6ccdb93fcb545fdc3cd980a8d526137d7f192bd..f7f0f356b6d6e4721ab6e6fc6477e17d3860073a 100644 --- a/build/lib/iexcode/macros/__init__.py +++ b/build/lib/iexcode/macros/__init__.py @@ -3,7 +3,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.ARPES import * from iexcode.instruments.bakeout import * #not tested from iexcode.instruments.conversions_constants import * -from iexcode.instruments.current_amplifiers import * #need to test SRS +from iexcode.instruments.SRS_current_amplifiers import * #need to test SRS from iexcode.instruments.diagnostics import * from iexcode.instruments.electron_analyzer import * #didn't test, but not much changed from iexcode.instruments.encoders import * #didn't test encoder reset diff --git a/build/lib/iexcode/macros/commissioning.py b/build/lib/iexcode/macros/commissioning.py index e38328327e3cc263ff5dfba58413d4a6455d8c32..3e627f0e8889e65e60d0514d58615a2e9fa34322 100644 --- a/build/lib/iexcode/macros/commissioning.py +++ b/build/lib/iexcode/macros/commissioning.py @@ -10,7 +10,7 @@ from iexcode.instruments.xrays import * from iexcode.instruments.VLS_PGM import * from iexcode.instruments.IEX_VPU import * -from iexcode.instruments.current_amplifiers import * +from iexcode.instruments.SRS_current_amplifiers import * from iexcode.instruments.diagnostics import diagnostics_all_out, diagnostics_all_in,diode_c,diode_d from iexcode.instruments.m3r import * from iexcode.instruments.slits import _slits_wide_open_dictionary diff --git a/build/lib/iexcode/macros/start_of_the_week.py b/build/lib/iexcode/macros/start_of_the_week.py index eab7679e72bcda066eb38e64c4c7a998ba790145..f76be91f9dc479f15f7d900fc8429d7604ae93fd 100644 --- a/build/lib/iexcode/macros/start_of_the_week.py +++ b/build/lib/iexcode/macros/start_of_the_week.py @@ -8,7 +8,7 @@ from iexcode.instruments.Kappa import kappa_init from iexcode.instruments.scanRecord import * from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d -from iexcode.instruments.current_amplifiers import * +from iexcode.instruments.SRS_current_amplifiers import * from iexcode.instruments.xrays import * from iexcode.instruments.VLS_PGM import * from iexcode.instruments.Logfile import log_name_set,log_print diff --git a/iexcode/__init__.py b/iexcode/__init__.py index 8b137891791fe96927ad78e64b0aad7bded08bdc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/iexcode/__init__.py +++ b/iexcode/__init__.py @@ -1 +0,0 @@ - diff --git a/iexcode/cheatsheet.txt b/iexcode/cheatsheet.txt index acc3a959c37634ce85c9cb1494d5f9bc4f755a7d..59a4a8875504dee244619d10b612f5209db6e82a 100644 --- a/iexcode/cheatsheet.txt +++ b/iexcode/cheatsheet.txt @@ -165,11 +165,31 @@ ScanRecord => class for handling scanRecord_user scan_fillin => same as iex.BL.mda.fillin scan_fillin_table => same as iex.BL.mda.fillin_table scan_go => same as iex.BL.mda.go -.trigger_get -.trigger_set -.trigger_clear -.detectors_set -detectors_clear => clears all + +mda_filepath => same as iex.BL.mda.filepath +mda_prefix => same as iex.BL.mda.prefix +mda_user_name => same as iex.BL.mda.prefix +mda_run_cycle => same as iex.BL.mda.run_cycle +mda_reset => same as iex.BL.mda.reset_all + +.fillin => checks progress, clears positions and writes new values, updates kwarg settings +.fillin_table => checks progress, clears positions and writes new values, updates kwarg settings +.table_reset_after => sets back to linear and clears positioners + +.positioner_settling_time_get/set => gets/sets the positioner settling time +.positioner_absolute_mode_set => sets the positioner mode absolute or relative +.positioner_after_scan_set => sets positioner after scan to "PRIOR POS" or 'STAY' + +.detectors_clear => clears all detector for scan_dim +.detectors_get/set => gets/set detectors +.detector_settling_time => sets to the default unless specified + +.trigger_clear => clears all the detector triggers +.trigger_get/set => gets/sets detector triggers + +.before_scan_set => sets the before scan pv, before_scan_pv = '' clears +.after_scan_set => sets the after scan pv, after_scan_pv = '' clears + .fileNum .lastFileNum .filepath @@ -265,6 +285,7 @@ mono_cff_set mono_arm_set #xrays +safe_state energy_get_all energy_get => retuns the mono energy getE => same as energy_get diff --git a/iexcode/instruments/AD_utilities.py b/iexcode/instruments/AD_utilities.py index d1e324da81e3a4c3629f1f568b0e3d7ba9ed31f9..ae1f3646562bed8f0e60cc7af9bab049b636a74e 100644 --- a/iexcode/instruments/AD_utilities.py +++ b/iexcode/instruments/AD_utilities.py @@ -31,7 +31,7 @@ def AD_exposure_time(ADplugin,exp_time,**kwargs): caput(kwargs["P"]+kwargs["R"]+"AcquireTime",exp_time+.01) -def AD_CurrentDirectory(ADplugin): +def AD_filepath(ADplugin): """ returns the current directory for area detector SavePlugin handles both Winodws and linux IOCs @@ -50,8 +50,8 @@ def AD_CurrentDirectory(ADplugin): else: Dir = SubDir SubDir=[] - FilePath=os.path.join(Dir,*SubDir,'') - return FilePath + filepath=os.path.join(Dir,*SubDir,'') + return filepath def AD_prefix(ADplugin): """ diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index 5e6ad6c6e6cf46e00234fe2aad89fe83aa258563..9f394e9528010db1443198196e33a30f3e586772 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -1,8 +1,9 @@ import os from re import A from time import sleep +from iexcode.instruments.scanRecord import * import numpy as np -from epics import caget,caput,PV +from epics import caget,caput import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config @@ -11,14 +12,14 @@ 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 from iexcode.instruments.staff import staff_detector_dictionary -from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all, xrays_log_dictionary +from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all, xrays_log_dictionary from iexcode.instruments.conversions_constants import * from iexcode.instruments.utilities import * from iexcode.instruments.userCalcs import * from iexcode.instruments.Motors import Motors -from iexcode.instruments.current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence +from iexcode.instruments.Keithley_current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence from iexcode.instruments.valves import branch_valve_close from iexcode.instruments.shutters import branch_shutter_close @@ -77,7 +78,7 @@ def ARPES_init(*userName,**kwargs): print(user_name) folders_ARPES(user_name,**kwargs) else: - user_name = iex.BL.mda.user_name() + user_name = mda_user_name() #update for default scanRecord advanced parameters iex.BL.mda.log=Logfile('ARPES',user_name,_ARPES_log_dictionary,set_file=False) @@ -88,7 +89,7 @@ def ARPES_init(*userName,**kwargs): EA.get() _EA_init_Motors(ARPES_Motors) if kwargs['set_folders']: - userPath = os.path.dirname(iex.BL.mda.filepath()) + userPath = os.path.dirname(mda_filepath()) folders_EA(userPath,filePrefix="EA",**kwargs) else: @@ -110,8 +111,8 @@ def ARPES_init(*userName,**kwargs): _enable_endstation_cameras() print ('\nARPES initalized') - print('\tpath = "'+iex.BL.mda.filepath()+'"') - print('\tprefix = "'+iex.BL.mda.prefix()+'"') + print('\tpath = "'+mda_filepath()+'"') + print('\tprefix = "'+mda_prefix()+'"') #return any detectors or other parameters that you want access to from jupyter return tey,ca15 @@ -136,9 +137,10 @@ def _ARPES_detector_dictionary(): det_dict={ 14:"29idc:ca2:read", 16:"29idc:ca1:read", - 17:"", + 17:"", 18:"29idARPES:LS335:TC1:IN1", 19:"29idARPES:LS335:TC1:IN2", + 20:"",#EA_scanNum } #add Scienta if ioc is on @@ -147,7 +149,7 @@ def _ARPES_detector_dictionary(): #add detectors related to beamline if iex.BL.xrays: - det_dict.update(_xrays_detector_dictionary()) + det_dict.update(xrays_detector_dictionary()) return det_dict @@ -256,7 +258,7 @@ def ARPES_reset(): """ #resetting the scanRecord print("resetting the scanRecord - "+iex.BL.ioc) - iex.BL.mda.reset_all() + mda_reset() #resetting the current amplifiers print("resetting the current amplifiers") @@ -326,13 +328,6 @@ def ARPES_get_all(verbose=True): ############################################################################################################## ############################## logging ############################## ############################################################################################################## -def _ARPES_log_header(): - header_list={ - 'EA': "scan,x,y,z,th,chi,phi,T,scan_mode,E1,E2,step,i,f,PE,lens_mode,SES slit #,hv,exit_slit,GRT,ID_SP,ID_RBV,ID_Mode,ID_QP,TEY1,TEY2,time,comment", - 'ARPES':"scan,motor,start,stop,step,x,y,z,th,chi,phi,T,hv,exit_slit,GRT,ID_SP,ID_RBV,ID_Mode,ID_QP,TEY_1,TEY_2,time,comment" - } - return header_list - def _ARPES_log_dictionary(): """ endstation info for log file @@ -469,6 +464,7 @@ def _ARPES_detector_triggers_sequence(**kwargs): userStringSeq_clear(scan_ioc, seq_num) caput(detector_triggers_pv+".DESC","ARPES_Trigger1") + #trigger Keithleys if any ca_list = _ARPES_ca_list() last = len(ca_list) for i,ca in enumerate(ca_list): @@ -476,6 +472,8 @@ def _ARPES_detector_triggers_sequence(**kwargs): caput(detector_triggers_pv+".LNK" +str(i+1),ca_pv) caput(detector_triggers_pv+".WAIT"+str(i+1),"After"+str(last)) + #trigger scaler if any + return detector_triggers_proc def _ARPES_trigger_dictionary(**kwargs): @@ -782,7 +780,11 @@ def scanfocus(x_start,x_stop,x_step,**kwargs): +<<<<<<< HEAD def ARPES_map_sample(y_start=-2,y_stop=2,y_step=0.5,z_start=12,z_stop=16,z_step=0.5,**kwargs): +======= +def ARPES_map_sample(inner_loop=["y",0,4,0.5],outer_loop=["z",12,16,0.5]): +>>>>>>> 95226a1fe706ac74c0a7efeef77197a87c943634 """ 2D map of sample area in ARPES chamber @@ -793,6 +795,10 @@ def ARPES_map_sample(y_start=-2,y_stop=2,y_step=0.5,z_start=12,z_stop=16,z_step= Previously: Map_ARPES_Sample """ +<<<<<<< HEAD kwargs.setdefault('snake',True) ARPES_Motors.scan_2D(["y",y_start,y_stop,y_step],["z",z_start,z_stop,z_step],**kwargs) +======= + ARPES_Motors.scan_2D(inner_loop,outer_loop) +>>>>>>> 95226a1fe706ac74c0a7efeef77197a87c943634 diff --git a/iexcode/instruments/AUX100_diode.py b/iexcode/instruments/AUX100_diode.py new file mode 100644 index 0000000000000000000000000000000000000000..907279f8025482d79cc01bfc86bbfcbfba650fb4 --- /dev/null +++ b/iexcode/instruments/AUX100_diode.py @@ -0,0 +1,79 @@ + +import numpy as np + +from iexcode.instruments.VLS_PGM import mono_energy_get + +def _load_responsivity_curve(): + """ + Loads the responsivity curve for the AUX100 photo diode, used to convert + current to flux at a given photon energy + + Previously: loadResponsivityCurve + """ + FilePath='/home/beams/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries/' + FileName="DiodeResponsivityCurve" + data = np.loadtxt(FilePath+FileName, delimiter=' ', skiprows=1) + return data + +def current2flux(current,hv=None,verbose=True): + """ + Converts the current to flux for of an AUX 100 diode using the responisity curves + + hv = None; gets the current mono energy; otherwise you will need to specify + + Previously CA2flux + """ + try: + curve=_load_responsivity_curve() + except: + print('responsivity curve not loaded') + return + responsivity=curve[:,0] + energy=curve[:,1] + charge = 1.602e-19 + if hv is None: + try: + hv = mono_energy_get() + except: + print('specify hv') + return + eff=np.interp(hv,energy,responsivity) + flux = current/(eff*hv*charge) + if verbose: + print("\nCalculating flux for:") + print(" hv = %.1f eV" % hv) + print(" current = %.3e Amp" % current) + print("Flux = %.3e ph/s\n" % flux) + return flux + + +def flux2current(flux,hv=None,verbose=True): + """ + Converts the specified flux to a current for of an AUX 100 diode using the responisity curves + + hv = None; gets the current mono energy; otherwise you will need to specify + """ + try: + curve=_load_responsivity_curve() + except: + print('responsivity curve not loaded') + return + responsivity=curve[:,0] + energy=curve[:,1] + charge = 1.602e-19 + if hv is None: + try: + hv = mono_energy_get() + except: + print('specify hv') + return + eff=np.interp(hv,energy,responsivity) + current = flux*(eff*hv*charge) + if verbose: + print("\nCalculating current for:") + print(" hv = %.1f eV" % hv) + print(" flux = %.3e ph/s" % flux) + print("Current = %.3e Amp/n" % current) + return current + + \ No newline at end of file diff --git a/iexcode/instruments/IEX_VPU_backup.py b/iexcode/instruments/IEX_VPU_backup.py deleted file mode 100644 index 57ff364f320ee130b3bdf16224505fe6b9ef60e5..0000000000000000000000000000000000000000 --- a/iexcode/instruments/IEX_VPU_backup.py +++ /dev/null @@ -1,544 +0,0 @@ -from os import path -from math import * -from time import sleep -import numpy.polynomial.polynomial as poly - -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 - -IDcal_path="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries" - -############################################################################################################## -################################ ID limits and calibration ############################## -############################################################################################################## - -def ID_calc_SP(mono_grating,ID_mode,hv_eV,QP_ratio): # Mode = state (0=RCP,1=LCP,2=V,3=H) - """Calculate the ID SP for a given polarization mode and energy; - with Mode = 0 (RCP),1 (LCP), 2 (V), 3 (H) - - Previously: ID_Calc - """ - - - if type(ID_mode)== str: - ID_state=ID_state_mode(ID_mode) - try: - K=ID_coef(mono_grating,ID_state,hv_eV,QP_ratio) - ID=poly.polyval(hv_eV,K) - except KeyError: - message_string='Not a valid ID mode!'+"\nValid Modes: "+str(ID_mode_list()) - print_warning_message(message_string) - ID=caget("ID29:EnergySeteV") - return round(ID,1) - -############################################################################################################## -################################ ID Functions ############################## -############################################################################################################## - - -def ID_wait_for_permission(): - """ - Monitors the ID permissions and waits for the ID to be in User Mode and then breaks - Checks the status every 30 seconds - - Previously: WaitForPermission - """ - while True: - ID_Access=caget("ID29:AccessSecurity.VAL") - if (ID_Access!=0): - print("Checking ID permission, please wait..."+dateandtime()) - sleep(30) - else: - print("ID now in user mode -"+dateandtime()) - break - -############################################################################################################## -def ID_get_all(verbose=False): - """ - returns dictionary with: ID_Mode, ID_QP_ratio, ID_SP, ID_RBV - - Previously: Get_energy - """ - vals={ - "ID_mode":ID_mode_get(verbose=False), - "ID_QP_ratio":ID_QP_ratio_get(verbose=False), - "ID_sp":ID_SP_get_eV(verbose=False), - "ID_rbv":ID_rbv_get_eV(verbose=False) - } - - if verbose: - print(" ID SP : "+"%.2f" % vals["ID_sp"] , "eV ID mode : "+vals["ID_mode"]) - print(" ID RBV : "+"%.2f" % vals['ID_rbv'], "eV QP mode : "+str(vals['ID_QP_ratio']) +" %") - return vals - -def ID_energy_range(ID_mode=None): - """ - Returns the ID_min_SP, ID_max_SP for a given ID mode - - Previously: ID_Range - """ - if ID_mode == None: - ID_state=caget("ID29:ActualMode") - else: - ID_state = ID_state_mode(ID_mode) - # RCP,LCP, V , H , HN - ID_min_SP = [400,400,440,250,250] - ID_max_SP = 3800 - #hv_min=[390,390,430,245,245] - - return ID_min_SP[ID_state],ID_max_SP - -def ID_mode_list(): - """ - returns the ID_mode_List - current mode = - """ - return ["RCP", "LCP", "V", "H", "HN"] - - -def ID_state_mode(ID_mode): - """ - Returns the state number if mode is a string - Returns the mode string if mode is an int or float - - Previously: ID_State2Mode(which,mode) - """ - try: - ID_mode = ID_mode.upper() - ID_state =ID_mode_list().index(ID_mode) - return ID_state - - except: - message_string='Not a valid ID mode!'+"\nValid Modes: "+str(ID_mode_list()) - print_warning_message(message_string) - -def ID_state_get(): - """ - Returns the current ID state - """ - ID_state = caget("ID29:ActualMode") - return ID_state - -def ID_mode_get(verbose=True): - """ - Returns the current ID mode - """ - ID_state = caget("ID29:ActualMode") - ID_mode = ID_mode_list()[ID_state] - - if verbose: - print('ID mode: '+ID_mode) - return ID_mode - -def ID_mode_set(ID_mode): - """ - writes the desired mode to the correct ID pv - """ - caput("ID29:DesiredMode.VAL",ID_mode,wait=True,timeout=18000) # RCP - - -def ID_ready(verbose=True): - """ - check both the read and busy pv every 2 seconds - - Previously: ID_Ready - """ - while True: - RBV=caget("ID29:Energy.VAL") - checkready=caget("ID29:feedback.VAL") - checkbusy=caget("ID29:BusyRecord") - if (checkready!="Ready") or (RBV < 3.7): - sleep(2) - elif ((checkready=="Ready") and (RBV > 3.7)) and (checkbusy=="Busy"): - caput("ID29:Busy.VAL",0) - else: - if verbose: - print("ID Ready") - return True - -def ID_power_status(): - """ - gets if the ID power supplies are On or Off - """ - ID_OnOff=caget('ID29:Main_on_off.VAL') - if ID_OnOff == 1: - return 'Off' - elif ID_OnOff == 0: - return 'On' - -def ID_off(verbose=True): - """ - waits for permission then turns on the main coils OFF - """ - ID_wait_for_permission() - caput("ID29:Main_on_off.VAL",1,wait=True,timeout=18000) - sleep(5) - if verbose: - print("ID is now off") - - -def ID_on(verbose=True): - """ - waits for permission then turns on the main coils On - """ - ID_wait_for_permission() - if verbose: - print("Starting ID - "+dateandtime()) - - caput("ID29:EnergySet.VAL",3.8) - caput("ID29:Main_on_off.VAL",0,wait=True,timeout=18000) - -def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True): - """ - waits for ID permission and then - starts ID with a specific polarization - mode = \"H\", \"V\", \"RCP\" or \"LCP\" - QP ratio if specified - """ - #turns on if ID is off - if ID_power_status =='Off': - ID_on() - #set QP - if ID_ready(): - ID_QP_mode_set(QP_ratio,verbose) - #set ID mode - if ID_ready(): - ID_mode_set(ID_mode, verbose) - #opens the main shutter - if ID_ready(): - main_shutter_open() - - if verbose: - print('ID is now on, please set your energy') - -def ID_switch_mode(ID_mode): - """ - Change ID polarization; which = 'H', 'V', 'RCP' or 'LCP' - if ID_mode = current mode then does nothing - - WARNING: Does not set the energy - - Previously Switch_IDMode - """ - ID_wait_for_permission() - main_shutter_open() - ID_state = ID_state_get() - - try: - if ID_state_mode(ID_mode) != ID_state: - print("Turning ID off...") - ID_off(verbose=True) - sleep(10) - - print("Switching ID mode, please wait...") - ID_mode_set(ID_mode) - ID_ready() - print("ID Mode:",ID_mode) - except: - print_warning_message("Not a valid ID mode") - -def ID_SP_get(verbose=False): - """ - returns the ID setpoint in keV - """ - ID_SP = caget("ID29:EnergyScanSet.VAL") - if verbose: - print("ID_SP: ", ID_SP) - return ID_SP - -def ID_SP_get_eV(verbose=False): - """ - returns the ID setpoint in eV - """ - ID_SP = ID_SP_get(verbose=False) - if verbose: - print("ID_SP: ", ID_SP) - return ID_SP - -def ID_rbv_get(verbose=False): - """ - returns the readback value for the - """ - ID_RBV = caget("ID29:EnergyRBV") - if verbose: - print("ID_RBV: ", ID_RBV) - return ID_RBV - -def ID_rbv_get_eV(verbose=False): - """ - returns the readback value for the - """ - ID_RBV = ID_rbv_get(verbose=False) - if verbose: - print("ID_RBV: ", ID_RBV) - return ID_RBV - - -def ID_SP_set(hv_eV,verbose=True): - """ - "Sets the ID set point to a specific value (hv(eV)) which will not likely be optimum" - - Previously: SetID_Raw - """ - def _ID_write_SP_proc(keV): - caput("ID29:EnergyScanSet.VAL",keV,wait=True,timeout=18000) - sleep(0.5) - caput("ID29:EnergyScanSet.VAL",(keV+0.001),wait=True,timeout=18000) - caput('ID29:StartRamp.VAL',1) - - def _ID_bw_ok(ID_SP): - ID_bw = ID_SP*0.095 - ID_diff = abs(ID_rbv_get()-ID_SP) - if ID_diff > ID_bw: - return False - else: - return True - - #checking permissions and opening the main shutter - ID_wait_for_permission() - main_shutter_open() - - #checking if desired is with allowed range, if not printing the nearest allowed value - ID_max,ID_min = ID_energy_range() - ID_SP=min(max(hv_eV,ID_min),ID_max)*1.0 - if hv_eV < ID_min or hv_eV > ID_max: - message_string="Set point out of BL energy range \nPlease select a different energy." - message_string+="\nClosest allowed value is "+str(ID_SP) - print_warning_message(message_string) - else: - #desired energy is within range - ID_SP_RBV=round(caget("ID29:EnergySet.VAL"),3)*1000 - ID_RBV=caget("ID29:EnergyRBV") - if ID_SP == ID_SP_RBV: - #ID is already at the SP energy - if verbose: - print("ID SET : "+"%.1f" % ID_SP, "eV") - print("ID RBV : "+"%.1f" % ID_RBV, "eV") - print(caget('ID29:TableDirection',as_string=True)) - - else: - # 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) == False: - ID_QP_ratio_get print("QP ratio =", round(ratio,3)*100,"%") - print("QP RBV =", ratio_RBV,"%") - -def ID_energy_set(hv_eV,QP_ratio=None): - """ - Sets optimum ID set point for hv(eV) (max intensity) - and opens the main shutter - - Note that QP is generally not calibrated - - Previously: SetID - """ - ID_mode = ID_mode_list()[ID_state_get()] - mono_grating = mono_grating_get() - ID_SP = ID_calc_SP(mono_grating,ID_mode,hv_eV,QP_ratio) - ID_SP_set(ID_SP) - - -def ID_QP_ratio_get(verbose=True): - """ - gets the read back for the QP ratio - calculate the QP ratio - - """ - Byq=caget("ID29:ByqRdbk") - Vcoil=caget("ID29:ByRdbk.VAL") - ratio_calc=Byq/Vcoil - ratio_RBV=caget("ID29:QuasiRatio.RVAL") - if verbose: - print("QP ratio =", round(ratio_RBV,3)*100,"%") - print("QP RBV =", ratio_RBV,"%") - - if abs(ratio_RBV-ratio_calc)>1: - message_string="QP RBV and QP calc do not agree \nCheck Interlocks" - print_warning_message(message_string) - return ratio_RBV, ratio_calc - -def ID_QP_mode_set(QP_ratio=None,verbose=True): - """ - switched to QP mode, if not currently in - sets the QP ratio (QP ratio min is 70) and polarization (ID mode) - - WARNING: you will need to set the polarization and mode afterward - - Previously: Switch_IDQP - """ - - #checking if above the minimum allowed value - QP_min = 70 - if QP_ratio < QP_min: - message_string="QP ratio is too small, setting it to minimum allowed value ("+str(QP_min)+")" - print_warning_message(message_string) - QP_ratio=max(70,QP_ratio) - - if QP_ratio != None: - #checking to see if already in specified QP - ratio_RBV, ratio_calc = ID_QP_ratio_get() - #not the same ratio - if ratio_RBV != QP_ratio: - ID_off() - caput("ID29:QuasiRatioIn.C",QP_ratio) - - ID_on() - sleep(15) - - -def ID_coef(grt,ID_state,hv_eV,QP_ratio): # Mode = state (0=RCP,1=LCP,2=V,3=H); - - """Return the ID coeff for a given polarization mode and energy; - with Mode = 0 (RCP),1 (LCP), 2 (V), 3 (H). - Current coefficient dictionary: - /home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries/Dict_IDCal.txt - - Previously: ID_Coef - """ - - if QP_ratio == None: - QP_ratio = ID_QP_ratio_get()[0] - - def ListRange(grt,ID_state,IDdict): # extract the list of break pts for a given mode/grt - tmp_list=[] - for item in (IDdict[grt][ID_state]): - tmp_list.append(item[0]) - return tmp_list - - - def FindRange(hv_eV,range_list): # returns the index for the corresponding range - B = [x - hv_eV for x in range_list] - #print(B) - index = [i for (i, x) in enumerate(B) if x > 0] - #print(index) - return(index[0]) - - - - if QP_ratio < 100: - if isinstance(QP_ratio,float) or isinstance(QP_ratio,int): - QP_ratio=str(floor(QP_ratio)) - dictfile='Dict_IDCal_QP'+QP_ratio+'.txt' - error_msg="calibration curve might not exist for this QP value" - else: - print('invalid QP value') - return - else: - dictfile='Dict_IDCal.txt' - error_msg="" - try: - IDcal_fpath = path.join(IDcal_path,dictfile) - ID_function=read_dict(IDcal_fpath) - - except KeyError: - print("Unable to read dictionary "+dictfile+" ; "+error_msg) - - try: - Lrange = ListRange(grt,ID_state,ID_function) - Erange = FindRange(hv_eV,Lrange) - K = ID_function[grt][ID_state][Erange][1] - return K - - except KeyError: - print("WARNING: PLease select one of the following: "+str(ID_mode_list())) - - -def ID_scan_pvs(): - """ - returns the rbv and val for scanning - """ - val_pv="ID29:EnergyScanSeteV" - rbv_pv="ID29:EnergySetRBV" - return val_pv, rbv_pv - -def ID_scan_fillin(mda,scan_dim,start,stop,step,**kwargs): - """ - fills in the scanRecord for scanning the ID set point - - **kwargs => scanRecord.fillin kwargs - """ - #Setting up the ScanRecord for ID in Table mode - val_pv, rbv_pv = ID_scan_pvs() - mda.fillin(scan_dim,val_pv,rbv_pv,start,stop,step,**kwargs) - - -def ID_scan_fillin_table(mda,scan_dim,ID_array,**kwargs): - """ - fills in the scanRecord for scanning the ID set point - - **kwargs => scanRecord.fillin kwargs - """ - #Setting up the ScanRecord for ID in Table mode - val_pv, rbv_pv = ID_scan_pvs() - mda.fillin.table(scan_dim,val_pv,rbv_pv,ID_array,**kwargs) - -############################################################################################################## -############################## ID direction table ############################## -############################################################################################################## - -def ID_Table(): - """ - - Previously: ID_Table - """ - table = caget("ID29:TableDirection") # up = 1 , down = 0 - By = caget("ID29:ByPolaritySet") # pos = 1, neg = 0 - - mode = ID_mode_get() - - if By > 0: - print("\nBy > 0") - if table == 1: # By=1, table = 1 => -1 => A=B - print("table = up") - ID_direction = -1 - elif table == 0: # By=1, table = 0 => +1 => A#B - print("table = down") - ID_direction = 1 - elif By <= 0: - print("\nBy < 0") - if table == 1: # By=0, table = 1 => +1 => A=B - print("table = up") - ID_direction = 1 - elif table == 0: # By=0, table = 0 => -1 => A#B - print("table = down") - ID_direction = -1 - - - if mode == "H" and mode == "RCP": - if By > 0 and table == 0: - print_warning_message("will do a long hysteresis if decreasing energy !!!") -# if Mode == "HN" and Mode == "LCP": -# if By = 0 and table == 1: -# print "WARNING: will do a long hysteresis if decreasing energy !!!" - print("ID direction", ID_direction) - return ID_direction - -def ID_table_userCalcOut(): - """ - # Work in progress - - Previously:ID_Table_CalcOut - """ - n=4 - userCalcOut_clear("b",n) - pvstr="29idb:userCalcOut"+str(n) - caput(pvstr+".DESC","ID_Table") - table="ID29:TableDirection" # up = 1 , down = 0 - By="ID29:ByPolaritySet" # pos = 1, neg = 0 - caput(pvstr+".INPA",table+" CP NMS") - caput(pvstr+".INPB",By+" CP NMS") - caput(pvstr+".CALC$","A#B") - caput(pvstr+".OOPT","On Change") - caput(pvstr+".DOPT","Use CALC") \ No newline at end of file diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py index 7c3ca56b35d1da10ea0fe0ee6c2ff2be5cb6e77a..cb565d1633d08e3922fbd990af567de242f27d5d 100644 --- a/iexcode/instruments/Kappa.py +++ b/iexcode/instruments/Kappa.py @@ -12,15 +12,15 @@ 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 from iexcode.instruments.staff import staff_detector_dictionary -from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all +from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all from iexcode.instruments.conversions_constants import * from iexcode.instruments.utilities import * from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs from iexcode.instruments.Motors import Motors -from iexcode.instruments.current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence -from iexcode.instruments.current_amplifiers import SRS +from iexcode.instruments.SRS_current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence +from iexcode.instruments.SRS_current_amplifiers import SRS from iexcode.instruments.valves import branch_valve_close from iexcode.instruments.shutters import branch_shutter_close @@ -185,7 +185,7 @@ def _kappa_detector_dictionary(**kwargs): #add detectors related to beamline if iex.BL.xrays: - det_dict.update(_xrays_detector_dictionary()) + det_dict.update(xrays_detector_dictionary()) return det_dict diff --git a/iexcode/instruments/current_amplifiers.py b/iexcode/instruments/Keithley_current_amplifiers.py similarity index 53% rename from iexcode/instruments/current_amplifiers.py rename to iexcode/instruments/Keithley_current_amplifiers.py index 47327a8acac2ee40b338b0da252ab2cb8c0f729e..4ce8304280da680fd40c52260a629c4293a67faf 100644 --- a/iexcode/instruments/current_amplifiers.py +++ b/iexcode/instruments/Keithley_current_amplifiers.py @@ -17,7 +17,7 @@ def ca_detector_list(branch): return ca_list -def _ca_dictionary(): +def ca_dictionary(): """ dictionary of connected Keithley and thier names @@ -64,7 +64,7 @@ class Keithley: """ self._pv = _Keithley_pv(ca_crate, ca_num) try: - self.name = _ca_dictionary()[ca_crate][ca_num] + self.name = ca_dictionary()[ca_crate][ca_num] except: self.name = 'CA'+ca_crate+str(ca_num) @@ -201,7 +201,7 @@ def ca_reset_all(rate="Slow"): Previously: Reset_CA_all """ - ca_dict = _ca_dictionary() + ca_dict = ca_dictionary() for ca_crate in ca_dict.keys(): for ca_num in ca_dict[ca_crate].keys(): CA = Keithley(ca_crate,ca_num) @@ -261,181 +261,3 @@ def ca_average(avg_pts,**kwargs): ca.avg(avg_pts,rate=kwargs['rate'],verbose=kwargs['verbose']) -def _load_responsivity_curve(): - """ - Loads the responsivity curve for the AUX100 photo diode, used to convert - current to flux at a given photon energy - - Previously: loadResponsivityCurve - """ - FilePath='/home/beams/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries/' - FileName="DiodeResponsivityCurve" - data = np.loadtxt(FilePath+FileName, delimiter=' ', skiprows=1) - return data - -def current2flux(current,hv=None,verbose=True): - """ - Converts the current to flux for of an AUX 100 diode using the responisity curves - - hv = None; gets the current mono energy; otherwise you will need to specify - - Previously CA2flux - """ - try: - curve=_load_responsivity_curve() - except: - print('responsivity curve not loaded') - return - responsivity=curve[:,0] - energy=curve[:,1] - charge = 1.602e-19 - if hv is None: - try: - hv = mono_energy_get() - except: - print('specify hv') - return - eff=np.interp(hv,energy,responsivity) - flux = current/(eff*hv*charge) - if verbose: - print("\nCalculating flux for:") - print(" hv = %.1f eV" % hv) - print(" current = %.3e Amp" % current) - print("Flux = %.3e ph/s\n" % flux) - return flux - - -def flux2current(flux,hv=None,verbose=True): - """ - Converts the specified flux to a current for of an AUX 100 diode using the responisity curves - - hv = None; gets the current mono energy; otherwise you will need to specify - """ - try: - curve=_load_responsivity_curve() - except: - print('responsivity curve not loaded') - return - responsivity=curve[:,0] - energy=curve[:,1] - charge = 1.602e-19 - if hv is None: - try: - hv = mono_energy_get() - except: - print('specify hv') - return - eff=np.interp(hv,energy,responsivity) - current = flux*(eff*hv*charge) - if verbose: - print("\nCalculating current for:") - print(" hv = %.1f eV" % hv) - print(" flux = %.3e ph/s" % flux) - print("Current = %.3e Amp/n" % current) - return current - - - -############################################################################################################## -################################ SRS ############################## -############################################################################################################## -class SRS: - """ - SRS current amplifier and corresponding scalers - """ - - def __init__(self,scaler_pv,srs_pv): - self._scaler_pv = scaler_pv - self._srs_pv = srs_pv - - self.scaler_value = None - self.gain = None - self.current_Amp = None - self.current_unit = None - self.invert = None - self.offset_value = None - self.offset_unit = None - self.offset_sign = None - self.offset_factor = None - self.set_all() - self.get_all(verbose=False) - - def set_all(self): - """ - set all PV to current SP values (what the screen shows in not necessarely what the PV are set to) - """ - pv=self._srs_pv+"init.PROC" - caput(pv,1) - - - def get_all(self,verbose): - """ - reads the current SRS and corresponding scaler values - """ - self.scaler_value = caget(self._scaler_pv) - self.gain = float(caget(self._srs_pv+'sens_num.VAL',as_string=True)) - self.current_unit = caget(self._srs_pv+'sens_unit.VAL',as_string=True) - self.invert = caget(self._srs_pv+'invert_on.VAL',as_string=True) - unit_sciNote = {'pA':1e-12, 'nA':1e-9, 'uA':1e-6, 'mA':1e-3} - - self.offset_value=float(caget(self._srs_pv+"offset_num.VAL",as_string=True)) - self.offset_unit=caget(self._srs_pv+"offset_unit.VAL",as_string=True) - self.offset_sign=caget(self._srs_pv+"offset_sign.VAL",as_string=True) - self.offset_factor=float(caget(self._srs_pv+"off_u_put.VAL",as_string=True)) - - - current_Amp = self.scaler_value * self.gain * unit_sciNote[self.current_unit[:-2]] - baseline = self.offset_value * self.offset_factor * unit_sciNote[self.offset_unit] - - if self.invert == 1: - current_Amp *= -1 - if self.offset_sign == '+': - self.current_Amp = current_Amp + baseline - elif self.offset_sign == '-': - self.current_Amp = current_Amp - baseline - - self.filter_type=caget(self._srs_pv+'filter_type.VAL',as_string=True) - self.filter_low=caget(self._srs_pv+'low_freq.VAL',as_string=True) - self.filter_high=caget(self._srs_pv+'high_freq.VAL',as_string=True) - self.blank=caget(self._srs_pv+'blank_on.VAL',as_string=True) - self.bias_OnOff=caget(self._srs_pv+'bias_on.VAL',as_string=True) - self.bias_value=caget(self._srs_pv+'bias_put.VAL',as_string=True) - - if verbose: - self.print_all(extended=True) - - def get(self,verbose=True): - """ - returns the current in Amps with offset removed - """ - current = self.current_Amp - if verbose: - print(format(current,'.3E')) - return current - - def setgain(self,gain,unit): - """ - gain = 1,2,5,10,20,50,100,200,500 - unit = 'pA, 'nA', 'uA', 'mA' - """ - caput(self._srs_pv+'sens_num.VAL',str(gain)) - caput(self._srs_pv+'sens_unit.VAL',str(unit)) - - - def srs_print_all(self, extended=False): - """ - prints SRS setting - """ - print('Gain: '+str(self.scaler_value)+' '+str(self.current_unit)+' (invert '+str(self.invert)+')') - print('Baseline: '+str(self.offset_sign)+' '+str(self.offset_factor)+' x '+str(self.offset_value)+" "+str(self.offset_unit)) - if extended: - filterType = str(self.filter_type) - filterLow = str(self.filter_low) - filterHigh = str(self.filter_high) - blank = str(self.blank) - biasOnOff = str(self.bias_OnOff) - biasValue = str(self.bias_value) - print('Filter: '+filterType+' - Low/High: '+filterLow+' -'+filterHigh) - print('Bias: '+biasOnOff+'- '+biasValue) - print('Blank: '+blank) - diff --git a/iexcode/instruments/Octupole.py b/iexcode/instruments/Octupole.py index a3abb5a71ed63bbf802ee180b3b7fecf7794f364..9924a741cb2d5a30a781507ecd679934d8db5af1 100644 --- a/iexcode/instruments/Octupole.py +++ b/iexcode/instruments/Octupole.py @@ -12,14 +12,15 @@ 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 from iexcode.instruments.staff import staff_detector_dictionary -from iexcode.instruments.xrays import _xrays_detector_dictionary, _xrays_reset, xrays_get_all +from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all from iexcode.instruments.conversions_constants import * from iexcode.instruments.utilities import * from iexcode.instruments.userCalcs import * from iexcode.instruments.Motors import Motors -from iexcode.instruments.current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence,SRS +from iexcode.instruments.SRS_current_amplifiers import SRS +from iexcode.instruments.Keithley_current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence from iexcode.instruments.valves import branch_valve_close from iexcode.instruments.shutters import branch_shutter_close @@ -180,6 +181,7 @@ def _Octupole_detector_dictionary(**kwargs): } #hkl are listed just a place holders, they are filled in by thier scanning functions det_dict.update(sample_temp) + det_dict.update(m3r) det_dict.update(scalers) det_dict.update(xmcd_raw) det_dict.update(xmcd_norm) @@ -188,7 +190,7 @@ def _Octupole_detector_dictionary(**kwargs): #add detectors related to beamline if iex.BL.xrays: - det_dict.update(_xrays_detector_dictionary()) + det_dict.update(xrays_detector_dictionary()) return det_dict @@ -342,15 +344,6 @@ def Octupole_get_all(verbose=True): ############################################################################################################## ############################## logging ############################## ############################################################################################################## -def _Octupole_log_header(): - """ - header for the log file - """ - h = "scan,motor,start,stop,step,x,y,z,th,tth,TA" - h += "hv,exit_slit,GRT,ID_SP,ID_RBV,ID_Mode,ID_QP,TEY,mesh,det_name,mpa_HV,m3r_centroid,time,comment" - header_list = {'Octupole':h} - return header_list - def _Octupole_log_dictionary(): """ enstation info for log file @@ -431,6 +424,13 @@ def _Octupole_scan_after_sequence(**kwargs): kwargs.setdefault('scan_dim',1) scan_dim = kwargs['scan_dim'] +<<<<<<< HEAD +======= + scan_ioc = iex.BL.ioc + + after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) + +>>>>>>> 95226a1fe706ac74c0a7efeef77197a87c943634 #clear and write the after scan user sequence after_scan_pv,after_scan_proc = _Octupole_scan_after_pvs(clear=True,**kwargs) @@ -446,7 +446,11 @@ def _Octupole_scan_after_sequence(**kwargs): caput(after_scan_pv+".LNK3",scan_pv+".PDLY NPP NMS") caput(after_scan_pv+".DO3",0.1) +<<<<<<< HEAD ## Clear DetTriggers 2: +======= + ## Clear DetTriggers 2 : +>>>>>>> 95226a1fe706ac74c0a7efeef77197a87c943634 caput(after_scan_pv+".LNK4",scan_pv+".T2PV NPP NMS") #remove trigger 2 (used for EA) after scan ##Snake goes in LNKA (10) @@ -468,6 +472,7 @@ def _Octupole_detector_triggers_sequence(**kwargs): # do we need to add 29idb userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num']) caput(detector_triggers_pv+".DESC","Octupole_Trigger1") + #trigger Keithleys if any ca_list = _Octupole_ca_list() last = len(ca_list) if last !=0: @@ -476,9 +481,9 @@ def _Octupole_detector_triggers_sequence(**kwargs): # do we need to add 29idb caput(detector_triggers_pv+".LNK" +str(i+2),ca_pv) caput(detector_triggers_pv+".WAIT"+str(i+2),"After"+str(last)) + #trigger scaler if any last+=1 scaler_pv = Octupole_scaler_pv() - caput(detector_triggers_pv+".LNK" +str(1),scaler_pv) caput(detector_triggers_pv+".WAIT"+str(1),"After"+str(last)) diff --git a/iexcode/instruments/SRS_current_amplifiers.py b/iexcode/instruments/SRS_current_amplifiers.py new file mode 100644 index 0000000000000000000000000000000000000000..736a1f4767f54aeefc49ae129b6e7b4525fda793 --- /dev/null +++ b/iexcode/instruments/SRS_current_amplifiers.py @@ -0,0 +1,106 @@ +from epics import caget, caput + +############################################################ +################################################### +################################ SRS ############################## +############################################################################################################## +class SRS: + """ + SRS current amplifier and corresponding scalers + """ + + def __init__(self,scaler_pv,srs_pv): + self._scaler_pv = scaler_pv + self._srs_pv = srs_pv + + self.scaler_value = None + self.gain = None + self.current_Amp = None + self.current_unit = None + self.invert = None + self.offset_value = None + self.offset_unit = None + self.offset_sign = None + self.offset_factor = None + self.set_all() + self.get_all(verbose=False) + + def set_all(self): + """ + set all PV to current SP values (what the screen shows in not necessarely what the PV are set to) + """ + pv=self._srs_pv+"init.PROC" + caput(pv,1) + + + def get_all(self,verbose): + """ + reads the current SRS and corresponding scaler values + """ + self.scaler_value = caget(self._scaler_pv) + self.gain = float(caget(self._srs_pv+'sens_num.VAL',as_string=True)) + self.current_unit = caget(self._srs_pv+'sens_unit.VAL',as_string=True) + self.invert = caget(self._srs_pv+'invert_on.VAL',as_string=True) + unit_sciNote = {'pA':1e-12, 'nA':1e-9, 'uA':1e-6, 'mA':1e-3} + + self.offset_value=float(caget(self._srs_pv+"offset_num.VAL",as_string=True)) + self.offset_unit=caget(self._srs_pv+"offset_unit.VAL",as_string=True) + self.offset_sign=caget(self._srs_pv+"offset_sign.VAL",as_string=True) + self.offset_factor=float(caget(self._srs_pv+"off_u_put.VAL",as_string=True)) + + + current_Amp = self.scaler_value * self.gain * unit_sciNote[self.current_unit[:-2]] + baseline = self.offset_value * self.offset_factor * unit_sciNote[self.offset_unit] + + if self.invert == 1: + current_Amp *= -1 + if self.offset_sign == '+': + self.current_Amp = current_Amp + baseline + elif self.offset_sign == '-': + self.current_Amp = current_Amp - baseline + + self.filter_type=caget(self._srs_pv+'filter_type.VAL',as_string=True) + self.filter_low=caget(self._srs_pv+'low_freq.VAL',as_string=True) + self.filter_high=caget(self._srs_pv+'high_freq.VAL',as_string=True) + self.blank=caget(self._srs_pv+'blank_on.VAL',as_string=True) + self.bias_OnOff=caget(self._srs_pv+'bias_on.VAL',as_string=True) + self.bias_value=caget(self._srs_pv+'bias_put.VAL',as_string=True) + + if verbose: + self.print_all(extended=True) + + def get(self,verbose=True): + """ + returns the current in Amps with offset removed + """ + current = self.current_Amp + if verbose: + print(format(current,'.3E')) + return current + + def setgain(self,gain,unit): + """ + gain = 1,2,5,10,20,50,100,200,500 + unit = 'pA, 'nA', 'uA', 'mA' + """ + caput(self._srs_pv+'sens_num.VAL',str(gain)) + caput(self._srs_pv+'sens_unit.VAL',str(unit)) + + + def srs_print_all(self, extended=False): + """ + prints SRS setting + """ + print('Gain: '+str(self.scaler_value)+' '+str(self.current_unit)+' (invert '+str(self.invert)+')') + print('Baseline: '+str(self.offset_sign)+' '+str(self.offset_factor)+' x '+str(self.offset_value)+" "+str(self.offset_unit)) + if extended: + filterType = str(self.filter_type) + filterLow = str(self.filter_low) + filterHigh = str(self.filter_high) + blank = str(self.blank) + biasOnOff = str(self.bias_OnOff) + biasValue = str(self.bias_value) + print('Filter: '+filterType+' - Low/High: '+filterLow+' -'+filterHigh) + print('Bias: '+biasOnOff+'- '+biasValue) + print('Blank: '+blank) + diff --git a/iexcode/instruments/cfg.py b/iexcode/instruments/cfg.py index 6fe1b1ff7d8c15ea272ff2939118f5eb9e54e238..bbce76b6a18b4752a16b64f491326cd53d4f69ae 100644 --- a/iexcode/instruments/cfg.py +++ b/iexcode/instruments/cfg.py @@ -2,4 +2,3 @@ BL=None mpa=None -ca_list=[] \ No newline at end of file diff --git a/iexcode/instruments/diagnostics.py b/iexcode/instruments/diagnostics.py index d021dc45f4cb4e471fc0b356c32014d204a20db1..5def6af5696498c7ff4818c92797a47af93b3d99 100644 --- a/iexcode/instruments/diagnostics.py +++ b/iexcode/instruments/diagnostics.py @@ -3,13 +3,19 @@ from numpy import nan from epics import caput, caget import iexcode.instruments.cfg as iex -from iexcode.instruments.current_amplifiers import Keithley,SRS +from iexcode.instruments.SRS_current_amplifiers import SRS +from iexcode.instruments.Keithley_current_amplifiers import Keithley from iexcode.instruments.utilities import print_warning_message + ############################################################################################################## ################################ default positions ############################## ############################################################################################################## #For new endstation modify here: def diagnostics_presets(): + """ + returns a dictionary with the diagnostic presets and motor pv + {preset_name: ([presets_positions], motor_pv)} + """ presets={ 'H-wire':(['OUT','Start'],'29id:m1'), 'V-wire':(['OUT','Start'],'29id:m2'), @@ -38,7 +44,6 @@ def _diagnostics_inout_dict(): 'diode_c':('gas-cell','Diode1','OUT'), 'diode_d':('gas-D4D','Diode','OUT'), } - return d #For new endstation modify here: diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py index d7c92a143556e4c24c99ee9eeb70bc25c03f71be..028f5067e50b44d48ff9ec4f01af08abe2a1fd61 100644 --- a/iexcode/instruments/electron_analyzer.py +++ b/iexcode/instruments/electron_analyzer.py @@ -15,13 +15,13 @@ from scipy.interpolate import interp1d from epics import caput,caget from iexcode.instruments.IEX_BL_config import * +from iexcode.instruments.AD_utilities import AD_filepath,AD_prefix from iexcode.instruments.scanRecord import * from iexcode.instruments.conversions_constants import * from iexcode.instruments.xrays import energy, scanXAS, BL_energy_tables from iexcode.instruments.shutters import branch_shutter_close from iexcode.instruments.VLS_PGM import mono_energy_get from iexcode.instruments.files_and_folders import get_next_fileNumber -from iexcode.instruments.Logfile import log_print from iexcode.instruments.Scienta import * global EA @@ -146,6 +146,22 @@ def folders_EA(userPath,filePrefix="EA",**kwargs): df='h5' fpath=join(userPath,df) +def EA_filepath(): + """ + returns the filepath in EA._savePlugin + """ + filepath = AD_filepath(EA._savePlugin) + print('filepath = "'+filepath+'"') + return filepath + +def EA_prefix(): + """ + returns the filepath in EA._savePlugin + """ + prefix = AD_prefix(EA._savePlugin)+"_" + print('prefix = "'+prefix+'"') + return prefix + def EA_log_dictionary(): """ dictionary for writing spectra to logfile @@ -227,19 +243,30 @@ def _scanEATrigger(EAlist,before_after,**kwargs): if kwargs["debug"]: print("before_after: "+before_after) + + scantype, HVscanPV, KElist, parms = EA._spectraSetup(EAlist,**kwargs) #setting EA._savePlugin FilePath, FileName,FileNumber if before_after == "before": + #set prefix _scanEAPrefix("mda",**kwargs) - scantype, HVscanPV, KElist, parms =EA._spectraSetup(EAlist,**kwargs) - iex.BL.mda.trigger_dictionary.update({kwargs['detTrig']:HVscanPV}) + #set det trigger + mda_kwargs={'scan_dim':kwargs['scan_dim'],'trigger_dictionary':{kwargs['detTrig']:HVscanPV}} + iex.BL.mda.trigger_set(mda_kwargs) + #add scanNum as detector + iex.BL.mda.detectors_set(detector_dictionary={20:EA._savePlugin +"FileName"}) if before_after == "after": + #set prefix _scanEAPrefix(kwargs["prefix"],**kwargs) - iex.BL.mda.trigger_dictionary.update({kwargs['detTrig']:""}) - + #set det trigger + mda_kwargs={'scan_dim':kwargs['scan_dim'],'trigger_dictionary':{kwargs['detTrig']:''}} + iex.BL.mda.trigger_set(mda_kwargs) + #remove scanNum as detector + iex.BL.mda.detectors_set(detector_dictionary={20:''}) + if kwargs["debug"]: - print("trigger_dictionary",iex.BL.mda.trigger_dictionary) + print("mda_kwargs",mda_kwargs) return @@ -349,7 +376,7 @@ def scanEA(EAlist,**kwargs): pvCalcOut1=_BE2KE_setupCalc(EAlist[1],"BE_center",10,"29idcScienta:HV:fixedEnergy.VAL") EAlist[1]=caget(pvCalcOut1+'.VAL') arrayP1=list(np.full(sweeps, EAlist[1])) - iex.BL.mda.fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) + scan_fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) EAlist[1]=arrayP1[0] if kwargs['debug']: print('\npvCalcOut1: ',pvCalcOut1) @@ -358,7 +385,7 @@ def scanEA(EAlist,**kwargs): pvCalcOut1=_BE2KE_setupCalc(EAlist[1],"BE_center",10,"29idcScienta:HV:babySweepCenter.VAL") EAlist[1]=caget(pvCalcOut1+'.VAL') arrayP1=list(np.full(sweeps, EAlist[1])) - iex.BL.mda.fillin_table(pvCalcOut1+'PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) + scan_fillin_table(pvCalcOut1+'PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) print('\npvCalcOut1: ',pvCalcOut1) print('Pos1 table:',arrayP1) elif len(EAlist)==7: #Sweep @@ -368,8 +395,8 @@ def scanEA(EAlist,**kwargs): EAlist[2]=caget(pvCalcOut2+'.VAL') arrayP1=list(np.full(sweeps, EAlist[1])) arrayP2=list(np.full(sweeps, EAlist[2])) - iex.BL.mda.fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) - iex.BL.mda.fillin_table(pvCalcOut2+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP2,2) + scan_fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) + scan_fillin_table(pvCalcOut2+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP2,2) if kwargs['debug']: print("\npvCalcOut1",pvCalcOut1) print("\npvCalcOut2",pvCalcOut2) @@ -392,13 +419,8 @@ def scanEA(EAlist,**kwargs): iex.BL.mda.positioners_clear(**kwargs) VAL="" RBV="" - iex.BL.mda.fillin(VAL,RBV,1,sweeps,1,**kwargs) - if kwargs['debug']: - scanPV="29id"+kwargs["scanIOC"]+":scan"+str(kwargs["scan_dim"]) - print("scanPV: "+scanPV) - - - + scan_fillin(VAL,RBV,1,sweeps,1,**kwargs) + #Writing EA parameters EAscanType, EAscanPV, KElist, EAparms =EA._spectraSetup(EAlist,**kwargs) @@ -415,7 +437,7 @@ def scanEA(EAlist,**kwargs): time.sleep(10) EA.put(EAlist[1]-.05,EAlist[-3],LensMode="Angular") time.sleep(2) - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) #After scan EAlog_update() scanEA_reset(**kwargs) @@ -462,7 +484,7 @@ def scanFM(RoughPositions,thList,EAlist,**kwargs): if kwargs["execute"]==True: print(EAparms) EA.put(EAparms['KineticEnergy'],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) EAlog_update() scanEA_reset(**kwargs) diff --git a/iexcode/instruments/resolution.py b/iexcode/instruments/resolution.py index c6f5a73169e11f831e562c9b6ec8555b3ed52f7e..81e452dacd1176f7477d6a3e4f3804a6859b54c2 100644 --- a/iexcode/instruments/resolution.py +++ b/iexcode/instruments/resolution.py @@ -17,12 +17,11 @@ def resolution(): ARPES: total resolution i.e. sqrt(kbT^2 + analyzer^2 + BL^2); default SES slit = 5. Kappa: beamline contribution only """ - branch = iex.BL.branch grt = mono_grating_get() hv_eV = getE() slit_size = take_closest_value([10,20,50,100,200],round(slit_get(),0)) - if branch == "c": + if iex.BL.endstation_name == "ARPES": slit_SES = SES_slit_get() PE = int(EA.PassEnergy) Tsample = caget(ARPES_extra_pvs['TA']) diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py index d0537a2db0d1643cb064429a838ea48a242e62c2..0658ba59cb65f20cfb538e90ccc8e990c6899266 100644 --- a/iexcode/instruments/scanRecord.py +++ b/iexcode/instruments/scanRecord.py @@ -54,12 +54,36 @@ def last_mda(): except: print("IEX_endstations has not been initialized") -def user_path(): +def mda_filepath(): """ returns to the user directory as found in the mda scanRecord """ return iex.BL.mda.filepath() +def mda_prefix(): + """ + returns the prefix for the mda files + """ + return iex.BL.mda.prefix() + +def mda_user_name(): + """ + returns the user name form the mda filepath + """ + return iex.BL.mda.user_name() + +def mda_user_name(): + """ + returns the run cycle form the mda filepath + """ + return iex.BL.mda.run_cycle() + +def mda_reset(): + """ + resets the scanRecord to the default settings + """ + iex.BL.mda.reset_all() + def saveData_get_all(ioc_pv): """ returns saveData info: @@ -172,7 +196,6 @@ class ScanRecord: - ############################################################################################################## ################################ MDA (ScanRecord) files and folders ############################## @@ -214,7 +237,7 @@ class ScanRecord: """ return saveData_get_all(self.ioc)['baseName'] - def current_run(self): + def run_cycle(self): """ returns the current run by parsing the filepath in the SaveData for ioc @@ -222,8 +245,8 @@ class ScanRecord: """ filepath = self.filepath() m=filepath.find('data_29id')+len('data_29id')+2 - current_run=filepath[m:m+6] - return current_run + run_cycle=filepath[m:m+6] + return run_cycle def user_name(self): """ @@ -249,158 +272,96 @@ class ScanRecord: ### before and after scans - def _before_after_scan_set(self,scan_dim,**kwargs): + def before_scan_set(self,**kwargs): """ - Clears the before_scan and after_scan in all dims - Fills in the before_scan and after_after pv for kwargs['scan_dim'] only + sets the before scan pv + before_scan_pv = '' to clear + **kwargs - before_scan_pv - after_scan_pv + scan_dim: 1 (default) + before_scan_pv: self.before_scan_pv (default) """ + kwargs.setdefault('scan_dim',1) + if kwargs['scan_dim'] == 1: + kwargs.setdefault('before_scan_pv',self.before_scan_pv) + kwargs.setdefault('before_scan_pv',self.before_scan_pv) - scan_pv = self.ioc+"scan"+str(scan_dim) - - if 'before_scan_pv' in kwargs: - self.before_scan_pv = kwargs['before_scan_pv'] - caput(scan_pv+".BSPV",self.before_scan_pv) - caput(scan_pv+".BSCD",1) - caput(scan_pv+".BSWAIT","Wait") - - if 'after_scan_pv' in kwargs: - self.before_scan_pv = kwargs['after_scan_pv'] - caput(scan_pv+".ASPV",self.after_scan_pv) - caput(scan_pv+".ASCD",1) - caput(scan_pv+".ASWAIT","Wait") - + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + caput(scan_pv+".BSPV",kwargs['before_scan_pv']) + caput(scan_pv+".BSCD",1) + caput(scan_pv+".BSWAIT","Wait") - def default_after_scan_seq(self,**kwargs): + def after_scan_set(self,**kwargs): """ - writes the user string sequence to happen at the end of a scan - returns after_scan_pv = pv for userStringSeq for after scan - - uses links 1-4, link 10 is reserved for snake scans + sets the after scan pv + after_scan_pv = '' to clear **kwargs - seq_num: userStringSeq number in ioc => 10 (default) - positioner_settling_time - detector_settling_time - - Previously: AfterScan_StrSeq + scan_dim: 1 (default) + default => self.after_scan_pv if scan_dim = 1 + default => '{}' if scan_dim > 1 (i.e. does nothing) + after_scan_pv: self.after_scan_pv (default) """ - kwargs.setdefault('seq_num',10) - kwargs.setdefault('positioner_settling_time',default_positioner_settling_time) - kwargs.setdefault('detector_settling_time',default_detector_settling_time) - - scan_dim = 1 - scan_pv = self.ioc+"scan"+str(scan_dim) - - seq_num=kwargs['seq_num'] - after_scan_pv = userStringSeq_pvs(self.ioc, seq_num)[0] - self.after_scan_pv = after_scan_pv - - #clear and write the after scan user sequence - userStringSeq_clear(self.ioc,seq_num) - caput(after_scan_pv+".DESC","After Scan") - - #link 1 - clears positioners - caput(after_scan_pv+".LNK1",scan_pv+'.P1AR'+" PP NMS") - caput(after_scan_pv+".STR1","Clear pos&rdbk PV's, etc") - - #link 2 - sets positioner mode to to abosolute - caput(after_scan_pv+".LNK2",scan_pv+'.CMND'+" PP NMS") - caput(after_scan_pv+".STR2","ABSOLUTE") + kwargs.setdefault('scan_dim',1) + kwargs.setdefault('after_scan_pv','') + if kwargs['scan_dim'] == 1: + kwargs.setdefault('after_scan_pv',self.after_scan_pv) - #link 3 - sets positioner delay time to default - settling_time = kwargs['positioner_settling_time'] - caput(after_scan_pv+".LNK3",scan_pv+'.PDLY'+" PP NMS") - caput(after_scan_pv+".DO3",settling_time) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - #link 4 - sets detector delay time to default - settling_time = kwargs['detector_settling_time'] - caput(after_scan_pv+".LNK4",scan_pv+'.DDLY'+" PP NMS") - caput(after_scan_pv+".DO4",settling_time) + caput(scan_pv+".ASPV",kwargs['after_scan_pv']) + caput(scan_pv+".ASCD",1) + caput(scan_pv+".ASWAIT","Wait") - return after_scan_pv+".PROC" ### Resetting: - def reset_scan_dim(self,scan_dim,**kwargs): + def reset_scan_dim(self,**kwargs): """ - Resets all the scanRecords (scanDIM=1,2,3,4) for a given IOC - **kwargs: + Clears the scanRecord and then writes the default parameters unless specified in kwargs + + kwargs: + scan_dim: 1 (default) + positioner_settling_time + positioner_after_scan detector_dictionary + detector_settling_time trigger_dictionary before_scan_pv after_scan_pv Previously: Reset_ScanAll """ - - #clearing - self.detectors_clear(scan_dim,{}) - self.triggers_clear(scan_dim,{}) - self.positioners_clear({scan_dim:scan_dim}) + kwargs.setdefault('scan_dim',1) - #resetting - if 'detector_dictionary' in kwargs: - self.detectors_set(scan_dim,kwargs['detector_dictionary']) - if 'trigger_dictionary' in kwargs: - self.triggers_set(scan_dim,kwargs['trigger_dictionary']) + #positioners + self.positioners_clear(**kwargs) + self.positioner_settling_time_set(**kwargs) + self.positioner_after_scan_set(**kwargs) + self.positioner_absolute_mode_set(**kwargs) + + #detectors + self.detectors_clear(**kwargs) + self.detectors_set(**kwargs) + #detector settling time + self.detector_settling_time_set(**kwargs) - self._before_after_scan_set(scan_dim,**kwargs) + #detector triggers + self.triggers_clear(**kwargs) + self.triggers_set(**kwargs) - #settling time - kwargs.setdefault('scan_dim',scan_dim) - self.detector_settling_time(**kwargs) - self.positioner_settling_time(**kwargs) + self.before_scan_set(**kwargs) + self.after_scan_set(**kwargs) - def reset_all(self,**kwargs): + def reset_all(self): """ Resets all the scanRecords (scanDIM=1,2,3,4) for a given IOC - - - **kwargs - detector_dictionary - trigger_dictionary - before_scan_pv - after_scan_pv - - Note that for scan_dim = 1; default values are those that were set to attributes Previously: Reset_ScanAll """ - kwargs.setdefault('detector_dictionary',self.detector_dictionary) - kwargs.setdefault('trigger_dictionary',self.trigger_dictionary) - if self.before_scan_pv != None: - kwargs.setdefault('before_scan_pv',self.before_scan_pv) - if self.after_scan_pv != None: - kwargs.setdefault('after_scan_pv',self.after_scan_pv) - - #clearing all for scan_dim in range(4,1): - self.reset_scan_dim(scan_dim,{},{},'','') - - #setting to defaults - self.reset_scan_dim(1,**kwargs) - - ### default setting - def settings_defaults(self,scan_dim,verbose=True,**kwargs): - """ - Reset scan settings to default: ABSOLUTE, STAY, 0.05/0.1 positioner/detector settling time - - Previous: Reset_Scan - """ - kwargs.setdefault('scan_dim',scan_dim) - scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - self.positioner_absolute_mode(absolute=True,**kwargs) # Absolute position - self.positioner_after_scan(after="PRIOR POS",**kwargs) # After scan: prior position - self.positioner_settling_time(**kwargs)# Positioner Settling time => default - self.detector_settling_time(**kwargs)# Detector Settling time => default - self.triggers_reset(verbose=False,**kwargs) - - if verbose: - print("Scan record "+self.ioc+" reset to default settings.") - + self.reset_scan_dim(scan_dim=scan_dim) + ### positioners def positioners_clear(self,verbose=True,**kwargs): """ @@ -416,43 +377,69 @@ class ScanRecord: if verbose: print("\nAll extra positionners cleared") - def positioner_settling_time(self,**kwargs): + def positioner_settling_time_set(self,**kwargs): """ sets the positioner settling time + + **kwargs: + scan_dim: 1 (default) + positioner_settling_time: self.positioner_settling_time (default) + """ kwargs.setdefault('scan_dim',1) kwargs.setdefault('positioner_settling_time',self.default_positioner_settling_time) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - caput(scan_pv+".PDLY",kwargs['positioner_settling_time']) # Positioner Settling time - return scan_pv+".PDLY",kwargs['positioner_settling_time'] + caput(scan_pv+".PDLY",kwargs['positioner_settling_time']) + + def positioner_settling_time_get(self,**kwargs): + """ + returns the positioner settling time + + **kwargs: + scan_dim: 1 (default) + """ + kwargs.setdefault('scan_dim',1) + + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + + return caget(scan_pv+".PDLY") + - def positioner_after_scan(self,after="PRIOR POS",**kwargs): + def positioner_after_scan_set(self,**kwargs): """ sets the positioner after scan - after = "PRIOR POS" - "STAY" + + **kwargs + scan_dim: 1 (default) + positioner_after_scan + = "PRIOR POS" (default) + = "STAY" """ kwargs.setdefault('scan_dim',1) + kwargs.setdefault('positioner_after_scan',"PRIOR POS") scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - caput(scan_pv+".PASM",after) + caput(scan_pv+".PASM",kwargs['positioner_after_scan']) - def positioner_absolute_mode(self,absolute=True,**kwargs): + def positioner_absolute_mode_set(self,**kwargs): """ - absolute = True - = False => relative + sets the positioner mode + **kwargs + absolute = True + = False => relative + scan_dim: 1 (default) """ + kwargs.setdefault('positioner_absolute_mode',True) kwargs.setdefault('scan_dim',1) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - if absolute: + if kwargs['positioner_absolute_mode']: ab_state = 0 else: ab_state = 1 - caput(scan_pv+".P1AR",ab_state) # Absolute position def fillin(self,val_pv,rbv_pv,start,stop,steps_points,**kwargs): @@ -467,16 +454,17 @@ class ScanRecord: kwargs: num_points: False (default) => steps_points is the step size True => steps_points is the number of points + scan_dim: default => 1 positioner_num: default => 1 - positioner_settling_time: default => 0.1 - detector_settling_time: default => 0.1 + --- the following only changed if called, reset_scan to set to defaults --- + positioner_settling_time + detector_settling_time + trigger_dictionary Previously: Scan_FillIn """ kwargs.setdefault('scan_dim',1) 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']) @@ -487,11 +475,16 @@ class ScanRecord: if kwargs['debug']: print('fillin: ',val_pv,rbv_pv,start,stop,steps_points) + #clear positioners + self.positioners_clear(**kwargs) + #write new positioners + caput(scan_pv+".P"+str(posNum)+"SM","LINEAR") 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) caput(scan_pv+".P"+str(posNum)+"EP",stop*1.0) + #set the number of points if posNum == 1: if 'num_points' in kwargs: if kwargs['num_points'] : @@ -499,106 +492,171 @@ class ScanRecord: else: caput(scan_pv+".P1SI",steps_points*1.0) - self.detector_settling_time(**kwargs) - self.positioner_settling_time(**kwargs) - + # kwargs + if 'detector_settling_time' in kwargs: + self.detector_settling_time_set(**kwargs) + if 'positioner_settling_time' in kwargs: + self.positioner_settling_time_set(**kwargs) if 'trigger_dictionary' in kwargs: - self.trigger_dictionary = kwargs['trigger_dictionary'] - self.triggers_set(kwargs['scan_dim'],self.trigger_dictionary) + self.triggers_set(**kwargs) #checking that PVs and positioner limits are good + time.sleep(.1) self.check(kwargs['scan_dim']) ### detectors and detector settling time - def detectors_clear(self,scan_dim,verbose=True): + def detectors_clear(self,**kwargs): """ Clear all scan detectors + **kwargs: + scan_dim: 1 (default) + Previously: Clear_Scan_Detectors """ - scan_pv = self.ioc+"scan"+str(scan_dim) + kwargs.setdefault('scan_dim',1) + kwargs.setdefault('verbose',True) + + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) for i in range(1,10): caput(scan_pv+".D0"+str(i)+"PV","") for i in range(10,71): caput(scan_pv+".D"+str(i)+"PV","") - if verbose: + if kwargs['verbose']: print("\nAll detectors cleared") - def detectors_set(self,scan_dim,detector_dictionary): + def detectors_set(self,**kwargs): """ - sets the detectors - detector_dictionary = {detNum:pv} + sets the detectors, doesn not clear the record first (only adds/overwrites) + + **kwargs: + scan_dim: 1 (default) + detector_dictionary: + default => self.detector_dictionary if scan_dim = 1 + default => {} if scan_dim > 1 (i.e. does nothing) """ - scan_pv = self.ioc+"scan"+str(scan_dim) + kwargs.setdefault('scan_dim',1) + kwargs.setdefault('detector_dictionary',{}) + if kwargs['scan_dim'] == 1: + kwargs.setdefault('detector_dictionary',self.detector_dictionary) + + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + detector_dictionary = kwargs['detector_dictionary'] + for det_num in detector_dictionary.keys(): det_pv=scan_pv+".D"+str(det_num).zfill(2)+"PV" caput(det_pv,detector_dictionary[det_num]) - def detector_settling_time(self,**kwargs): + def detectors_get(self,**kwargs): + """ + gets and returns detector_dictionary = {detNum:pv} + + **kwargs: + scan_dim: 1 (default) + """ + kwargs.setdefault('scan_dim',1) + + detector_dictionary = {} + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + for det_num in detector_dictionary.keys(): + det_pv=scan_pv+".D"+str(det_num).zfill(2)+"PV" + detector_dictionary.update({det_num:caget(det_pv)}) + + + def detector_settling_time_set(self,**kwargs): """ set the detector settling time + + **kwargs + scan_dim: 1 (default) + detector_settling_time: self.detector_settling_time(default) + """ + kwargs.setdefault('scan_dim',1) kwargs.setdefault('detector_settling_time',self.default_detector_settling_time) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) caput(scan_pv+".DDLY",kwargs['detector_settling_time']) - return scan_pv+".DDLY",kwargs['detector_settling_time'] + return + + def detector_settling_time_get(self,**kwargs): + """ + set the detector settling time + + **kwargs + scan_dim: 1 (default) + + """ + kwargs.setdefault('scan_dim',1) + + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + + return caget(scan_pv+".DDLY") ### triggers - def triggers_set(self,scan_dim,trigger_dictionary): + def triggers_clear(self,**kwargs): """ Clear all scan detectors triggers + **kwargs: + scan_dim: 1 (default) + verbose: Falase (default) - trigger_dictionary = {trigger_num:pv} + Previously: Clear_Scan_Triggers """ - scan_pv = self.ioc+"scan"+str(scan_dim) - if len(trigger_dictionary.keys())>0: - for tigger_num in trigger_dictionary.keys(): - caput(scan_pv+".T"+str(tigger_num)+"PV",trigger_dictionary[tigger_num]) + kwargs.setdefault('scan_dim',1) + kwargs.setdefault('verbose',False) + + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + + for trig_num in range(1,5): + caput(scan_pv+'.T'+str(trig_num)+'PV',"") - def triggers_get(self,scan_dim): + def triggers_get(self,**kwargs): """ returns a dictionary of the current scan striggers for scan_dim + **kwargs: + scan_dim: 1 (default) """ - scan_pv = self.ioc+"scan"+str(scan_dim) + kwargs.setdefault('scan_dim',1) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) scan_trigger = {} for tigger_num in range(1,5): scan_trigger.update({tigger_num:caget(scan_pv+".T"+str(tigger_num)+"PV")}) - - def triggers_clear(self,scan_dim,trigger_dictionary,verbose=True): - """ - Clear all scan detectors triggers - - Previously: Clear_Scan_Triggers - """ - scan_pv = self.ioc+"scan"+str(scan_dim) - inner_scan_trigger = self.ioc+"scan"+str(scan_dim-1)+".EXSC" - - if len(trigger_dictionary.keys())>0: - for dim in range(1,5): - if dim==1 and scan_dim>1: - caput(scan_pv+".T1PV",inner_scan_trigger) - else: - caput(scan_pv+'.T'+str(dim)+'PV',"") - - def triggers_reset(self,verbose=True,**kwargs): + def triggers_set(self,**kwargs): """ sets the trigger1 to be the lower dim execute, does not change the other triggers does nothing if scan_dim = 1 + **kwargs: + scan_dim: 1 (default) + verbose: False (default) """ kwargs.setdefault('scan_dim',1) + kwargs.setdefault('trigger_dictionary',self.trigger_dictionary) + kwargs.setdefault('verbose',False) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) + #clear all triggers for scan_dim + self.triggers_clear(**kwargs) + + #reset scan_dim trigger inner_scan_trigger = self.ioc+"scan"+str(kwargs['scan_dim']-1)+".EXSC" if kwargs['scan_dim'] > 1: caput(scan_pv+".T1PV",inner_scan_trigger) #Resets the higher dimensional scans to trigger the inner scan - if verbose: - print("Scan record "+self.ioc+"Trigger 1 is reset") + #set detector triggers to dictionary values + trigger_dictionary = kwargs['trigger_dictionary'] + + if len(trigger_dictionary.keys())>0: + for tigger_num in trigger_dictionary.keys(): + caput(scan_pv+".T"+str(tigger_num)+"PV",trigger_dictionary[tigger_num]) + if kwargs['verbose']: + print("Scan record "+self.ioc+"Triggers are reset") + ### checks def check(self,scan_dim): @@ -682,36 +740,51 @@ class ScanRecord: myarray can be generated by myarray=Scan_MakeTable(StartStopStepLists) kwargs: + num_points: False (default) => steps_points is the step size + True => steps_points is the number of points + scan_dim: default => 1 positioner_num: default => 1 - scan_dim: default =>1 - detector_settling_time: + --- the following only changed if called, reset_scan to set to defaults --- positioner_settling_time + detector_settling_time + trigger_dictionary + Previously: Scan_FillIn_Table """ kwargs.setdefault("scan_dim",1) kwargs.setdefault("positioner_num",1) - kwargs.setdefault('detector_settling_time',default_detector_settling_time) - kwargs.setdefault('positioner_settling_time',default_positioner_settling_time) - - scan_dim = kwargs['scan_dim'] - - self.progress(scan_dim) - scan_pv = self.ioc+"scan"+str(scan_dim) + 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,myarray[0],myarray[-1],myarray.shape()[0]) + + #clear positioners + self.positioners_clear(**kwargs) + #write new positioners and set to table mode caput(scan_pv+".P"+str(posNum)+"SM","TABLE") caput(scan_pv+".P"+str(posNum)+"PV",val_pv) #Drive caput(scan_pv+".R"+str(posNum)+"PV",rbv_pv) #Read caput(scan_pv+".P"+str(posNum)+"PA",myarray) + + #set the number of points caput(scan_pv+'.NPTS',len(myarray)) - self.detector_settling_time(**kwargs) - self.positioner_settling_time(**kwargs) - + # kwargs + if 'detector_settling_time' in kwargs: + self.detector_settling_time_set(**kwargs) + if 'positioner_settling_time' in kwargs: + self.positioner_settling_time_set(**kwargs) + if 'trigger_dictionary' in kwargs: + self.triggers_set(**kwargs) + #checking that PVs and positioner limits are good - self.check(scan_dim) + time.sleep(.1) + self.check(kwargs['scan_dim']) def table_reset_after(self,**kwargs): """ @@ -722,14 +795,13 @@ class ScanRecord: Previously: Scan_Reset_AfterTable """ kwargs.setdefault('scan_dim',1) - #Setting everything back + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - - self.detector_settling_time(**kwargs) - + + #Setting back to linear for i in range(1,5): caput(scan_pv+".P"+str(i)+"SM","LINEAR") - + #clears positioners self.positioners_clear(**kwargs) ############################################################################################################## diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py index 6eb545e43108965e99ecb9ea4c0d00da7115d42e..262a2b0efd14c133905e802482ec22faea6a951c 100644 --- a/iexcode/instruments/xrays.py +++ b/iexcode/instruments/xrays.py @@ -9,7 +9,7 @@ from time import sleep from epics import caget,caput import iexcode.instruments.cfg as iex -from iexcode.instruments.current_amplifiers import ca_average, ca_detector_list +from iexcode.instruments.SRS_current_amplifiers import ca_average, ca_detector_list from iexcode.instruments.diagnostics import * from iexcode.instruments.FMB_mirrors import FMB_mirror_get from iexcode.instruments.IEX_VPU import * @@ -57,7 +57,7 @@ def _xrays_detector_list(): return ca_list -def _xrays_detector_dictionary(): +def xrays_detector_dictionary(): """ returns a dictionary of the default detectors @@ -382,11 +382,10 @@ def scanmono(start,stop,step,average_pnts=1,**kwargs): -def scanXAS(start_stop_step_lists,ID_eV=None,ID_tracking=False, **kwargs): +def scanXAS(start_stop_step_lists,ID_tracking=False, **kwargs): """ scans the beamline energy: ID_eV = None => the ID stays at the current value (default) - ID_eV = value => set the ID ID_track = True => ID will follow with the mono (SLOW but required in ARPES) start_stop_step_lists is a list of lists for the different scan ranges @@ -395,6 +394,7 @@ def scanXAS(start_stop_step_lists,ID_eV=None,ID_tracking=False, **kwargs): **kwargs: scan_dim = 1 (default) + ID_eV: sets the ID, only works if ID_tracking is False average_pnts: if using Keithlys this set the averaging; None for no averaging m3r: if True the mirror is optimized before the start of the scan mcp @@ -424,9 +424,10 @@ def scanXAS(start_stop_step_lists,ID_eV=None,ID_tracking=False, **kwargs): kwargs.update({'positioner_num':2}) ID_scan_fillin_table(ID_array,**kwargs) energy(ID_array[0],m3r=kwargs["m3r"]) - elif ID_eV != None: - #Setting the beamline energy - energy(ID_eV,m3r=kwargs["m3r"]) + else: + if ID_eV != None: + #Setting the beamline energy + energy(ID_eV,m3r=kwargs["m3r"]) #Averaging and Normalization ca_average(kwargs['average_pnts']) diff --git a/iexcode/macros/ID_energy_calibration.py b/iexcode/macros/ID_energy_calibration.py index f61c17ebf259cdbd116cc75fef9a78ee55757c26..ab9d3c5b2f7393510945f8d4f0556c4a042db1d1 100644 --- a/iexcode/macros/ID_energy_calibration.py +++ b/iexcode/macros/ID_energy_calibration.py @@ -15,7 +15,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.xrays import * from iexcode.instruments.xrays import _energy_range_min_max -from iexcode.instruments.current_amplifiers import current2flux +from iexcode.instruments.SRS_current_amplifiers import current2flux from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d from iexcode.instruments.m3r import * from iexcode.instruments.slits import * diff --git a/iexcode/macros/__init__.py b/iexcode/macros/__init__.py index e6ccdb93fcb545fdc3cd980a8d526137d7f192bd..f7f0f356b6d6e4721ab6e6fc6477e17d3860073a 100644 --- a/iexcode/macros/__init__.py +++ b/iexcode/macros/__init__.py @@ -3,7 +3,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.ARPES import * from iexcode.instruments.bakeout import * #not tested from iexcode.instruments.conversions_constants import * -from iexcode.instruments.current_amplifiers import * #need to test SRS +from iexcode.instruments.SRS_current_amplifiers import * #need to test SRS from iexcode.instruments.diagnostics import * from iexcode.instruments.electron_analyzer import * #didn't test, but not much changed from iexcode.instruments.encoders import * #didn't test encoder reset diff --git a/iexcode/macros/commissioning.py b/iexcode/macros/commissioning.py index e38328327e3cc263ff5dfba58413d4a6455d8c32..3e627f0e8889e65e60d0514d58615a2e9fa34322 100644 --- a/iexcode/macros/commissioning.py +++ b/iexcode/macros/commissioning.py @@ -10,7 +10,7 @@ from iexcode.instruments.xrays import * from iexcode.instruments.VLS_PGM import * from iexcode.instruments.IEX_VPU import * -from iexcode.instruments.current_amplifiers import * +from iexcode.instruments.SRS_current_amplifiers import * from iexcode.instruments.diagnostics import diagnostics_all_out, diagnostics_all_in,diode_c,diode_d from iexcode.instruments.m3r import * from iexcode.instruments.slits import _slits_wide_open_dictionary diff --git a/iexcode/macros/quick_plot.py b/iexcode/macros/quick_plot.py index 80b46d352d621245f9f89c525fa26daa9985e9e8..325ee38db988f10639867f685a64a1c397514463 100755 --- a/iexcode/macros/quick_plot.py +++ b/iexcode/macros/quick_plot.py @@ -19,7 +19,7 @@ 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 +from iexcode.instruments.SRS_current_amplifiers import current2flux #print("EPICS package and dependent functions are not installed") diff --git a/iexcode/macros/start_of_the_week.py b/iexcode/macros/start_of_the_week.py index eab7679e72bcda066eb38e64c4c7a998ba790145..f76be91f9dc479f15f7d900fc8429d7604ae93fd 100644 --- a/iexcode/macros/start_of_the_week.py +++ b/iexcode/macros/start_of_the_week.py @@ -8,7 +8,7 @@ from iexcode.instruments.Kappa import kappa_init from iexcode.instruments.scanRecord import * from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d -from iexcode.instruments.current_amplifiers import * +from iexcode.instruments.SRS_current_amplifiers import * from iexcode.instruments.xrays import * from iexcode.instruments.VLS_PGM import * from iexcode.instruments.Logfile import log_name_set,log_print