diff --git a/build/lib/iexcode/instruments/AD_utilities.py b/build/lib/iexcode/instruments/AD_utilities.py index cbe60f3ee47135bbcc4875ba9ae578ebf5139c1e..d1e324da81e3a4c3629f1f568b0e3d7ba9ed31f9 100644 --- a/build/lib/iexcode/instruments/AD_utilities.py +++ b/build/lib/iexcode/instruments/AD_utilities.py @@ -17,6 +17,19 @@ from epics import caget, caput import iexcode.instruments.cfg as iex from iexcode.instruments.files_and_folders import get_next_fileNumber +def AD_exposure_time(ADplugin,exp_time,**kwargs): + """ + sets the aquiretime and the exposure time + overwrites what is in kwargs + """ + kwargs.setdefault("P",ADplugin.split(":")[0]+":") + kwargs.setdefault("R","cam1:") + kwargs.setdefault("P",ADplugin.split(":")[0]+":") + kwargs.setdefault("R","cam1:") + + caput(kwargs["P"]+kwargs["R"]+"AcquireTime",exp_time) + caput(kwargs["P"]+kwargs["R"]+"AcquireTime",exp_time+.01) + def AD_CurrentDirectory(ADplugin): """ @@ -223,8 +236,7 @@ def AD_snap(ADplugin,**kwargs): AD_DoneSingleSave(ADplugin,**kwargs) if "ExposureTime" in kwargs: - caput(kwargs["P"]+kwargs["R"]+"AcquireTime",kwargs["ExposureTime"]) - caput(kwargs["P"]+kwargs["R"]+"AcquireTime",kwargs["ExposureTime"]+.01) + AD_exposure_time(ADplugin,kwargs["ExposureTime"]) caput(kwargs["P"]+kwargs["R"]+"Acquire","Acquire",wait=True,timeout=5*60) @@ -288,6 +300,9 @@ def ADplugin_ScanSetup(ADplugin, **kwargs): kwargs.setdefault("R","cam1:") AD_DoneSingleSave(ADplugin,**kwargs) + + if "ExposureTime" in kwargs: + AD_exposure_time(ADplugin,kwargs["ExposureTime"]) AD_SaveFileSetup(ADplugin,**kwargs) AD_ScanTrigger(ADplugin, **kwargs) diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py index 82be3b4f2402ae96d21c7d588c90211dff7cf70f..debe940c10e2ea72a044db5b460e4f0cbb423e62 100644 --- a/build/lib/iexcode/instruments/ARPES.py +++ b/build/lib/iexcode/instruments/ARPES.py @@ -320,7 +320,7 @@ def _ARPES_log_dictionary(): "x":(ARPES_Motors.get('x'),".2f"), "y":(ARPES_Motors.get('y'),".2f"), "z":(ARPES_Motors.get('z'),".2f"), - "th":(ARPES_Motors.get('thi'),".2f"), + "th":(ARPES_Motors.get('th'),".2f"), "chi":(ARPES_Motors.get('chi'),".2f"), "phi":(ARPES_Motors.get('phi'),".2f"), "TA":(caget(ARPES_extra_pvs()['TA']),".2f"), diff --git a/build/lib/iexcode/instruments/electron_analyzer.py b/build/lib/iexcode/instruments/electron_analyzer.py index 9ae62cf6feae4851469d0295b166579967709c9e..c72f5f77ccee81a0bd9a81c11b71311edbab2117 100644 --- a/build/lib/iexcode/instruments/electron_analyzer.py +++ b/build/lib/iexcode/instruments/electron_analyzer.py @@ -145,37 +145,41 @@ def folders_EA(userPath,filePrefix="EA",**kwargs): except: df='h5' fpath=join(userPath,df) - -def EA_log_update(): - """ - spectra entries for the log file + +def EA_log_dictionary(): """ - spectra_info = { - 'PE':[EA.PassEnergy,".0f"], + dictionary for writing spectra to logfile + """ + d = { + "spectra_mode":[EA.SpectraMode,"s"], 'lens_mode':[EA.LensMode,"s"], - "scan_mode":[EA.scan_mode,"s"], - "KE":[str(EA.KE),"s"], - "sweeps":[EA.Sweeps,".0f"], - "frames":[EA.ExpFrames,".0f"] - } + 'PE':[EA.PassEnergy,".0f"], + "KE":[EA.KineticEnergy,".0f"], + "sweeps":[caget(iex.BL.mda.ioc+'scan1.NPTS'),".0f"], + "frames":[EA.Frames,".0f"] + } + return d +def EAlog_update(): + """ + spectra entries for the log file + """ + d=EA_log_dictionary() try: - entry_list=[] - pv_list=[] - format_list=[] - for key in spectra_info: - entry_list.append(key) - pv_list.append(spectra_info[key][0]) - format_list.append(spectra_info[key][1]) - iex.BL.mda.log.update(entry_list,pv_list,format_list) + header_list,data_list,format_list = iex.BL.mda.log.log_entries(d) + iex.BL.mda.log.write_entry(data_list,format_list) except: print("EAlog did not write to file, check for errors.") -def log_headerEA():##JM - need to update so that we get the keys from log_EA - s="\nscan x y z th chi phi T scan_mode E1 E2 step i f PE lens_mode SES slit # ID_mode hv exit_slit GRT TEY1 TEY2 time\n" - log_print(s) +def EAlog_header(): + d=EA_log_dictionary() + try: + header_list,data_list,format_list = iex.BL.mda.log.log_entries(d) + iex.BL.mda.log.write_entry(header_list,label="EA Header: ") + except: + print("EAlog did not write header") -def EAsweptTime_estimate(EAlist,overhead=[60,.22]): +def EA_sweptTime_estimate(EAlist,overhead=[60,.22]): """ estimates the time for spectra with the current analyzer settings overhead[0] = intiating scan (seconds) @@ -200,7 +204,7 @@ def EAsweptTime_estimate(EAlist,overhead=[60,.22]): DDLY=caget(EA.PHV+"scan"+str(HVscanDIM)+".PDLY") time_seconds=overhead[0]+numPnts*(1/17+PDLY+DDLY+overhead[1]) print(C,D,B, EAlist[4]) - return str(timedelta(seconds=time_seconds)) + return str(timedelta(seconds=time_seconds)*EAlist[-1]) def _scanEATrigger(EAlist,before_after,**kwargs): @@ -418,7 +422,7 @@ def scanEA(EAlist,**kwargs): time.sleep(2) iex.BL.mda.go(**kwargs) #After scan - EA_log_update() + EAlog_update() scanEA_reset(**kwargs) iex.BL.mda.table_reset_after(**kwargs) else: @@ -464,7 +468,7 @@ def scanFM(RoughPositions,thList,EAlist,**kwargs): print(EAparms) EA.put(EAparms['KineticEnergy'],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) iex.BL.mda.go(**kwargs) - EA_log_update() + EAlog_update() scanEA_reset(**kwargs) @@ -630,7 +634,7 @@ def scanEA_motor(EAlist, motor,start,stop,step,mode='absolute',**kwargs): #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) iex.BL.mda.go(kwargs["scanIOC"],scan_dim) - EA_log_update() + EAlog_update() #After scan scanEA_reset(**kwargs) @@ -677,7 +681,7 @@ def scanEA_Mesh(EAlist,y_start_stop_step,z_start_stop_step,**kwargs): #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) iex.BL.mda.go(scan_dim=outer_scan_dim) - EA_log_update() + EAlog_update() #After scan scanEA_reset(**kwargs) diff --git a/build/lib/iexcode/macros/commissioning.py b/build/lib/iexcode/macros/commissioning.py index 0425d5a31f6f9243f33f0fbbf69aee8c1e629201..e38328327e3cc263ff5dfba58413d4a6455d8c32 100644 --- a/build/lib/iexcode/macros/commissioning.py +++ b/build/lib/iexcode/macros/commissioning.py @@ -1,24 +1,23 @@ from os.path import join, isfile, exists, dirname from time import sleep +import matplotlib.pyplot as plt from epics import caget, caput import iexcode.instruments.cfg as iex -from iexcode.instruments.ARPES import ARPES_init -from iexcode.instruments.kappa import kappa_init from iexcode.instruments.xrays import * -from iexcode.instruments.xrays import _energy_range_min_max -from iexcode.instruments.current_amplifiers import current2flux -from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d +from iexcode.instruments.VLS_PGM import * +from iexcode.instruments.IEX_VPU import * + +from iexcode.instruments.current_amplifiers import * +from iexcode.instruments.diagnostics import diagnostics_all_out, diagnostics_all_in,diode_c,diode_d from iexcode.instruments.m3r import * +from iexcode.instruments.slits import _slits_wide_open_dictionary from iexcode.instruments.slits import * 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 iexcode.macros.cam_macros import * from .quick_plot import fit_mda, mda_1D @@ -26,14 +25,14 @@ from .quick_plot import fit_mda, mda_1D ################################ checking alignment ############################## ############################################################################################################## -def check_flux_scan(hv=500,stay=False,**kwargs) +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) + kwargs.setdefault('sound',True) diagnostics_all_out(diode_stay_in=True) slit(50) energy(hv) @@ -59,7 +58,7 @@ def check_flux_read(hv=500,ID_mode='RCP',stay=False): ring_current=round(caget("S:SRcurrentAI.VAL"),2) diagnostics_all_out(diode_stay_in=True) - exit_slit(50) + exit_slit_get(50) sleep(10) if m3r_branch() == "c": @@ -75,7 +74,7 @@ def check_flux_read(hv=500,ID_mode='RCP',stay=False): if not stay: diagnostics_all_out() - exit_slit(current_slit) + exit_slit_set(current_slit) def scan_wire(direction,all_diag=True,**kwargs): @@ -101,8 +100,8 @@ def scan_wire(direction,all_diag=True,**kwargs): elif direction == 'V': name = "V-wire" - diag = _diagnostics_dict() - pv = "29idb:m"+str(diag["motor"][name]) + diagnostics_presets_go(name,'Start') + pv = diagnostics_presets()[name][1] print("\n================== "+name+" scan (29idb:ca2):") iex.BL.mda.fillin(pv+".VAL",pv+".RBV",1,-17,-30,-0.25,**kwargs) @@ -178,7 +177,7 @@ def scan_mono_vs_slit(slit='2V',slit_parameters=[0.25,-2,2,0.5],energy_parameter """ hv_start,hv_stop,hv_step = energy_parameters # Filling Scans: - mono_scan_fillin(hv_start,hv_stop,hv_step) + mono_scan(hv_start,hv_stop,hv_step) scan_narrow_slit(slit='2V',slit_parameters=[0.25,-2,2,0.5],**kwargs) # Resetting everybody to normal: @@ -200,7 +199,7 @@ def mono_MIR_GRT_find_offset(grt,slit_list,**kwargs): kwargs.setdefault("detNum",15) grating(grt) - exit_slit(50) + exit_slit_set(50) diode_c('In') slit2B_set(2,0.5,0,0) @@ -210,11 +209,9 @@ def mono_MIR_GRT_find_offset(grt,slit_list,**kwargs): mono_zero_order(ang) print("Mirror pitch: "+str(ang)+"\r") for s in slit_list: - exit_slit(s) + exit_slit_set(s) print("\r") - - mono_motor_scan_fillin("GRT:P",ang-0.0005*s, ang+0.0005*s ,0.00002*s) - iex.BL.mda.go(**kwargs) + mono_motor_scan("GRT:P",ang-0.0005*s, ang+0.0005*s ,0.00002*s) sleep(1) print("\r") @@ -457,7 +454,13 @@ def M0M1_steering(H2,V2): 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)) + print(' - horizontal: reset slit 2BH center to ',str(H2)) + + print("\n\nM1 roll vs energy calibration/flux:") + print(" - 1.0 mm @ slit2V ~ 1.0 mrad on M1 roll") + print(" - 1.0 mm @ slit2V = 0.4 eV shift in energy") + print(" - 0.8 mm @ slit2V = 25% loss in intensity on Au 4f\n") + def beamsteering_2B(v_position): vroll=round(v_position*0.05/0.04,3) @@ -545,6 +548,8 @@ def monoVslit_quick_scan(slit_name, **kwargs): H,V = _slits_wide_open_dictionary()[slit_name] + c = mono_grating_density_get()/1200.0 + slits_scan_center(slit_name,'V',-V,V,0.25,size=(inf,0.25*c)) sleep(1) @@ -591,7 +596,6 @@ def check_slit1A(step=0.1): VAL='29idb:m'+str(m)+'.VAL' RBV='29idb:m'+str(m)+'.RBV' iex.BL.mda.fillin(VAL,RBV,-4,4.0,step) - iex.BL.mda.go() FileNum1 = iex.BL.mda.lastFileNum() #scanning inboard-blade @@ -601,7 +605,6 @@ def check_slit1A(step=0.1): VAL='29idb:m'+str(m)+'.VAL' RBV='29idb:m'+str(m)+'.RBV' iex.BL.mda.fillin(VAL,RBV,-4,4.0,step) - iex.BL.mda.go() FileNum2 = iex.BL.mda.lastFileNum() return FileNum1, FileNum2 @@ -630,7 +633,7 @@ def check_ID_steering(hv=2000): - beam center vs fixed aperture: given by the position of the bump in the middle """ slit1A_set(0.25,0.25,0,0) - ID_SP_set(hv) + ID_set(hv) scan_slit_center('1H',-3,3,0.1) scan_slit_center('1V',-3,3,0.1) @@ -733,7 +736,7 @@ def CheckSlitCalibration(slit_list,BL=500,hvList=[485,510],scanIOC=None,**kwargs """ if scanIOC is None: scanIOC=BL_ioc() - exit_slit(50) + exit_slit_set(50) apertures_set(BL) for hv in hvList: mono_energy_set(hv) @@ -787,31 +790,18 @@ def FermiEdges(Energy,Slit): def QP_curves(ID_energy,ID_mode_list,hv_start,hv_stop,hv_step): """ + Sets the ID to setpoint and scans the mono for a list of polarizations + + Does not set the QP_ratio first use, ID_QP_mode_set(QP_ratio) """ - exit_slit(200) - #Switch_Grating("MEG") - #print "\r" - #print "**************** QP OFF ****************" - #for mode in list_mode: - # Switch_IDMode(mode) - # SetID_Raw(hv) - # SetSlit_BL() - # SetMono(250) - # Scan_Mono(1,start,stop,step) - # Scan_Go("b",1) - #print "\r" - #print "**************** QP ON ****************" - #Switch_IDQP("on") + exit_slit_set(200) + for ID_mode in ID_mode_list: polarization(ID_mode) - ID_SP_set(ID_energy) - apertures_set()() - mono_energy_set(250) - mono_scan_fillin(hv_start,hv_stop,hv_step) - iex.BL.mda.go() - #Switch_IDQP("off") - #Switch_Grating("HEG") - #Switch_IDMode("RCP") + ID_set_eV(ID_energy) + apertures_set() + mono_scan(hv_start,hv_stop,hv_step) + @@ -826,7 +816,8 @@ def scan_cam_motor(motor_name,start,stop,step,cam_num,ExposureTime): Previously: Pixel_Calibration """ - cam_scan_setup(cam_num,ADtype='TIFF') + + cam_scan_setup(cam_num,ADtype='TIFF',) iex.BL.motors.scan(motor_name,start,stop,step) cam_live() diff --git a/build/lib/iexcode/macros/start_of_the_week.py b/build/lib/iexcode/macros/start_of_the_week.py index 7182a726d8c2fc07eb08b7260f6f90d890556435..eab7679e72bcda066eb38e64c4c7a998ba790145 100644 --- a/build/lib/iexcode/macros/start_of_the_week.py +++ b/build/lib/iexcode/macros/start_of_the_week.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt import iexcode.instruments.cfg as iex from iexcode.instruments.ARPES import ARPES_init -from iexcode.instrumetns.kappa import kappa_init +from iexcode.instruments.Kappa import kappa_init from iexcode.instruments.scanRecord import * from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d @@ -18,15 +18,13 @@ from iexcode.macros.commissioning import * from iexcode.macros.quick_plot import * -def detectors(branch): +def StartOfTheWeek_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: @@ -45,7 +43,7 @@ def interactive_fct(mirror=False): \t (4) move M1 roll ''') options=options+',4' - flag=input('\nType ('+options+') >') + flag=input('\nType ('+options+'), or press enter to abort script >') if flag not in options.split(","): print('\ninvalid input; please try again...\n') flag=input('\nType ('+options+') >') @@ -54,7 +52,7 @@ def interactive_fct(mirror=False): print('\n================================') log_print(cmt) print('================================\n') - flag=input('\nType ('+options+') >') + flag=input('\nType ('+options+'), or press enter to abort script >') if flag == '1': print('\nresuming script...\n'); flag=1 if flag == '2': print('\nrepeating scan...\n'); flag=2 if flag == '3': flag=3 @@ -93,7 +91,7 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): kwargs.setdefault('monoVslit_quick',True) - detCA4,detH,detV,detDiode = detectors() + detCA4,detH,detV,detDiode = StartOfTheWeek_detectors() branch=branch.lower() if iex.BL == None: @@ -108,7 +106,7 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): BL_init('staff',reset=False,set_folders=False) switch_branch(branch) log_name_set('StartOfTheWeek_log.txt') - log_print("\n\n================== Start Of The Week @ "+today('slash')+':\n',FileName=FileName) + log_print("\n\n================== Start Of The Week @ "+today('slash')+':\n') for scan in kwargs['scanType']: if scan not in ['slit1','wire','flux','monoVslit']: @@ -191,12 +189,13 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): #want to refit while flag == 3: try: - fitH=input('do you want to fit mda #'+str(m-1)+' ie horizontal (y or n)? >') + fitH=input('do you want to fit mda #'+str(scanNum_h)+' ie horizontal (y or n)? >') if fitH.lower() == 'y' or fitH.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') - 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)? >') - + h_position = ID_steering_plots(scanNum_h,detCA4,xrange=[float(x1),float(x2)]) + + fitV=input('do you want to fit mda #'+str(scanNum_v)+' ie vertical (y or n)? >') if fitV.lower() == 'y' or fitV.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') @@ -207,10 +206,11 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): 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() + if flag == '': + return ###### Wire scans: if 'wire' in kwargs['scanType']: @@ -241,7 +241,7 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): diagnostics_all_out(diode_stay_in=True) print("\n\n================== Mono/slit scans:") if kwargs['monoVslit_quick']: - for i,slit_name in enumerate(['slit2B','slit1A']) + for i,slit_name in enumerate(['slit2B','slit1A']): print('\n---------- Scanning '+slit_name+':\n') flag=2 while flag==2: @@ -261,7 +261,7 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): 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)? >') + fitV2=input('do you want to FIT mda #'+str(scanNum_v)+' ie slit2-V (y or n)? >') if fitV2.lower() == 'y' or fitV2.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') @@ -271,7 +271,7 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): 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)? >') + fitH2=input('do you want to FIT mda #'+str(scanNum_h)+' ie slit2-H (y or n)? >') if fitH2.lower() == 'y' or fitH2.lower() == 'yes': x1=input('x1 >') x2=input('x2 >') @@ -281,12 +281,12 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): if foo.lower() == 'y' or foo.lower() == 'yes': list_position[1]=H2 - if slit_name = 'slit2B': + if slit_name == 'slit2B': M0M1_steering(H2,V2) list_position[4] = V2 list_position[3] = H2 mirror = True - elif slit_name: 'slit1A': + elif slit_name == 'slit1A': list_position[2] = V2 list_position[1] = H2 mirror = False @@ -326,6 +326,8 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): #interactive flag=interactive_fct() + if flag == '': + return ###### Check flux: if 'flux' in kwargs['scanType']: @@ -340,8 +342,10 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): 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()") + print("plot_mda("+str(scanNum)+","+str(detDiode)+",flux=3);plt.show()") flag=interactive_fct() + if flag == '': + return diagnostics_all_out() diff --git a/iexcode/cheatsheet.txt b/iexcode/cheatsheet.txt index df37e4aaea4f87beec4a2661a8aed05fd0142260..acc3a959c37634ce85c9cb1494d5f9bc4f755a7d 100644 --- a/iexcode/cheatsheet.txt +++ b/iexcode/cheatsheet.txt @@ -132,6 +132,10 @@ Kappa_Detector => for detset etc in kappa chamber log_print => print a comment in the logfile log_update => updates the logfile with the current info (used if script is aborted) log_name_set => change name of logfile +.log_entries => turns dictionary to header_list,data_list,format_list +.write_header +.write_entry + #m3r: functions for dealin with m3r m3r_tweak_pitch => tweaks the pitch of m3r diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index 82be3b4f2402ae96d21c7d588c90211dff7cf70f..debe940c10e2ea72a044db5b460e4f0cbb423e62 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -320,7 +320,7 @@ def _ARPES_log_dictionary(): "x":(ARPES_Motors.get('x'),".2f"), "y":(ARPES_Motors.get('y'),".2f"), "z":(ARPES_Motors.get('z'),".2f"), - "th":(ARPES_Motors.get('thi'),".2f"), + "th":(ARPES_Motors.get('th'),".2f"), "chi":(ARPES_Motors.get('chi'),".2f"), "phi":(ARPES_Motors.get('phi'),".2f"), "TA":(caget(ARPES_extra_pvs()['TA']),".2f"), diff --git a/iexcode/instruments/Logfile.py b/iexcode/instruments/Logfile.py index 4d5b60e665cee7c1d944829d5c135461ea42b3e4..63c6ef5e171495cd012659630512bdc9c318fd93 100644 --- a/iexcode/instruments/Logfile.py +++ b/iexcode/instruments/Logfile.py @@ -20,13 +20,17 @@ def log_print(comment=''): except: print('No logfile written') -def log_update(): +def log_update(d=None): """ updates the log file with the last scan info + d = dictionary of {header:[data,format]} """ - try: - entry_list,pv_list, format_list = iex.BL.log.entries_function() - iex.BL.mda.log.update(entry_list,pv_list,format_list) + try: + if d == None: + d = iex.BL.mda.log.log_dictionary() + + iex.BL.mda.log.update(d) + except: print('No logfile written') @@ -146,28 +150,26 @@ class Logfile: print("Logprint failed") - def _log_entries(self): + def log_entries(self,d=None): """ gets the meta data to write in the log file """ - d = self.log_dictionary() - entry_list = [] - pv_list = [] + if d is None: + d = self.log_dictionary() + header_list = [] + data_list = [] format_list = [] for key in d.keys(): val = d[key] - entry_list.append(key) - pv_list.append(val[0]) + header_list.append(key) + data_list.append(val[0]) format_list.append(val[1]) - return entry_list,pv_list,format_list + return header_list,data_list,format_list - - def write_header(self): + def _intit_log(self,header_list): """ - file path = path to where file_name lives - file_name = name of the logfile - entry is a list - + writes the header to the logfile + Previously: SaveFile_Header """ version = '1.4' @@ -176,14 +178,36 @@ class Logfile: f.write('@Log version: '+ version+'\n\n') f.write('FilePath '+self.endstation_name+': '+self.filepath+'\n') - header_list,pv_list,format_list = self._log_entries() + label = self.endstation_name+' Header: ' + self.write_header(header_list,label ) - entry = self.endstation_name+' Header: ' + def write_header(self,header_list,label='Header: '): + """ + writes the header to the logfile + + Previously: SaveFile_Header + """ + entry = label + with open(self.filepath, "a+") as f: for item in header_list: - entry+=item - f.write(entry +'\n\n') + entry+=item+"," + f.write(entry[:-1] +'\n\n') + def write_entry(self,data_list, format_list): + """ + writes an entry to the logfile + """ + + if not isfile(self.filepath): + self.write_header() + with open(self.filepath, "a+") as f: + for i in range(len(format_list)): + pv_format = "{0:"+format_list[i]+"}," + f.write(pv_format.format(data_list[i])) + last_entry=len(format_list)-1 + pv_format="{0:"+format_list[last_entry]+"}\n" + f.write(pv_format.format(data_list[last_entry])) def update(self): """ @@ -192,17 +216,12 @@ class Logfile: Previously: SaveFile """ - header_list,pv_list,format_list = self._log_entries() - + header_list,data_list,format_list = self.log_entries() + if not isfile(self.filepath): - self.write_header() + self._intit_log(header_list) + + self.write_entry(self,data_list, format_list) - with open(self.filepath, "a+") as f: - for i in range(len(format_list)): - pv_format = "{0:"+format_list[i]+"}," - f.write(pv_format.format(pv_list[i])) - last_entry=len(format_list)-1 - pv_format="{0:"+format_list[last_entry]+"}\n" - f.write(pv_format.format(pv_list[last_entry])) diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py index 9ae62cf6feae4851469d0295b166579967709c9e..c72f5f77ccee81a0bd9a81c11b71311edbab2117 100644 --- a/iexcode/instruments/electron_analyzer.py +++ b/iexcode/instruments/electron_analyzer.py @@ -145,37 +145,41 @@ def folders_EA(userPath,filePrefix="EA",**kwargs): except: df='h5' fpath=join(userPath,df) - -def EA_log_update(): - """ - spectra entries for the log file + +def EA_log_dictionary(): """ - spectra_info = { - 'PE':[EA.PassEnergy,".0f"], + dictionary for writing spectra to logfile + """ + d = { + "spectra_mode":[EA.SpectraMode,"s"], 'lens_mode':[EA.LensMode,"s"], - "scan_mode":[EA.scan_mode,"s"], - "KE":[str(EA.KE),"s"], - "sweeps":[EA.Sweeps,".0f"], - "frames":[EA.ExpFrames,".0f"] - } + 'PE':[EA.PassEnergy,".0f"], + "KE":[EA.KineticEnergy,".0f"], + "sweeps":[caget(iex.BL.mda.ioc+'scan1.NPTS'),".0f"], + "frames":[EA.Frames,".0f"] + } + return d +def EAlog_update(): + """ + spectra entries for the log file + """ + d=EA_log_dictionary() try: - entry_list=[] - pv_list=[] - format_list=[] - for key in spectra_info: - entry_list.append(key) - pv_list.append(spectra_info[key][0]) - format_list.append(spectra_info[key][1]) - iex.BL.mda.log.update(entry_list,pv_list,format_list) + header_list,data_list,format_list = iex.BL.mda.log.log_entries(d) + iex.BL.mda.log.write_entry(data_list,format_list) except: print("EAlog did not write to file, check for errors.") -def log_headerEA():##JM - need to update so that we get the keys from log_EA - s="\nscan x y z th chi phi T scan_mode E1 E2 step i f PE lens_mode SES slit # ID_mode hv exit_slit GRT TEY1 TEY2 time\n" - log_print(s) +def EAlog_header(): + d=EA_log_dictionary() + try: + header_list,data_list,format_list = iex.BL.mda.log.log_entries(d) + iex.BL.mda.log.write_entry(header_list,label="EA Header: ") + except: + print("EAlog did not write header") -def EAsweptTime_estimate(EAlist,overhead=[60,.22]): +def EA_sweptTime_estimate(EAlist,overhead=[60,.22]): """ estimates the time for spectra with the current analyzer settings overhead[0] = intiating scan (seconds) @@ -200,7 +204,7 @@ def EAsweptTime_estimate(EAlist,overhead=[60,.22]): DDLY=caget(EA.PHV+"scan"+str(HVscanDIM)+".PDLY") time_seconds=overhead[0]+numPnts*(1/17+PDLY+DDLY+overhead[1]) print(C,D,B, EAlist[4]) - return str(timedelta(seconds=time_seconds)) + return str(timedelta(seconds=time_seconds)*EAlist[-1]) def _scanEATrigger(EAlist,before_after,**kwargs): @@ -418,7 +422,7 @@ def scanEA(EAlist,**kwargs): time.sleep(2) iex.BL.mda.go(**kwargs) #After scan - EA_log_update() + EAlog_update() scanEA_reset(**kwargs) iex.BL.mda.table_reset_after(**kwargs) else: @@ -464,7 +468,7 @@ def scanFM(RoughPositions,thList,EAlist,**kwargs): print(EAparms) EA.put(EAparms['KineticEnergy'],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) iex.BL.mda.go(**kwargs) - EA_log_update() + EAlog_update() scanEA_reset(**kwargs) @@ -630,7 +634,7 @@ def scanEA_motor(EAlist, motor,start,stop,step,mode='absolute',**kwargs): #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) iex.BL.mda.go(kwargs["scanIOC"],scan_dim) - EA_log_update() + EAlog_update() #After scan scanEA_reset(**kwargs) @@ -677,7 +681,7 @@ def scanEA_Mesh(EAlist,y_start_stop_step,z_start_stop_step,**kwargs): #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) iex.BL.mda.go(scan_dim=outer_scan_dim) - EA_log_update() + EAlog_update() #After scan scanEA_reset(**kwargs) diff --git a/iexcode/macros/start_of_the_week.py b/iexcode/macros/start_of_the_week.py index 3fdeaa31e7a235342647e55a6b249d5179ff94a6..eab7679e72bcda066eb38e64c4c7a998ba790145 100644 --- a/iexcode/macros/start_of_the_week.py +++ b/iexcode/macros/start_of_the_week.py @@ -18,15 +18,13 @@ from iexcode.macros.commissioning import * from iexcode.macros.quick_plot import * -def detectors(branch): +def StartOfTheWeek_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: @@ -93,7 +91,7 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs): kwargs.setdefault('monoVslit_quick',True) - detCA4,detH,detV,detDiode = detectors() + detCA4,detH,detV,detDiode = StartOfTheWeek_detectors() branch=branch.lower() if iex.BL == None: