diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py index 5a172a0dc673fae173f1c7ac115af4f2feb51023..a01087d4f3175cb4cf8756491a91e712af154405 100644 --- a/build/lib/iexcode/instruments/ARPES.py +++ b/build/lib/iexcode/instruments/ARPES.py @@ -77,6 +77,7 @@ def ARPES_init(*userName,**kwargs): #EA if EA.connected: + sleep(1) EA.get() _EA_init_Motors(ARPES_Motors) if kwargs['set_folders']: diff --git a/build/lib/iexcode/instruments/FMB_mirrors.py b/build/lib/iexcode/instruments/FMB_mirrors.py index ca1996ff8a74d75340d281c7cc85a680223ffff2..5af10702dc9fc621863cb0b57556b199f8c3f8b6 100644 --- a/build/lib/iexcode/instruments/FMB_mirrors.py +++ b/build/lib/iexcode/instruments/FMB_mirrors.py @@ -74,7 +74,7 @@ def FMB_mirror_move(mirror_num,axis,val,verbose=True): caput(pv+axis+"_POS_SP",val) caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000) while True: - if FMB_mirror_status != 1: + if FMB_mirror_status(mirror_num) != 1: sleep(.5) else: break diff --git a/build/lib/iexcode/instruments/IEX_VPU.py b/build/lib/iexcode/instruments/IEX_VPU.py index 709408271c90ae9cceb6c9d0380a5f5a747dec53..f59da73a401fcaca60be8e5e2e0e221de3336673 100644 --- a/build/lib/iexcode/instruments/IEX_VPU.py +++ b/build/lib/iexcode/instruments/IEX_VPU.py @@ -276,9 +276,10 @@ def ID_switch_mode(ID_mode): print("Turning ID off...") ID_off(verbose=True) sleep(10) - ID_on(verbose=True) + print("Switching ID mode, please wait...") ID_mode_set(ID_mode) + ID_on(verbose=True) ID_ready() print("ID Mode:",ID_mode) except: diff --git a/build/lib/iexcode/instruments/Scienta.py b/build/lib/iexcode/instruments/Scienta.py index 315ad0d73ec4aa1e0b149751b49bb7f64e2d198e..8417aac2d5f8e4558722fee2ebf07355d6ff227e 100644 --- a/build/lib/iexcode/instruments/Scienta.py +++ b/build/lib/iexcode/instruments/Scienta.py @@ -81,7 +81,8 @@ class Scienta: self.Frames = None pv = PV(self.PHV+"WorkFunction") - if pv.connect(): + time.sleep(1) + if pv.connected: self.get() self.connected = True else: @@ -96,7 +97,7 @@ class Scienta: """ for key in vars(self): - if key not in ["PHV","_Pcam","_savePlugin","_statsPlugin","wk","Frames","dtype"]: + if key not in ["PHV","_Pcam","_savePlugin","_statsPlugin","wk","Frames","dtype","connected"]: vars(self)[key]=caget(self.PHV+key+".VAL") if key in ["LensMode","SpectraMode"]: vars(self)[key]=caget(self.PHV+key+".VAL",as_string=True) diff --git a/build/lib/iexcode/instruments/m3r.py b/build/lib/iexcode/instruments/m3r.py index fe8d151fd14b930d65df4b8c7c442ce418045d62..402a22067293708d204e406593be6ba7b389a878 100644 --- a/build/lib/iexcode/instruments/m3r.py +++ b/build/lib/iexcode/instruments/m3r.py @@ -104,9 +104,10 @@ def m3r_switch_branch(branch): position = m3r_table(branch) FMB_mirror_move_all(3,position,verbose=False) # Relax bellows by doing large Z translation: - FMB_mirror_move_all(3,"TY",5,verbose=False) - FMB_mirror_move_all(3,"TY",5,verbose=False) - + FMB_mirror_move(3,"TY",5,verbose=False) + sleep(.1) + FMB_mirror_move(3,"TY",0,verbose=False) + sleep(.1) FMB_mirror_get(3,verbose=True) ############################################################################################################## @@ -137,7 +138,7 @@ def _m3r_align_start(pxl=None): caput(M3R_align_pv+'startAlign',1,wait=True,timeout=180) def m3r_align(pxl=None): - if iex.BL.branch() == 'd': + if iex.BL.branch == 'd': print('\nalign_m3r()') try: _m3r_align_start() diff --git a/build/lib/iexcode/instruments/slits.py b/build/lib/iexcode/instruments/slits.py index ea616f095e03b0aa0b68122c7e99b546bda1635e..89e6de49a748ea29edbecfc055b9eecc94dd7a44 100644 --- a/build/lib/iexcode/instruments/slits.py +++ b/build/lib/iexcode/instruments/slits.py @@ -350,7 +350,7 @@ def slit3C_set(size,verbose=True): center = None slits_set(slit_name,size,center, verbose=verbose) -def slit3C_get(size,verbose=True): +def slit3C_get(verbose=True): """ gets slit-3C (ARPES resolution defining slit) returns size, position @@ -409,35 +409,34 @@ def slit3D_encoders_reset(Vcenter): encoders_reset_zero(slit_name) slits_synch(slit_name) -def exit_slit(size, verbose=True): +def exit_slit_set(branch, size, verbose=True): """ - verbose used to supress printing + sets the size for the iex.BL.branch exit slit Previously: SetExitSlit """ - branch=iex.BL.mda.branch if branch == "c": slit3C_set(size, verbose) elif branch == "d": slit3D_set(size, verbose) +def exit_slit_get(branch, verbose=True): + """ + gets the size for the iex.BL.branch exit slit + """ + if branch == "c": + slit_size,slit_center = slit3C_get(verbose=False) + elif branch == "d": + slit_size,slit_center = slit3D_get(verbose=False) + + return slit_size,slit_center ############################################################################################################## ################################ slit fits ############################## ############################################################################################################## -def aperture_fit(hv,slit_num): - """ - used close the beamline apertures/slits to only take the center of the beam, - i.e. no heat bump (determined emperically by looking at the the shift in energy vs slit position) - Previously Aperture_Fit - """ - K=slit_coef(slit_num)[1] - sizeH=K[0]+K[1]*hv+K[2]*hv*hv - sizeV=K[3]+K[4]*hv+K[5]*hv*hv - return [round(sizeH,3),round(sizeV,3)] def slit_coef(slit_num): """ diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py index f80bed6511198b890c40f47ca5f7ab4126108008..161b48fdd494a472b7dede31f8e732b1e538c692 100644 --- a/build/lib/iexcode/instruments/xrays.py +++ b/build/lib/iexcode/instruments/xrays.py @@ -287,6 +287,17 @@ def qp(QP_ratio): ############################################################################################################## ################################ beamline slits = apertures ############################## ############################################################################################################## +def aperture_fit(hv,slit_num): + """ + used close the beamline apertures/slits to only take the center of the beam, + i.e. no heat bump (determined emperically by looking at the the shift in energy vs slit position) + + Previously Aperture_Fit + """ + K=slit_coef(slit_num)[1] + sizeH=K[0]+K[1]*hv+K[2]*hv*hv + sizeV=K[3]+K[4]*hv+K[5]*hv*hv + return [round(sizeH,3),round(sizeV,3)] def apertures_set(c_2B=1,c_1A=1,verbose=True): """ @@ -580,14 +591,15 @@ def get_mirrors(): ############################################################################################################## ########################### slits and resolution ###################### ############################################################################################################## -def slit(size): +def slit(size,verbose=True): """ sets the exit slit based on iex.BL.endstation ARPES = 0 < x < 300 um Kappa = 0 < x < 1000 um """ - exit_slit(size) + branch = iex.BL.branch + exit_slit(branch,size,verbose=verbose) def slit_get(verbose=True): @@ -597,17 +609,7 @@ def slit_get(verbose=True): ARPES = 0 < x < 300 um Kappa = 0 < x < 1000 um """ - branch = iex.BL.branch - if branch == "c": - slit_size = slit3C_get(verbose=False) - slit_center = np.nan - elif branch == "d": - slit_size,slit_center = slit3D_get(verbose=False) - - if verbose: - message = iex.BL.branch+' exit slit: '+str(slit_size) - message += ", @ "+str(slit_center) - print(message) + exit_slit_get(branch,verbose=verbose) return slit_size,slit_center diff --git a/build/lib/iexcode/macros/commissioning.py b/build/lib/iexcode/macros/commissioning.py index 76741ddc54c3e355fa039ea55ab9960a9bbc352b..0425d5a31f6f9243f33f0fbbf69aee8c1e629201 100644 --- a/build/lib/iexcode/macros/commissioning.py +++ b/build/lib/iexcode/macros/commissioning.py @@ -17,74 +17,66 @@ from iexcode.instruments.utilities import * from iexcode.instruments.electron_analyzer import scanEA from iexcode.instruments.Logfile import log_name_set,log_print from iexcode.instruments.cameras import * - - - - - - - +from instruments.slits import exit_slit_get, slit1A_get, slit1A_set, slits_set_size +from instruments.xrays import apertures_set from .quick_plot import fit_mda, mda_1D - - ############################################################################################################## ################################ checking alignment ############################## ############################################################################################################## -def check_flux(hv=500,ID_mode='RCP',stay=False): +def check_flux_scan(hv=500,stay=False,**kwargs) + """ + puts the diode in and scans the mono + stay: + True => leaves the diode in + False => takes the diode out + """ + kwargs.setdefault('sound',Ture) + diagnostics_all_out(diode_stay_in=True) + slit(50) + energy(hv) + hv_start = hv*.95 + hv_stop = hv*1.05 + hv_step = round(1.0*hv/500,0) + scanmono(hv_start,hv_stop,hv_step,comment='Mono Scan @ '+str(hv)+' eV') + if kwargs['sound']: + playsound() + +def check_flux_read(hv=500,ID_mode='RCP',stay=False): """ - puts the diode in + puts the diode in in the branch defined my position of m3r measures flux at energy ID_mode specified - stay: diode position after the scan + stay = True => leaves the diode in Previously: CheckFlux """ + current_slit = exit_slit_get(verbose=True) ID_switch_mode(ID_mode) energy(hv) - diagnostics_all_out(diode_to_stay_in=m3r_branch()) - SR=round(caget("S:SRcurrentAI.VAL"),2) + + ring_current=round(caget("S:SRcurrentAI.VAL"),2) + + diagnostics_all_out(diode_stay_in=True) + exit_slit(50) + sleep(10) + if m3r_branch() == "c": - current_slit=caget('29idb:Slit3CFit.A') - diode_c('In') - exit_slit(50) - sleep(10) diode=diode_c_read() elif m3r_branch() == "d": - current_slit=caget('29idb:Slit4Vsize.VAL') - sleep(10) - diode_d("In") - exit_slit(50) diode=diode_d_read() + flux=current2flux(diode) print("\n----- Current on diode : %.3e" % diode, "A") print("----- Corresponding flux: %.3e" % flux, "ph/s \n") - print("----- Storage ring current: %.2f" % SR, "mA") + print("----- Storage ring current: %.2f" % ring_current, "mA") print("\nFlux at hv=500 as off Feb 2019 for RCP and HEG: ~3.3e-06 A = ~1.5e+11 ph/s") if not stay: diagnostics_all_out() exit_slit(current_slit) -def check_m0m1(hv=500,stay=True,wire=True,**kwargs): - """ - Prints Flux in C-branch - stay = 'yes' => Leaves diagnostics in the beam - wire ='yes'=> Does wire scans to determine M0M1 alignment - Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details - - Previously: CheckM0M1 - """ - - switch_branch('c') - grating('HEG') - print("\nFlux at hv=500 as off Feb 2019: ~3.3e-06 A = ~1.5e+11 ph/s") - branch_shutter_open() - check_flux(hv=hv,stay=stay) - if wire is not None: - scan_wire('H',**kwargs) - scan_wire('V',**kwargs) def scan_wire(direction,all_diag=True,**kwargs): """ @@ -421,14 +413,20 @@ def procedure_align_m1(): # 2017_3 - HEG after opitmization: mba_b_0241-0244 # 2018_1 - HEG before opitmization: mba_b_0005-0008 - - -def beamsteering_2B(v_position): - vroll=round(v_position*0.05/0.04,3) - if v_position<0: v_direction=' +' - else: v_direction=' -' - v_steering=v_direction+str(abs(vroll))+' urad' - return v_steering,float(v_steering.split(" ")[1]) + +def iex_steering(h_position,v_position): + """ + prints the required steering to compensate for the current + """ + print('\nBeam position:') + print(' - horizontal: '+str(h_position)) + print(' - vertical: '+str(v_position)) + h_steering,v_steering=beamsteering_1A(h_position,v_position) + print('\nBeam steering:') + print(' - horizontal: '+h_steering) + print(' - vertical: '+v_steering) + print('\n') + return h_steering,v_steering def beamsteering_1A(h_position,v_position,FE_center_h=0,FE_center_v=0): h_correction=FE_center_h-h_position @@ -443,9 +441,125 @@ def beamsteering_1A(h_position,v_position,FE_center_h=0,FE_center_v=0): v_steering=str(vrad)+v_direction return h_steering,v_steering +def M0M1_steering(H2,V2): + """ + M1 steering: (monoVslit-2V and 2H) + Roll: Rz more positive => 2V more positive (0.25 => .25 mm) + Pitch: Ry more positive => 2H more positive (0.03 => .5 mm + """ + print('\nBeam position:') + print(f" - vertical: V2 = {round(V2,3)}") + print(f" - horizontal: H2 = {round(H2,3)}") + v_steering=beamsteering_2B(V2) + m1_roll=beamsteering_2B(V2)[1] + print('\nCurrent position:') + current_roll=FMB_mirror_get(1)[5] + new_roll=current_roll+m1_roll + print('\nREMEMBER: 2V slit should always be centered at zero by steering M1 roll!') + print(" - vertical: "+str(current_roll)+str(v_steering[1])+" => Move_M1('RZ',"+str(new_roll)+")") + print(' - horizontal: reset slit 2BH center to ',str(H2)) + +def beamsteering_2B(v_position): + vroll=round(v_position*0.05/0.04,3) + if v_position<0: v_direction=' +' + else: v_direction=' -' + v_steering=v_direction+str(abs(vroll))+' urad' + return v_steering,float(v_steering.split(" ")[1]) + + + + + +def ID_steering_scans(**kwargs): + """ + slit1 - Scanning front-end slit center + cutoffs are defined by the fixed aperature midpoint is slit center + beam should be center at slit center, steer ID until the coincide + + **kwargs: + verbose: default => True + sound: playsound, default => True + extended_range True/False + False: default range = -3,3,0.1 + True: -5,5,0.1 + + Note: Does not set the ID, mvID = 2.0 gives a nice gaussian + """ + kwargs.setdefault('sound',True) + + if 'extended_range' in kwargs: + start,stop = (-5,5) + else: + start,stop = (-3,3) + + size,center = slit1A_get(verbose=False) + + slits_scan_center('slit1A','H',start,stop,0.1,size=(0.25,inf),comment='Slit center - 1H') + slits_scan_center('slit1A','V',start,stop,0.1,size=(inf,0.25),comment='Slit center - 1V') + slit1A_set(size,center,verbose=False) + + + if kwargs['sound']: + playsound() + if kwargs['verbose']: + print('\nsteering out => move beam more positive (10 urad ~ 0.25 mm)') + print('steering up => move beam more positive (10 urad ~ 0.25 mm)\n') + +def ID_steering_plots(scanNum,det_num,xrange=[-1,1]): + """ + plots data from ID_steering_scans and returns the positions + """ + position=fit_mda(scanNum,det_num,1,'gauss',xrange=xrange) + plt.show() + + return position + +def wire_scans(**kwargs): + """ + Checks for large misaligment or clipping by M0/M1 + + Note: Does not set the ID, mvID = 2.0 gives a nice gaussian + """ + kwargs.setdefault('sound',True) + + slits_set_size('slit1A',(4.5,4.5)) + scan_wire('H',comment='Wire scan - H',all_diag=False) # by default puts all meshes in + DiodeC + scan_wire('V',comment='Wire scan - V',all_diag=False) + + if kwargs['sound']: + playsound() + +def monoVslit_quick_scan(slit_name, **kwargs): + """ + sets the slit to be narrow and scans along and across the grating + at 500 eV to see if M0/M1 are steering the beam to the center of the grating + + """ + kwargs.setdefault('sound',True) + + energy(500) + mvmono(505) + + H,V = _slits_wide_open_dictionary()[slit_name] + + slits_scan_center(slit_name,'V',-V,V,0.25,size=(inf,0.25*c)) + sleep(1) + + slits_scan_center(slit_name,'H',-H,H,0.25,size=(0.25,inf)) + sleep(1) + + if kwargs['sound']: + playsound() + + +def monoVslit_quick_plot(scanNum,detDiode,c,xrange=None): + position = fit_mda(scanNum,detDiode,c,'gauss',xrange) + plt.show() + return position + ##################################################################################### ### Slit-1A Procedures @@ -554,39 +668,38 @@ def scan_slit_size(slit,start,stop,step,center=(0,0)): # and that the slits are centered ##################################################################################### -def ID_beam_profile(grt,slit_list,c_slit=1,c_energy=1,**kwargs): +def beam_profile(grt,slit_list): """ Makes a nice 2D image of the energy distribution of the beam across the grating at ID=500 - Does NOT put the diagnostics into the beam you need to run the following if you haven't already (AllDiagOut(); DiodeCIn()) SlitList=["2H","2V","1H","1V"] - c_slit = scaling of step size (c=1 Slit-1: step = 0.25. Slit-2: step = 0.5) - c_energy = scaling of mono step size ( c=1 eV step = 2) - with c_slit=1 and c_energy = 1 Each slit ~ 1:10 min + + Note: Does NOT put the diagnostics into the beam Previously BeamProfile """ grating(grt) - grt_density = mono_grating_density_get() - c=grt_density/1200 - ID=500 - eVstart,eVstop,eVstep=460,540,4 + c = mono_grating_density_get()/1200 + + mvID(500) + apertures_set() + + eVstart = 460 + eVstop = 540 + eVstep = 4 + for slit in slit_list: if slit=="1H": #Hsize,Vsize,Hstart,Hstop,Hstep = 0.50,2,-2,2,0.25*c_slit # => 35 min - #MonoVsSlit1AH_Go(ID,eVstart,eVstop,eVstep*c_energy,Hstart,Hstop,Hstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('1H',[0.5,-2,2,0.25*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1H') + scan_mono_vs_slit('1H',[0.5,-2,2,0.25*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1H') elif slit == "1V": #Hsize,Vsize,Vstart,Vstop,Vstep = 2,0.50,-2,2,0.25*c_slit - #MonoVsSlit1AV_Go(ID,eVstart,eVstop,eVstep*c_energy,Vstart,Vstop,Vstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('1V',[0.5,-2,2,0.25*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1V') + scan_mono_vs_slit('1V',[0.5,-2,2,0.25*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1V') elif slit =="2H": #Hsize,Vsize,Hstart,Hstop,Hstep = 0.50,8,-3,3,0.5*c_slit - #MonoVsSlit2BH_Go(ID,eVstart,eVstop,eVstep*c_energy,Hstart,Hstop,Hstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('2H',[0.5,-3,3,0.5*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2H') + scan_mono_vs_slit('2H',[0.5,-3,3,0.5*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2H') elif slit =="2V": #Hsize,Vsize,Vstart,Vstop,Vstep = 6,0.25*c,-4*c,4*c,0.5*c_slit - #MonoVsSlit2BV_Go(ID,eVstart,eVstop,eVstep*c_energy,Vstart,Vstop,Vstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('2V',[0.5,-4,4,0.5*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2V') + scan_mono_vs_slit('2V',[0.5,-4,4,0.5*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2V') def CheckAllSlits_long(hv_list=[500],slit_list=["1H","1V","2H","2V"],**kwargs): diff --git a/build/lib/iexcode/macros/start_of_the_week.py b/build/lib/iexcode/macros/start_of_the_week.py index beb866cb2fcc68ffeeef59fce3573a170a0854f6..7182a726d8c2fc07eb08b7260f6f90d890556435 100644 --- a/build/lib/iexcode/macros/start_of_the_week.py +++ b/build/lib/iexcode/macros/start_of_the_week.py @@ -6,6 +6,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.ARPES import ARPES_init from iexcode.instrumetns.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.xrays import * @@ -16,34 +17,83 @@ from iexcode.instruments.utilities import * from iexcode.macros.commissioning import * from iexcode.macros.quick_plot import * + +def detectors(branch): + """ + returns detCA4,detH,detV,detDiode + """ + DetDict={'c':(9,7,8,15),'d':(9,7,8,14)} + return DetDict[branch] + + + +def interactive_fct(mirror=False): + options='0,1,2,3' + if not mirror: + print('''\nDo you want to: + \t (0) write comment + \t (1) continue + \t (2) repeat scan + \t (3) adjust xrange for fit + ''') + else: + print('''\nDo you want to: + \t (0) write comment + \t (1) continue + \t (2) repeat scan + \t (3) adjust xrange for fit + \t (4) move M1 roll + ''') + options=options+',4' + flag=input('\nType ('+options+') >') + if flag not in options.split(","): + print('\ninvalid input; please try again...\n') + flag=input('\nType ('+options+') >') + if flag == '0': + cmt=input('\nType comment >') + print('\n================================') + log_print(cmt) + print('================================\n') + flag=input('\nType ('+options+') >') + if flag == '1': print('\nresuming script...\n'); flag=1 + if flag == '2': print('\nrepeating scan...\n'); flag=2 + if flag == '3': flag=3 + if mirror: + if flag == '4': flag=4 + + return flag + + def StartOfTheWeek(GRT,branch,wait=False,**kwargs): """ This should be run every at the start of every week; 50 min total. Switch to C-branch,. If wait=True, wait for next day a 8:05. - kwargs defaults: - mode = polarization - run = None: used today's date to set run appropriately - repeat = False: sets everything: switches branch, sets BL_Mode to Staff, resets scan/CAs/mono - scanType = ['slit1','wire','flux','monoVslit'] - sound = False; no sounds - = True => plays sound after Slit1A scans and when script is complete - } - ID steering: (slit1A) - steering out => move beam more positive (10 urad ~ 0.25 mm) - steering up => move beam more positive (10 urad ~ 0.25 mm) + **kwargs: + mode: polarization, default => RCP + repeat: True/False + True => doesn't do any initialization + False => resets everything (switches branch and grating) + scanType = ['slit1','wire','monoVslit','flux',] + sound: plays sound when a scantype is completed, default => True + # for individiual scantypes + slit1A_extended: to take a larger range, default => False + monoVslit_quick: + True => takes a single line cut (defaule) + False => - M1 steering: (monoVslit-2V and 2H) - Roll: Rz more positive => 2V more positive (0.25 => .25 mm) - Pitch: Ry more positive => 2H more positive (0.03 => .5 mm - """ + """ kwargs.setdefault('mode','RCP') kwargs.setdefault('repeat',False) - kwargs.setdefault('quick',True) kwargs.setdefault('scanType',['slit1','wire','flux','monoVslit']) kwargs.setdefault('sound',True) - kwargs.setdefault('extended_range',False) + + kwargs.setdefault('slit1A_extended',False) + kwargs.setdefault('monoVslit_quick',True) + + + detCA4,detH,detV,detDiode = detectors() branch=branch.lower() if iex.BL == None: @@ -57,9 +107,9 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): else: BL_init('staff',reset=False,set_folders=False) switch_branch(branch) - FileName='StartOfTheWeek_log.txt' - log_name_set(FileName) - + log_name_set('StartOfTheWeek_log.txt') + log_print("\n\n================== Start Of The Week @ "+today('slash')+':\n',FileName=FileName) + for scan in kwargs['scanType']: if scan not in ['slit1','wire','flux','monoVslit']: print(scan+" is not a valid scan scanType=['slit1','wire','flux','monoVslit']") @@ -69,16 +119,19 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): if branch == 'c': ca15 = Keithley('b',15) ca15.autoscale('Off') - diode_c('In') + else: foo=input('Do you have a diode in direct beam (y or n)? >') if foo.lower() == 'y' or foo.lower() == 'yes': print('Resuming...') - ### Stuff that doesn't need beam & does not need to be run if repeating SoTW: print("\n\n================== Sets Beamline & Scans:") grating(GRT) + ########################################################################### + ### stuff that requires beam + ########################################################################### + ### checking branch shutter: shutter_open = branch_shutter_status() if shutter_open == False: @@ -89,7 +142,6 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): print('Aborting...') return - ### checking QP ratio: QP=caget('ID29:QuasiRatio.RVAL') if QP != 100: @@ -111,264 +163,153 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): ### Ready to start: FirstScan=iex.BL.mda.filenum() - if not kwargs['repeat']: - log_print("\n\n================== Start Of The Week @ "+today('slash')+':\n',FileName=FileName) - - - - def interactive_fct(mirror=False): - options='0,1,2,3' - if not mirror: - print('''\nDo you want to: - \t (0) write comment - \t (1) continue - \t (2) repeat scan - \t (3) adjust xrange for fit - ''') - else: - print('''\nDo you want to: - \t (0) write comment - \t (1) continue - \t (2) repeat scan - \t (3) adjust xrange for fit - \t (4) move M1 roll - ''') - options=options+',4' - flag=input('\nType ('+options+') >') - if flag not in options.split(","): - print('\ninvalid input; please try again...\n') - flag=input('\nType ('+options+') >') - if flag == '0': - cmt=input('\nType comment >') - print('\n================================') - log_print(cmt) - print('================================\n') - flag=input('\nType ('+options+') >') - if flag == '1': print('\nresuming script...\n'); flag=1 - if flag == '2': print('\nrepeating scan...\n'); flag=2 - if flag == '3': flag=3 - if mirror: - if flag == '4': flag=4 - - return flag - - - - # if foo.lower() == 'y' or foo.lower() == 'yes': - # print('\nType any comments here - you have 30s! >') - # i, o, e = select.select( [sys.stdin], [], [], 5 ) - # if (i): - # print ('\n==============\n'+sys.stdin.readline().strip()+'\n==============\n') - # else: - # print('\nTimeout...'); - # print('\nRepeating scan...\n');flag=2 - - # else: - # print('\nResuming script...\n'); flag=3 - # return flag - - - - def iex_steering(h_position,v_position): - print('\nBeam position:') - print(' - horizontal: '+str(h_position)) - print(' - vertical: '+str(v_position)) - h_steering,v_steering=beamsteering_1A(h_position,v_position) - print('\nBeam steering:') - print(' - horizontal: '+h_steering) - print(' - vertical: '+v_steering) - print('\n') - return h_steering,v_steering - - DetDict={'c':(9,7,8,15),'d':(9,7,8,14)} - detCA4,detH,detV,detDiode=DetDict[branch] - list_position=[GRT,0,0,0,0] - - ###### Scan front-end slit center: + ########################################################################### if 'slit1' in kwargs['scanType']: print("\n\n================== Slit 1A scans:") mvID(2000) flag=2 while flag==2: - slits_scan_center('slit1A','H',-3,3,0.1,size=(0.25,inf),comment='Slit center - 1H') - slits_scan_center('slit1A','V',-3,3,0.1,size=(inf,0.25),comment='Slit center - 1V') - slit1A_set(4.5,4.5,0,0) - m=iex.BL.mda.last_mda() - print('\nsteering out => move beam more positive (10 urad ~ 0.25 mm)') - print('steering up => move beam more positive (10 urad ~ 0.25 mm)\n') + #scanning + slit1A_kwargs = { + 'sound':kwargs['sound'], + 'extended_range':kwargs['slit1A_extended'] + } + ID_steering_scans(**slit1A_kwargs) + + #plotting try: - h_position=fit_mda(m-1,detCA4,1,'gauss',xrange=[-1,1]);plt.show() - v_position=fit_mda(m ,detCA4,1,'gauss',xrange=[-1,1]);plt.show() - iex_steering(h_position,v_position) + scanNum_h = last_mda()-1 + scanNum_v = last_mda() + h_position = ID_steering_plots(scanNum_h,detCA4,xrange=[-1,1]) + v_position = ID_steering_plots(scanNum_v,detCA4,xrange=[-1,1]) + iex_steering(h_position,v_position) except: print('\nUnable to fit position; try to adjust xrange.\n') - # print('h_position=fit_mda('+str(m-1)+','+str(detCA4)+',1,"gauss",xrange=[-1,1])') - # print('v_position=fit_mda('+str(m)+','+str(detCA4)+',1,"gauss",xrange=[-1,1])') - # print('\nThen use:') - # print('\tbeamsteering_1A(h_position,v_position)') - if kwargs['sound']:playsound() + flag=interactive_fct() + + #want to refit while flag == 3: try: fitH=input('do you want to fit mda #'+str(m-1)+' ie horizontal (y or n)? >') if fitH.lower() == 'y' or fitH.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') - h_position=fit_mda(m-1,detCA4,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - fitV=input('do you want to fit mda #'+str(m)+' ie vertical (y or n)? >') + h_position = ID_steering_plots(scanNum_h,detCA4,xrange=[float(x1),float(x2)]) fitV=input('do you want to fit mda #'+str(m)+' ie vertical (y or n)? >') + if fitV.lower() == 'y' or fitV.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') - v_position=fit_mda(m ,detCA4,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() + v_position = ID_steering_plots(scanNum_v,detCA4,xrange=[float(x1),float(x2)]) + iex_steering(h_position,v_position) foo=input('\nare you happy with the fit (y or n)? >') if foo.lower() == 'y' or foo.lower() == 'yes': flag=interactive_fct() + + except: print('\nUnable to fit position; try to tweak xrange again\n') flag=interactive_fct() ###### Wire scans: if 'wire' in kwargs['scanType']: + #scanning mvID(2000) - slit1A_set(4.5,4.5,0,0) - scan_wire('H',comment='Wire scan - H',all_diag=False) # by default puts all meshes in + DiodeC - scan_wire('V',comment='Wire scan - V',all_diag=False) - m=iex.BL.mda.last_mda() + wire_scans(**kwargs) + + #plotting try: - plot_mda(m-1,detH,m,detV,title='wire-H (blue) & wire-V (orange)');plt.show() + scanNum_h = last_mda()-1 + scanNum_v = last_mda() + plot_mda(scanNum_h,detH,scanNum_v,detV,title='wire-H (blue) & wire-V (orange)');plt.show() except: print('Unable to plot. Try:') - print("plot_mda("+str(m-1)+","+str(detH)+","+str(m)+","+str(detV)+",title='wire-H (blue) & wire-V (orange)');plt.show()") - if kwargs['sound']:playsound() - + print("plot_mda("+str(scanNum_h)+","+str(detH)+","+str(scanNum_v)+","+str(detV)+",title='wire-H (blue) & wire-V (orange)');plt.show()") + ###### Mono/slit scans: if 'monoVslit' in kwargs['scanType']: - c=mono_grating_density_get()/1200 - if c==2: + list_position=[GRT,'S1H','S1V','S2H','S2v'] + if mono_grating_get('HEG'): slit(300) + c=2 else: slit(200) + c=1 + + diagnostics_all_out(diode_stay_in=True) print("\n\n================== Mono/slit scans:") - if 'quick' in kwargs: - energy(500) - mvmono(505) - print('\n---------- Scanning slit 2B:\n') - flag=2 - while flag==2: - slits_scan_center('slit2B','V',-8,8,0.25,size=(inf,0.25*c));sleep(1) - slits_scan_center('slit2B','H',-6,6,0.25,size=(0.25,inf));sleep(1) - m=iex.BL.mda.last_mda() - try: - V2=fit_mda(m-1,detDiode,1*c,'gauss');plt.show() - H2=fit_mda(m ,detDiode,1,'gauss');plt.show() - list_position[1]=V2 - list_position[2]=H2 - #print(f"V2 = {round(V2,3)}") - #print(f"H2 = {round(H2,3)}") - - print('\nBeam position:') - print(f" - vertical: V2 = {round(V2,3)}") - print(f" - horizontal: H2 = {round(H2,3)}") - v_steering=beamsteering_2B(V2) - m1_roll=beamsteering_2B(V2)[1] - print('\nCurrent position:') - current_roll=FMB_mirror_get(1)[5] - new_roll=current_roll+m1_roll - print('\nREMEMBER: 2V slit should always be centered at zero by steering M1 roll!') - print(" - vertical: "+str(current_roll)+str(v_steering[1])+" => Move_M1('RZ',"+str(new_roll)+")") - print(' - horizontal: reset slit 2BH center to ',str(H2)) - - except: - print('Unable to fit position; try to adjust xrange.') - # print('c='+str(c)) - # print('V2=fit_mda('+str(m-1)+','+str(detDiode)+',1*c+,"gauss")') - # print('H2=fit_mda('+str(m)+','+str(detDiode)+',1,"gauss")') - # print('\nThen use:') - # print('\tbeamsteering_2B(V2)') - # list_position.append(np.nan) - # list_position.append(np.nan) - flag=interactive_fct(mirror=True) - - if kwargs['sound']:playsound() - flag=interactive_fct(mirror=True) - while flag == 3: - fitV2=input('do you want to FIT mda #'+str(m-1)+' ie slit2-V (y or n)? >') - if fitV2.lower() == 'y' or fitV2.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - V2=fit_mda(m-1,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to replace slit2-V value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[1]=V2 - fitH2=input('do you want to FIT mda #'+str(m)+' ie slit2-H (y or n)? >') - if fitH2.lower() == 'y' or fitH2.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - H2=fit_mda(m ,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to REPLACE slit2-H value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[1]=H2 - foo=input('\nare you happy with the fit (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - flag=interactive_fct(mirror=True) - if flag == 4: - x=input('New M1 roll value >') - x=float(x) + if kwargs['monoVslit_quick']: + for i,slit_name in enumerate(['slit2B','slit1A']) + print('\n---------- Scanning '+slit_name+':\n') + flag=2 + while flag==2: + #scanning + monoVslit_quick_scan(slit_name,**kwargs) + + #plotting try: - FMB_mirror_move(1,'RZ',x) - sleep(2); - FMB_mirror_get(1) - print('\nrepeating scan...\n') - flag=2 + scanNum_v = last_mda()-1 + scanNum_h = last_mda() + V2 = monoVslit_quick_plot(scanNum_v,detDiode,c) + H2 = monoVslit_quick_plot(scanNum_h,detDiode,1) + except: - print('\ninvalid input; unable to move M1...\n') - flag=interactive_fct(mirror=True) - print('\n---------- Scanning slit 1A:\n') - flag=2 - while flag==2: - slits_scan_center('slit1A','V',-4, 4, 0.1,size=(inf,0.25)) - slits_scan_center('slit1A','H',-3, 3, 0.1,size=(0.25,inf)) - apertures_set() - m=iex.BL.mda.last_mda() - try: - V1=fit_mda(m-1,detDiode,1,'gauss');plt.show() - H1=fit_mda(m ,detDiode,1,'gauss');plt.show() - list_position[3]=V1 - list_position[4]=H1 - print('\nBeam position:') - print(f" - vertical: V1 = {round(V1,3)}") - print(f" - horizontal: H1 = {round(H1,3)}") - except: - print('\nUnable to fit position; try to adjust xrange.') - # print('V1=fit_mda('+str(m-1)+','+str(detDiode)+',1,"gauss")') - # print('H1=fit_mda('+str(m)+','+str(detDiode)+',1,"gauss")') - # list_position.append(np.nan) - # list_position.append(np.nan) - if kwargs['sound']:playsound() - flag=interactive_fct() #interactive_fct('slit 1A') - while flag == 3: - fitV1=input('do you want to fit mda #'+str(m-1)+' ie slit1-V (y or n)? >') - if fitV1.lower() == 'y' or fitV1.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - V1=fit_mda(m-1,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to replace slit1-V value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[3]=V1 - fitH1=input('do you want to fit mda #'+str(m)+' ie slit1-H (y or n)? >') - if fitH1.lower() == 'y' or fitH1.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - H1=fit_mda(m ,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to replace slit1-H value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[4]=H1 + print('Unable to fit position; try to adjust xrange.') + + flag=interactive_fct(mirror=True) + #want to refit + while flag == 3: + fitV2=input('do you want to FIT mda #'+str(m-1)+' ie slit2-V (y or n)? >') + if fitV2.lower() == 'y' or fitV2.lower() == 'yes': + x1=input('x1 >') + x2=input('x2 >') + xrange=[float(x1),float(x2)] + V2 = monoVslit_quick_plot(scanNum_v,detDiode,c,xrange=xrange) + foo=input('do you want to replace '+slit_name+'-V value in list_position (y or n)? >') + if foo.lower() == 'y' or foo.lower() == 'yes': + list_position[1]=V2 + + fitH2=input('do you want to FIT mda #'+str(m)+' ie slit2-H (y or n)? >') + if fitH2.lower() == 'y' or fitH2.lower() == 'yes': + x1=input('x1 >') + x2=input('x2 >') + xrange=[float(x1),float(x2)] + H2 = monoVslit_quick_plot(scanNum_h,detDiode,1,xrange=xrange) + foo=input('do you want to REPLACE '+slit_name+'-H value in list_position (y or n)? >') + if foo.lower() == 'y' or foo.lower() == 'yes': + list_position[1]=H2 + + if slit_name = 'slit2B': + M0M1_steering(H2,V2) + list_position[4] = V2 + list_position[3] = H2 + mirror = True + elif slit_name: 'slit1A': + list_position[2] = V2 + list_position[1] = H2 + mirror = False + foo=input('\nare you happy with the fit (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - flag=interactive_fct() - print('\nBeam center fit @ ['+GRT+',2V,2H,1V,1H]:',list_position) + if foo.lower() == 'y' or foo.lower() == 'yes': + flag=interactive_fct(mirror=mirror) + + #happy with fitting but want to adjust roll + if flag == 4: + x=input('New M1 roll value >') + x=float(x) + try: + FMB_mirror_move(1,'RZ',x) + sleep(2); + FMB_mirror_get(1) + print('\nrepeating scan...\n') + flag=2 + except: + print('\ninvalid input; unable to move M1...\n') + flag=interactive_fct(mirror=True) + + print('\nBeam center fit @ '+str(list_position)) foo=input('do you want to update the slit dictionary (y or n)? >') if foo.lower() == 'y' or foo.lower() == 'yes': slit_list=input('do you want to use '+str(list_position)+' (y or n)? >') @@ -376,17 +317,13 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): update_slit_dict(list_position) else: update_slit_dict() - else: # longer full slit scans + + else: # 2D map mvID(500) flag=2 while flag==2: - mvmono(500) - apertures_set() - n=2 if 'extended_range' in kwargs else 1 - scan_mono_vs_slit('2V',[0.25*c,-2*c*n,2*c*n,0.5],[475,515,2],comment='Mono/Slit - 2V') #10/20 min for MEG/HEG - scan_mono_vs_slit('2H',[0.25,-2*n,2*n,0.5],[475,515,2],comment='Mono/Slit - 2H') #10min - scan_mono_vs_slit('1V',[0.5,-0.75*n,0.75*n,0.25*c],[475,515,2],comment='Mono/Slit - 1V') #10min - scan_mono_vs_slit('1H',[0.5,-0.75*n,0.75*n,0.25],[475,515,2],comment='Mono/Slit - 1H') #10min + beam_profile(GRT,["2V","2H","1V","1H"]) + #interactive flag=interactive_fct() @@ -396,13 +333,11 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): print("\n\n================== Check Flux:") flag=2 while flag==2: - check_flux(stay='y') - slit(50) - energy(500) - scanmono(475,525,1,comment='Mono Scan @ 500eV') - m=iex.BL.mda.last_mda() + check_flux_scan(stay=True) + + scanNum = last_mda() try: - plot_mda(m,detDiode,Flux=3);plt.show() + plot_mda(scanNum,detDiode,Flux=3);plt.show() except: print('Unable to plot. Try:') print("plot_mda("+str(m)+","+str(detDiode)+",flux=3);plt.show()") @@ -562,283 +497,3 @@ def update_slit_dict(**kwargs): apertures_set() return slit_position -############################################################################################### -######################################### Start Of The Week plotting -- old!!!! ################################### -############################################################################################### - -def plot_StartOfTheWeek_DetDict(branch): - """ - returns the detectors for a given branch - - """ - DetDict={'c':(9,7,8,15),'d':(9,7,8,14)} - return DetDict[branch] - -def StartOfTheWeek_plot(branch,FirstScanNum,**kwargs): - """ - Plots the data from StartOfTheWeek - - branch is used to set the detectors - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_Det(branch) - - FirstScanNum is based on slit1A - slit1A-H = FirstScanNum - slit1A-V = FirstScanNum + 1 - wire1-H = FirstScanNum + 2 - wire1-V = FirstScanNum + 3 - monoVslit = FirstScanNum + 4/5/6/7 - flux = FirstScanNum + 8 - - Slit 1A and Wire scans: determine ID steering and Slit1A position - Scan_MonoVsSlit: determine the steering from M0/M1 - by default the full range is plotted (pnt_first=0, pnt_last=inf) - refine the plot via - plot_StartOfTheWeek_mono(branch,FirstScanNum,pnt_first,pnt_last) - - kwargs: - filepath = None, uses current mda filepath unless specified - e.g. user : filepath='/net/s29data/export/data_29idc/2018_2/UserName/mda/' - e.g. staff: filepath='/net/s29data/export/data_29idb/2018_2/mda/' - prefix = None, uses current mda prefix unless specified - scanIOC = None, uses BL_ioc() unless specified - - scanType = ['slit1','wire','flux','monoVslit'], full set by default - - ref_firstScanNum to plot reference spectra - ref_branch = branch, unless specified - ref_filepath = filepath, unless specified - ref_prefix = prefix, unless specified - - steering out => moves beam more positive (20 urad ~ 0.5 mm) - steering up => moves beam more positive (20 urad ~ 0.5 mm) - -figure, axes = plt.subplots(nrows=2, ncols=2) -axes[0, 0].plot(x, y) - """ - - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - - kwargs.setdefault('scanType',['slit1','wire','flux','monoVslit']) - - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - - kwargs.setdefault('debug',False) - - - scanNum=FirstScanNum - ref_firstScanNum=kwargs['ref_firstScanNum'] - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - - - if 'slit1' in kwargs['scanType']: - if kwargs['debug']: - print('slit1') - plot_StartOfTheWeek_slit1A(branch,scanNum,**kwargs) - scanNum+=2 - if kwargs['ref_firstScanNum'] is not None: - kwargs.update({'ref_firstScanNum':ref_firstScanNum+2}) - - - if 'wire' in kwargs['scanType']: - if kwargs['debug']: - print('wire') - plot_StartOfTheWeek_wire(branch,scanNum,**kwargs) - scanNum+=2 - if kwargs['ref_firstScanNum'] is not None: - ref_firstScanNum+=2 - kwargs.update({'ref_firstScanNum':ref_firstScanNum+2}) - - if 'monoVslit' in kwargs['scanType']: - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - if d.mda[scanNum].header.all['rank']<2: #quick - print(scanNum, detDiode) - V2=fit_mda(scanNum,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='2V - mda_'+str(scanNum)) - H2=fit_mda(scanNum+1,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='2H - mda_'+str(scanNum+1)) - V1=fit_mda(scanNum+2,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='1V - mda_'+str(scanNum+2)) - H1=fit_mda(scanNum+3,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='1H - mda_'+str(scanNum+3)) - plt.show() - print('\nFit positions:') - print(f"V2={round(V2,3)}") - print(f"H2={round(H2,3)}") - print(f"V1={round(V1,3)}") - print(f"H1={round(H1,3)}") - - else: #MonoVsSlit - print('\n# To plot the Mono vs Slit data use:\n') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum)+','+str(detDiode)+',0,inf)'+'\t#2V') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum+1)+','+str(detDiode)+',0,inf)'+'\t#2H') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum+2)+','+str(detDiode)+',0,inf)'+'\t#1V') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum+3)+','+str(detDiode)+',0,inf)'+'\t#1H') - print('\n# (pnt_first,pnt_last0=(0,inf) => plots all') - print('# select specific first/last to refine.') - - print('\nREMEMBER to update slit center using: \tupdate_slit_dict()' ) - scanNum+=4 - if kwargs['ref_firstScanNum'] is not None: - kwargs.update({'ref_firstScanNum':ref_firstScanNum+4}) - - if 'flux' in kwargs['scanType']: - if kwargs['debug']: - print('flux') - plot_StartOfTheWeek_flux(branch,scanNum,**kwargs) - -def plot_StartOfTheWeek_slit1A(branch,scanNum,**kwargs): - """ - plots the slit1A scans - scanNum = slit1A-H scanNum - """ - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - kwargs.setdefault('plotType',['slit1','wire','flux','monoVslit']) - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - kwargs.setdefault('debug',False) - - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - ref_detCA4,ref_detH,ref_detV,ref_detDiode=plot_StartOfTheWeek_DetDict(kwargs['ref_branch']) - - figure, axes = plt.subplots(nrows=1, ncols=2,figsize=(10,3)) - for i,t in enumerate(['1H center scan','1V center scan']): - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - axes[i].plot(d.mda[scanNum].det[detCA4].scale['x'], d.mda[scanNum].det[detCA4].data,marker='x',label=str(scanNum)) - scanNum+=1 - if kwargs['ref_firstScanNum'] is not None: - ref_scanNum=kwargs['ref_firstScanNum']+i - ref_d=IEXdata(ref_scanNum,path=kwargs['ref_filepath'],prefix=kwargs['ref_prefix'],q=1) - axes[i].plot(ref_d.mda[ref_scanNum].det[ref_detCA4].scale['x'], ref_d.mda[ref_scanNum].det[ref_detCA4].data,marker='x',label=str(ref_scanNum)) - axes[i].grid(color='lightgray', linestyle='-', linewidth=0.5) - axes[i].title.set_text(t) - axes[i].legend() - plt.show() - print("\nsteering out => move beam more positive (10 urad ~ 0.25 mm)") - print("steering up => move beam more positive (10 urad ~ 0.25 mm)") - print("\nTo fit beam position use:\n") - print("detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict('"+kwargs['ref_branch']+"')") - print("fit_mda("+str(scanNum-2)+",detCA4,1,'gauss',xrange=(-1,1))") - print("fit_mda("+str(scanNum-1)+",detCA4,1,'gauss',xrange=(-1,1))\n") - - -def plot_StartOfTheWeek_wire(branch,scanNum,**kwargs): - """ - plots the wire scans - scanNum = wire-H scanNum - """ - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - kwargs.setdefault('plotType',['slit1','wire','flux','monoVslit']) - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - kwargs.setdefault('debug',False) - - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - ref_detCA4,ref_detH,ref_detV,ref_detDiode=plot_StartOfTheWeek_DetDict(kwargs['ref_branch']) - - figure, axes = plt.subplots(nrows=1, ncols=2,figsize=(10,3)) - for i,t in enumerate(['H-wire','V-wire']): - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - #niceplot(d.mda[scanNum].det[DetDict[branch][1+i]],marker='x',label=str(scanNum)) - detNum=plot_StartOfTheWeek_DetDict(branch)[1+i] - axes[i].plot(d.mda[scanNum].det[detNum].scale['x'], d.mda[scanNum].det[detNum].data,marker='x',label=str(scanNum)) - scanNum+=1 - if kwargs['ref_firstScanNum'] is not None: - ref_scanNum=kwargs['ref_firstScanNum']+i - ref_d=IEXdata(ref_scanNum,path=kwargs['ref_filepath'],prefix=kwargs['ref_prefix'],q=1) - #niceplot(ref_d.mda[ref_scanNum].det[DetDict[kwargs["ref_branch"]][1+i]],marker='x',label=str(ref_scanNum)) - detNum=plot_StartOfTheWeek_DetDict(kwargs["ref_branch"])[1+i] - axes[i].plot(ref_d.mda[ref_scanNum].det[detNum].scale['x'], ref_d.mda[ref_scanNum].det[detNum].data,marker='x',label=str(ref_scanNum)) - axes[i].grid(color='lightgray', linestyle='-', linewidth=0.5) - axes[i].title.set_text(t) - axes[i].legend() - plt.show() - -def plot_StartOfTheWeek_flux(branch,scanNum,**kwargs): - """ - plots the wire scans - scanNum = wire-H scanNum - """ - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - kwargs.setdefault('plotType',['slit1','wire','flux','monoVslit']) - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - kwargs.setdefault('debug',False) - - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - ref_detCA4,ref_detH,ref_detV,ref_detDiode=plot_StartOfTheWeek_DetDict(kwargs['ref_branch']) - - for t in ['ID peak @ 500eV']: - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - niceplot(d.mda[scanNum].det[detDiode],marker='x',label=str(scanNum)) - scanNum+=1 - if kwargs['ref_firstScanNum'] is not None: - ref_scanNum=kwargs['ref_firstScanNum']+2 - ref_d=IEXdata(ref_scanNum,path=kwargs['ref_filepath'],prefix=kwargs['ref_prefix'],q=1) - niceplot(ref_d.mda[ref_scanNum].det[ref_detDiode],marker='x',label=str(ref_scanNum)) - ref_scanNum+=1 - plt.grid(color='lightgray', linestyle='-', linewidth=0.5) - plt.title(t) - plt.legend() - plt.show() - -def plot_MonoVsSlit(branch,ScanNum,detDiode,pnt_first,pnt_last,norm=True,filepath=None,prefix=None,scanIOC=None): - """ - Plots Scan_MonoVsSlit to determine the steering from M0/M1 - To plot the full range (pnt_first=0, pnt_last=inf) - plot_StartofWeek_mono(branch,FirstScanNum+4,pnt_first,pnt_last) - - filepath: by default plot scans for the current data folder (as defined in BL_ioc() ScanRecord SaveData) - or specified folder path ending with '/': - e.g. user : filepath='/net/s29data/export/data_29idc/2018_2/UserName/mda/' - e.g. staff: filepath='/net/s29data/export/data_29idb/2018_2/mda/' - prefix: by default, uses prefix as defined in ScanRecord ("mda_") - """ - x,y,z,x_name,y_name,z_name=mda_2D(ScanNum,detDiode,filepath,prefix,scanIOC) - Which=str(y_name)[10:12] - if pnt_last is inf: - pnt_last=len(z)-1 - for i in range(pnt_first,pnt_last+1): - maxvalue=max(z[i]) - if norm == True: - plt.plot(x,z[i]/maxvalue,label='#'+str(i)+': '+str(round(y[i],2))) - else: - plt.plot(x,z[i],label='#'+str(i)+': '+str(round(y[i],2))) - plt.legend(bbox_to_anchor=(1, 0), loc='lower left', ncol=2,shadow=True, title="ScanNum: "+str(ScanNum)+"\nSlit-"+Which+" position", fancybox=True) - #plt.legend(loc='lower left',ncol=2, shadow=True, title="ScanNum: "+str(ScanNum)+"\nSlit-"+Which+" position", fancybox=True) - plt.grid(color='lightgray', linestyle='-', linewidth=0.5) - plt.show() - - -def read_flux(FileName='Flux_Curves.txt',FilePath="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries/"): - print('test') - with open(join(FilePath, FileName)) as f: - for c,line in enumerate(f.readlines()): - if line[0] == '=': - lastdate=line[8:16] - print(lastdate) - if line[0] == '-' and line[-2] == 'x': - axis='x' - print(axis) - line_x=line - if line[0] == '-' and line[-2] == 'y': - axis='y' - print(axis) - line_y=line - mydict_x=ast.literal_eval(line_x) - mydict_y=ast.literal_eval(line_y) - return mydict_x,mydict_y - - diff --git a/iexcode/cheatsheet.txt b/iexcode/cheatsheet.txt index 668cf78b59f1739179b4d2d0daa386a86f836a90..cc825ed4950f043e0fb4889f539ce8c236d3e7be 100644 --- a/iexcode/cheatsheet.txt +++ b/iexcode/cheatsheet.txt @@ -272,4 +272,3 @@ switch_branch => moves m3R to default position for the branch; close/reopens shu get_mirros => gets all the FMB mirror positions slit => sets the exit_slit slit_get => gets the exit slit -apertures_set => sets beamline aperatures \ No newline at end of file diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index 5a172a0dc673fae173f1c7ac115af4f2feb51023..a01087d4f3175cb4cf8756491a91e712af154405 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -77,6 +77,7 @@ def ARPES_init(*userName,**kwargs): #EA if EA.connected: + sleep(1) EA.get() _EA_init_Motors(ARPES_Motors) if kwargs['set_folders']: diff --git a/iexcode/instruments/FMB_mirrors.py b/iexcode/instruments/FMB_mirrors.py index ca1996ff8a74d75340d281c7cc85a680223ffff2..5af10702dc9fc621863cb0b57556b199f8c3f8b6 100644 --- a/iexcode/instruments/FMB_mirrors.py +++ b/iexcode/instruments/FMB_mirrors.py @@ -74,7 +74,7 @@ def FMB_mirror_move(mirror_num,axis,val,verbose=True): caput(pv+axis+"_POS_SP",val) caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000) while True: - if FMB_mirror_status != 1: + if FMB_mirror_status(mirror_num) != 1: sleep(.5) else: break diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py index 709408271c90ae9cceb6c9d0380a5f5a747dec53..f59da73a401fcaca60be8e5e2e0e221de3336673 100644 --- a/iexcode/instruments/IEX_VPU.py +++ b/iexcode/instruments/IEX_VPU.py @@ -276,9 +276,10 @@ def ID_switch_mode(ID_mode): print("Turning ID off...") ID_off(verbose=True) sleep(10) - ID_on(verbose=True) + print("Switching ID mode, please wait...") ID_mode_set(ID_mode) + ID_on(verbose=True) ID_ready() print("ID Mode:",ID_mode) except: diff --git a/iexcode/instruments/Scienta.py b/iexcode/instruments/Scienta.py index 315ad0d73ec4aa1e0b149751b49bb7f64e2d198e..8417aac2d5f8e4558722fee2ebf07355d6ff227e 100644 --- a/iexcode/instruments/Scienta.py +++ b/iexcode/instruments/Scienta.py @@ -81,7 +81,8 @@ class Scienta: self.Frames = None pv = PV(self.PHV+"WorkFunction") - if pv.connect(): + time.sleep(1) + if pv.connected: self.get() self.connected = True else: @@ -96,7 +97,7 @@ class Scienta: """ for key in vars(self): - if key not in ["PHV","_Pcam","_savePlugin","_statsPlugin","wk","Frames","dtype"]: + if key not in ["PHV","_Pcam","_savePlugin","_statsPlugin","wk","Frames","dtype","connected"]: vars(self)[key]=caget(self.PHV+key+".VAL") if key in ["LensMode","SpectraMode"]: vars(self)[key]=caget(self.PHV+key+".VAL",as_string=True) diff --git a/iexcode/instruments/m3r.py b/iexcode/instruments/m3r.py index 9619e8d67d07965ef86b014ceb6f39217c51e0fd..402a22067293708d204e406593be6ba7b389a878 100644 --- a/iexcode/instruments/m3r.py +++ b/iexcode/instruments/m3r.py @@ -104,9 +104,10 @@ def m3r_switch_branch(branch): position = m3r_table(branch) FMB_mirror_move_all(3,position,verbose=False) # Relax bellows by doing large Z translation: - FMB_mirror_move_all(3,"TY",5,verbose=False) - FMB_mirror_move_all(3,"TY",5,verbose=False) - + FMB_mirror_move(3,"TY",5,verbose=False) + sleep(.1) + FMB_mirror_move(3,"TY",0,verbose=False) + sleep(.1) FMB_mirror_get(3,verbose=True) ############################################################################################################## diff --git a/iexcode/instruments/slits.py b/iexcode/instruments/slits.py index 460734f6803877e837408edee4884bffec066910..89e6de49a748ea29edbecfc055b9eecc94dd7a44 100644 --- a/iexcode/instruments/slits.py +++ b/iexcode/instruments/slits.py @@ -409,23 +409,21 @@ def slit3D_encoders_reset(Vcenter): encoders_reset_zero(slit_name) slits_synch(slit_name) -def exit_slit_set(size, verbose=True): +def exit_slit_set(branch, size, verbose=True): """ sets the size for the iex.BL.branch exit slit Previously: SetExitSlit """ - branch=iex.BL.mda.branch if branch == "c": slit3C_set(size, verbose) elif branch == "d": slit3D_set(size, verbose) -def exit_slit_get(verbose=True): +def exit_slit_get(branch, verbose=True): """ gets the size for the iex.BL.branch exit slit """ - branch = iex.BL.branch if branch == "c": slit_size,slit_center = slit3C_get(verbose=False) elif branch == "d": @@ -438,17 +436,7 @@ def exit_slit_get(verbose=True): ################################ slit fits ############################## ############################################################################################################## -def aperture_fit(hv,slit_num): - """ - used close the beamline apertures/slits to only take the center of the beam, - i.e. no heat bump (determined emperically by looking at the the shift in energy vs slit position) - Previously Aperture_Fit - """ - K=slit_coef(slit_num)[1] - sizeH=K[0]+K[1]*hv+K[2]*hv*hv - sizeV=K[3]+K[4]*hv+K[5]*hv*hv - return [round(sizeH,3),round(sizeV,3)] def slit_coef(slit_num): """ diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py index f80bed6511198b890c40f47ca5f7ab4126108008..161b48fdd494a472b7dede31f8e732b1e538c692 100644 --- a/iexcode/instruments/xrays.py +++ b/iexcode/instruments/xrays.py @@ -287,6 +287,17 @@ def qp(QP_ratio): ############################################################################################################## ################################ beamline slits = apertures ############################## ############################################################################################################## +def aperture_fit(hv,slit_num): + """ + used close the beamline apertures/slits to only take the center of the beam, + i.e. no heat bump (determined emperically by looking at the the shift in energy vs slit position) + + Previously Aperture_Fit + """ + K=slit_coef(slit_num)[1] + sizeH=K[0]+K[1]*hv+K[2]*hv*hv + sizeV=K[3]+K[4]*hv+K[5]*hv*hv + return [round(sizeH,3),round(sizeV,3)] def apertures_set(c_2B=1,c_1A=1,verbose=True): """ @@ -580,14 +591,15 @@ def get_mirrors(): ############################################################################################################## ########################### slits and resolution ###################### ############################################################################################################## -def slit(size): +def slit(size,verbose=True): """ sets the exit slit based on iex.BL.endstation ARPES = 0 < x < 300 um Kappa = 0 < x < 1000 um """ - exit_slit(size) + branch = iex.BL.branch + exit_slit(branch,size,verbose=verbose) def slit_get(verbose=True): @@ -597,17 +609,7 @@ def slit_get(verbose=True): ARPES = 0 < x < 300 um Kappa = 0 < x < 1000 um """ - branch = iex.BL.branch - if branch == "c": - slit_size = slit3C_get(verbose=False) - slit_center = np.nan - elif branch == "d": - slit_size,slit_center = slit3D_get(verbose=False) - - if verbose: - message = iex.BL.branch+' exit slit: '+str(slit_size) - message += ", @ "+str(slit_center) - print(message) + exit_slit_get(branch,verbose=verbose) return slit_size,slit_center diff --git a/iexcode/macros/commissioning.py b/iexcode/macros/commissioning.py index 1499dcca0f96f794a500a51f06022c9e6ff4091c..0425d5a31f6f9243f33f0fbbf69aee8c1e629201 100644 --- a/iexcode/macros/commissioning.py +++ b/iexcode/macros/commissioning.py @@ -17,6 +17,8 @@ from iexcode.instruments.utilities import * from iexcode.instruments.electron_analyzer import scanEA from iexcode.instruments.Logfile import log_name_set,log_print from iexcode.instruments.cameras import * +from instruments.slits import exit_slit_get, slit1A_get, slit1A_set, slits_set_size +from instruments.xrays import apertures_set from .quick_plot import fit_mda, mda_1D @@ -24,7 +26,25 @@ from .quick_plot import fit_mda, mda_1D ################################ checking alignment ############################## ############################################################################################################## -def check_flux(hv=500,ID_mode='RCP',stay=False): +def check_flux_scan(hv=500,stay=False,**kwargs) + """ + puts the diode in and scans the mono + stay: + True => leaves the diode in + False => takes the diode out + """ + kwargs.setdefault('sound',Ture) + diagnostics_all_out(diode_stay_in=True) + slit(50) + energy(hv) + hv_start = hv*.95 + hv_stop = hv*1.05 + hv_step = round(1.0*hv/500,0) + scanmono(hv_start,hv_stop,hv_step,comment='Mono Scan @ '+str(hv)+' eV') + if kwargs['sound']: + playsound() + +def check_flux_read(hv=500,ID_mode='RCP',stay=False): """ puts the diode in in the branch defined my position of m3r measures flux at energy ID_mode specified @@ -32,26 +52,21 @@ def check_flux(hv=500,ID_mode='RCP',stay=False): Previously: CheckFlux """ + current_slit = exit_slit_get(verbose=True) ID_switch_mode(ID_mode) energy(hv) ring_current=round(caget("S:SRcurrentAI.VAL"),2) - diagnostics_all_out(diode_to_stay_in=m3r_branch()) - exit_slit() + diagnostics_all_out(diode_stay_in=True) + exit_slit(50) + sleep(10) if m3r_branch() == "c": - current_slit=caget('29idb:Slit3CFit.A') - diode_c('In') - exit_slit(50) - sleep(10) diode=diode_c_read() elif m3r_branch() == "d": - current_slit=caget('29idb:Slit4Vsize.VAL') - sleep(10) - diode_d("In") - exit_slit(50) diode=diode_d_read() + flux=current2flux(diode) print("\n----- Current on diode : %.3e" % diode, "A") print("----- Corresponding flux: %.3e" % flux, "ph/s \n") @@ -62,24 +77,6 @@ def check_flux(hv=500,ID_mode='RCP',stay=False): diagnostics_all_out() exit_slit(current_slit) -def check_m0m1(hv=500,stay=True,wire=True,**kwargs): - """ - Prints Flux in C-branch - stay = 'yes' => Leaves diagnostics in the beam - wire ='yes'=> Does wire scans to determine M0M1 alignment - Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details - - Previously: CheckM0M1 - """ - - switch_branch('c') - grating('HEG') - print("\nFlux at hv=500 as off Feb 2019: ~3.3e-06 A = ~1.5e+11 ph/s") - branch_shutter_open() - check_flux(hv=hv,stay=stay) - if wire is not None: - scan_wire('H',**kwargs) - scan_wire('V',**kwargs) def scan_wire(direction,all_diag=True,**kwargs): """ @@ -416,14 +413,20 @@ def procedure_align_m1(): # 2017_3 - HEG after opitmization: mba_b_0241-0244 # 2018_1 - HEG before opitmization: mba_b_0005-0008 - - -def beamsteering_2B(v_position): - vroll=round(v_position*0.05/0.04,3) - if v_position<0: v_direction=' +' - else: v_direction=' -' - v_steering=v_direction+str(abs(vroll))+' urad' - return v_steering,float(v_steering.split(" ")[1]) + +def iex_steering(h_position,v_position): + """ + prints the required steering to compensate for the current + """ + print('\nBeam position:') + print(' - horizontal: '+str(h_position)) + print(' - vertical: '+str(v_position)) + h_steering,v_steering=beamsteering_1A(h_position,v_position) + print('\nBeam steering:') + print(' - horizontal: '+h_steering) + print(' - vertical: '+v_steering) + print('\n') + return h_steering,v_steering def beamsteering_1A(h_position,v_position,FE_center_h=0,FE_center_v=0): h_correction=FE_center_h-h_position @@ -438,9 +441,125 @@ def beamsteering_1A(h_position,v_position,FE_center_h=0,FE_center_v=0): v_steering=str(vrad)+v_direction return h_steering,v_steering +def M0M1_steering(H2,V2): + """ + M1 steering: (monoVslit-2V and 2H) + Roll: Rz more positive => 2V more positive (0.25 => .25 mm) + Pitch: Ry more positive => 2H more positive (0.03 => .5 mm + """ + print('\nBeam position:') + print(f" - vertical: V2 = {round(V2,3)}") + print(f" - horizontal: H2 = {round(H2,3)}") + v_steering=beamsteering_2B(V2) + m1_roll=beamsteering_2B(V2)[1] + print('\nCurrent position:') + current_roll=FMB_mirror_get(1)[5] + new_roll=current_roll+m1_roll + print('\nREMEMBER: 2V slit should always be centered at zero by steering M1 roll!') + print(" - vertical: "+str(current_roll)+str(v_steering[1])+" => Move_M1('RZ',"+str(new_roll)+")") + print(' - horizontal: reset slit 2BH center to ',str(H2)) + +def beamsteering_2B(v_position): + vroll=round(v_position*0.05/0.04,3) + if v_position<0: v_direction=' +' + else: v_direction=' -' + v_steering=v_direction+str(abs(vroll))+' urad' + return v_steering,float(v_steering.split(" ")[1]) + + + + + +def ID_steering_scans(**kwargs): + """ + slit1 - Scanning front-end slit center + cutoffs are defined by the fixed aperature midpoint is slit center + beam should be center at slit center, steer ID until the coincide + + **kwargs: + verbose: default => True + sound: playsound, default => True + extended_range True/False + False: default range = -3,3,0.1 + True: -5,5,0.1 + + Note: Does not set the ID, mvID = 2.0 gives a nice gaussian + """ + kwargs.setdefault('sound',True) + + if 'extended_range' in kwargs: + start,stop = (-5,5) + else: + start,stop = (-3,3) + + size,center = slit1A_get(verbose=False) + + slits_scan_center('slit1A','H',start,stop,0.1,size=(0.25,inf),comment='Slit center - 1H') + slits_scan_center('slit1A','V',start,stop,0.1,size=(inf,0.25),comment='Slit center - 1V') + slit1A_set(size,center,verbose=False) + + + if kwargs['sound']: + playsound() + + if kwargs['verbose']: + print('\nsteering out => move beam more positive (10 urad ~ 0.25 mm)') + print('steering up => move beam more positive (10 urad ~ 0.25 mm)\n') +def ID_steering_plots(scanNum,det_num,xrange=[-1,1]): + """ + plots data from ID_steering_scans and returns the positions + """ + position=fit_mda(scanNum,det_num,1,'gauss',xrange=xrange) + plt.show() + + return position + +def wire_scans(**kwargs): + """ + Checks for large misaligment or clipping by M0/M1 + + Note: Does not set the ID, mvID = 2.0 gives a nice gaussian + """ + kwargs.setdefault('sound',True) + + slits_set_size('slit1A',(4.5,4.5)) + scan_wire('H',comment='Wire scan - H',all_diag=False) # by default puts all meshes in + DiodeC + scan_wire('V',comment='Wire scan - V',all_diag=False) + + if kwargs['sound']: + playsound() + +def monoVslit_quick_scan(slit_name, **kwargs): + """ + sets the slit to be narrow and scans along and across the grating + at 500 eV to see if M0/M1 are steering the beam to the center of the grating + + """ + kwargs.setdefault('sound',True) + + energy(500) + mvmono(505) + + H,V = _slits_wide_open_dictionary()[slit_name] + + slits_scan_center(slit_name,'V',-V,V,0.25,size=(inf,0.25*c)) + sleep(1) + + slits_scan_center(slit_name,'H',-H,H,0.25,size=(0.25,inf)) + sleep(1) + + if kwargs['sound']: + playsound() + + +def monoVslit_quick_plot(scanNum,detDiode,c,xrange=None): + position = fit_mda(scanNum,detDiode,c,'gauss',xrange) + plt.show() + return position + ##################################################################################### ### Slit-1A Procedures @@ -549,39 +668,38 @@ def scan_slit_size(slit,start,stop,step,center=(0,0)): # and that the slits are centered ##################################################################################### -def ID_beam_profile(grt,slit_list,c_slit=1,c_energy=1,**kwargs): +def beam_profile(grt,slit_list): """ Makes a nice 2D image of the energy distribution of the beam across the grating at ID=500 - Does NOT put the diagnostics into the beam you need to run the following if you haven't already (AllDiagOut(); DiodeCIn()) SlitList=["2H","2V","1H","1V"] - c_slit = scaling of step size (c=1 Slit-1: step = 0.25. Slit-2: step = 0.5) - c_energy = scaling of mono step size ( c=1 eV step = 2) - with c_slit=1 and c_energy = 1 Each slit ~ 1:10 min + + Note: Does NOT put the diagnostics into the beam Previously BeamProfile """ grating(grt) - grt_density = mono_grating_density_get() - c=grt_density/1200 - ID=500 - eVstart,eVstop,eVstep=460,540,4 + c = mono_grating_density_get()/1200 + + mvID(500) + apertures_set() + + eVstart = 460 + eVstop = 540 + eVstep = 4 + for slit in slit_list: if slit=="1H": #Hsize,Vsize,Hstart,Hstop,Hstep = 0.50,2,-2,2,0.25*c_slit # => 35 min - #MonoVsSlit1AH_Go(ID,eVstart,eVstop,eVstep*c_energy,Hstart,Hstop,Hstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('1H',[0.5,-2,2,0.25*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1H') + scan_mono_vs_slit('1H',[0.5,-2,2,0.25*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1H') elif slit == "1V": #Hsize,Vsize,Vstart,Vstop,Vstep = 2,0.50,-2,2,0.25*c_slit - #MonoVsSlit1AV_Go(ID,eVstart,eVstop,eVstep*c_energy,Vstart,Vstop,Vstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('1V',[0.5,-2,2,0.25*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1V') + scan_mono_vs_slit('1V',[0.5,-2,2,0.25*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 1V') elif slit =="2H": #Hsize,Vsize,Hstart,Hstop,Hstep = 0.50,8,-3,3,0.5*c_slit - #MonoVsSlit2BH_Go(ID,eVstart,eVstop,eVstep*c_energy,Hstart,Hstop,Hstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('2H',[0.5,-3,3,0.5*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2H') + scan_mono_vs_slit('2H',[0.5,-3,3,0.5*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2H') elif slit =="2V": #Hsize,Vsize,Vstart,Vstop,Vstep = 6,0.25*c,-4*c,4*c,0.5*c_slit - #MonoVsSlit2BV_Go(ID,eVstart,eVstop,eVstep*c_energy,Vstart,Vstop,Vstep,Hsize,Vsize,scanIOC,**kwargs) - scan_mono_vs_slit('2V',[0.5,-4,4,0.5*c_slit],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2V') + scan_mono_vs_slit('2V',[0.5,-4,4,0.5*c],[eVstart,eVstop,eVstep],comment='Mono/Slit - 2V') def CheckAllSlits_long(hv_list=[500],slit_list=["1H","1V","2H","2V"],**kwargs): diff --git a/iexcode/macros/start_of_the_week.py b/iexcode/macros/start_of_the_week.py index beb866cb2fcc68ffeeef59fce3573a170a0854f6..7182a726d8c2fc07eb08b7260f6f90d890556435 100644 --- a/iexcode/macros/start_of_the_week.py +++ b/iexcode/macros/start_of_the_week.py @@ -6,6 +6,7 @@ import iexcode.instruments.cfg as iex from iexcode.instruments.ARPES import ARPES_init from iexcode.instrumetns.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.xrays import * @@ -16,34 +17,83 @@ from iexcode.instruments.utilities import * from iexcode.macros.commissioning import * from iexcode.macros.quick_plot import * + +def detectors(branch): + """ + returns detCA4,detH,detV,detDiode + """ + DetDict={'c':(9,7,8,15),'d':(9,7,8,14)} + return DetDict[branch] + + + +def interactive_fct(mirror=False): + options='0,1,2,3' + if not mirror: + print('''\nDo you want to: + \t (0) write comment + \t (1) continue + \t (2) repeat scan + \t (3) adjust xrange for fit + ''') + else: + print('''\nDo you want to: + \t (0) write comment + \t (1) continue + \t (2) repeat scan + \t (3) adjust xrange for fit + \t (4) move M1 roll + ''') + options=options+',4' + flag=input('\nType ('+options+') >') + if flag not in options.split(","): + print('\ninvalid input; please try again...\n') + flag=input('\nType ('+options+') >') + if flag == '0': + cmt=input('\nType comment >') + print('\n================================') + log_print(cmt) + print('================================\n') + flag=input('\nType ('+options+') >') + if flag == '1': print('\nresuming script...\n'); flag=1 + if flag == '2': print('\nrepeating scan...\n'); flag=2 + if flag == '3': flag=3 + if mirror: + if flag == '4': flag=4 + + return flag + + def StartOfTheWeek(GRT,branch,wait=False,**kwargs): """ This should be run every at the start of every week; 50 min total. Switch to C-branch,. If wait=True, wait for next day a 8:05. - kwargs defaults: - mode = polarization - run = None: used today's date to set run appropriately - repeat = False: sets everything: switches branch, sets BL_Mode to Staff, resets scan/CAs/mono - scanType = ['slit1','wire','flux','monoVslit'] - sound = False; no sounds - = True => plays sound after Slit1A scans and when script is complete - } - ID steering: (slit1A) - steering out => move beam more positive (10 urad ~ 0.25 mm) - steering up => move beam more positive (10 urad ~ 0.25 mm) + **kwargs: + mode: polarization, default => RCP + repeat: True/False + True => doesn't do any initialization + False => resets everything (switches branch and grating) + scanType = ['slit1','wire','monoVslit','flux',] + sound: plays sound when a scantype is completed, default => True + # for individiual scantypes + slit1A_extended: to take a larger range, default => False + monoVslit_quick: + True => takes a single line cut (defaule) + False => - M1 steering: (monoVslit-2V and 2H) - Roll: Rz more positive => 2V more positive (0.25 => .25 mm) - Pitch: Ry more positive => 2H more positive (0.03 => .5 mm - """ + """ kwargs.setdefault('mode','RCP') kwargs.setdefault('repeat',False) - kwargs.setdefault('quick',True) kwargs.setdefault('scanType',['slit1','wire','flux','monoVslit']) kwargs.setdefault('sound',True) - kwargs.setdefault('extended_range',False) + + kwargs.setdefault('slit1A_extended',False) + kwargs.setdefault('monoVslit_quick',True) + + + detCA4,detH,detV,detDiode = detectors() branch=branch.lower() if iex.BL == None: @@ -57,9 +107,9 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): else: BL_init('staff',reset=False,set_folders=False) switch_branch(branch) - FileName='StartOfTheWeek_log.txt' - log_name_set(FileName) - + log_name_set('StartOfTheWeek_log.txt') + log_print("\n\n================== Start Of The Week @ "+today('slash')+':\n',FileName=FileName) + for scan in kwargs['scanType']: if scan not in ['slit1','wire','flux','monoVslit']: print(scan+" is not a valid scan scanType=['slit1','wire','flux','monoVslit']") @@ -69,16 +119,19 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): if branch == 'c': ca15 = Keithley('b',15) ca15.autoscale('Off') - diode_c('In') + else: foo=input('Do you have a diode in direct beam (y or n)? >') if foo.lower() == 'y' or foo.lower() == 'yes': print('Resuming...') - ### Stuff that doesn't need beam & does not need to be run if repeating SoTW: print("\n\n================== Sets Beamline & Scans:") grating(GRT) + ########################################################################### + ### stuff that requires beam + ########################################################################### + ### checking branch shutter: shutter_open = branch_shutter_status() if shutter_open == False: @@ -89,7 +142,6 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): print('Aborting...') return - ### checking QP ratio: QP=caget('ID29:QuasiRatio.RVAL') if QP != 100: @@ -111,264 +163,153 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): ### Ready to start: FirstScan=iex.BL.mda.filenum() - if not kwargs['repeat']: - log_print("\n\n================== Start Of The Week @ "+today('slash')+':\n',FileName=FileName) - - - - def interactive_fct(mirror=False): - options='0,1,2,3' - if not mirror: - print('''\nDo you want to: - \t (0) write comment - \t (1) continue - \t (2) repeat scan - \t (3) adjust xrange for fit - ''') - else: - print('''\nDo you want to: - \t (0) write comment - \t (1) continue - \t (2) repeat scan - \t (3) adjust xrange for fit - \t (4) move M1 roll - ''') - options=options+',4' - flag=input('\nType ('+options+') >') - if flag not in options.split(","): - print('\ninvalid input; please try again...\n') - flag=input('\nType ('+options+') >') - if flag == '0': - cmt=input('\nType comment >') - print('\n================================') - log_print(cmt) - print('================================\n') - flag=input('\nType ('+options+') >') - if flag == '1': print('\nresuming script...\n'); flag=1 - if flag == '2': print('\nrepeating scan...\n'); flag=2 - if flag == '3': flag=3 - if mirror: - if flag == '4': flag=4 - - return flag - - - - # if foo.lower() == 'y' or foo.lower() == 'yes': - # print('\nType any comments here - you have 30s! >') - # i, o, e = select.select( [sys.stdin], [], [], 5 ) - # if (i): - # print ('\n==============\n'+sys.stdin.readline().strip()+'\n==============\n') - # else: - # print('\nTimeout...'); - # print('\nRepeating scan...\n');flag=2 - - # else: - # print('\nResuming script...\n'); flag=3 - # return flag - - - - def iex_steering(h_position,v_position): - print('\nBeam position:') - print(' - horizontal: '+str(h_position)) - print(' - vertical: '+str(v_position)) - h_steering,v_steering=beamsteering_1A(h_position,v_position) - print('\nBeam steering:') - print(' - horizontal: '+h_steering) - print(' - vertical: '+v_steering) - print('\n') - return h_steering,v_steering - - DetDict={'c':(9,7,8,15),'d':(9,7,8,14)} - detCA4,detH,detV,detDiode=DetDict[branch] - list_position=[GRT,0,0,0,0] - - ###### Scan front-end slit center: + ########################################################################### if 'slit1' in kwargs['scanType']: print("\n\n================== Slit 1A scans:") mvID(2000) flag=2 while flag==2: - slits_scan_center('slit1A','H',-3,3,0.1,size=(0.25,inf),comment='Slit center - 1H') - slits_scan_center('slit1A','V',-3,3,0.1,size=(inf,0.25),comment='Slit center - 1V') - slit1A_set(4.5,4.5,0,0) - m=iex.BL.mda.last_mda() - print('\nsteering out => move beam more positive (10 urad ~ 0.25 mm)') - print('steering up => move beam more positive (10 urad ~ 0.25 mm)\n') + #scanning + slit1A_kwargs = { + 'sound':kwargs['sound'], + 'extended_range':kwargs['slit1A_extended'] + } + ID_steering_scans(**slit1A_kwargs) + + #plotting try: - h_position=fit_mda(m-1,detCA4,1,'gauss',xrange=[-1,1]);plt.show() - v_position=fit_mda(m ,detCA4,1,'gauss',xrange=[-1,1]);plt.show() - iex_steering(h_position,v_position) + scanNum_h = last_mda()-1 + scanNum_v = last_mda() + h_position = ID_steering_plots(scanNum_h,detCA4,xrange=[-1,1]) + v_position = ID_steering_plots(scanNum_v,detCA4,xrange=[-1,1]) + iex_steering(h_position,v_position) except: print('\nUnable to fit position; try to adjust xrange.\n') - # print('h_position=fit_mda('+str(m-1)+','+str(detCA4)+',1,"gauss",xrange=[-1,1])') - # print('v_position=fit_mda('+str(m)+','+str(detCA4)+',1,"gauss",xrange=[-1,1])') - # print('\nThen use:') - # print('\tbeamsteering_1A(h_position,v_position)') - if kwargs['sound']:playsound() + flag=interactive_fct() + + #want to refit while flag == 3: try: fitH=input('do you want to fit mda #'+str(m-1)+' ie horizontal (y or n)? >') if fitH.lower() == 'y' or fitH.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') - h_position=fit_mda(m-1,detCA4,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - fitV=input('do you want to fit mda #'+str(m)+' ie vertical (y or n)? >') + h_position = ID_steering_plots(scanNum_h,detCA4,xrange=[float(x1),float(x2)]) fitV=input('do you want to fit mda #'+str(m)+' ie vertical (y or n)? >') + if fitV.lower() == 'y' or fitV.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') - v_position=fit_mda(m ,detCA4,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() + v_position = ID_steering_plots(scanNum_v,detCA4,xrange=[float(x1),float(x2)]) + iex_steering(h_position,v_position) foo=input('\nare you happy with the fit (y or n)? >') if foo.lower() == 'y' or foo.lower() == 'yes': flag=interactive_fct() + + except: print('\nUnable to fit position; try to tweak xrange again\n') flag=interactive_fct() ###### Wire scans: if 'wire' in kwargs['scanType']: + #scanning mvID(2000) - slit1A_set(4.5,4.5,0,0) - scan_wire('H',comment='Wire scan - H',all_diag=False) # by default puts all meshes in + DiodeC - scan_wire('V',comment='Wire scan - V',all_diag=False) - m=iex.BL.mda.last_mda() + wire_scans(**kwargs) + + #plotting try: - plot_mda(m-1,detH,m,detV,title='wire-H (blue) & wire-V (orange)');plt.show() + scanNum_h = last_mda()-1 + scanNum_v = last_mda() + plot_mda(scanNum_h,detH,scanNum_v,detV,title='wire-H (blue) & wire-V (orange)');plt.show() except: print('Unable to plot. Try:') - print("plot_mda("+str(m-1)+","+str(detH)+","+str(m)+","+str(detV)+",title='wire-H (blue) & wire-V (orange)');plt.show()") - if kwargs['sound']:playsound() - + print("plot_mda("+str(scanNum_h)+","+str(detH)+","+str(scanNum_v)+","+str(detV)+",title='wire-H (blue) & wire-V (orange)');plt.show()") + ###### Mono/slit scans: if 'monoVslit' in kwargs['scanType']: - c=mono_grating_density_get()/1200 - if c==2: + list_position=[GRT,'S1H','S1V','S2H','S2v'] + if mono_grating_get('HEG'): slit(300) + c=2 else: slit(200) + c=1 + + diagnostics_all_out(diode_stay_in=True) print("\n\n================== Mono/slit scans:") - if 'quick' in kwargs: - energy(500) - mvmono(505) - print('\n---------- Scanning slit 2B:\n') - flag=2 - while flag==2: - slits_scan_center('slit2B','V',-8,8,0.25,size=(inf,0.25*c));sleep(1) - slits_scan_center('slit2B','H',-6,6,0.25,size=(0.25,inf));sleep(1) - m=iex.BL.mda.last_mda() - try: - V2=fit_mda(m-1,detDiode,1*c,'gauss');plt.show() - H2=fit_mda(m ,detDiode,1,'gauss');plt.show() - list_position[1]=V2 - list_position[2]=H2 - #print(f"V2 = {round(V2,3)}") - #print(f"H2 = {round(H2,3)}") - - print('\nBeam position:') - print(f" - vertical: V2 = {round(V2,3)}") - print(f" - horizontal: H2 = {round(H2,3)}") - v_steering=beamsteering_2B(V2) - m1_roll=beamsteering_2B(V2)[1] - print('\nCurrent position:') - current_roll=FMB_mirror_get(1)[5] - new_roll=current_roll+m1_roll - print('\nREMEMBER: 2V slit should always be centered at zero by steering M1 roll!') - print(" - vertical: "+str(current_roll)+str(v_steering[1])+" => Move_M1('RZ',"+str(new_roll)+")") - print(' - horizontal: reset slit 2BH center to ',str(H2)) - - except: - print('Unable to fit position; try to adjust xrange.') - # print('c='+str(c)) - # print('V2=fit_mda('+str(m-1)+','+str(detDiode)+',1*c+,"gauss")') - # print('H2=fit_mda('+str(m)+','+str(detDiode)+',1,"gauss")') - # print('\nThen use:') - # print('\tbeamsteering_2B(V2)') - # list_position.append(np.nan) - # list_position.append(np.nan) - flag=interactive_fct(mirror=True) - - if kwargs['sound']:playsound() - flag=interactive_fct(mirror=True) - while flag == 3: - fitV2=input('do you want to FIT mda #'+str(m-1)+' ie slit2-V (y or n)? >') - if fitV2.lower() == 'y' or fitV2.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - V2=fit_mda(m-1,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to replace slit2-V value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[1]=V2 - fitH2=input('do you want to FIT mda #'+str(m)+' ie slit2-H (y or n)? >') - if fitH2.lower() == 'y' or fitH2.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - H2=fit_mda(m ,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to REPLACE slit2-H value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[1]=H2 - foo=input('\nare you happy with the fit (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - flag=interactive_fct(mirror=True) - if flag == 4: - x=input('New M1 roll value >') - x=float(x) + if kwargs['monoVslit_quick']: + for i,slit_name in enumerate(['slit2B','slit1A']) + print('\n---------- Scanning '+slit_name+':\n') + flag=2 + while flag==2: + #scanning + monoVslit_quick_scan(slit_name,**kwargs) + + #plotting try: - FMB_mirror_move(1,'RZ',x) - sleep(2); - FMB_mirror_get(1) - print('\nrepeating scan...\n') - flag=2 + scanNum_v = last_mda()-1 + scanNum_h = last_mda() + V2 = monoVslit_quick_plot(scanNum_v,detDiode,c) + H2 = monoVslit_quick_plot(scanNum_h,detDiode,1) + except: - print('\ninvalid input; unable to move M1...\n') - flag=interactive_fct(mirror=True) - print('\n---------- Scanning slit 1A:\n') - flag=2 - while flag==2: - slits_scan_center('slit1A','V',-4, 4, 0.1,size=(inf,0.25)) - slits_scan_center('slit1A','H',-3, 3, 0.1,size=(0.25,inf)) - apertures_set() - m=iex.BL.mda.last_mda() - try: - V1=fit_mda(m-1,detDiode,1,'gauss');plt.show() - H1=fit_mda(m ,detDiode,1,'gauss');plt.show() - list_position[3]=V1 - list_position[4]=H1 - print('\nBeam position:') - print(f" - vertical: V1 = {round(V1,3)}") - print(f" - horizontal: H1 = {round(H1,3)}") - except: - print('\nUnable to fit position; try to adjust xrange.') - # print('V1=fit_mda('+str(m-1)+','+str(detDiode)+',1,"gauss")') - # print('H1=fit_mda('+str(m)+','+str(detDiode)+',1,"gauss")') - # list_position.append(np.nan) - # list_position.append(np.nan) - if kwargs['sound']:playsound() - flag=interactive_fct() #interactive_fct('slit 1A') - while flag == 3: - fitV1=input('do you want to fit mda #'+str(m-1)+' ie slit1-V (y or n)? >') - if fitV1.lower() == 'y' or fitV1.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - V1=fit_mda(m-1,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to replace slit1-V value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[3]=V1 - fitH1=input('do you want to fit mda #'+str(m)+' ie slit1-H (y or n)? >') - if fitH1.lower() == 'y' or fitH1.lower() == 'yes': - x1=input('x1 >') - x2=input('x2 >') - H1=fit_mda(m ,detDiode,1,'gauss',xrange=[float(x1),float(x2)]);plt.show() - foo=input('do you want to replace slit1-H value in list_position (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - list_position[4]=H1 + print('Unable to fit position; try to adjust xrange.') + + flag=interactive_fct(mirror=True) + #want to refit + while flag == 3: + fitV2=input('do you want to FIT mda #'+str(m-1)+' ie slit2-V (y or n)? >') + if fitV2.lower() == 'y' or fitV2.lower() == 'yes': + x1=input('x1 >') + x2=input('x2 >') + xrange=[float(x1),float(x2)] + V2 = monoVslit_quick_plot(scanNum_v,detDiode,c,xrange=xrange) + foo=input('do you want to replace '+slit_name+'-V value in list_position (y or n)? >') + if foo.lower() == 'y' or foo.lower() == 'yes': + list_position[1]=V2 + + fitH2=input('do you want to FIT mda #'+str(m)+' ie slit2-H (y or n)? >') + if fitH2.lower() == 'y' or fitH2.lower() == 'yes': + x1=input('x1 >') + x2=input('x2 >') + xrange=[float(x1),float(x2)] + H2 = monoVslit_quick_plot(scanNum_h,detDiode,1,xrange=xrange) + foo=input('do you want to REPLACE '+slit_name+'-H value in list_position (y or n)? >') + if foo.lower() == 'y' or foo.lower() == 'yes': + list_position[1]=H2 + + if slit_name = 'slit2B': + M0M1_steering(H2,V2) + list_position[4] = V2 + list_position[3] = H2 + mirror = True + elif slit_name: 'slit1A': + list_position[2] = V2 + list_position[1] = H2 + mirror = False + foo=input('\nare you happy with the fit (y or n)? >') - if foo.lower() == 'y' or foo.lower() == 'yes': - flag=interactive_fct() - print('\nBeam center fit @ ['+GRT+',2V,2H,1V,1H]:',list_position) + if foo.lower() == 'y' or foo.lower() == 'yes': + flag=interactive_fct(mirror=mirror) + + #happy with fitting but want to adjust roll + if flag == 4: + x=input('New M1 roll value >') + x=float(x) + try: + FMB_mirror_move(1,'RZ',x) + sleep(2); + FMB_mirror_get(1) + print('\nrepeating scan...\n') + flag=2 + except: + print('\ninvalid input; unable to move M1...\n') + flag=interactive_fct(mirror=True) + + print('\nBeam center fit @ '+str(list_position)) foo=input('do you want to update the slit dictionary (y or n)? >') if foo.lower() == 'y' or foo.lower() == 'yes': slit_list=input('do you want to use '+str(list_position)+' (y or n)? >') @@ -376,17 +317,13 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): update_slit_dict(list_position) else: update_slit_dict() - else: # longer full slit scans + + else: # 2D map mvID(500) flag=2 while flag==2: - mvmono(500) - apertures_set() - n=2 if 'extended_range' in kwargs else 1 - scan_mono_vs_slit('2V',[0.25*c,-2*c*n,2*c*n,0.5],[475,515,2],comment='Mono/Slit - 2V') #10/20 min for MEG/HEG - scan_mono_vs_slit('2H',[0.25,-2*n,2*n,0.5],[475,515,2],comment='Mono/Slit - 2H') #10min - scan_mono_vs_slit('1V',[0.5,-0.75*n,0.75*n,0.25*c],[475,515,2],comment='Mono/Slit - 1V') #10min - scan_mono_vs_slit('1H',[0.5,-0.75*n,0.75*n,0.25],[475,515,2],comment='Mono/Slit - 1H') #10min + beam_profile(GRT,["2V","2H","1V","1H"]) + #interactive flag=interactive_fct() @@ -396,13 +333,11 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): print("\n\n================== Check Flux:") flag=2 while flag==2: - check_flux(stay='y') - slit(50) - energy(500) - scanmono(475,525,1,comment='Mono Scan @ 500eV') - m=iex.BL.mda.last_mda() + check_flux_scan(stay=True) + + scanNum = last_mda() try: - plot_mda(m,detDiode,Flux=3);plt.show() + plot_mda(scanNum,detDiode,Flux=3);plt.show() except: print('Unable to plot. Try:') print("plot_mda("+str(m)+","+str(detDiode)+",flux=3);plt.show()") @@ -562,283 +497,3 @@ def update_slit_dict(**kwargs): apertures_set() return slit_position -############################################################################################### -######################################### Start Of The Week plotting -- old!!!! ################################### -############################################################################################### - -def plot_StartOfTheWeek_DetDict(branch): - """ - returns the detectors for a given branch - - """ - DetDict={'c':(9,7,8,15),'d':(9,7,8,14)} - return DetDict[branch] - -def StartOfTheWeek_plot(branch,FirstScanNum,**kwargs): - """ - Plots the data from StartOfTheWeek - - branch is used to set the detectors - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_Det(branch) - - FirstScanNum is based on slit1A - slit1A-H = FirstScanNum - slit1A-V = FirstScanNum + 1 - wire1-H = FirstScanNum + 2 - wire1-V = FirstScanNum + 3 - monoVslit = FirstScanNum + 4/5/6/7 - flux = FirstScanNum + 8 - - Slit 1A and Wire scans: determine ID steering and Slit1A position - Scan_MonoVsSlit: determine the steering from M0/M1 - by default the full range is plotted (pnt_first=0, pnt_last=inf) - refine the plot via - plot_StartOfTheWeek_mono(branch,FirstScanNum,pnt_first,pnt_last) - - kwargs: - filepath = None, uses current mda filepath unless specified - e.g. user : filepath='/net/s29data/export/data_29idc/2018_2/UserName/mda/' - e.g. staff: filepath='/net/s29data/export/data_29idb/2018_2/mda/' - prefix = None, uses current mda prefix unless specified - scanIOC = None, uses BL_ioc() unless specified - - scanType = ['slit1','wire','flux','monoVslit'], full set by default - - ref_firstScanNum to plot reference spectra - ref_branch = branch, unless specified - ref_filepath = filepath, unless specified - ref_prefix = prefix, unless specified - - steering out => moves beam more positive (20 urad ~ 0.5 mm) - steering up => moves beam more positive (20 urad ~ 0.5 mm) - -figure, axes = plt.subplots(nrows=2, ncols=2) -axes[0, 0].plot(x, y) - """ - - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - - kwargs.setdefault('scanType',['slit1','wire','flux','monoVslit']) - - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - - kwargs.setdefault('debug',False) - - - scanNum=FirstScanNum - ref_firstScanNum=kwargs['ref_firstScanNum'] - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - - - if 'slit1' in kwargs['scanType']: - if kwargs['debug']: - print('slit1') - plot_StartOfTheWeek_slit1A(branch,scanNum,**kwargs) - scanNum+=2 - if kwargs['ref_firstScanNum'] is not None: - kwargs.update({'ref_firstScanNum':ref_firstScanNum+2}) - - - if 'wire' in kwargs['scanType']: - if kwargs['debug']: - print('wire') - plot_StartOfTheWeek_wire(branch,scanNum,**kwargs) - scanNum+=2 - if kwargs['ref_firstScanNum'] is not None: - ref_firstScanNum+=2 - kwargs.update({'ref_firstScanNum':ref_firstScanNum+2}) - - if 'monoVslit' in kwargs['scanType']: - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - if d.mda[scanNum].header.all['rank']<2: #quick - print(scanNum, detDiode) - V2=fit_mda(scanNum,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='2V - mda_'+str(scanNum)) - H2=fit_mda(scanNum+1,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='2H - mda_'+str(scanNum+1)) - V1=fit_mda(scanNum+2,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='1V - mda_'+str(scanNum+2)) - H1=fit_mda(scanNum+3,detDiode,1,'gauss',filepath=kwargs['filepath'],prefix=kwargs['prefix'],scanIOC=kwargs['scanIOC'],title='1H - mda_'+str(scanNum+3)) - plt.show() - print('\nFit positions:') - print(f"V2={round(V2,3)}") - print(f"H2={round(H2,3)}") - print(f"V1={round(V1,3)}") - print(f"H1={round(H1,3)}") - - else: #MonoVsSlit - print('\n# To plot the Mono vs Slit data use:\n') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum)+','+str(detDiode)+',0,inf)'+'\t#2V') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum+1)+','+str(detDiode)+',0,inf)'+'\t#2H') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum+2)+','+str(detDiode)+',0,inf)'+'\t#1V') - print('\tplot_MonoVsSlit(\"'+branch+'\",'+str(scanNum+3)+','+str(detDiode)+',0,inf)'+'\t#1H') - print('\n# (pnt_first,pnt_last0=(0,inf) => plots all') - print('# select specific first/last to refine.') - - print('\nREMEMBER to update slit center using: \tupdate_slit_dict()' ) - scanNum+=4 - if kwargs['ref_firstScanNum'] is not None: - kwargs.update({'ref_firstScanNum':ref_firstScanNum+4}) - - if 'flux' in kwargs['scanType']: - if kwargs['debug']: - print('flux') - plot_StartOfTheWeek_flux(branch,scanNum,**kwargs) - -def plot_StartOfTheWeek_slit1A(branch,scanNum,**kwargs): - """ - plots the slit1A scans - scanNum = slit1A-H scanNum - """ - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - kwargs.setdefault('plotType',['slit1','wire','flux','monoVslit']) - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - kwargs.setdefault('debug',False) - - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - ref_detCA4,ref_detH,ref_detV,ref_detDiode=plot_StartOfTheWeek_DetDict(kwargs['ref_branch']) - - figure, axes = plt.subplots(nrows=1, ncols=2,figsize=(10,3)) - for i,t in enumerate(['1H center scan','1V center scan']): - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - axes[i].plot(d.mda[scanNum].det[detCA4].scale['x'], d.mda[scanNum].det[detCA4].data,marker='x',label=str(scanNum)) - scanNum+=1 - if kwargs['ref_firstScanNum'] is not None: - ref_scanNum=kwargs['ref_firstScanNum']+i - ref_d=IEXdata(ref_scanNum,path=kwargs['ref_filepath'],prefix=kwargs['ref_prefix'],q=1) - axes[i].plot(ref_d.mda[ref_scanNum].det[ref_detCA4].scale['x'], ref_d.mda[ref_scanNum].det[ref_detCA4].data,marker='x',label=str(ref_scanNum)) - axes[i].grid(color='lightgray', linestyle='-', linewidth=0.5) - axes[i].title.set_text(t) - axes[i].legend() - plt.show() - print("\nsteering out => move beam more positive (10 urad ~ 0.25 mm)") - print("steering up => move beam more positive (10 urad ~ 0.25 mm)") - print("\nTo fit beam position use:\n") - print("detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict('"+kwargs['ref_branch']+"')") - print("fit_mda("+str(scanNum-2)+",detCA4,1,'gauss',xrange=(-1,1))") - print("fit_mda("+str(scanNum-1)+",detCA4,1,'gauss',xrange=(-1,1))\n") - - -def plot_StartOfTheWeek_wire(branch,scanNum,**kwargs): - """ - plots the wire scans - scanNum = wire-H scanNum - """ - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - kwargs.setdefault('plotType',['slit1','wire','flux','monoVslit']) - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - kwargs.setdefault('debug',False) - - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - ref_detCA4,ref_detH,ref_detV,ref_detDiode=plot_StartOfTheWeek_DetDict(kwargs['ref_branch']) - - figure, axes = plt.subplots(nrows=1, ncols=2,figsize=(10,3)) - for i,t in enumerate(['H-wire','V-wire']): - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - #niceplot(d.mda[scanNum].det[DetDict[branch][1+i]],marker='x',label=str(scanNum)) - detNum=plot_StartOfTheWeek_DetDict(branch)[1+i] - axes[i].plot(d.mda[scanNum].det[detNum].scale['x'], d.mda[scanNum].det[detNum].data,marker='x',label=str(scanNum)) - scanNum+=1 - if kwargs['ref_firstScanNum'] is not None: - ref_scanNum=kwargs['ref_firstScanNum']+i - ref_d=IEXdata(ref_scanNum,path=kwargs['ref_filepath'],prefix=kwargs['ref_prefix'],q=1) - #niceplot(ref_d.mda[ref_scanNum].det[DetDict[kwargs["ref_branch"]][1+i]],marker='x',label=str(ref_scanNum)) - detNum=plot_StartOfTheWeek_DetDict(kwargs["ref_branch"])[1+i] - axes[i].plot(ref_d.mda[ref_scanNum].det[detNum].scale['x'], ref_d.mda[ref_scanNum].det[detNum].data,marker='x',label=str(ref_scanNum)) - axes[i].grid(color='lightgray', linestyle='-', linewidth=0.5) - axes[i].title.set_text(t) - axes[i].legend() - plt.show() - -def plot_StartOfTheWeek_flux(branch,scanNum,**kwargs): - """ - plots the wire scans - scanNum = wire-H scanNum - """ - kwargs.setdefault('filepath',BL.mda.filepath()) - kwargs.setdefault('prefix',BL.mda.prefix()) - kwargs.setdefault('plotType',['slit1','wire','flux','monoVslit']) - kwargs.setdefault('ref_firstScanNum',None) - kwargs.setdefault('ref_fpath',None) - kwargs.setdefault('ref_branch',branch) - kwargs.setdefault('ref_filepath',BL.mda.filepath()) - kwargs.setdefault('ref_prefix',BL.mda.prefix()) - kwargs.setdefault('debug',False) - - detCA4,detH,detV,detDiode=plot_StartOfTheWeek_DetDict(branch) - ref_detCA4,ref_detH,ref_detV,ref_detDiode=plot_StartOfTheWeek_DetDict(kwargs['ref_branch']) - - for t in ['ID peak @ 500eV']: - d=IEXdata(scanNum,path=kwargs['filepath'],prefix=kwargs['prefix'],q=1) - niceplot(d.mda[scanNum].det[detDiode],marker='x',label=str(scanNum)) - scanNum+=1 - if kwargs['ref_firstScanNum'] is not None: - ref_scanNum=kwargs['ref_firstScanNum']+2 - ref_d=IEXdata(ref_scanNum,path=kwargs['ref_filepath'],prefix=kwargs['ref_prefix'],q=1) - niceplot(ref_d.mda[ref_scanNum].det[ref_detDiode],marker='x',label=str(ref_scanNum)) - ref_scanNum+=1 - plt.grid(color='lightgray', linestyle='-', linewidth=0.5) - plt.title(t) - plt.legend() - plt.show() - -def plot_MonoVsSlit(branch,ScanNum,detDiode,pnt_first,pnt_last,norm=True,filepath=None,prefix=None,scanIOC=None): - """ - Plots Scan_MonoVsSlit to determine the steering from M0/M1 - To plot the full range (pnt_first=0, pnt_last=inf) - plot_StartofWeek_mono(branch,FirstScanNum+4,pnt_first,pnt_last) - - filepath: by default plot scans for the current data folder (as defined in BL_ioc() ScanRecord SaveData) - or specified folder path ending with '/': - e.g. user : filepath='/net/s29data/export/data_29idc/2018_2/UserName/mda/' - e.g. staff: filepath='/net/s29data/export/data_29idb/2018_2/mda/' - prefix: by default, uses prefix as defined in ScanRecord ("mda_") - """ - x,y,z,x_name,y_name,z_name=mda_2D(ScanNum,detDiode,filepath,prefix,scanIOC) - Which=str(y_name)[10:12] - if pnt_last is inf: - pnt_last=len(z)-1 - for i in range(pnt_first,pnt_last+1): - maxvalue=max(z[i]) - if norm == True: - plt.plot(x,z[i]/maxvalue,label='#'+str(i)+': '+str(round(y[i],2))) - else: - plt.plot(x,z[i],label='#'+str(i)+': '+str(round(y[i],2))) - plt.legend(bbox_to_anchor=(1, 0), loc='lower left', ncol=2,shadow=True, title="ScanNum: "+str(ScanNum)+"\nSlit-"+Which+" position", fancybox=True) - #plt.legend(loc='lower left',ncol=2, shadow=True, title="ScanNum: "+str(ScanNum)+"\nSlit-"+Which+" position", fancybox=True) - plt.grid(color='lightgray', linestyle='-', linewidth=0.5) - plt.show() - - -def read_flux(FileName='Flux_Curves.txt',FilePath="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries/"): - print('test') - with open(join(FilePath, FileName)) as f: - for c,line in enumerate(f.readlines()): - if line[0] == '=': - lastdate=line[8:16] - print(lastdate) - if line[0] == '-' and line[-2] == 'x': - axis='x' - print(axis) - line_x=line - if line[0] == '-' and line[-2] == 'y': - axis='y' - print(axis) - line_y=line - mydict_x=ast.literal_eval(line_x) - mydict_y=ast.literal_eval(line_y) - return mydict_x,mydict_y - -