From f6dc4e21f0f5512a814e18e722a7ef4009208ca7 Mon Sep 17 00:00:00 2001 From: Jessica McChesney <jmcchesn@anl.gov> Date: Thu, 25 Aug 2022 16:15:51 -0500 Subject: [PATCH] cleaning up --- build/lib/iexcode/instruments/ARPES.py | 2 +- iexcode/instruments/ARPES.py | 17 +++---- iexcode/instruments/Kappa.py | 16 ++++--- iexcode/instruments/Motors.py | 4 +- iexcode/instruments/cheatsheet.txt | 42 +++++++++++++++++ iexcode/instruments/conversions_constants.py | 10 ++-- iexcode/instruments/diagnostics.py | 7 +-- iexcode/instruments/electron_analyzer.py | 48 ++++++++++---------- iexcode/instruments/staff.py | 2 +- 9 files changed, 97 insertions(+), 51 deletions(-) create mode 100644 iexcode/instruments/cheatsheet.txt diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py index 5237aa1..d54b041 100644 --- a/build/lib/iexcode/instruments/ARPES.py +++ b/build/lib/iexcode/instruments/ARPES.py @@ -211,7 +211,7 @@ def ARPES_reset(**kwargs): """ #writing default parameters to iex.BL.mda if iex.BL.mode=='staff': - iex.BL.mda.detector_dictionary = staff_detector_dictionary(kwargs['xrays']) + iex.BL.mda.detector_dictionary = staff_detector_dictionary() else: iex.BL.mda.detector_dictionary = ARPES_detector_dictionary(kwargs['xrays']) iex.BL.mda.trigger_dictionary = ARPES_trigger_dictionary(**kwargs) diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index 01feb78..0fca9d7 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -108,7 +108,7 @@ def _ARPES_detector_list(): ca_list=[["c",1],["b",15],["b",4],["b",13]] return ca_list -def _ARPES_detector_dictionary(xrays=True): +def _ARPES_detector_dictionary(): """ returns a dictionary of the default detectors for the scan record @@ -127,8 +127,9 @@ def _ARPES_detector_dictionary(xrays=True): det_dict.update({17:EA._statsPlugin+"Total_RBV"}) #add detectors related to beamline - if xrays: + if iex.BL.xrays: det_dict.update(_xrays_detector_dictionary()) + return det_dict def _ARPES_motor_dictionary(): @@ -208,18 +209,18 @@ def folders_ARPES(user_name,**kwargs): else: print_warning_message("EA ioc is not running, h5 folder not set") -def ARPES_reset(**kwargs): +def ARPES_reset(): """ resets scanRecord, current amplifiers, mono limits and lakeshore """ #writing default parameters to iex.BL.mda if iex.BL.mode=='staff': - iex.BL.mda.detector_dictionary = staff_detector_dictionary(kwargs['xrays']) + iex.BL.mda.detector_dictionary = staff_detector_dictionary() else: - iex.BL.mda.detector_dictionary = _ARPES_detector_dictionary(kwargs['xrays']) - iex.BL.mda.trigger_dictionary = _ARPES_trigger_dictionary(**kwargs) - iex.BL.mda.scan_before_sequence = _ARPES_scan_before_sequence(**kwargs) - iex.BL.mda.scan_after_sequence = _ARPES_scan_after_sequence(**kwargs) + iex.BL.mda.detector_dictionary = _ARPES_detector_dictionary() + iex.BL.mda.trigger_dictionary = _ARPES_trigger_dictionary() + iex.BL.mda.scan_before_sequence = _ARPES_scan_before_sequence() + iex.BL.mda.scan_after_sequence = _ARPES_scan_after_sequence() #resetting the scanRecord print("resetting the scanRecord - "+iex.BL.ioc) diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py index ba236cc..b329f6d 100644 --- a/iexcode/instruments/Kappa.py +++ b/iexcode/instruments/Kappa.py @@ -58,7 +58,7 @@ def Kappa_init(*userName,**kwargs): Kappa_Motors = Motors('Kappa',_Kappa_motor_dictionary(),physical_motors,psuedo_motors) #endstation - iex.BL = Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors) + iex.BL = Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],Kappa_Motors) #setting folders if kwargs['set_folders']: @@ -175,6 +175,10 @@ def _Kappa_detector_dictionary(**kwargs): if kwargs['add_vortex']: det_dict.update(vortex) + #add detectors related to beamline + if iex.BL.xrays: + det_dict.update(_xrays_detector_dictionary()) + return det_dict @@ -283,12 +287,12 @@ def Kappa_reset(): """ #writing default parameters to iex.BL.mda if iex.BL.mode=='staff': - iex.BL.mda.detector_dictionary = staff_detector_dictionary(kwargs['xrays']) + iex.BL.mda.detector_dictionary = staff_detector_dictionary() else: - iex.BL.mda.detector_dictionary = _Kappa_detector_dictionary(kwargs['xrays']) - iex.BL.mda.trigger_dictionary = _Kappa_trigger_dictionary(**kwargs) - iex.BL.mda.scan_before_sequence = _Kappa_scan_before_sequence(**kwargs) - iex.BL.mda.scan_after_sequence = _Kappa_scan_after_sequence(**kwargs) + iex.BL.mda.detector_dictionary = _Kappa_detector_dictionary() + iex.BL.mda.trigger_dictionary = _Kappa_trigger_dictionary() + iex.BL.mda.scan_before_sequence = _Kappa_scan_before_sequence() + iex.BL.mda.scan_after_sequence = _Kappa_scan_after_sequence() #resetting the scanRecord print("resetting the scanRecord - "+iex.BL.ioc) diff --git a/iexcode/instruments/Motors.py b/iexcode/instruments/Motors.py index 43229d9..a5caf6b 100644 --- a/iexcode/instruments/Motors.py +++ b/iexcode/instruments/Motors.py @@ -427,12 +427,12 @@ def uan(tth,th): #move tth and th mvth(th,wait=False) mvtth(tth,wait=False) - sleep(0.2) + time.sleep(0.2) while True: status = iex.BL.Motors.status() if status == 0: - sleep(0.2) + time.sleep(0.2) else: tth_RBV=round(iex.BL.Motors.get('tth',verbose=False),3) th_RBV=round(iex.BL.Motors.get('th',verbose=False),3) diff --git a/iexcode/instruments/cheatsheet.txt b/iexcode/instruments/cheatsheet.txt new file mode 100644 index 0000000..222259e --- /dev/null +++ b/iexcode/instruments/cheatsheet.txt @@ -0,0 +1,42 @@ +# beamline +from re import L +from iexcode.instruments.conversions_constants import Lambda2eV, deg2rad, eV2Lambda, rad2deg +from iexcode.instruments.diagnostics import diodeC_read, meshD, meshD_read +from iexcode.instruments.xrays import energy_get, energy_get_all, mvid, switch_gratings + + +get_all() + +# cameras import +cam_snap(cam_num) + +#converstions_constants +deg2rad(angle_deg) +rad2deg(angle_rad) +eV2Lambda(eV) +Lambda2eV(Angstrom) + +#diagnostics +diodeC(In_Out) +diodeC_read() + +meshD(In_Out) +meshD_read() + +#electron_analyzer +EA.get() +EA.put(KE,PE) +scanEA(EAlist) +scanEA_hv() + +#xrays +energy_get_all() +energy_get() +getE() +energy(hv_eV) + +mvid() +mvmono() + +switch_gratings(grt) +polarization(ID_mode) \ No newline at end of file diff --git a/iexcode/instruments/conversions_constants.py b/iexcode/instruments/conversions_constants.py index 68cae3f..9bbdd27 100644 --- a/iexcode/instruments/conversions_constants.py +++ b/iexcode/instruments/conversions_constants.py @@ -96,15 +96,13 @@ def KtoE(k_theta,k_kappa,k_phi,k_arm=50): e_chi = 2.0 * np.asin( np.sin(k_kappa*conv/2.0) * np.sin(k_ang) ) e_phi = k_phi*conv - delta #print round(e_theta,1),round(e_phi,1),round(e_chi,1) - def rounder(val): # convert from rad to deg - conv = np.pi/180.0 - roundVal=round(1000.0*val/conv)/1000.0 - return roundVal theta = rounder(e_theta)+(57.045-kth_offset) chi = rounder(e_chi) # convert from rad to deg phi = rounder(e_phi) #print round(delta,1) return (theta,chi,phi) - - +def rounder(val): # convert from rad to deg + conv = np.pi/180.0 + roundVal=round(1000.0*val/conv)/1000.0 + return roundVal \ No newline at end of file diff --git a/iexcode/instruments/diagnostics.py b/iexcode/instruments/diagnostics.py index 0127d98..84148ad 100644 --- a/iexcode/instruments/diagnostics.py +++ b/iexcode/instruments/diagnostics.py @@ -1,7 +1,8 @@ from numpy import nan from epics import caput, caget -#from iexcode.instruments.IEX_endstations import * + +import iexcode.instruments.cfg as iex ############################################################################################################## ################################ default positions ############################## @@ -70,7 +71,7 @@ def diagnostics_all_out(diode_stay_in=False): #which motor is Diode of interest if diode_stay_in: - branch = BL.branch + branch = iex.BL.branch if branch == 'c': diode_motor=diag["motor"]["gas-cell"] @@ -82,7 +83,7 @@ def diagnostics_all_out(diode_stay_in=False): #Taking out the diagnostic for motor in list(diag["Out"].keys()): if motor is diode_motor: - text=' except Diode-'+BL.branch + text=' except Diode-'+iex.BL.branch #putting Diode In if not already in -JM position=diag["In"][motor] caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000) diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py index 28aaec7..e80d937 100644 --- a/iexcode/instruments/electron_analyzer.py +++ b/iexcode/instruments/electron_analyzer.py @@ -170,14 +170,14 @@ def EA_log_update(): entry_list.append(key) pv_list.append(spectra_info[key][0]) format_list.append(spectra_info[key][1]) - logfile_update("ARPES",BL.ioc,entry_list,pv_list,format_list) + logfile_update("ARPES",iex.BL.ioc,entry_list,pv_list,format_list) except: print("EAlog did not write to file, check for errors.") def log_headerEA():##JM - need to update so that we get the keys from log_EA s="\nscan x y z th chi phi T scan_mode E1 E2 step i f PE lens_mode SES slit # ID_mode hv exit_slit GRT TEY1 TEY2 time\n" kwargs={'comment': s} - logfile_print("ARPES",BL.ioc,comment='') + logfile_print("ARPES",iex.BL.ioc,comment='') def EAsweptTime_estimate(EAlist,overhead=[60,.22]): """ @@ -226,7 +226,7 @@ def _scanEATrigger(EAlist,before_after,**kwargs): kwargs.setdefault("prefix","EA")# if not None then over rides the auto kwargs.setdefault("debug",False) - scanPV=BL.ioc+"scan"+str(kwargs["scan_dim"]) + scanPV=iex.BL.ioc+"scan"+str(kwargs["scan_dim"]) triggerPV=scanPV+".T"+str(kwargs["detTrig"])+"PV" if kwargs["debug"]: @@ -266,8 +266,8 @@ def _scanEAPrefix(ptype,**kwargs): print(ptype) if ptype == "mda": - fpath = BL.mda.filepath[0:-3]+EA.dtype - nextMDA = BL.mda.fileNum + fpath = iex.BL.mda.filepath[0:-3]+EA.dtype + nextMDA = iex.BL.mda.fileNum prefix = "MDAscan"+str.zfill(str(nextMDA),kwargs["nzeros"]) else: prefix = ptype @@ -310,7 +310,7 @@ def scanEA_reset(**kwargs): kwargs.setdefault("scan_dim",1) _scanEATrigger([],"after",**kwargs) - BL.mda.positioners_clear(kwargs["scan_dim"]) + iex.BL.mda.positioners_clear(kwargs["scan_dim"]) def scanEA(EAlist,**kwargs): """ @@ -331,7 +331,7 @@ def scanEA(EAlist,**kwargs): """ - kwargs.setdefault('scanIOC',BL.ioc()) + kwargs.setdefault('scanIOC',iex.BL.ioc()) kwargs.setdefault('scan_dim',1) kwargs.setdefault('execute',True) kwargs.setdefault("debug",False) @@ -354,7 +354,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])) - BL.mda.fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) + iex.BL.mda.fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) EAlist[1]=arrayP1[0] if kwargs['debug']: print('\npvCalcOut1: ',pvCalcOut1) @@ -363,7 +363,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])) - BL.mda.fillin_table(pvCalcOut1+'PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) + iex.BL.mda.fillin_table(pvCalcOut1+'PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) print('\npvCalcOut1: ',pvCalcOut1) print('Pos1 table:',arrayP1) elif len(EAlist)==7: #Sweep @@ -373,8 +373,8 @@ def scanEA(EAlist,**kwargs): EAlist[2]=caget(pvCalcOut2+'.VAL') arrayP1=list(np.full(sweeps, EAlist[1])) arrayP2=list(np.full(sweeps, EAlist[2])) - BL.mda.fillin_table(pvCalcOut1+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP1,1) - BL.mda.fillin_table(pvCalcOut2+'.PROC',"",kwargs["scanIOC"],kwargs["scan_dim"],arrayP2,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) if kwargs['debug']: print("\npvCalcOut1",pvCalcOut1) print("\npvCalcOut2",pvCalcOut2) @@ -394,10 +394,10 @@ def scanEA(EAlist,**kwargs): if kwargs['debug']: print("Clearing scan positioners and filling in sweeps") #Fill in Sweeps scan - BL.mda.positioners_clear(**kwargs) + iex.BL.mda.positioners_clear(**kwargs) VAL="" RBV="" - BL.mda.fillin(VAL,RBV,1,sweeps,1,**kwargs) + 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) @@ -420,11 +420,11 @@ def scanEA(EAlist,**kwargs): time.sleep(10) EA.put(EAlist[1]-.05,EAlist[-3],LensMode="Angular") time.sleep(2) - BL.mda.go(**kwargs) + iex.BL.mda.go(**kwargs) #After scan EA_log_update() scanEA_reset(**kwargs) - BL.mda.table_reset_after(**kwargs) + iex.BL.mda.table_reset_after(**kwargs) else: return EAparms @@ -451,10 +451,10 @@ def scanFM(RoughPositions,thList,EAlist,**kwargs): if kwargs['debug']: print(x,y,z,th,chi,phi) - BL.mda.fillin_table(EA.Motors._motor_dictionary("th")[1],EA.Motors._motor_dictionary("th")[0],th,positioner_num=1) - BL.mda.fillin_table(EA.Motors._motor_dictionary("x")[1],EA.Motors._motor_dictionary("x")[0],x,positioner_num=2) - BL.mda.fillin_table(EA.Motors._motor_dictionary("y")[1],EA.Motors._motor_dictionary("y")[0],y,positioner_num=3) - BL.mda.fillin_table(EA.Motors._motor_dictionary("z")[1],EA.Motors._motor_dictionary("z")[0],z,positioner_num=4) + iex.BL.mda.fillin_table(EA.Motors._motor_dictionary("th")[1],EA.Motors._motor_dictionary("th")[0],th,positioner_num=1) + iex.BL.mda.fillin_table(EA.Motors._motor_dictionary("x")[1],EA.Motors._motor_dictionary("x")[0],x,positioner_num=2) + iex.BL.mda.fillin_table(EA.Motors._motor_dictionary("y")[1],EA.Motors._motor_dictionary("y")[0],y,positioner_num=3) + iex.BL.mda.fillin_table(EA.Motors._motor_dictionary("z")[1],EA.Motors._motor_dictionary("z")[0],z,positioner_num=4) #setting up EA EAkwargs={ @@ -467,7 +467,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) - BL.mda.go(**kwargs) + iex.BL.mda.go(**kwargs) EA_log_update() scanEA_reset(**kwargs) @@ -580,10 +580,10 @@ def scanEA_hv(hv_start_stop_step_lists,EAlist=[],**kwargs): energy(mono_array[0]) #Scanning EA.put(mono_array[0]-EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - BL.mda.go(**kwargs) + iex.BL.mda.go(**kwargs) #After scan scanEA_reset(**kwargs) - BL.mda.table_reset_after(**kwargs) + iex.BL.mda.table_reset_after(**kwargs) def scanEA_y(EAlist, start,stop,step,mode='absolute',**kwargs): scanEA_motor(EAlist,'y',start,stop,step,mode=mode,**kwargs) @@ -631,7 +631,7 @@ def scanEA_motor(EAlist, motor,start,stop,step,mode='absolute',**kwargs): if kwargs["execute"]==True: #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - BL.mda.go(kwargs["scanIOC"],scan_dim) + iex.BL.mda.go(kwargs["scanIOC"],scan_dim) EA_log_update() #After scan scanEA_reset(**kwargs) @@ -678,7 +678,7 @@ def scanEA_Mesh(EAlist,y_start_stop_step,z_start_stop_step,**kwargs): if kwargs['execute']: #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - BL.mda.go(scan_dim=outer_scan_dim) + iex.BL.mda.go(scan_dim=outer_scan_dim) EA_log_update() #After scan diff --git a/iexcode/instruments/staff.py b/iexcode/instruments/staff.py index ba5648b..e7c1fbb 100644 --- a/iexcode/instruments/staff.py +++ b/iexcode/instruments/staff.py @@ -36,7 +36,7 @@ def folders_startup(run): ############################################################################################################## -def staff_detector_dictionary(xrays=True): +def staff_detector_dictionary(): """ returns a dictionary of the default detectors -- GitLab